Jump to content

[1.10.2] Trouble registering item variants for custom logs


Daeruin

Recommended Posts

I have created some custom logs (in my mod, you can harvest bark from logs, leaving a stripped log). I'm updated to 1.10.2 and trying to register the item models for the log variants. I know I'm doing something wrong, but can't figure out what it is.

 

I have two log classes that mimic the old and new log classes from vanilla, and I have my own enum that specifies the log types. I need to register both log blocks, and all the variants for the items. Here's what I have so far.

 

My block registry:

public final class PrimalBlockRegistry
{
public static Block logStrippedOld = new PrimalBlockStrippedLogOld("log_stripped_old");
public static Block logStrippedNew = new PrimalBlockStrippedLogNew("log_stripped_new");
}

public static void createBlocks()
{
	registerBlockLogs(logStrippedOld, logStrippedNew);
}


private static void registerBlockLogs(Block block1, Block block2)
{
	GameRegistry.register(block1);
	GameRegistry.register(block2);
	for (EnumWoodType woodType : EnumWoodType.values())
	{
//			System.out.println("woodType: " + itemBlock);
		if (woodType.getMetadata() <= 3)
		{
			ItemBlock itemBlock = new ItemBlock(block1);
			itemBlock.setRegistryName(woodType.getName());
			GameRegistry.register(itemBlock);
			ModelLoader.setCustomModelResourceLocation(itemBlock, woodType.getMetadata(), new ModelResourceLocation(block1.getRegistryName(), "axis=y,variant=" + woodType.getName()));
		}
		if (woodType.getMetadata() >= 4)
		{
			ItemBlock itemBlock2 = new ItemBlock(block2);
			itemBlock2.setRegistryName(woodType.getName());
			GameRegistry.register(itemBlock2);
			ModelLoader.setCustomModelResourceLocation(itemBlock2, woodType.getMetadata(), new ModelResourceLocation(block2.getRegistryName(), "axis=y,variant=" + woodType.getName()));
		}
	}
}

 

The problem is I'm seeing only the four old log variants in my creative inventory, plus about 20 additional untextured items, and they are all named "tile.primalcraft:log_stripped_old:name" or "tile.primalcraft:log_stripped_new:name", and they all use the default texture (oak for old logs, acacia for new logs).

 

My wood type enum:

 

public static enum EnumWoodType implements IStringSerializable
{
	OAK		(0, "log_oak_stripped", MapColor.WOOD), 
	SPRUCE	(1, "log_spruce_stripped", MapColor.OBSIDIAN), 
	BIRCH		(2, "log_birch_stripped", MapColor.SAND), 
	JUNGLE	(3, "log_jungle_stripped", MapColor.DIRT), 
	ACACIA	(4, "log_acacia_stripped", MapColor.ADOBE), 
	DARK_OAK	(5, "log_dark_oak_stripped", "log_dark_oak_stripped", MapColor.BROWN);

	private static final PrimalBlockLog.EnumWoodType[]	META_LOOKUP	= new PrimalBlockLog.EnumWoodType[values().length];
	private final int												meta;
	private final String											registryName;
	private final String											unlocalizedName;
	private final MapColor										field_181071_k;

	private EnumWoodType(int meta, String registryName, MapColor color)
	{
		this(meta, registryName, registryName, color);
	}

	private EnumWoodType(int meta, String registryName, String unlocalizedName, MapColor color)
	{
		this.meta = meta;
		this.registryName = registryName;
		this.unlocalizedName = unlocalizedName;
		this.field_181071_k = color;
	}

	public int getMetadata()
	{
		return this.meta;
	}

	public MapColor func_181070_c()
	{
		return this.field_181071_k;
	}

	public String toString()
	{
		return this.registryName;
	}

	public static PrimalBlockLog.EnumWoodType byMetadata(int meta)
	{
		if (meta < 0 || meta >= META_LOOKUP.length)
		{
			meta = 0;
		}

		return META_LOOKUP[meta];
	}

	public String getName()
	{
		return this.registryName;
	}

