TLHPoE Posted February 21, 2014 Posted February 21, 2014 I have this custom chest that uses it's own render. It renders perfectly in the world, but it's icon is the flat obsidian texture. Block Code: package enderstorage.block; import java.util.Random; import net.minecraft.block.BlockEnderChest; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import enderstorage.EnderStorage; import enderstorage.Reference; import enderstorage.tileentity.TileEntityExpEnderChest; public class BlockExpEnderChest extends BlockEnderChest { public BlockExpEnderChest() { super(); setHardness(22.5F); setResistance(1000.0F); setStepSound(soundTypePiston); setLightLevel(0.5F); } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { TileEntityExpEnderChest tileentityenderchest = (TileEntityExpEnderChest) world.getTileEntity(x, y, z); if(tileentityenderchest != null) { if(world.getBlock(x, y + 1, z).isNormalCube()) { return true; } else if(world.isRemote) { return true; } else { tileentityenderchest.func_145969_a(); player.openGui(EnderStorage.instance, Reference.EXP_ENDER_GUI_ID, world, x, y, z); return true; } } else { return true; } } @Override public int getRenderType() { return -1; } @Override public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { return Item.getItemFromBlock(Blocks.ender_chest); } @Override public int quantityDropped(Random p_149745_1_) { return 1; } @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { return new TileEntityExpEnderChest(); } } TileEntity Code: package enderstorage.tileentity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntityEnderChest; import enderstorage.helper.BlockHelper; public class TileEntityExpEnderChest extends TileEntityEnderChest { public float field_145972_a; public float field_145975_i; public int field_145973_j; private int field_145974_k; public void updateEntity() { super.updateEntity(); if(++this.field_145974_k % 20 * 4 == 0) { this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, BlockHelper.expEnderChest, 1, this.field_145973_j); } this.field_145975_i = this.field_145972_a; float f = 0.1F; double d1; if(this.field_145973_j > 0 && this.field_145972_a == 0.0F) { double d0 = (double) this.xCoord + 0.5D; d1 = (double) this.zCoord + 0.5D; this.worldObj.playSoundEffect(d0, (double) this.yCoord + 0.5D, d1, "random.chestopen", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); } if(this.field_145973_j == 0 && this.field_145972_a > 0.0F || this.field_145973_j > 0 && this.field_145972_a < 1.0F) { float f2 = this.field_145972_a; if(this.field_145973_j > 0) { this.field_145972_a += f; } else { this.field_145972_a -= f; } if(this.field_145972_a > 1.0F) { this.field_145972_a = 1.0F; } float f1 = 0.5F; if(this.field_145972_a < f1 && f2 >= f1) { d1 = (double) this.xCoord + 0.5D; double d2 = (double) this.zCoord + 0.5D; this.worldObj.playSoundEffect(d1, (double) this.yCoord + 0.5D, d2, "random.chestclosed", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); } if(this.field_145972_a < 0.0F) { this.field_145972_a = 0.0F; } } } /** * Called when a client event is received with the event number and argument, see World.sendClientEvent */ public boolean receiveClientEvent(int p_145842_1_, int p_145842_2_) { if(p_145842_1_ == 1) { this.field_145973_j = p_145842_2_; return true; } else { return super.receiveClientEvent(p_145842_1_, p_145842_2_); } } /** * invalidates a tile entity */ public void invalidate() { this.updateContainingBlockInfo(); super.invalidate(); } public void func_145969_a() { ++this.field_145973_j; this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, BlockHelper.expEnderChest, 1, this.field_145973_j); } public void func_145970_b() { --this.field_145973_j; this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, BlockHelper.expEnderChest, 1, this.field_145973_j); } public boolean func_145971_a(EntityPlayer p_145971_1_) { return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : p_145971_1_.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D; } } Renderer Code: package enderstorage.render; import net.minecraft.client.model.ModelChest; import net.minecraft.client.renderer.tileentity.TileEntityEnderChestRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import enderstorage.tileentity.TileEntityExpEnderChest; @SideOnly(Side.CLIENT) public class TileEntityExpEnderChestRenderer extends TileEntityEnderChestRenderer { private final ResourceLocation texture = new ResourceLocation("enderstorage:textures/entity/expEnderChest.png");; private ModelChest model = new ModelChest(); public void renderTileEntityAt(TileEntityExpEnderChest tileentity, double x, double y, double z, float something) { int i = 0; if(tileentity.hasWorldObj()) { i = tileentity.getBlockMetadata(); } this.bindTexture(texture); GL11.glPushMatrix(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F); GL11.glScalef(1.0F, -1.0F, -1.0F); GL11.glTranslatef(0.5F, 0.5F, 0.5F); short short1 = 0; if(i == 2) { short1 = 180; } if(i == 3) { short1 = 0; } if(i == 4) { short1 = 90; } if(i == 5) { short1 = -90; } GL11.glRotatef((float) short1, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); float f1 = tileentity.field_145975_i + (tileentity.field_145972_a - tileentity.field_145975_i) * something; f1 = 1.0F - f1; f1 = 1.0F - f1 * f1 * f1; this.model.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F); this.model.renderAll(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); } public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_) { renderTileEntityAt((TileEntityExpEnderChest) p_147500_1_, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_); } } Quote Kain
Alexiy Posted February 21, 2014 Posted February 21, 2014 What version? In 1.6 to render block in inventory customarily (or customly?) one has to implement ISimpleBlockRenderingHandler, its method renderInventoryBlock() and return true in shouldRender3DInInventory(). Quote
TLHPoE Posted February 21, 2014 Author Posted February 21, 2014 I'm using 1.7. I'll try what you suggested. Any pointers on what to do here? @Override public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { } Quote Kain
TLHPoE Posted February 22, 2014 Author Posted February 22, 2014 Ok, I've got every thing mostly working, except if I play it now, it bugs the world out. Also this: Code: package enderstorage.render; import net.minecraft.block.Block; import net.minecraft.client.model.ModelChest; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.tileentity.TileEntityEnderChestRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import enderstorage.tileentity.TileEntityExpEnderChest; @SideOnly(Side.CLIENT) public class TileEntityExpEnderChestRenderer extends TileEntityEnderChestRenderer implements ISimpleBlockRenderingHandler { private final ResourceLocation texture = new ResourceLocation("enderstorage:textures/entity/expEnderChest.png");; private ModelChest model = new ModelChest(); public void renderTileEntityAt(TileEntityExpEnderChest tileentity, double x, double y, double z, float something) { int i = 1; if(tileentity != null) { if(tileentity.hasWorldObj()) { i = tileentity.getBlockMetadata(); } } this.bindTexture(texture); GL11.glPushMatrix(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F); GL11.glScalef(1.0F, -1.0F, -1.0F); GL11.glTranslatef(0.5F, 0.5F, 0.5F); short short1 = 0; if(i == 2) { short1 = 180; } if(i == 3) { short1 = 0; } if(i == 4) { short1 = 90; } if(i == 5) { short1 = -90; } if(tileentity != null) { GL11.glRotatef((float) short1, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); float f1 = tileentity.field_145975_i + (tileentity.field_145972_a - tileentity.field_145975_i) * something; f1 = 1.0F - f1; f1 = 1.0F - f1 * f1 * f1; this.model.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F); } this.model.renderAll(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); } public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_) { renderTileEntityAt((TileEntityExpEnderChest) p_147500_1_, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_); } @Override public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { this.renderTileEntityAt(null, 0, 0, 0, 0); } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); this.renderTileEntityAt(null, x, y, z, 0); GL11.glEnable(GL12.GL_RESCALE_NORMAL); return false; } @Override public boolean shouldRender3DInInventory(int modelId) { return true; } @Override public int getRenderId() { return -24; } } Quote Kain
coolAlias Posted February 22, 2014 Posted February 22, 2014 You just have to play with the glTranslatef values until you get it in the right spot. // here, I typically just use x, y, and z GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F); GL11.glScalef(1.0F, -1.0F, -1.0F); // and do my messing around here: GL11.glTranslatef(0.5F, 0.5F, 0.5F); Obviously, do whatever works for you. Quote http://i.imgur.com/NdrFdld.png[/img]
TLHPoE Posted February 22, 2014 Author Posted February 22, 2014 Ok, I've got it kind of working. Only problem now is that it does this when I place it: Here's the code: package enderstorage.render; import net.minecraft.block.Block; import net.minecraft.client.model.ModelChest; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.tileentity.TileEntityEnderChestRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import enderstorage.tileentity.TileEntityExpEnderChest; @SideOnly(Side.CLIENT) public class TileEntityExpEnderChestRenderer extends TileEntityEnderChestRenderer implements ISimpleBlockRenderingHandler { private final ResourceLocation texture = new ResourceLocation("enderstorage:textures/entity/expEnderChest.png");; private ModelChest model = new ModelChest(); TileEntityExpEnderChest idk = new TileEntityExpEnderChest(); public void renderTileEntityAt(TileEntityExpEnderChest tileentity, double x, double y, double z, float something) { int i = 1; if(tileentity != null) { if(tileentity.hasWorldObj()) { i = tileentity.getBlockMetadata(); } } this.bindTexture(texture); GL11.glPushMatrix(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F); GL11.glScalef(1.0F, -1.0F, -1.0F); GL11.glTranslatef(0.5F, 0.5F, 0.5F); short short1 = 0; if(i == 2) { short1 = 180; } if(i == 3) { short1 = 0; } if(i == 4) { short1 = 90; } if(i == 5) { short1 = -90; } if(tileentity != null) { GL11.glRotatef((float) short1, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); float f1 = tileentity.field_145975_i + (tileentity.field_145972_a - tileentity.field_145975_i) * something; f1 = 1.0F - f1; f1 = 1.0F - f1 * f1 * f1; this.model.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F); } this.model.renderAll(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); } public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_) { renderTileEntityAt((TileEntityExpEnderChest) p_147500_1_, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_); } @Override public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); TileEntityRendererDispatcher.instance.renderTileEntityAt(this.idk, 0.0D, 0.0D, 0.0D, 0.0F); GL11.glEnable(GL12.GL_RESCALE_NORMAL); } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { this.renderTileEntityAt(world.getTileEntity(x, y, z), x, y, z, 0); return true; } @Override public boolean shouldRender3DInInventory(int modelId) { return true; } @Override public int getRenderId() { return -24; } } Quote Kain
coolAlias Posted February 22, 2014 Posted February 22, 2014 Oh yeah, that's pretty funky! Lots of rendering stuff seems trickier in 1.7.2. Anyway, it might have something to do with the final openGL calls you make, the one for setting the color when you render the tile entity, and another that enables GL_RESCALE_NORMAL in your render inventory block method. Try commenting out one or the other or both and see if that helps at all. If it doesn't, then the problem might be something going on in your super class. Quote http://i.imgur.com/NdrFdld.png[/img]
TLHPoE Posted February 22, 2014 Author Posted February 22, 2014 I've messed with almost everything at this point. I've tried commenting them out, rearranging them, tried extending TileEntitySpecialRenderer, and tried enabling GL_LIGHTING. Also I've looked at the Iron Chests repo, and tried duplicating cpw's way. Nothing Here's another pic of this craziness: And here's the code that causes it: package enderstorage.render; import net.minecraft.block.Block; import net.minecraft.client.model.ModelChest; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import enderstorage.tileentity.TileEntityExpEnderChest; @SideOnly(Side.CLIENT) public class TileEntityExpEnderChestRenderer extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler { private final ResourceLocation texture = new ResourceLocation("enderstorage:textures/entity/expEnderChest.png");; private ModelChest model = new ModelChest(); TileEntityExpEnderChest idk = new TileEntityExpEnderChest(); public void renderTileEntityAt(TileEntityExpEnderChest tileentity, double x, double y, double z, float something) { int i = 0; if(tileentity.hasWorldObj()) { i = tileentity.getBlockMetadata(); } this.bindTexture(texture); GL11.glPushMatrix(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F); GL11.glScalef(1.0F, -1.0F, -1.0F); GL11.glTranslatef(0.5F, 0.5F, 0.5F); short short1 = 0; if(i == 2) { short1 = 180; } if(i == 3) { short1 = 0; } if(i == 4) { short1 = 90; } if(i == 5) { short1 = -90; } GL11.glRotatef((float) short1, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); float f1 = tileentity.field_145975_i + (tileentity.field_145972_a - tileentity.field_145975_i) * something; f1 = 1.0F - f1; f1 = 1.0F - f1 * f1 * f1; model.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F); model.renderAll(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); } public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_) { renderTileEntityAt((TileEntityExpEnderChest) p_147500_1_, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_); } @Override public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); renderTileEntityAt(idk, 0, 0, 0, 0); GL11.glEnable(GL12.GL_RESCALE_NORMAL); } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { renderTileEntityAt(world.getTileEntity(x, y, z), x, y, z, 0); return true; } @Override public boolean shouldRender3DInInventory(int modelId) { return true; } @Override public int getRenderId() { return -24; } } Quote Kain
coolAlias Posted February 22, 2014 Posted February 22, 2014 Your code looks so innocuous... I don't really have any idea, but I wonder if it has to do with your render class both extending TileEntitySpecialRenderer AND implementing ISimpleBlockRenderingHandler. Have you tried using just one or the other? Quote http://i.imgur.com/NdrFdld.png[/img]
TLHPoE Posted February 22, 2014 Author Posted February 22, 2014 I tried extending only TileEntitySpecialRenderer, and it didn't render it in the inventory. So I implemented ISimpleBlockRenderingHandler. Quote Kain
TLHPoE Posted February 22, 2014 Author Posted February 22, 2014 Oh my god. I did it. I had to bind the texture, and comment out code in the renderWorldBlock method. Quote Kain
Draco18s Posted February 22, 2014 Posted February 22, 2014 I tried extending only TileEntitySpecialRenderer, and it didn't render it in the inventory. So I implemented ISimpleBlockRenderingHandler. You don't have to do that, you know. Check out how I did item renders for TESR blocks. https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/client/ClientProxy.java Quote 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.
Recommended Posts
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.