Customiser votre bloc
-
Dans le TileEntityLedVerte, il me met une erreur a .data : “this.readFromNBT(pkt.data);”
Ainsi que a isEnable, iconGreen, iconDark dans BlockLedVerte.Sinon, y a pas un moyen de le faire avec deux blocks ? Sa serais peut-être plus facile ?
-
Désolé, j’avais mal compris ta demande. Par contre, tu pourrais nous dire quelles sont tes erreurs?
-
Je les aie marqué dans le post précédent
-
Tu as bien préciser que iconGreen et iconBlack, correspondent aux bonnes textures?
-
Oups, c’est de ma faute. Dans ton TileEntity, ajoute :
public void readFromNBT(NBTTagCompound nbtTag) { super.readFromNBT(nbtTag); enable = nbtTag.getBoolean("enable"); } public void writeToNBT(NBTTagCompound nbtTag) { super.writeToNBT(nbtTag); nbtTag.setBoolean("enable", enable); } -
=> robin4002 : Y’a une erreur a setString
=> Superloup10 : Comment je fais pour mettre deux textures dans ma classe ?
Je suis sur forge 1.6.2 -
setBoolean*

-
Je dois mettre quoi pour iconGreen, iconDark, isEnable plz ?
Parce que je vois pas du tout comment faire.
Merci -
public void registerIcons(IconRegister iconRegister) { iconGreen = iconRegister.registerIcon("modid:TextureVerte"); iconDark = iconRegister.registerIcon("modid:TextureNoire"); }Voilà pour la gestion des textures, après à toi de faire en sorte que la TextureNoire soit celle, par défaut.
-
Merci mais l’on ne peut pas utiliser cette méthode ?
if(world.isBlockIndirectlyGettingPowered(x, y, z) && world.getBlockPowerInput(x, y, z) >
{
//Action à faire si le bloc est alimenté par un signale de redstone avec une force supérieur à 8.
}Parce que la je ne comprend pas le code que vous m’avez passé.
Il y a une erreur a " return te.enable() " -
-> return tetuto.isEnable()
À nouveau, fail de ma partEt sinon dans le tileEntiy :
public void updateEntity() { enable = this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) && this.worldObj.getBlockPowerInput(this.xCoord, this.yCoord, this.zCoord) > 8; } -
“Type mismatch: cannot convert from Object to Icon” pour ton erreur corrigé

et quand je change “tetuto.isEnable()” par “TileEntityLedVerte.isEnable()” parce que j’imagine que sa fait référence à mon TileEntity mais maintenant sa me marque “Cannot make a static reference to the non-static method isEnable() from the type TileEntityLedVerte” et quand je veut fixer l’erreur, je peut changer
"
public boolean isEnable()
{
return enable;
}
"
par
"
public static isEnable()
{
return enable;
}
"
mais y a d’autres erreurs qui apparaissent, bref sa fait une impasse d’erreur
Merci de ta patience
-
La méthode ne doit pas être static.
Envoie toute ta fonction getBlockTexture -
@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.
