Jump to content

RenderTileEntity issue


RafaMv

Recommended Posts

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
	}
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");
}

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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.