Posted August 26, 201411 yr Hello again. I seem to have some trouble with this block having metadata. It's setup to have 3 blocks, a red, green, and blue ornament but for some reason when they all use the same texture in-game (ornamentItem0.png) instead of the others using their textures of ornamentItem1.png and ornamentItem2.png . Here's my ornament block code: http://pastebin.com/VgfD7Byj Could it because I'm using a custom model for it? The model itself selects the correct texture for each one by the way. It's only the texture when you hold it in your hand that's messed up.
August 26, 201411 yr If you use a custom model you need to have a custom itemBlock class to render that model in your inventory. And since you have a tileentity you might want to give us your tileentity, clientproxy and tileentityspecialrenderer class. It's mere guesswork if we only have 1/4th of the code that makes up the block.
August 26, 201411 yr Hi I assume you want the item in your hand to just show an ordinary texture, like most of the vanilla items do? Holding the block in your hand is actually rendered using the item, not the block. You can troubleshoot it further by placing a breakpoint in the Item Rendering code and seeing why it returns the wrong texture See here for some background info (1.6.4 but still similar) http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-first-person-view-items.html see ItemRenderer.renderItemInFirstPerson() -TGG
August 26, 201411 yr Author Yeah sorry for not including the rest but here it is: Ornamanet Renderer public class OrnamentRenderer extends TileEntitySpecialRenderer { static final float scale = (float)(1.0 / 16.0); private ModelOrnament model; public OrnamentRenderer() { model = new ModelOrnament(); } @Override public void renderTileEntityAt(TileEntity var1, double x, double y, double z, float tick) { this.renderAModelAt((TileEntityOrnament)var1, x, y, z, tick); } public void renderAModelAt(TileEntityOrnament tileentity1, double x, double y, double z, float f) { GL11.glPushMatrix(); GL11.glTranslated((float)x + 0.5F, (float)y, (float)z + 0.5F); this.bindTexture(new ResourceLocation(Wintercraft.modid.toLowerCase(), "textures/blocks/ornament" + tileentity1.getBlockMetadata() + ".png")); GL11.glPushMatrix(); model.render(0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } } Item Renderer - Ornament public class ItemOrnamentRenderer implements IItemRenderer { protected ModelOrnament model; public ItemOrnamentRenderer() { model = new ModelOrnament(); } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { switch (type) { case EQUIPPED: return true; case EQUIPPED_FIRST_PERSON: return true; case ENTITY: return true; default: return false; } } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return false; } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { switch (type) { case EQUIPPED_FIRST_PERSON: { GL11.glPushMatrix(); Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(Wintercraft.modid.toLowerCase(), "textures/blocks/ornament" + item.getItemDamage() + ".png")); GL11.glRotatef(0.0f, 0.0F, -0.0F, -1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glRotatef(40.0f, 0.0F, -0.0F, 1.0F); GL11.glTranslatef(0.6F, -0.9F, -0.3F); float scale1 = 1.5F; GL11.glScalef(scale1, scale1, scale1); model.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); } default: break; } switch (type) { case ENTITY: { GL11.glPushMatrix(); Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(Wintercraft.modid.toLowerCase(), "textures/blocks/ornament" + item.getItemDamage() + ".png")); GL11.glRotatef(0.0f, 0.0F, -0.0F, -1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glTranslatef(-0.025F,-0.7F, 0F); float scale1 = 1.0F; GL11.glScalef(scale1, scale1, scale1); model.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); } default: break; } switch (type) { case EQUIPPED: { GL11.glPushMatrix(); Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(Wintercraft.modid.toLowerCase(), "textures/blocks/ornament" + item.getItemDamage() + ".png")); GL11.glRotatef(0.0f, 0.0F, -0.0F, -1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glRotatef(40.0f, 0.0F, -0.0F, 1.0F); GL11.glTranslatef(0.3F, -0.65F, -0.1F); float scale1 = 1.0F; GL11.glScalef(scale1, scale1, scale1); model.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); } default: break; } } } Client Proxy public class ClientProxy extends CommonProxy{ @Override public void registerRenderThings() { //Red Candle ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCandle.class, new CandleRenderer()); //Red Ornament ClientRegistry.bindTileEntitySpecialRenderer(TileEntityOrnament.class, new OrnamentRenderer()); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(WinterBlocks.ornament), new ItemOrnamentRenderer()); //Head ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySnowManHead.class, new SnowManHeadRenderer()); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(WinterBlocks.snowManHead), new ItemSnowManHeadRenderer()); RenderingRegistry.registerBlockHandler(2105, RenderFreezer.INSTANCE); } } Now the problem isn't seeing the texture when I hold it but the texture when it's in my inventory, here's a screenshot to kinda show what I mean:
August 26, 201411 yr Try using a custom ItemBlock. Have a look at https://github.com/Eternaldoom/Realms-of-Chaos/blob/master/com/eternaldoom/realmsofchaos/itemblock/ItemBlockModStoneBrick.java Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
August 26, 201411 yr Author Thanks, I already had one though and doing it your way doesn't seem to change anything either. ItemBlock public class ItemOrnamentBlock extends ItemBlock { final static String[] subBlocks = new String[]{"RedOrnament","GreenOrnament","BlueOrnament"}; public ItemOrnamentBlock(Block par1) { super(par1); setHasSubtypes(true); } public String getUnlocalizedName(ItemStack itemstack) { int i = itemstack.getItemDamage(); if(i < 0 || i >= subBlocks.length){ i = 0; } return super.getUnlocalizedName() + "." + subBlocks[i]; } public int getMetadata(int par1) { return par1; } }
August 26, 201411 yr What Forge build are you using? There was a bug with metadata in some releases. Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
August 26, 201411 yr Author I'm using forge-1.7.10-10.13.0.1180 but I will try updating it to the latest soon.
August 26, 201411 yr You registered your ItemBlock, right? Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
August 26, 201411 yr Author Like this, correct? GameRegistry.registerBlock(ornament, ItemOrnamentBlock.class, "ornamentItem");
August 26, 201411 yr Yes. Does the item display a metadata value when you mouse over it? Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
August 26, 201411 yr Hi I reckon the problem is here, you are missing the case for inventory. switch (type) { case EQUIPPED: return true; case EQUIPPED_FIRST_PERSON: return true; case ENTITY: return true; default: return false; } Look at this link for more information, the Item Rendering Sections and especially the "Using IItemRenderer" http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html I'm guessing you don't know how to use breakpoints? I'd recommend you spend a bit of time learning how, they are extremely powerful debugging methods and you'll wonder how you ever managed without it. -TGG
August 26, 201411 yr Author Oh wow you're right. I cleaned it up a bit, now the item is completely invisible which my guess is because there's nothing in INVENTORY yet. package wintercraft.render.item; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; import org.lwjgl.opengl.GL11; import cpw.mods.fml.client.FMLClientHandler; import wintercraft.Wintercraft; import wintercraft.render.models.ModelOrnament; public class ItemOrnamentRenderer implements IItemRenderer { private static RenderItem renderItem = new RenderItem(); protected ModelOrnament model; public ItemOrnamentRenderer() { model = new ModelOrnament(); } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { switch (type) { case EQUIPPED: return true; case EQUIPPED_FIRST_PERSON: return true; case ENTITY: return true; case INVENTORY: return true; default: return false; } } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return false; } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { switch (type) { case EQUIPPED_FIRST_PERSON: { GL11.glPushMatrix(); Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(Wintercraft.modid.toLowerCase(), "textures/blocks/ornament" + item.getItemDamage() + ".png")); GL11.glRotatef(0.0f, 0.0F, -0.0F, -1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glRotatef(40.0f, 0.0F, -0.0F, 1.0F); GL11.glTranslatef(0.6F, -0.9F, -0.3F); float scale1 = 1.5F; GL11.glScalef(scale1, scale1, scale1); model.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); }break; case ENTITY: { GL11.glPushMatrix(); Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(Wintercraft.modid.toLowerCase(), "textures/blocks/ornament" + item.getItemDamage() + ".png")); GL11.glRotatef(0.0f, 0.0F, -0.0F, -1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glTranslatef(-0.025F,-0.7F, 0F); float scale1 = 1.0F; GL11.glScalef(scale1, scale1, scale1); model.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); }break; case EQUIPPED: { GL11.glPushMatrix(); Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(Wintercraft.modid.toLowerCase(), "textures/blocks/ornament" + item.getItemDamage() + ".png")); GL11.glRotatef(0.0f, 0.0F, -0.0F, -1.0F); GL11.glRotatef(0.0f, 0.0F, -0.0F, 1.0F); GL11.glRotatef(40.0f, 0.0F, -0.0F, 1.0F); GL11.glTranslatef(0.3F, -0.65F, -0.1F); float scale1 = 1.0F; GL11.glScalef(scale1, scale1, scale1); model.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); }break; case INVENTORY: { }break; default: break; } } }
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.