First of all, hello everyone, I'm TheArni (I'm sure you have noticed it...) and I'm new to the Forge Forums .
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.
Code:
PipeRender.class
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);
@Override
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;
System.out.println(((GasPipe_softCopper)tileEntity).connectivity_0);
}
}
GasPipe_softCopper.class
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);
}
}
ModelPipe.class
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
{
//fields
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)
{
Pipe1.render(scale);
Pipemid.render(scale);
Pipe2.render(scale);
Pipe3.render(scale);
Pipe4.render(scale);
}
public void render(GasPipe_softCopper tile, double x, double y, double z) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glTranslated(x, y, z);
ForgeHooksClient.bindTexture("/TheArni/GasCraft/Textures/SoftCopperPipe.png", 0);
variableRender(tile);
Pipemid.render(scale);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
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);
//System.out.println(tile.connectivity_0);
}
}
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