Jump to content

Accesing a TileEntity's var in the rendering process


Recommended Posts

First of all, hello everyone, I'm TheArni (I'm sure you have noticed it...) and I'm new to the Forge Forums :D.

I'm working on a mod a couple of months ago: GasCraft. So, the problem I'm recently having is that I need to access to a variable of the TileEntity when I render it. But apparently, in the TileEntitySpecialRender class, in the method renderTileEntityAt() it gives me a copy of the class of the TileEntity, but I need the object because every TileEntity is different. BTW, I do this because every block renders different. It's essentially a pipe, and to *optimize* the rendering I only check the state of the pipe on block update, so I need to store it somewhere.


Long story short: I need to acces a specific TileEntity in the world because the method doesn't give the Tile in question, otherwise the class/type.


Oh, I hope I have explained correctly.




package TheArni.GasCraft.Render;

import TheArni.GasCraft.Models.ModelPipe;
import TheArni.GasCraft.Pipes.TileEntity.GasPipe_softCopper;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;

public class PipeRender extends TileEntitySpecialRenderer {
static final float scale = (float) (1.0 / 16.0);

private ModelPipe Pipe = new ModelPipe(scale);

public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) {
	Pipe.render((GasPipe_softCopper)tileEntity, x, y, z);
	int Blockx = tileEntity.xCoord;
	int Blocky = tileEntity.xCoord;
	int Blockz = tileEntity.xCoord;




package TheArni.GasCraft.Pipes.TileEntity;

import TheArni.GasCraft.GasCraft;
import TheArni.GasCraft.Network.IGasNetwork;
import TheArni.GasCraft.Network.IGasNetworkMachine;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class GasPipe_softCopper extends TileEntity {
public IGasNetwork network;

public boolean connectivity_0, connectivity_1, connectivity_2, connectivity_3;

public GasPipe_softCopper(){


public void checkConectivity(World world, int BlockX, int BlockY, int BlockZ){	
	if(world.getBlockId(BlockX+1, BlockY, BlockZ) == GasCraft.GasPipe1.blockID){

		this.connectivity_3 = true;
	} else if(world.getBlockTileEntity(BlockX+1, BlockY, BlockZ) instanceof IGasNetworkMachine){
		if(((IGasNetworkMachine)world.getBlockTileEntity(BlockX+1, BlockY, BlockZ)).canConectPipes()==true){
			this.connectivity_3 = true;
	} else this.connectivity_3 = false;
	if(world.getBlockId(BlockX, BlockY, BlockZ+1) == GasCraft.GasPipe1.blockID){
		this.connectivity_0 = true;
	} else if (world.getBlockTileEntity(BlockX, BlockY, BlockZ+1) instanceof IGasNetworkMachine){
		if(((IGasNetworkMachine)world.getBlockTileEntity(BlockX, BlockY, BlockZ+1)).canConectPipes()==true){
			this.connectivity_0 = true;
	} else this.connectivity_0 = false;
	if(world.getBlockId(BlockX-1, BlockY, BlockZ) == GasCraft.GasPipe1.blockID){
		this.connectivity_1 = true;
	} else if(world.getBlockTileEntity(BlockX-1, BlockY, BlockZ) instanceof IGasNetworkMachine){
		if(((IGasNetworkMachine)world.getBlockTileEntity(BlockX-1, BlockY, BlockZ)).canConectPipes()==true){
			this.connectivity_1 = true;
	} else this.connectivity_1 = false;
	if(world.getBlockId(BlockX, BlockY, BlockZ-1) == GasCraft.GasPipe1.blockID){
		this.connectivity_2 = true;
	} else if(world.getBlockTileEntity(BlockX, BlockY, BlockZ-1) instanceof IGasNetworkMachine){
		if(((IGasNetworkMachine)world.getBlockTileEntity(BlockX, BlockY, BlockZ-1)).canConectPipes()==true){
			this.connectivity_2 = true;
	} else this.connectivity_2 = false;
	System.out.println("Connectiviy checked, values are:"+connectivity_0+connectivity_1+connectivity_2+connectivity_3);



package TheArni.GasCraft.Models;

import org.lwjgl.opengl.GL11;
import TheArni.GasCraft.GasCraft;
import TheArni.GasCraft.Pipes.TileEntity.GasPipe_softCopper;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.ForgeHooksClient;

public class ModelPipe extends ModelBase
ModelRenderer Pipe1;
ModelRenderer Pipemid;
ModelRenderer Pipe2;
ModelRenderer Pipe3;
ModelRenderer Pipe4;
private float scale;

public ModelPipe(float scale)
	this.scale = scale;
	textureWidth = 64;
	textureHeight = 32;

	Pipemid = new ModelRenderer(this, 20, 0);
	Pipemid.addBox(0F, 0F, 0F, 4, 3, 4);
	Pipemid.setRotationPoint(6F, 0F, 6F);
	Pipemid.setTextureSize(64, 32);
	Pipemid.mirror = true;

	Pipe1 = new ModelRenderer(this, 0, 16);
	Pipe1.addBox(0F, 0F, 0F, 6, 3, 4);
	Pipe1.setRotationPoint(0F, 0F, 6F);
	Pipe1.setTextureSize(64, 32);
	Pipe1.mirror = true;

	Pipe2 = new ModelRenderer(this, 0, 0);
	Pipe2.addBox(0F, 0F, 0F, 4, 3, 6);
	Pipe2.setRotationPoint(6F, 0F, 0F);
	Pipe2.setTextureSize(64, 32);
	Pipe2.mirror = true;

	Pipe3 = new ModelRenderer(this, 0, 9);
	Pipe3.addBox(0F, 0F, 0F, 6, 3, 4);
	Pipe3.setRotationPoint(10F, 0F, 6F);
	Pipe3.setTextureSize(64, 32);
	Pipe3.mirror = true;

	Pipe4 = new ModelRenderer(this, 0, 23);
	Pipe4.addBox(0F, 0F, 0F, 4, 3, 6);
	Pipe4.setRotationPoint(6F, 0F, 10F);
	Pipe4.setTextureSize(64, 32);
	Pipe4.mirror = true;

public void render(float scale)
public void render(GasPipe_softCopper tile, double x, double y, double z) {
	GL11.glTranslated(x, y, z);
	ForgeHooksClient.bindTexture("/TheArni/GasCraft/Textures/SoftCopperPipe.png", 0);


private void variableRender(GasPipe_softCopper tile) {
	if(tile.connectivity_0) Pipe4.render(scale);
	if(tile.connectivity_1) Pipe1.render(scale);
	if(tile.connectivity_2) Pipe2.render(scale);
	if(tile.connectivity_3) Pipe3.render(scale);



Thanks a lot. If you need something else, tell me!


PD: I'm still working on 1.4.7 . I've got a lot of problems to solve before the mod-crushing 1.5.1 update :P

Link to comment
Share on other sites

Mmmm well, all that... I'm working arround, but it actually can update the TileEntity's vars. But it can't access it in the rendering process, so now I must care of the client side. Later I will test the mod with my friends... When I get a stable build...



Link to comment
Share on other sites

Please any idea? I tried to use:

tileEntity.worldObj.getBlockTileEntity(int x, int y, int z)

but that didn't work because in the models i only have this values on double format and I don't know why x.intValue doesn't work.


Help me please!

Link to comment
Share on other sites

OK, solved,

I tried casting the doubles to ints, so

tileEntity.worldObj.getBlockTileEntity((int) x,(int) y,(int) z);


But i though that it didn't work because of the casting, but it actually was because it was null, there was no entity there... at least now it doesn't crash, but now it doesn't render. OK, my job here it's done.


PD: Also thanks ChickenBones from the DW20 Irc, you helped me a lot, and I'm sorry to wasted your time D:

Link to comment
Share on other sites

If your using the coords the renderTileEntityAt is called with, it won't work. those values refer to the rendering position of the block and is different from its world position.


You need to use the tile entity that renderTileEntityAt is called with.


Have you overridden getDescriptionPacket and onDataPacket? You need to do this to properly access the values during rendering, even on single player.


Assuming you TileEntity has nbt saving properly implemented you can use

public Packet getDescriptionPacket()
NBTTagCompound tag = new NBTTagCompound();
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, tag);

public void onDataPacket(INetworkManager net, Packet132TileEntityData packet)
NBTTagCompound tag = packet.customParam1; // get tag

in you TileEntity class

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.

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.


  • Create New...

Important Information

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