Extended Entity Props. qui ne se savent pas
-
@‘sosoh’:
Merci !
je crois avoir compris mais avec le code que tu vas me donner je pense que ça ce être plus explicit
Juste si j’ai bien compris si je veux enregistrer une string je dois la mettre dans une NBTTagString ?Voilà :
@Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setDouble("Mana", this.mana); properties.setDouble("MaxMana", this.maxMana); properties.setString("spellRight", this.spellRight); properties.setString("spellLeft", this.spellLeft); if (this.spellsList != null) { NBTTagList list = new NBTTagList(); for (String spell : this.spellsList) { list.appendTag(new NBTTagString(spell)); } properties.setTag("Spells", list); } compound.setTag(EXT_PROP_NAME, properties); }Pour mettre un String, il y a 2 méthodes :
- Si c’est un NBTTagCompound : tonTagCompound.setString(key, value)
- Si c’est un NBTTagList : tonTagList.appendTag(new NBTTagString(value))
-
Ok merci et donc pour le load je fais pareil ?
-
@‘sosoh’:
Ok merci et donc pour le load je fais pareil ?
Même chose mais dans l’autre sens, je peux pas t’aider : je suis pressé mais regarde dans le TileEntityChest, ça devrait t’aider.
-
J’ai fait ca, mais ça ne marche pas:
@Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.mana = properties.getDouble("Mana"); this.maxMana = properties.getDouble("MaxMana"); this.spellRight = properties.getString("spellRight"); this.spellLeft = properties.getString("spellLeft"); int size = properties.getInteger("spellsListSize"); NBTTagList list = compound.getTagList("Spells", size); if(size > 0){ for(int i = 0; i < size; i++){ NBTTagCompound nbttag = list.getCompoundTagAt(i); this.spellsList.add(i, nbttag.getString("spellsList")); } } }[20:03:24] [Server thread/ERROR] [FML]: Failed to load extended properties for ExtHogs. This is a mod issue. [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.lang.ClassCastException: net.minecraft.nbt.NBTTagList cannot be cast to net.minecraft.nbt.NBTTagCompound [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at fr.sosoh.hogsmod.common.entity.props.ExtendedEntityProps.loadNBTData(ExtendedEntityProps.java:83) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.entity.Entity.readFromNBT(Entity.java:1616) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.management.ServerConfigurationManager.readPlayerDataFromFile(ServerConfigurationManager.java:271) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.management.ServerConfigurationManager.initializeConnectionToPlayer(ServerConfigurationManager.java:123) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:173) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeHandshake(NetworkDispatcher.java:446) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:17) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:11) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)La ligne 83: NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);.
-
@‘sosoh’:
J’ai fait ca, mais ça ne marche pas:
@Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.mana = properties.getDouble("Mana"); this.maxMana = properties.getDouble("MaxMana"); this.spellRight = properties.getString("spellRight"); this.spellLeft = properties.getString("spellLeft"); int size = properties.getInteger("spellsListSize"); NBTTagList list = compound.getTagList("Spells", size); if(size > 0){ for(int i = 0; i < size; i++){ NBTTagCompound nbttag = list.getCompoundTagAt(i); this.spellsList.add(i, nbttag.getString("spellsList")); } } }[20:03:24] [Server thread/ERROR] [FML]: Failed to load extended properties for ExtHogs. This is a mod issue. [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.lang.ClassCastException: net.minecraft.nbt.NBTTagList cannot be cast to net.minecraft.nbt.NBTTagCompound [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at fr.sosoh.hogsmod.common.entity.props.ExtendedEntityProps.loadNBTData(ExtendedEntityProps.java:83) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.entity.Entity.readFromNBT(Entity.java:1616) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.management.ServerConfigurationManager.readPlayerDataFromFile(ServerConfigurationManager.java:271) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.management.ServerConfigurationManager.initializeConnectionToPlayer(ServerConfigurationManager.java:123) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:173) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeHandshake(NetworkDispatcher.java:446) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:17) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:11) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [20:03:24] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)La ligne 83: NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);.
Il n’y a pas besoin de mettre d’integer pour la taille de la liste.
Voilà le code pour le load :
@Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.mana = properties.getDouble("Mana"); this.maxMana = properties.getDouble("MaxMana"); this.spellRight = properties.getString("spellRight"); this.spellLeft = properties.getString("spellLeft"); NBTTagList list = compound.getTagList("Spells", Constants.NBT.TAG_STRING); for (int i = 0; i < list.tagCount(); i++) { NBTTagString nbtstring = list.getStringTagAt(i); this.spellsList.add(i, nbtstring.getString()); } } -
Donc j’ai pas besoin de l’envoyer non plus ?
Edit: http://gyazo.com/c462db8e22923b3f9699364e41ca69ce -
@‘sosoh’:
Donc j’ai pas besoin de l’envoyer non plus ?
Edit: http://gyazo.com/c462db8e22923b3f9699364e41ca69ceJe penses que tu confond les paquets et les NBT : regarde le tutoriel sur les entityExtendProperties pour bien tout comprendre.
-
Ah oui, autant pour moi, mais le code que tu m’as donné ne marche toujours pas, je désespère…

