Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

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.

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

  • 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.

  • Author

Found it! I forgot to write super.writeToNBT(), and super.readFromNBT()... Ops :x

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.