Customiser votre bloc
-
@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)tetuto; //return TileEntityLedVerte.isEnable() ? this.iconGreen : this.iconDark; } return this.getIcon(side, blockaccess.getBlockMetadata(x, y, z)); }
La ou il y a les // de commentaire, c’est la ou il y a les erreurs.___
Je te met tous mes codes :
BlockLedVertepackage 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 Object iconDark; private Object iconGreen; public BlockLedVerte(int par1) { super(par1, Material.rock); this.setCreativeTab(ModAssabody.AssabodyCreativeTabs); } public void registerIcons(IconRegister iconRegister) { iconGreen = iconRegister.registerIcon("modid:TextureVerte"); iconDark = iconRegister.registerIcon("modid:TextureNoire"); } @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)tetuto; //return TileEntityLedVerte.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) { //par1World.setBlock(par2, par3, par4, ModAssabody.BlockSoin.blockID, 0, 2); } } 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() { enable = this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) && this.worldObj.getBlockPowerInput(this.xCoord, this.yCoord, this.zCoord) > 8; } 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); } public void readFromNBT(NBTTagCompound nbtTag) { super.readFromNBT(nbtTag); enable = nbtTag.getBoolean("enable"); } public void writeToNBT(NBTTagCompound nbtTag) { super.writeToNBT(nbtTag); nbtTag.setBoolean("enable", enable); } }
-
TileEntityLedVerte tetuto = (TileEntityLedVerte)te; return tetuto.isEnable() ? this.iconGreen : this.iconDark;
-
Quand je fais sa, sa me dis “Type mismatch: cannot convert from Object to Icon”
-
Ha oui normal :
private Object iconDark;
private Object iconGreen;
->
private Icon iconDark;
private Icon iconGreen;En passant, il faut aussi les enregistrer :
public void registerIcons(IconRegister iconRegister) { iconDark = iconRegister.registerIcon("modid:led_dark"); iconGreen = iconRegister.registerIcon("modid:led_green"); }
Et dans ton TileEntity :
//this.readFromNBT(pkt.data);
Enlève le // sinon ça ne marchera pas.Je te conseil également de faire un tour sur les tutoriels suivant :
http://www.minecraftforgefrance.fr/showthread.php?tid=78
http://www.minecraftforgefrance.fr/showthread.php?tid=106
http://www.minecraftforgefrance.fr/showthread.php?tid=115 (surtout le cas “sur un bloc avec metadata”)
Tu comprendra surement mieux les codes que je t’ai donné. -
Ok merci, plus aucune erreur(s) dans BlockLedVerte mais une dans TileEntityLedVerte
justement la "this.readFromNBT(pkt.data); "
/
|
ICI -
Sur le data ?
Tu as surement une veille mise à jour de forge, le field doit avoir un autre nom.
Fait un ctrl + clic sur Packet132TileEntityData ça va ouvrir la classe, regarde la ligne 25, moi j’ai :
public NBTTagCompound data;
Sur ta version tu as surement autre chose, il faut que change en fonction de ce que tu as. -
Comment on fais pour afficher les lignes déjà ?
J’ai sa moi
package net.minecraft.network.packet; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import net.minecraft.nbt.NBTTagCompound; public class Packet132TileEntityData extends Packet { /** The X position of the tile entity to update. */ public int xPosition; /** The Y position of the tile entity to update. */ public int yPosition; /** The Z position of the tile entity to update. */ public int zPosition; /** The type of update to perform on the tile entity. */ public int actionType; /** Custom parameter 1 passed to the tile entity on update. */ public NBTTagCompound customParam1; public Packet132TileEntityData() { this.isChunkDataPacket = true; } public Packet132TileEntityData(int par1, int par2, int par3, int par4, NBTTagCompound par5NBTTagCompound) { this.isChunkDataPacket = true; this.xPosition = par1; this.yPosition = par2; this.zPosition = par3; this.actionType = par4; this.customParam1 = par5NBTTagCompound; } /** * Abstract. Reads the raw packet data from the data stream. */ public void readPacketData(DataInput par1DataInput) throws IOException { this.xPosition = par1DataInput.readInt(); this.yPosition = par1DataInput.readShort(); this.zPosition = par1DataInput.readInt(); this.actionType = par1DataInput.readByte(); this.customParam1 = readNBTTagCompound(par1DataInput); } /** * Abstract. Writes the raw packet data to the data stream. */ public void writePacketData(DataOutput par1DataOutput) throws IOException { par1DataOutput.writeInt(this.xPosition); par1DataOutput.writeShort(this.yPosition); par1DataOutput.writeInt(this.zPosition); par1DataOutput.writeByte((byte)this.actionType); writeNBTTagCompound(this.customParam1, par1DataOutput); } /** * Passes this Packet on to the NetHandler for processing. */ public void processPacket(NetHandler par1NetHandler) { par1NetHandler.handleTileEntityData(this); } /** * Abstract. Return the size of the packet (not counting the header). */ public int getPacketSize() { return 25; } }
PS : Desolé mais la fonction Edit veut pas marcher.
-
Il s’appelle customParam1
Pour afficher les lignes, tu vas dans Windows, Preferences, General, Editor, Text Editor (sans dérouler, clic dessus), show line number -
C’est bon j’ai affiché les lignes mais maintenant, j’ai déclaré mon item:
Block BlockLedVerte = new BlockLedVerte(2004).func_111022_d("assabody-mod:led_verte_off"); GameRegistry.registerBlock(BlockLedVerte, "BlockLedVerte"); LanguageRegistry.addName(BlockLedVerte, "BlockLedVerte");
public static Block BlockLedVerte;
Ainsi que la TileEntity :
GameRegistry.registerTileEntity(TileEntityLedVerte.class,"tileEntityLedVerte");
Mais aucune des deux icones n’est affiché sur le block et avec un signal de redstone non plus.
-
.func_111022_d(“assabody-mod:led_verte_off”) retire-ça et LanguageRegistry.addName(BlockLedVerte, “BlockLedVerte”); ça, c’est inutile et ta version de Forge est très ancienne.
-
forge1.6.2-9.10.0.804
La derniere version est la .871, je la prend sur http://files.minecraftforge.net/ ? -
Oui, mais prends plutôt minecraftforge-1.6.4-9.11.1.958
-
La 1.6.4, elle change beaucoup sur forge ?
-
Juste un changement au niveau de la génération des structures, mais tu auras plus de chances de réussir à passer en 1.7.
-
Ok lol, bah je passe en 1.6.4 mais je sais pas si sa reglera le problème
-
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; world.markBlockForUpdate(x, y, z); } } else { if(this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) && this.worldObj.getBlockPowerInput(this.xCoord, this.yCoord, this.zCoord) > 8) { this.enable = true; world.markBlockForUpdate(x, y, z); } } }
Utilise plutôt ça, avec l’autre fonction que je t’ai donné ça envoyait pas un update du rendu.
-
Lol mon eclipse adore les erreurs, il m’en met sur world, x, y et z
-
Heu non, c’est pas ton eclipse qui adore les erreurs, c’est moi qui t’envoie des codes que je tape directement sur le forum x)
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); -
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");
-
bloc :
package tutoriel.common; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockLed extends Block { private Icon iconDark; private Icon iconGreen; public BlockLed(int id) { super(id, Material.rock); } public void registerIcons(IconRegister iconRegister) { iconDark = iconRegister.registerIcon("stone"); iconGreen = iconRegister.registerIcon("glass"); } @Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityLedVerte(); } @SideOnly(Side.CLIENT) @Override 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; } @Override public void onNeighborBlockChange(World world, int x, int y, int z, int neighborblockid) { if(!world.isRemote) { TileEntity te = world.getBlockTileEntity(x, y, z); if( && te != null && te instanceof TileEntityLedVerte) { TileEntityLedVerte tetuto = (TileEntityLedVerte)te; if(world.getBlockPowerInput(x, y, z) > 8 || world.getBlockPowerInput(x, y + 1, z) > 8) { tetuto.setEnable(true); } else { tetuto.setEnable(false); } } } } }
Tile entity :
package tutoriel.common; 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 setEnable(boolean b) { enable = b; this.worldObj.markBlockForUpdate(xCoord, yCoord, 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); } }
Cette fois si j’ai fais les tests, ça fonctionne.
En revanche la fonction world.getBlockPowerInput(x, y, z) > 8 ne fonctionne que si tu as une poudre de redstone à côté, si tu mets une torche ça ne marchera pas.