19 nov. 2013, 22:16

Passe par un TileEntity

@Override
public TileEntity createTileEntity(World world, int metadata)
{
return new TileEntityTutorial();
}
public boolean hasTileEntity(int metadata)
{
return true;
}
@SideOnly(Side.CLIENT)
public Icon getBlockTexture(IBlockAccess blockaccess, int x, int y, int z, int side)
{
TileEntity te = blockaccess.getBlockTileEntity(x, y, z);
if(te != null && te instanceof TileEntityTutorial)
{
TileEntityTutorial tetuto = (TileEntityTutorial)te;
return te.isEnable() ? this.iconGreen : this.iconDark
}
return this.getIcon(side, blockaccess.getBlockMetadata(x, y, z));
}

iconGreen et iconDark sont tes deux icônes. Ne supprime pas la méthode getIcon, elle est nécessaire pour l’icône en main, getBlockTexture ne fait que la texture sur le monde.

TileEntityTutorial ->

public class TileEntityTutorial extends TileEntity
{
private boolean enable;

public void updateEntity()
{
enable = this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)
}

public boolean isEnable()
{
return enable;
}

public Packet getDescriptionPacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 4, nbttagcompound);
}

public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
{
this.readFromNBT(pkt.data);
}
}

ÉDIT : n’oublie pas d’enregistrer ton TileEntity, sinon tu vas avoir des erreurs.
http://www.minecraftforgefrance.fr/showthread.php?tid=106