Jump to content

[1.8.8] Help with custom sapling texture rendering in inventory.


Recommended Posts

Posted

I've literally been struggling with this for over an hour and am ready to give up and see if anybody knows how to get this to work. I have custom saplings and the textures work fine when placed, however when in the inventory they don't work. This confuses the heck out of me because I have blocks registered that do work and know how they should be registered, they just don't want to work, no matter what I try.

 

Below are all relevant classes, jsons, etc. All irrelevant parts of the code are cut out for simplicity sake. If someone can tell me what the problem is, that would really really help. Thanks.

 

[spoiler=RainbowSaplingBlockZL.java]

public class RainbowSaplingBlockZL extends BlockBush implements IGrowable {

public static final PropertyEnum<TreeColor> TYPE = PropertyEnum.<TreeColor>create("type", TreeColor.class);

public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1);

 

public RainbowSaplingBlockZL() {

super();

}

 

@Override

@SideOnly(Side.CLIENT)

public void getSubBlocks(Item item, CreativeTabs tab, List list) {

for (TreeColor color : TreeColor.values()) {

list.add(new ItemStack(item, 1, color.getMeta()));

}

}

 

@Override public IBlockState getStateFromMeta(int meta) {

return this.getDefaultState().withProperty(TYPE, TreeColor.get(meta & 7)).withProperty(STAGE, Integer.valueOf((meta & 8) >> 3));

}

 

@Override public int getMetaFromState(IBlockState state) {

        int i = 0;

        i = i | ((TreeColor) state.getValue(TYPE)).getMeta();

        i = i | ((Integer) state.getValue(STAGE)).intValue() << 3;

        return i;

}

 

@Override protected BlockState createBlockState() {

return new BlockState(this, new IProperty[] {TYPE, STAGE});

}

}

 

 

 

[spoiler=TreeColor.java]

public enum TreeColor implements IStringSerializable {

RED(0, "red"),

ORANGE(1, "orange"),

YELLOW(2, "yellow"),

GREEN(3, "green"),

BLUE(4, "blue"),

INDIGO(5, "indigo"),

VIOLET(6, "violet");

 

private String name;

private int meta;

 

private TreeColor(int meta, String name) {

this.name = name;

this.meta = meta;

}

 

@Override public String getName() {

return this.name;

}

 

public int getMeta() {

return this.meta;

}

 

public static TreeColor get(int meta2) {

for (TreeColor color : values()) {

if (color.getMeta() == meta2) return color;

}

return RED;

}

}

 

 

 

[spoiler=ClientProxy.java]

@Override

public void registerItemRenderers() { // Called in init phase of mod

ModelHelper.registerBlock(ModBlocks.rainbowSaplingBlockZL, (new StateMap.Builder()).withName(RainbowSaplingBlockZL.TYPE).withSuffix("_sapling").ignore(RainbowSaplingBlockZL.STAGE).build(), 0, 1, 2, 3, 4, 5, 6);

}

 

 

 

[spoiler=ModelHelper.java]

@SideOnly(Side.CLIENT) public class ModelHelper {

public static void registerItem(Item item, int... metadata) {

ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

for (int i : metadata) {

mesher.register(item, i, new ModelResourceLocation(item.getUnlocalizedName().substring(5), "inventory"));

}

}

 

public static void registerBlock(Block block, IStateMapper mapper, int... metadata) {

registerItem(Item.getItemFromBlock(block), metadata);

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().registerBlockWithStateMapper(block, mapper);

}

}

 

 

red_sapling, there is one for each color.

[spoiler=blockstates/red_sapling.json]

{

    "variants": {

        "normal": { "model": "zylroth:tree/redSapling" }

    }

}

 

 

 

[spoiler=models/block/tree/redSapling.json]

{

    "parent": "block/cross",

    "textures": {

        "cross": "zylroth:blocks/tree/redSapling"

    }

}

 

 

Posted

You're using the same item model for every metadata value (the item's unlocalised name without the

item.

prefix).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

ok that sort of helped, however it still doesn't work for whatever reason. Here's what I have for the registering now.

 

[spoiler=ModelHelper.java]

public static void registerItem(Item item, int... metadata) {

ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

if (item instanceof RainbowSaplingItemBlock) {

LogHelper.warn("Special cased RainbowSapling ItemBlock");

for (int i : metadata) {

LogHelper.warn("Registering " + RainbowSaplingItemBlock.getVariants());

mesher.register(item, i, new ModelResourceLocation(RainbowSaplingItemBlock.getVariants(), "inventory"));

}

} else {

for (int i : metadata) {

LogHelper.warn("Registering " + item.getUnlocalizedName().substring(5) + ":" + i);

mesher.register(item, i, new ModelResourceLocation(item.getUnlocalizedName().substring(5), "inventory"));

}

}

}

 

public static void registerBlock(Block block, IStateMapper mapper, int... metadata) {

registerItem(Item.getItemFromBlock(block), metadata);

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().registerBlockWithStateMapper(block, mapper);

}

 

 

 

[spoiler=ClientProxy.java]

ModelBakery.addVariantName(Item.getItemFromBlock(ModBlocks.rainbowSaplingBlockZL), RainbowSaplingItemBlock.getVariants());

ModelHelper.registerBlock(ModBlocks.rainbowSaplingBlockZL, (new StateMap.Builder()).withName(RainbowSaplingBlockZL.TYPE).withSuffix("_sapling").ignore(RainbowSaplingBlockZL.STAGE).build(), 0, 1, 2, 3, 4, 5, 6);

 

 

 

[spoiler=log]

[07:21:07] [Client thread/WARN] [Zylroth]: Special cased RainbowSapling ItemBlock

[07:21:07] [Client thread/WARN] [Zylroth]: Registering zylroth:red_sapling

[07:21:07] [Client thread/WARN] [Zylroth]: Registering zylroth:orange_sapling

[07:21:07] [Client thread/WARN] [Zylroth]: Registering zylroth:yellow_sapling

[07:21:07] [Client thread/WARN] [Zylroth]: Registering zylroth:green_sapling

[07:21:07] [Client thread/WARN] [Zylroth]: Registering zylroth:blue_sapling

[07:21:07] [Client thread/WARN] [Zylroth]: Registering zylroth:indigo_sapling

[07:21:07] [Client thread/WARN] [Zylroth]: Registering zylroth:violet_sapling

[... Irrelevant ...]

[07:21:14] [Client thread/ERROR] [FML]: Model definition for location zylroth:violet_sapling#inventory not found

[07:21:14] [Client thread/ERROR] [FML]: Model definition for location zylroth:red_sapling#inventory not found

[07:21:14] [Client thread/ERROR] [FML]: Model definition for location zylroth:indigo_sapling#inventory not found

[07:21:14] [Client thread/ERROR] [FML]: Model definition for location zylroth:green_sapling#inventory not found

[07:21:14] [Client thread/ERROR] [FML]: Model definition for location zylroth:yellow_sapling#inventory not found

[07:21:14] [Client thread/ERROR] [FML]: Model definition for location zylroth:orange_sapling#inventory not found

[07:21:14] [Client thread/ERROR] [FML]: Model definition for location zylroth:blue_sapling#inventory not found

 

 

Posted

Have you got item models with those names in src/main/resources/assets/zylroth/models/item?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Nope, because for whatever reason I thought the items folder just had to mirror the blocks folder, and the item in the inventory went to blockstates to find out what model to use. That solved it, thank you!

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.