Posted July 6, 201411 yr Hello guys! I was wondering, is it possible to render an TE depending on a variable in the TE class? I tried something but it doesn't work, and I also think that is not the best way to do that. Is there a better way to do that (or at least something that works)? My attempt: public class RenderTileEntityModelAndBase extends TileEntitySpecialRenderer { private ModelBase modelBase = new ModelBase(); private static final ResourceLocation textureBase = new ResourceLocation(DEX.MODID + ":" + "textures/models/StoneBase.png"); private static final ResourceLocation textureModel = new ResourceLocation(DEX.MODID + ":" + "textures/models/Model.png"); private Model0 model0 = new Model0(); private Model1 model1 = new Model1(); @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) { if (tileEntity instanceof TileEntityMyModel) { TileEntityMyModel tile= (TileEntityMyModel) tileEntity; System.out.println("ID: " + tile.getID()); GL11.glPushMatrix(); GL11.glDisable(GL11.GL_LIGHTING); GL11.glScalef(1.0F, 1.0F, 1.0F); GL11.glTranslatef((float) x + 0.5F, (float) y, (float) z + 0.5F); GL11.glRotatef(0.0F, 0.0F, 0.0F, 0.0F); FMLClientHandler.instance().getClient().renderEngine.bindTexture(textureBase); modelBase.render(); GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); // ------------------------------------------------------------------------------ GL11.glPushMatrix(); GL11.glDisable(GL11.GL_LIGHTING); GL11.glScalef(1.0F, 1.0F, 1.0F); GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F); GL11.glRotatef(0.0F, 0.0F, 0.0F, 0.0F); FMLClientHandler.instance().getClient().renderEngine.bindTexture(textureModel); switch (tile.getID()) { case 1: model0.render(); break; case 0: model1.render(); break; default: } GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); } } } More info: The variable that I want to use is only set later by this method: public TileEntityMyModel() { id = -1; } public void setID(int id) { this.fossilID = id; } //Here public int getID() { if (id >= 0) { return id; } else { return 200; // just a test } }
July 6, 201411 yr public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) should be: public void renderTileEntityAt(TileEntityMyModel tileEntity, double x, double y, double z, float tick) That way you don't have to use instances and create an instace of you tile entity.
July 6, 201411 yr Author Thanks diesieben, it worked! Although It worked, I have never done this kind of synchronization before... so I would like to know if I did it right: @Override public Packet getDescriptionPacket() { NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.setByte("idnumber", (byte) id); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbttagcompound); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.id= pkt.func_148857_g().getByte("idnumber"); }
July 8, 201411 yr Author Ok, I still have a little problem, how can I sync the TE when the game restart... I get the wrong texture if I reenter the world.
July 8, 201411 yr Author Found it! I forgot to write super.writeToNBT(), and super.readFromNBT()... Ops
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.