	public String getUnlocalizedName()
	{
		return this.unlocalizedName;
	}

	static
	{
		for (PrimalBlockLog.EnumWoodType PrimalBlockPlanks$enumtype : values())
		{
			META_LOOKUP[PrimalBlockPlanks$enumtype.getMetadata()] = PrimalBlockPlanks$enumtype;
		}
	}
}

 

 

My old log block class:

 

public class PrimalBlockStrippedLogOld extends BlockLog
{

public static final PropertyEnum<PrimalBlockLog.EnumWoodType> VARIANT = PropertyEnum.<PrimalBlockLog.EnumWoodType> create(
		"variant", PrimalBlockLog.EnumWoodType.class, new Predicate<PrimalBlockLog.EnumWoodType>()
		{
			public boolean apply(PrimalBlockLog.EnumWoodType p_apply_1_)
			{
				return p_apply_1_.getMetadata() < 4;
			}
		});
protected String registryName;

public PrimalBlockStrippedLogOld(String registryName)
{
	this.registryName = registryName;
	this.setRegistryName(registryName);
	this.setUnlocalizedName(getRegistryName().toString());
	this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, PrimalBlockLog.EnumWoodType.OAK)
			.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
	this.setCreativeTab(PrimalCreativeTabs.tabPrimalcraft);
}

public MapColor getMapColor(IBlockState state)
{
	PrimalBlockLog.EnumWoodType PrimalBlockPlanks$enumtype = (PrimalBlockLog.EnumWoodType) state.getValue(VARIANT);

	switch ((BlockLog.EnumAxis) state.getValue(LOG_AXIS))
	{
		case X:
		case Z:
		case NONE:
		default:

			switch (PrimalBlockPlanks$enumtype)
			{
				case OAK:
				default:
					return PrimalBlockLog.EnumWoodType.SPRUCE.func_181070_c();
				case SPRUCE:
					return PrimalBlockLog.EnumWoodType.DARK_OAK.func_181070_c();
				case BIRCH:
					return MapColor.QUARTZ;
				case JUNGLE:
					return PrimalBlockLog.EnumWoodType.SPRUCE.func_181070_c();
			}

		case Y:
			return PrimalBlockPlanks$enumtype.func_181070_c();
	}
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
{
	list.add(new ItemStack(itemIn, 1, PrimalBlockLog.EnumWoodType.OAK.getMetadata()));
	list.add(new ItemStack(itemIn, 1, PrimalBlockLog.EnumWoodType.SPRUCE.getMetadata()));
	list.add(new ItemStack(itemIn, 1, PrimalBlockLog.EnumWoodType.BIRCH.getMetadata()));
	list.add(new ItemStack(itemIn, 1, PrimalBlockLog.EnumWoodType.JUNGLE.getMetadata()));
}

public IBlockState getStateFromMeta(int meta)
{
	IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT,
			PrimalBlockLog.EnumWoodType.byMetadata((meta & 3) % 4));

	switch (meta & 12)
	{
		case 0:
			iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
			break;
		case 4:
			iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
			break;
		case 8:
			iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
			break;
		default:
			iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
	}

	return iblockstate;
}

@SuppressWarnings("incomplete-switch")
public int getMetaFromState(IBlockState state)
{
	int i = 0;
	i = i | ((PrimalBlockLog.EnumWoodType) state.getValue(VARIANT)).getMetadata();

	switch ((BlockLog.EnumAxis) state.getValue(LOG_AXIS))
	{
		case X:
			i |= 4;
			break;
		case Z:
			i |= 8;
			break;
		case NONE:
			i |= 12;
	}

	return i;
}

protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[] { VARIANT, LOG_AXIS });
}

protected ItemStack createStackedBlock(IBlockState state)
{
	return new ItemStack(Item.getItemFromBlock(this), 1,
			((PrimalBlockLog.EnumWoodType) state.getValue(VARIANT)).getMetadata());
}

public int damageDropped(IBlockState state)
{
	return ((PrimalBlockLog.EnumWoodType) state.getValue(VARIANT)).getMetadata();
}
}

 

 