-
@‘sosoh’:
Ah oui, autant pour moi, mais le code que tu m’as donné ne marche toujours pas, je désespère…

Recopie le code, je viens de le modifier : j’avais fais une erreur
-
Mais il y a toujours un erreur, list.getStringTagAt(i); renvoie une string mais tu mets NBTTagString nbtstring = list.getStringTagAt(i);
-
@‘sosoh’:
Mais il y a toujours un erreur, list.getStringTagAt(i); renvoie une string mais tu mets NBTTagString nbtstring = list.getStringTagAt(i);
C’est une simple erreur que tu peux corriger toi-même.
-
Je l’ai corrigé comme ca, mais rien n’y fait ca ne marche pas(je suis désolé de te “harceler” mais je comprends pas j’ai relu plein de tutos ect, mais ca ne marche pas):
-
@‘sosoh’:
Je l’ai corrigé comme ca, mais rien n’y fait ca ne marche pas(je suis désolé de te “harceler” mais je comprends pas j’ai relu plein de tutos ect, mais ca ne marche pas):
Essaie avec çà :
@Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.mana = properties.getDouble("Mana"); this.maxMana = properties.getDouble("MaxMana"); this.spellRight = properties.getString("spellRight"); this.spellLeft = properties.getString("spellLeft"); NBTTagList list = compound.getTagList("Spells", Constants.NBT.TAG_STRING); for (int i = 0; i < list.tagCount(); i++) { this.spellsList.add(list.getStringTagAt(i)); } } -
C’est ce que j’avais mis, ça marche pas. Si quelqu’un pense savoir d’ou vient le problème, je peux lui passer les sources.
-
J’ai fait un post sur le Forum Anglais de Minecraft Forge, http://www.minecraftforge.net/forum/index.php/topic,29735.msg153884.html#msg153884, la solution est simple, le tuto du site n’est pas a jour, enfin pour moi il ne fonctionnait pas ^^ Mais en tout cas il y a plus simple !

-
@‘sosoh’:
J’ai fait un post sur le Forum Anglais de Minecraft Forge, http://www.minecraftforge.net/forum/index.php/topic,29735.msg153884.html#msg153884, la solution est simple, le tuto du site n’est pas a jour, enfin pour moi il ne fonctionnait pas ^^ Mais en tout cas il y a plus simple !

J’ai toujours dis que les tutos de MinecraftForge n’étaient pas à jour : je parlais du tutoriel sur le forum MinecraftForgeFrance.
-
En tout cas ça ne se sauvegarde pas quand je deco/reco j’attends une réponse sur le forum anglais.
-
En fait ca ne marchait pas car c’est pas
NBTTagList list = compound.getTagList("Spells", Constants.NBT.TAG_STRING);mais:
NBTTagList list = properties.getTagList("Spells", Constants.NBT.TAG_STRING);