Sa ne marche pas, le bloc ne change pas de texture. je ne sais pas pourquoi.
BlockLedVerte:
| package Assabody.mod; |
| |
| import java.util.Random; |
| |
| import cpw.mods.fml.relauncher.Side; |
| import cpw.mods.fml.relauncher.SideOnly; |
| |
| import net.minecraft.block.Block; |
| import net.minecraft.block.material.Material; |
| import net.minecraft.client.renderer.texture.IconRegister; |
| import net.minecraft.creativetab.CreativeTabs; |
| import net.minecraft.tileentity.TileEntity; |
| import net.minecraft.util.Icon; |
| import net.minecraft.world.IBlockAccess; |
| import net.minecraft.world.World; |
| |
| public class BlockLedVerte extends Block{ |
| private Icon iconDark; |
| private Icon iconGreen; |
| |
| public BlockLedVerte(int par1) |
| { |
| super(par1, Material.rock); |
| this.setCreativeTab(ModAssabody.AssabodyCreativeTabs); |
| } |
| |
| public void registerIcons(IconRegister iconRegister) |
| { |
| iconDark = iconRegister.registerIcon("mod-assabody:led_led_verte_on"); |
| iconGreen = iconRegister.registerIcon("mod-assabody:led_led_verte_off"); |
| } |
| |
| @Override |
| public TileEntity createTileEntity(World world, int metadata) |
| { |
| return new TileEntityLedVerte(); |
| } |
| |
| @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 TileEntityLedVerte) |
| { |
| TileEntityLedVerte tetuto = (TileEntityLedVerte)te; |
| return tetuto.isEnable() ? this.iconGreen : this.iconDark; |
| } |
| return this.getIcon(side, blockaccess.getBlockMetadata(x, y, z)); |
| } |
| public boolean hasTileEntity(int metadata) |
| { |
| return true; |
| } |
| |
| public void onNeighborBlockChange(World world, int x, int y, int z, int neighborblockid, World par1World, int par2, int par3, int par4) |
| { |
| if(world.isBlockIndirectlyGettingPowered(x, y, z) && world.getBlockPowerInput(x, y, z) > 8) |
| { |
| } |
| } |
| |
| public int idDropped(int par1, Random par2Random, int par3) |
| { |
| return this.blockID; |
| } |
| |
| public boolean renderAsNormalBlock() |
| { |
| return true; |
| } |
| |
| public boolean isOpaqueCube() |
| { |
| return false; |
| } |
| } |
| |
TileEntityLedVerte:
| package Assabody.mod; |
| |
| import net.minecraft.nbt.NBTTagCompound; |
| import net.minecraft.network.INetworkManager; |
| import net.minecraft.network.packet.Packet; |
| import net.minecraft.network.packet.Packet132TileEntityData; |
| import net.minecraft.tileentity.TileEntity; |
| |
| public class TileEntityLedVerte extends TileEntity |
| { |
| private boolean enable; |
| |
| public void updateEntity() |
| { |
| if(this.enable) |
| { |
| if(!this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) || this.worldObj.getBlockPowerInput(this.xCoord, this.yCoord, this.zCoord) <= 8) |
| { |
| this.enable = false; |
| this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); } |
| } |
| else |
| { |
| if(this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) && this.worldObj.getBlockPowerInput(this.xCoord, this.yCoord, this.zCoord) > 8) |
| { |
| this.enable = true; |
| this.worldObj.markBlockForUpdate(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.customParam1); |
| } |
| public void readFromNBT(NBTTagCompound nbtTag) |
| { |
| super.readFromNBT(nbtTag); |
| enable = nbtTag.getBoolean("enable"); |
| } |
| |
| public void writeToNBT(NBTTagCompound nbtTag) |
| { |
| super.writeToNBT(nbtTag); |
| nbtTag.setBoolean("enable", enable); |
| } |
| } |
| |
Déclaration dans la classe principale :
| Block BlockLedVerte = new BlockLedVerte(2004); |
| GameRegistry.registerBlock(BlockLedVerte, "BlockLedVerte"); |
| |