My blockstate json for the old log (the new log is essentially the same, but for dark oak and acacia):

 

{
    "variants": {
        "axis=y,variant=log_oak_stripped":    { "model": "primalcraft:log_oak_stripped" },
        "axis=z,variant=log_oak_stripped":     { "model": "primalcraft:log_oak_stripped_side" },
        "axis=x,variant=log_oak_stripped":     { "model": "primalcraft:log_oak_stripped_side", "y": 90 },
        "axis=none,variant=log_oak_stripped":   { "model": "primalcraft:log_oak_stripped_bare" },
        "axis=y,variant=log_spruce_stripped":    { "model": "primalcraft:log_spruce_stripped" },
        "axis=z,variant=log_spruce_stripped":     { "model": "primalcraft:log_spruce_stripped_side" },
        "axis=x,variant=log_spruce_stripped":     { "model": "primalcraft:log_spruce_stripped_side", "y": 90 },
        "axis=none,variant=log_spruce_stripped":   { "model": "primalcraft:log_spruce_stripped_bare" },
        "axis=y,variant=log_birch_stripped":    { "model": "primalcraft:log_birch_stripped" },
        "axis=z,variant=log_birch_stripped":     { "model": "primalcraft:log_birch_stripped_side" },
        "axis=x,variant=log_birch_stripped":     { "model": "primalcraft:log_birch_stripped_side", "y": 90 },
        "axis=none,variant=log_birch_stripped":   { "model": "primalcraft:log_birch_stripped_bare" },
        "axis=y,variant=log_jungle_stripped":    { "model": "primalcraft:log_jungle_stripped" },
        "axis=z,variant=log_jungle_stripped":     { "model": "primalcraft:log_jungle_stripped_side" },
        "axis=x,variant=log_jungle_stripped":     { "model": "primalcraft:log_jungle_stripped_side", "y": 90 },
        "axis=none,variant=log_jungle_stripped":   { "model": "primalcraft:log_jungle_stripped_bare" }
    }
}

 

 

Each type of wood has three block models (for the three axes) and one item model. Examples:

 

Block model log_oak_stripped:

 

{
    "parent": "block/cube_column",
    "textures": {
        "end": "primalcraft:blocks/log_oak_stripped_top",
        "side": "primalcraft:blocks/log_oak_stripped"
    }
}

 

 

Block model log_oak_stripped_bare:

 

{
    "parent": "block/cube_all",
    "textures": {
        "all": "primalcraft:blocks/log_oak_stripped"
    }
}

 

 

Block model log_oak_stripped_side:

 

{
    "parent": "block/column_side",
    "textures": {
        "end": "primalcraft:blocks/log_oak_stripped_top",
        "side": "primalcraft:blocks/log_oak_stripped"
    }
}

 

 

Item model for oak:

 

{
    "parent": "primalcraft:block/log_oak_stripped",
    "display": {
        "thirdperson": {
            "rotation": [ 10, -45, 170 ],
            "translation": [ 0, 1.5, -2.75 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        }
    }
}

 

Link to comment
Share on other sites

Anyone? I've been wrestling this for hours. Apparently I don't understand what Forge wants from me. When I print the unlocalized name to the console as I register each item model, it appears correct as, for example, "primalcraft:log_oak_stripped". But when I run the game, it appears as "primalcraft:log_stripped_old". And there's all these extra untextured items with the same name in the creative inventory. Here's a screen shot of what it looks like. http://screencast.com/t/Q0QFvdqa

Link to comment
Share on other sites

I think there are those who would argue with you. One advantage of Minecraft's implementation is that it limits the number of blocks you have to register, and that helps with large modpacks.

 

If rewriting my log classes is what it takes, I may just have to go that direction. Sigh.

Link to comment
Share on other sites

The opposite of that is that minecraft now has too many logs and are having to make classes like logs_old and logs_new which seems like it's time to make the individual blocks. I do agree that using that kind of implementation on a small scale is beneficial but not for such a ubiquitous block type like a log.

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.