Jump to content

[SOLVED] Problem Registering Item Block Variants


pH7

Recommended Posts

Hello,

 

I have been struggling to resolve an "Attempted to set registry name with existing registry name! New: striketheblightmod:planks Old: striketheblightmod:planks" error. Basically, I have a BlockPlank class to register two plank variants using an EnumHandler. I would like to ask if anyone can help find out what's wrong as I couldn't find the culprit.

 

more error details:

Caused by: java.lang.IllegalStateException: Attempted to set registry name with existing registry name! New: striketheblightmod:planks Old: striketheblightmod:planks
	at net.minecraftforge.registries.IForgeRegistryEntry$Impl.setRegistryName(IForgeRegistryEntry.java:71)
	at net.minecraftforge.registries.IForgeRegistryEntry$Impl.setRegistryName(IForgeRegistryEntry.java:79)
	at striketheblight.striketheblightmod.blocks.BlockPlank.<init>(BlockPlank.java:41)
	at striketheblight.striketheblightmod.init.BlockList.<clinit>(BlockList.java:38)
	... 23 more

 

BlockPlank

public class BlockPlank extends Block implements IHasModel, IMetaName {
	
	public static final PropertyEnum<EnumHandler.EnumType> VARIANT = PropertyEnum.<EnumHandler.EnumType>create("variant", EnumHandler.EnumType.class);
		
	private String name;
	
	public BlockPlank(String name) {
		super(Material.WOOD);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.modTab);
		setSoundType(SoundType.WOOD);
		setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, EnumHandler.EnumType.WILLOW));
		this.name = name;
		
		BlockList.BLOCKS.add(this);
		ItemList.ITEMS.add(new ItemBlockVariants(this.setRegistryName(this.getRegistryName())));                 // line 41
	}
	
	
	@Override
	public int damageDropped(IBlockState state) {
		return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
	}
	
	@Override
	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
		for(EnumHandler.EnumType blockplank$enumtype : EnumHandler.EnumType.values()) {
			items.add(new ItemStack(this, 1, blockplank$enumtype.getMeta()));
		}
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		return this.getDefaultState().withProperty(VARIANT, EnumHandler.EnumType.byMetadata(meta));
	}

	@Override
	public int getMetaFromState(IBlockState state) {
		return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
	}
	
	@Override
	public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
		return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos)));
	}
	
	@Override
	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, new IProperty[] {VARIANT});
	}
	
	@Override
	public String getSpecialName(ItemStack stack) {
		return EnumHandler.EnumType.values()[stack.getItemDamage()].getName();
	}
	
	@Override
	public void registerModels() {
		for (int i = 0; i < EnumHandler.EnumType.values().length; i++) {
			Main.proxy.registerVariantRenderer(Item.getItemFromBlock(this), i, EnumHandler.EnumType.values()[i].getName() + "_planks", "inventory");
		}
	}
	
}

 

EnumHandler:

public class EnumHandler {

	public static enum EnumType implements IStringSerializable{
		
		WILLOW(0, "willow"), REDWOOD(1, "redwood");
		
		private static final EnumType[] META_LOOKUP = new EnumType[values().length];
		private final int meta;
		private final String name, unlocalizedName;
		
		private EnumType(int meta, String name) {
			this(meta, name, name);
		}
		
		private EnumType(int meta, String name, String unlocalizedName) {
			this.meta = meta;
			this.name = name;
			this.unlocalizedName = unlocalizedName;
		}
		
		@Override
		public String getName() {
			return this.name;
		}
		
		public String getUnlocalizedName() {
			return this.unlocalizedName;
		}
		
		public int getMeta() {
			return this.meta;
		}
		
		@Override
		public String toString() {
			return this.name;
		}
		
		public static EnumType byMetadata(int meta) {
			return META_LOOKUP[meta];
		}
		
		static {
			for (EnumType enumType : values()) {
				META_LOOKUP[enumType.getMeta()] = enumType;
			}
		}
	}
}

 

line 38 in BlockList (other people call the class BlockInit):

	public static final Block PLANKS = new BlockPlank("planks");

 

ItemBlockVariants:

public class ItemBlockVariants extends ItemBlock{
	
	public ItemBlockVariants(Block block) {
		super(block);
		setHasSubtypes(true);
		setMaxDamage(0);
	}
	
	@Override
	public int getMetadata(int damage) {
		return damage;
	}
	
	@Override
	public String getUnlocalizedName(ItemStack stack) {
		return ((IMetaName)this.block).getSpecialName(stack) + "_" + super.getUnlocalizedName();  //e.g.: willow_planks
	}
	
}

 

I usually resolve errors on my own but this one has me pondering for a while ^^ Thanks in advance,

 

Kris

Edited by pH7
edited lines of error into the code

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Link to comment
Share on other sites

1 hour ago, pH7 said:

IHasModel

Kill this with fire. You do not need this. All this interface does is make you implement the same code over and over and over again.

 

ALL items need models. All of them. And none of the information necessary to register that model is private. Just loop through your block and item lists in your model registry event. 

 

Anyway, you haven't provided enough code to identify the problem. 

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I have since stopped using IHasModel. That was not the issue, but I managed to sort it out. Basically:

 

		ItemList.ITEMS.add(new ItemBlockVariants(this.setRegistryName(this.getRegistryName())));                 // line 41

should have been:

		ItemList.ITEMS.add(new ItemBlockVariants(this).setRegistryName(this.getRegistryName()));                 // line 41

Damn syntax mistakes causing trouble ? This thread can now be closed.

 

Thanks for the advice.

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Link to comment
Share on other sites

2 minutes ago, pH7 said:

I have since stopped using IHasModel. That was not the issue, but I managed to sort it out. Basically:

 


		ItemList.ITEMS.add(new ItemBlockVariants(this.setRegistryName(this.getRegistryName())));                 // line 41

should have been:


		ItemList.ITEMS.add(new ItemBlockVariants(this).setRegistryName(this.getRegistryName()));                 // line 41

Damn syntax mistakes causing trouble ? This thread can now be closed.

 

Thanks for the advice.

Threads don't get "closed" really, just edit the title and add [SOLVED] just fyi

  • Like 1
Link to comment
Share on other sites

15 hours ago, hiotewdew said:

Threads don't get "closed" really, just edit the title and add [SOLVED] just fyi

Or don't. You don't have to do it. Its not a forum rule, just a thing some people do because they think its helpful.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



×
×
  • Create New...

Important Information

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