SOLVED Extended Entity Props. qui ne se savent pas


  • Salut, j’ai un probleme avec mes entity props, elles ne savent pas a ma mort ni quand je deco/reco.

    ​package fr.sosoh.hogsmod.common.entity.props;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.world.World;
    import net.minecraftforge.common.IExtendedEntityProperties;
    import fr.sosoh.hogsmod.common.Hogsmod;
    import fr.sosoh.hogsmod.common.packet.PacketMana;
    import fr.sosoh.hogsmod.common.packet.PacketSpellLeft;
    import fr.sosoh.hogsmod.common.packet.PacketSpellRight;
    import fr.sosoh.hogsmod.common.packet.PacketSpellsList;
    import fr.sosoh.hogsmod.proxy.CommonProxy;
    
    public class ExtendedEntityProps implements IExtendedEntityProperties
    {
    
    public final static String EXT_PROP_NAME = "ExtHogs";
    
    private final EntityPlayer player;
    
    public double mana;
        public double maxMana;
        public List <string>spellsList = new ArrayList<string>();
        public String spellRight, spellLeft;
    
        public ExtendedEntityProps(EntityPlayer player) 
        {
    this.player = player;
    this.mana = 1000;
    this.maxMana = 1000;
    
    this.spellRight = "";
    this.spellLeft = "";
    }
    
    @Override
    public void init(Entity entity, World world) 
    {
    
    }
    
    public static final void register(EntityPlayer player) 
    {
    player.registerExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME,
    new ExtendedEntityProps(player));
    }
    
    public static final ExtendedEntityProps get(EntityPlayer player) 
    {
    return (ExtendedEntityProps) player.getExtendedProperties(EXT_PROP_NAME);
    }
    
    @Override
    public void saveNBTData(NBTTagCompound compound) 
    {
    
    NBTTagCompound properties = new NBTTagCompound();
    compound.setTag(EXT_PROP_NAME, properties);
    properties.setDouble("Mana", this.mana);
    properties.setDouble("MaxMana", this.maxMana);
    properties.setString("spellRight", this.spellRight);
    properties.setString("spellLeft", this.spellLeft);
    properties.setInteger("spellsListSize", this.spellsList.size());
    if(this.spellsList != null){
    for(String spell : this.spellsList)
    {
    properties.setString("spellsList", spell);
    }
    }
    }
    
    @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");
    if(size < 0){
    for(int i = 0; i < size; i++){
    String stringI = this.spellsList.get(i);
    this.spellsList.add(i, stringI);
    }
    }
    }
    
    public final void sync() 
    {
    PacketMana packetMana = new PacketMana(this.mana, this.maxMana);
    PacketSpellRight packetSpellRight = new PacketSpellRight(this.spellRight);
    PacketSpellLeft packetSpellLeft = new PacketSpellLeft(this.spellLeft);
    PacketSpellsList packetSpellsList = new PacketSpellsList(this.spellsList);
    
    if (!player.worldObj.isRemote) 
    {
    EntityPlayerMP player1 = (EntityPlayerMP) player;
    Hogsmod.network.sendTo(packetMana, player1);
    Hogsmod.network.sendTo(packetSpellRight, player1);
    Hogsmod.network.sendTo(packetSpellLeft, player1);
    Hogsmod.network.sendTo(packetSpellsList, player1);
    }
    }
    
    private static String getSaveKey(EntityPlayer player) 
    {
    return player.getDisplayName() + ":" + EXT_PROP_NAME;
    }
    
    public static void saveProxyData(EntityPlayer player) {
    ExtendedEntityProps playerData = ExtendedEntityProps.get(player);
    NBTTagCompound savedData = new NBTTagCompound();
    playerData.saveNBTData(savedData);
    CommonProxy.storeEntityData(getSaveKey(player), savedData);
    }
    
    public static void loadProxyData(EntityPlayer player) 
    {
    ExtendedEntityProps playerData = ExtendedEntityProps.get(player);
    NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player));
    
    if (savedData != null) 
    {
    playerData.loadNBTData(savedData);
    }
    playerData.sync();
    }
    
    public boolean removeMana(double amount) 
    {
    boolean sufficient = amount <= this.mana;
    
    if (sufficient) 
    {
    this.mana -= amount;
    this.sync();
    } else 
    {
    return false;
    }
    
    return sufficient;
    }
    
    public void addMana(double amount) 
    {
    this.mana += amount;
    this.sync();
    }
    
    public double getMana() 
    {
    return this.mana;
    }
    
    public void setMana(double newMana) 
    {
    this.mana = newMana;
    this.sync();
    }
    
    public double getMaxMana() {
    return this.maxMana;
    }
    
    public boolean setSpellRight(String spell){
    
    if(this.spellsList.contains(spell)){
    this.spellRight = spell;
    this.sync();
    return true;
    }
    
    return false;
    }
    
    public boolean setSpellLeft(String spell){
    
    if(this.spellsList.contains(spell)){
    this.spellLeft = spell;
    this.sync();
    return true;
    }
    
    return false;
    }
    
    public String getSpellRight(){
    return this.spellRight;
    }
    
    public String getSpellLeft(){
    return this.spellLeft;
    }
    
    public boolean addSpellsList(String spell){
    if(this.getSpellsList().contains(spell) == false){
    this.spellsList.add(spell);
    this.sync();
    return true;
    }
    return false;
    }
    
    public boolean removeSpellsList(String spell){
    if(this.getSpellsList().contains(spell) == true){
    this.spellsList.remove(spell);
    this.sync();
    return true;
    }
    return false;
    }
    
    public List <string>getSpellsList(){
    return this.spellsList;
    }
    }
    
    package fr.sosoh.hogsmod.common.event;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.util.ChatComponentText;
    import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    import net.minecraftforge.event.entity.living.LivingDeathEvent;
    import net.minecraftforge.event.entity.living.LivingEvent;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import fr.sosoh.hogsmod.common.entity.props.ExtendedEntityProps;
    import fr.sosoh.hogsmod.proxy.CommonProxy;
    
    public class EventHandlerExtendedProps {
    
    private CommonProxy proxy;
    public int ticks;
    
    @SubscribeEvent
    public void onEntityConstructing(EntityConstructing event) 
    {
    if (event.entity instanceof EntityPlayer && ExtendedEntityProps.get((EntityPlayer) event.entity) == null)
    ExtendedEntityProps.register((EntityPlayer) event.entity);
    }
    
    @SubscribeEvent
    public void onLivingDeathEvent(LivingDeathEvent event) {
    if (!event.entity.worldObj.isRemote
    && event.entity instanceof EntityPlayer) {
    NBTTagCompound playerData = new NBTTagCompound();
    ((ExtendedEntityProps) (event.entity
    .getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME)))
    .saveNBTData(playerData);
    proxy.storeEntityData(
    ((EntityPlayer) event.entity).getDisplayName(), playerData);
    ExtendedEntityProps.saveProxyData((EntityPlayer) event.entity);
    } else {
    
    }
    }
    
    @SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!(event.entity.worldObj.isRemote) && event.entity instanceof EntityPlayer) {
    
    EntityPlayer player = (EntityPlayer)event.entity;
    NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
    
    if (playerData != null) {
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).loadNBTData(playerData);
    }
    
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    
    @SubscribeEvent
    public void LivingUpdateEvent(LivingEvent.LivingUpdateEvent event){
    
    if(event.entity instanceof EntityPlayer){
    ExtendedEntityProps props = ExtendedEntityProps.get(((EntityPlayer) event.entity));
    
    if(props.getMana() != props.getMaxMana()){
    ticks = ticks+1;
    if(ticks == 9){
    props.setMana(props.getMana()+1);
    ticks = 0;
    }
    }
    
    }
    
    }
    
    }
    
    ```</string></string></string>

  • C’est sur que si ils ne savent pas, ils ne vont pas marcher 😛 .

    tu n’as pas de fonction qui est appelé lorsque le joueur se déconnecte.


  • Mais quand je meurs et donc comment je fais pour quand je deco ?


  • @‘sosoh’:

    Mais quand je meurs et donc comment je fais pour quand je deco ?

    PlayerEvent.PlayerLoggedOutEvent


  • Et pour quand je meurs ?


  • @‘sosoh’:

    Et pour quand je meurs ?

    LivingDeathEvent, mais tu l’as déjà.


  • J’ai mis ca, mais ca ne marche pas:

    ​@SubscribeEvent
    
    public void onLivingDeathEvent(LivingDeathEvent event) {
    if (!event.entity.worldObj.isRemote
    && event.entity instanceof EntityPlayer) {
    NBTTagCompound playerData = new NBTTagCompound();
    ((ExtendedEntityProps) (event.entity
    .getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME)))
    .saveNBTData(playerData);
    proxy.storeEntityData(
    ((EntityPlayer) event.entity).getDisplayName(), playerData);
    ExtendedEntityProps.saveProxyData((EntityPlayer) event.entity);
    } else {
    
    }
    }
    
  • Administrateurs Rédacteurs Moddeurs confirmés

    Non, ce n’est pas ça le problème. La sauvegarde est sensé se faire automatiquement. Le problème se trouve dans la fonction saveNBTData

    ​    @Override
    
        public void saveNBTData(NBTTagCompound compound)
        {
    
            NBTTagCompound properties = new NBTTagCompound();
            compound.setTag(EXT_PROP_NAME, properties);
            properties.setDouble("Mana", this.mana);
            properties.setDouble("MaxMana", this.maxMana);
            properties.setString("spellRight", this.spellRight);
            properties.setString("spellLeft", this.spellLeft);
            properties.setInteger("spellsListSize", this.spellsList.size());
            if(this.spellsList != null){
                for(String spell : this.spellsList)
                {
                    properties.setString("spellsList", spell);
                }
            }
        }
    

    Regarde bien ce que tu fais. Dans un premier temps tu créé une variable local de type NBTTagCompound, puis tu écris dans le nbt tag d’entity ta variable, et seulement après tu ajoutes des choses dans ta variable local. Donc au final rien est écrit, sauf un tab nbt vide.
    Cela devrait être comme ça :

    ​    @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);
            properties.setInteger("spellsListSize", this.spellsList.size());
            if(this.spellsList != null){
                for(String spell : this.spellsList)
                {
                    properties.setString("spellsList", spell);
                }
            }
    compound.setTag(EXT_PROP_NAME, properties);
    }
    

  • J’ai corrigé mais ca ne marche pas 😞

    ​package fr.sosoh.hogsmod.common.event;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.util.ChatComponentText;
    import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    import net.minecraftforge.event.entity.living.LivingDeathEvent;
    import net.minecraftforge.event.entity.living.LivingEvent;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.PlayerEvent;
    import fr.sosoh.hogsmod.common.entity.props.ExtendedEntityProps;
    import fr.sosoh.hogsmod.proxy.CommonProxy;
    
    public class EventHandlerExtendedProps {
    
    private CommonProxy proxy;
    public int ticks;
    
    @SubscribeEvent
    public void onEntityConstructing(EntityConstructing event) 
    {
    if (event.entity instanceof EntityPlayer && ExtendedEntityProps.get((EntityPlayer) event.entity) == null)
    ExtendedEntityProps.register((EntityPlayer) event.entity);
    }
    
    @SubscribeEvent
    public void onLivingDeathEvent(LivingDeathEvent event)
    {
    if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
    {
    NBTTagCompound playerData = new NBTTagCompound();
    ((ExtendedEntityProps)(event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    proxy.storeEntityData(((EntityPlayer) event.entity).getDisplayName(), playerData);
    ExtendedEntityProps.saveProxyData((EntityPlayer) event.entity);
    }
    }
    
    @SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!(event.entity.worldObj.isRemote) && event.entity instanceof EntityPlayer) {
    
    EntityPlayer player = (EntityPlayer)event.entity;
    NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
    
    if (playerData != null) {
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).loadNBTData(playerData);
    }
    
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    
    @SubscribeEvent
    public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event){
    if (!(event.player.worldObj.isRemote)) {
    
    NBTTagCompound playerData = proxy.getEntityData((event.player).getDisplayName());
    
    if (playerData != null) {
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    }
    
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    }
    

  • @‘sosoh’:

    J’ai corrigé mais ca ne marche pas 😞

    ​package fr.sosoh.hogsmod.common.event;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.util.ChatComponentText;
    import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    import net.minecraftforge.event.entity.living.LivingDeathEvent;
    import net.minecraftforge.event.entity.living.LivingEvent;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.PlayerEvent;
    import fr.sosoh.hogsmod.common.entity.props.ExtendedEntityProps;
    import fr.sosoh.hogsmod.proxy.CommonProxy;
    
    public class EventHandlerExtendedProps {
    
    private CommonProxy proxy;
    public int ticks;
    
    @SubscribeEvent
    public void onEntityConstructing(EntityConstructing event) 
    {
    if (event.entity instanceof EntityPlayer && ExtendedEntityProps.get((EntityPlayer) event.entity) == null)
    ExtendedEntityProps.register((EntityPlayer) event.entity);
    }
    
    @SubscribeEvent
    public void onLivingDeathEvent(LivingDeathEvent event)
    {
    if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
    {
    NBTTagCompound playerData = new NBTTagCompound();
    ((ExtendedEntityProps)(event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    proxy.storeEntityData(((EntityPlayer) event.entity).getDisplayName(), playerData);
    ExtendedEntityProps.saveProxyData((EntityPlayer) event.entity);
    }
    }
     
    @SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!(event.entity.worldObj.isRemote) && event.entity instanceof EntityPlayer) {
    
    EntityPlayer player = (EntityPlayer)event.entity;
    NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
    
    if (playerData != null) {
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).loadNBTData(playerData);
    }
    
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    
    @SubscribeEvent
    public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event){
    if (!(event.player.worldObj.isRemote)) {
    
    NBTTagCompound playerData = proxy.getEntityData((event.player).getDisplayName());
    
    if (playerData != null) {
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    }
    
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    }
    

    Mets un System.out.print (ou un log.info si tu en as un à disposition) dans ta fonction de sauvegarde et regarde s’il s’affiche quand tu te deco/reco etc.


  • J’ai mis ca dans mes events, il affiche que c’est null (je peux t’envoyer mon src ?):

    ​@SubscribeEvent
    
    public void onLivingDeathEvent(LivingDeathEvent event)
    {
    if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer){
    System.out.println("Death");
    NBTTagCompound playerData = new NBTTagCompound();
    ((ExtendedEntityProps)(event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    proxy.storeEntityData(((EntityPlayer) event.entity).getDisplayName(), playerData);
    ExtendedEntityProps.saveProxyData((EntityPlayer) event.entity);
    }
    }
    
    @SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!(event.entity.worldObj.isRemote) && event.entity instanceof EntityPlayer) {
    System.out.println("LoggedIn");
    EntityPlayer player = (EntityPlayer)event.entity;
    NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
    
    if (playerData != null) {
    System.out.println("LoggedIn-null");
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).loadNBTData(playerData);
    }
    
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    
    @SubscribeEvent
    public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event){
    if (!(event.player.worldObj.isRemote)) {
    
    NBTTagCompound playerData = proxy.getEntityData((event.player).getDisplayName());
    
    if (playerData != null) {
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    System.out.println("LoggedOut-Null");
    }
    System.out.println("LoggedOut");
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    
    [22:15:48] [Server thread/INFO] [STDOUT]: [fr.sosoh.hogsmod.common.event.EventHandlerExtendedProps:onLivingDeathEvent:32]: Death
    [22:15:48] [Server thread/INFO]: sosoh fell out of the world
    [22:15:48] [Client thread/INFO]: [CHAT] sosoh fell out of the world
    [22:15:48] [Client thread/INFO]: [CHAT] Ouch! That looked like it hurt
    [22:15:50] [Server thread/INFO] [STDOUT]: [fr.sosoh.hogsmod.common.event.EventHandlerExtendedProps:onEntityJoinWorld:43]: LoggedIn
    [22:15:50] [Server thread/INFO] [STDOUT]: [fr.sosoh.hogsmod.common.event.EventHandlerExtendedProps:onEntityJoinWorld:48]: LoggedIn-null
    

  • @‘sosoh’:

    J’ai mis ca dans mes events, il affiche que c’est null (je peux t’envoyer mon src ?):

    ​@SubscribeEvent
    
    public void onLivingDeathEvent(LivingDeathEvent event)
    {
    if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer){
    System.out.println("Death");
    NBTTagCompound playerData = new NBTTagCompound();
    ((ExtendedEntityProps)(event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    proxy.storeEntityData(((EntityPlayer) event.entity).getDisplayName(), playerData);
    ExtendedEntityProps.saveProxyData((EntityPlayer) event.entity);
    }
    }
     
    @SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!(event.entity.worldObj.isRemote) && event.entity instanceof EntityPlayer) {
    System.out.println("LoggedIn");
    EntityPlayer player = (EntityPlayer)event.entity;
    NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
    
    if (playerData != null) {
    System.out.println("LoggedIn-null");
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).loadNBTData(playerData);
    }
    
    ((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    
    @SubscribeEvent
    public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event){
    if (!(event.player.worldObj.isRemote)) {
    
    NBTTagCompound playerData = proxy.getEntityData((event.player).getDisplayName());
    
    if (playerData != null) {
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).saveNBTData(playerData);
    System.out.println("LoggedOut-Null");
    }
    System.out.println("LoggedOut");
    ((ExtendedEntityProps) (event.player.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
    }
    }
    
    [22:15:48] [Server thread/INFO] [STDOUT]: [fr.sosoh.hogsmod.common.event.EventHandlerExtendedProps:onLivingDeathEvent:32]: Death
    [22:15:48] [Server thread/INFO]: sosoh fell out of the world
    [22:15:48] [Client thread/INFO]: [CHAT] sosoh fell out of the world
    [22:15:48] [Client thread/INFO]: [CHAT] Ouch! That looked like it hurt
    [22:15:50] [Server thread/INFO] [STDOUT]: [fr.sosoh.hogsmod.common.event.EventHandlerExtendedProps:onEntityJoinWorld:43]: LoggedIn
    [22:15:50] [Server thread/INFO] [STDOUT]: [fr.sosoh.hogsmod.common.event.EventHandlerExtendedProps:onEntityJoinWorld:48]: LoggedIn-null
    

    Mets les system.out.println dans ta fonction de sauvegarde, pas dans tes fonctions d’event. ça servirai pas à grand chose de m’envoyer tes sources car je m’y connait pas trop en EntityExtendedProperties.


  • J’ai mis dans la fonction store de mon common proxy, ça marche. Quelqu’un a une idée ?


  • @‘sosoh’:

    J’ai mis dans la fonction store de mon common proxy, ça marche. Quelqu’un a une idée ?

    Le problème vient de là:

    ​
    @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);
    properties.setInteger("spellsListSize", this.spellsList.size());
    if(this.spellsList != null){
    for(String spell : this.spellsList)
    {
    properties.setString("spellsList", spell);
    }
    }
    compound.setTag(EXT_PROP_NAME, properties);
    }
    

    Ta boucle for supprime l’ancienne valeur : il faut utiliser un NBTTagList.


  • Tu peux m’expliquer comment car je ne maîtrise pas tout à fait?


  • @‘sosoh’:

    Tu peux m’expliquer comment car je ne maîtrise pas tout à fait?

    Regarde dans le code tu TileEntity coffre car j’ai jamais utilisé ce NBTTag mais je sais qu’il existe.


  • Mais je mets un NBTTagList pour juste l’array ou pour toutes mes props ?


  • @‘sosoh’:

    Mais je mets un NBTTagList pour juste l’array ou pour toutes mes props ?

    juste pour ton array spellList.


  • J’ai fait ca, mais ca ne marche pas:

    ​@Override
    
    public void saveNBTData(NBTTagCompound compound) 
        {
    
            NBTTagCompound properties = new NBTTagCompound();
            NBTTagList nbtlist = new NBTTagList();
            properties.setDouble("Mana", this.mana);
            properties.setDouble("MaxMana", this.maxMana);
            properties.setString("spellRight", this.spellRight);
            properties.setString("spellLeft", this.spellLeft);
            properties.setInteger("spellsListSize", this.spellsList.size());
            nbtlist.appendTag(properties);
            if(this.spellsList != null){
                for(String spell : this.spellsList)
                {
                NBTTagCompound nbttag = new NBTTagCompound();
                nbttag.setString("spellsList", spell);
                    nbtlist.appendTag(nbttag);
                }
            }
            compound.setTag(EXT_PROP_NAME, nbtlist);
        }
    
    @Override
    public void loadNBTData(NBTTagCompound compound) 
    {
    NBTTagList nbtlist = (NBTTagList) compound.getTag(EXT_PROP_NAME);
    NBTTagCompound properties = nbtlist.getCompoundTagAt(1);
    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");
    if(size > 0){
    for(int i = 0; i < size; i++){
    NBTTagCompound nbttag = nbtlist.getCompoundTagAt(i);
    this.spellsList.add(i, nbttag.getString("spellsList"));
    }
    }
    }
    

  • @‘sosoh’:

    J’ai fait ca, mais ca ne marche pas:

    ​@Override
    
    public void saveNBTData(NBTTagCompound compound) 
        {
    
            NBTTagCompound properties = new NBTTagCompound();
            NBTTagList nbtlist = new NBTTagList();
            properties.setDouble("Mana", this.mana);
            properties.setDouble("MaxMana", this.maxMana);
            properties.setString("spellRight", this.spellRight);
            properties.setString("spellLeft", this.spellLeft);
            properties.setInteger("spellsListSize", this.spellsList.size());
            nbtlist.appendTag(properties);
            if(this.spellsList != null){
                for(String spell : this.spellsList)
                {
                NBTTagCompound nbttag = new NBTTagCompound();
                nbttag.setString("spellsList", spell);
                    nbtlist.appendTag(nbttag);
                }
            }
            compound.setTag(EXT_PROP_NAME, nbtlist);
        }
    
    @Override
    public void loadNBTData(NBTTagCompound compound) 
    {
    NBTTagList nbtlist = (NBTTagList) compound.getTag(EXT_PROP_NAME);
    NBTTagCompound properties = nbtlist.getCompoundTagAt(1);
    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");
    if(size > 0){
    for(int i = 0; i < size; i++){
    NBTTagCompound nbttag = nbtlist.getCompoundTagAt(i);
    this.spellsList.add(i, nbttag.getString("spellsList"));
    }
    }
    }
    

    regarde comment les NBTTagList fonctionne dans le TileEntityChest