Jump to content

ObjectHolder registered twice for the same name


Taskkill

Recommended Posts

[21:24:54] [Client thread/WARN] [FML]: ****************************************
[21:24:54] [Client thread/WARN] [FML]: * Registry Block: The object Block{doge:fishless_ice} has been registered twice for the same name doge:fishless_ice.
[21:24:54] [Client thread/WARN] [FML]: *  at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:307)
[21:24:54] [Client thread/WARN] [FML]: *  at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:288)
[21:24:54] [Client thread/WARN] [FML]: *  at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:120)
[21:24:54] [Client thread/WARN] [FML]: *  at cn.glycol.doge.event.RegistrationEvent.registerBlock(RegistrationEvent.java:76)
[21:24:54] [Client thread/WARN] [FML]: *  at cn.glycol.doge.event.RegistrationEvent.registerModel(RegistrationEvent.java:93)
[21:24:54] [Client thread/WARN] [FML]: *  at cn.glycol.doge.event.RegistrationEvent.onModelRegistration(RegistrationEvent.java:57)...
[21:24:54] [Client thread/WARN] [FML]: ****************************************

What's the right way to register a Block with ItemBlock, and register its model.

The document is... ummm

Link to comment
Share on other sites

You don't register a Block from an ItemBlock; instead, you get an ItemBlock from a Block, then register the ItemBlock as an Item.

To get an (registered) ItemBlock from a Block (which I believe is what you are trying to do during ModelRegistryEvent), use Item::getItemFromBlock.

 

Please post your code so we can figure out what exactly went wrong.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

@ObjectHolder(Doge.MODID)
public class ModObjects {
	
	public static final Item doge = null;
	
	public static final Block fishless_ice = null;
	
	public static final ItemSpell inf_food_bag = null;
	public static final ItemSpell double_death = null;
	public static final ItemSpell expelliarmus = null;
	public static final ItemSpell modearkar    = null;
	public static final ItemSpell alohomora    = null;
	public static final ItemSpell polymorph    = null;
	
}
import static cn.glycol.doge.ModObjects.*;

@Mod.EventBusSubscriber
public class RegistrationEvent {

	private static RegistryEvent.Register<Item> itemEvent;
	private static RegistryEvent.Register<Block> blockEvent;
	
	@SubscribeEvent
	public static void onItemRegistration(RegistryEvent.Register<Item> evt) {
		itemEvent = evt;
		registerItem(new ItemDoge());
		
		registerBlockItem(fishless_ice);
		
		registerSpell("inf_food_bag", new SpellInfFoodBag());
		registerSpell("double_death", new SpellDoubleDeath());
		registerSpell("expelliarmus", new SpellExpelliarmus());
		registerSpell("modearkar"   , new SpellModearkar());
		registerSpell("alohomora"   , new SpellAlohomora());
		registerSpell("polymorph"   , new SpellPolymorph());
	}
	
	@SubscribeEvent
	public static void onBlockRegistration(RegistryEvent.Register<Block> evt) {
		blockEvent = evt;
		registerBlock(new BlockFishlessIce());
	}
	
	@SubscribeEvent
	public static void onModelRegistration(ModelRegistryEvent evt) {
		registerModel(doge);
		registerModel(fishless_ice);
		registerModel(inf_food_bag);
		registerModel(double_death);
		registerModel(expelliarmus);
		registerModel(modearkar);
		registerModel(alohomora);
		registerModel(polymorph);
		
	}
	
	private static void registerItem(Item item) {
		if(itemEvent != null) itemEvent.getRegistry().register(item);
	}
	
	private static void registerSpell(String registry, IModSpell spell) {
		registerItem(new ItemSpell(registry, spell));
	}
	
	private static void registerBlock(Block block) {
		if(blockEvent != null) blockEvent.getRegistry().register(block);
	}
	
	private static void registerBlockItem(Block block) {
		registerItem(new ItemBlock(block).setRegistryName(block.getRegistryName()));
	}
	
	private static void registerModel(Item item) {
		registerModel(item, 0);
	}
	
	private static void registerModel(Item item, int metadata) {
		LogManager.getLogger().info("注册模型 {} {}", item.getRegistryName(), metadata);
		ModelLoader.setCustomModelResourceLocation(item, metadata, new ModelResourceLocation(item.getRegistryName(), "inventory"));
	}
	
	private static void registerModel(Block block) {
		registerBlock(block);
	}
	
	private static void registerModel(Block block, int metadata) {
		registerModel(Item.getItemFromBlock(block), metadata);
	}
	
}

 

Edited by Taskkill
Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

Also, you can't have ModelRegistryEvent there. It must be in a separate, client-only event handler.

Does ModelRegistryEvent also trigger on the server side?

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.