• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Résolu Extended Entity Properties les données restent à 0

    1.7.x
    1.7.2
    3
    25
    3631
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • mindany2
      mindany2 dernière édition par

      Salut  🙂 ,
      Suite au conseil d’elias dans la matinée j’ai déplacé mon problème ici :

      J’ai un problème avec les Extended Entity Properties, j’ai revu plusieurs fois mon code mais les packets n’ont pas l’air de se transmettre, peu importe ce que je fais les données restent toujours à 0
      Si vous avez une petite idée ^^ :
      PacketSonic :

      public class PacketSonic 
      extends FFMTPacket
      {
      
      public int Descendre;
      public boolean DoubleJump;
      public long Ring;
      
      public PacketSonic(){
      
      }
      
      public PacketSonic(int Descendre, boolean DoubleJump, long Ring){
      this.Descendre = Descendre;
      this.DoubleJump = DoubleJump;
      this.Ring = Ring;
      }
      
      @Override
      public void writeData(ByteBuf buffer) throws IOException {
      buffer.writeInt(Descendre);
      buffer.writeBoolean(DoubleJump);
      buffer.writeLong(Ring);
      
      }
      
      @Override
      public void readData(ByteBuf buffer) {
      this.Descendre = buffer.readInt();
      this.DoubleJump = buffer.readBoolean();
      this.Ring = buffer.readLong();
      
      }
      
      @Override
      public void handleClientSide(EntityPlayer player) {
      ExtendedEntityPropSonic props = ExtendedEntityPropSonic
      .get(player);
      props.Descendre = this.Descendre;
      props.DoubleJump = this.DoubleJump;
      props.Ring = this.Ring;
      }
      
      @Override
      public void handleServerSide(EntityPlayer player) {
      ExtendedEntityPropSonic props = ExtendedEntityPropSonic
      .get(player);
      props.Descendre = this.Descendre;
      props.DoubleJump = this.DoubleJump;
      props.Ring = this.Ring;
      }
      
      }
      

      ExtendedEntityPropSonic :

      public final static String EXT_PROP_NAME = "ExtPropSonic";
      
      private final EntityPlayer player;
      
      public int Descendre;
      public boolean DoubleJump;
      public long Ring;
      
      public ExtendedEntityPropSonic(EntityPlayer player) {
      this.player = player;
      this.Descendre = 0;
      this.DoubleJump = false;
      this.Ring = 0;
      
      }
      
      @Override
      public void saveNBTData(NBTTagCompound compound) {
      
      NBTTagCompound properties = new NBTTagCompound();
      
      properties.setInteger("Descendre", this.Descendre);
      properties.setBoolean("DoubleJump", this.DoubleJump);
      properties.setLong("Ring", this.Ring);
      
      compound.setTag(EXT_PROP_NAME, properties);
      
      }
      
      @Override
      public void loadNBTData(NBTTagCompound compound) {
      NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
      this.Descendre = properties.getInteger("Descendre");
      this.DoubleJump = properties.getBoolean("DoubleJump");
      this.Ring = properties.getLong("Ring");
      
      }
      
      @Override
      public void init(Entity entity, World world) {
      // TODO Auto-generated method stub
      
      }
      
      public static final void register(EntityPlayer player) {
      player.registerExtendedProperties(ExtendedEntityPropSonic.EXT_PROP_NAME,
      new ExtendedEntityPropSonic(player));
      }
      
      public static final ExtendedEntityPropSonic get(EntityPlayer player) {
      return (ExtendedEntityPropSonic) player.getExtendedProperties(EXT_PROP_NAME);
      }
      
      public final void sync() {
      PacketSonic packetSonic = new PacketSonic(this.Descendre, this.DoubleJump, this.Ring);
      Sonic_mod.rcModPacketHandler.sendToServer(packetSonic);
      
      if (!player.worldObj.isRemote) {
      EntityPlayerMP player1 = (EntityPlayerMP) player;
      Sonic_mod.rcModPacketHandler.sendTo(packetSonic, player1);
      }
      }
      private static String getSaveKey(EntityPlayer player) {
      return player.getDisplayName() + ":" + EXT_PROP_NAME;
      }
      
      public static void saveProxyData(EntityPlayer player) {
      ExtendedEntityPropSonic playerData = ExtendedEntityPropSonic.get(player);
      NBTTagCompound savedData = new NBTTagCompound();
      
      playerData.saveNBTData(savedData);
      CommonProxy.storeEntityData(getSaveKey(player), savedData);
      }
      
      public static void loadProxyData(EntityPlayer player) {
      ExtendedEntityPropSonic playerData = ExtendedEntityPropSonic.get(player);
      NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player));
      
      if (savedData != null) {
      playerData.loadNBTData(savedData);
      }
      playerData.sync();
      }
      
      public long getRing() {
      return this.Ring;
      }
      
      public void setRing(long newRing) {
      this.Ring = newRing;
      this.sync();
      
      }
      
      public int getDescendre() {
      return this.Descendre;
      }
      
      public void setDescendre(int newDescendre) {
      this.Descendre = newDescendre;
      this.sync();
      }
      
      public boolean getDoubleJump() {
      return this.DoubleJump;
      }
      
      public void setDoubleJump(boolean newDoubleJump) {
      this.DoubleJump = newDoubleJump;
      this.sync();
      }
      

      Une partie de ma classe event :

      /** Register data*/
      @SubscribeEvent
      public void onEntityConstructing(EntityConstructing event) {
      
      if (event.entity instanceof EntityPlayer
      && ExtendedEntityPropSonic.get((EntityPlayer) event.entity) == null)
      {
      ExtendedEntityPropSonic.register((EntityPlayer) event.entity);
      System.out.println("une entité a rejoint le monde");
      }
      }
      @SubscribeEvent
      public void onEntityJoinWorld(EntityJoinWorldEvent event) {
      if (!event.entity.worldObj.isRemote
      && event.entity instanceof EntityPlayer) {
      NBTTagCompound playerData = CommonProxy
      .getEntityData(((EntityPlayer) event.entity)
      .getDisplayName());
      if (playerData != null) {
      ((ExtendedEntityPropSonic) (event.entity
      .getExtendedProperties(ExtendedEntityPropSonic.EXT_PROP_NAME)))
      .loadNBTData(playerData);
      }
      
      ((ExtendedEntityPropSonic) (event.entity
      .getExtendedProperties(ExtendedEntityPropSonic.EXT_PROP_NAME)))
      .sync();
      }
      }
      }
      

      Je pense avoir tout mis
      Merci d’avance ^^’

      ^^

      1 réponse Dernière réponse Répondre Citer 0
      • robin4002
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

        Met des System.out.println(“quelque chose”) dans la fonction writeData, handleClientSide et handleServerSide pour vérifier que le paquet est bien reçu. Tu peux aussi faire afficher les valeurs de tes variables dans ces fonctions pour être sur qu’elles ne soit pas erronées.

        1 réponse Dernière réponse Répondre Citer 0
        • mindany2
          mindany2 dernière édition par

          Les fonction writeData et handleServerSide sont utilisées mais pas handleClientSide
          :::

          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 1
          Fonction handleServerSide : 0; false; 0
          Fonction handleClientSide : 0; false; 1
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction handleServerSide : 0; false; 0
          Fonction writeData : 0; false; 0
          Fonction writeData : 0; false; 0
          

          :::

          ^^

          1 réponse Dernière réponse Répondre Citer 0
          • robin4002
            robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

            Étrange ça, pourtant c’est bien le serveur qui envoie un paquet au client, donc il est sensé le recevoir. Il faudrait voir avec gugu, c’est sont code, personnellement je passe par les DataWatcher pour syncho les valeurs de mes custom prop.

            1 réponse Dernière réponse Répondre Citer 0
            • mindany2
              mindany2 dernière édition par

              Bah si tu veux me montrer une autre méthode qui marche ça ne me dérange pas 😛

              ^^

              1 réponse Dernière réponse Répondre Citer 0
              • robin4002
                robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                Dans ta classe IExtendedEntityProperties, dans le constructeur ajoute :

                        this.player.getDataWatcher().addObject(id, variable a syncro);
                

                les ids vont de 0 à 31, certains id sont déjà utilisé par mc, prends au dessus de 20 de préférence.

                dans saveNBTData, pour sauvegarder la variable fait comme ça :

                        compound.setInteger("nom dans le tag", this.player.getDataWatcher().getWatchableObjectInt(id));
                

                (getWatchableObjectInt c’est pour une variable de type int, tu en as d’autre pour les byte, string …)

                dans loadNBTData :

                        this.player.getDataWatcher().updateObject(id, compound.getInteger("nom dans le tag"));
                

                Et dernière changement, le getter et le setter :

                    public int getTaVariable()
                    {
                        return this.player.getDataWatcher().getWatchableObjectInt(id);
                    }
                
                    public void setTaVariable(int valeur)
                    {
                        this.player.getDataWatcher().updateObject(id, valeur);
                    }
                

                Il faut rien de plus, pas besoin de packet.

                1 réponse Dernière réponse Répondre Citer 1
                • mindany2
                  mindany2 dernière édition par

                  Ok je suis en train de l’essayer mais je vois qu’il n’y a pas de getWatchableObjectBoolean, je dois changer mon boolean en int (avec par exemple mon false qui sera 0 et mon true qui sera 1) ou il y a une autre méthode

                  Edit : de même pour les long :s

                  ^^

                  1 réponse Dernière réponse Répondre Citer 0
                  • robin4002
                    robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                    Oui en effet, pas de long ni de double. Pour les boolean suffit de faire passer un byte qui vaut 1 ou 0 et voila.
                    Mais pour les long ou double il faut passer par les paquets, donc la faudrait voir avec gugu.

                    1 réponse Dernière réponse Répondre Citer 0
                    • mindany2
                      mindany2 dernière édition par

                      Bah c’est pas grave ça m’étonnerais que les personnes récoltent assez afin de dépasser un la valeur maximal d’un int 😛 (2.147.483.647 il me semble)
                      En revanche j’ai essayé plusieurs ids > 20 mais à chaque fois ils étaient utilisés (aussi bien le 29 que le 21)

                      ^^

                      1 réponse Dernière réponse Répondre Citer 0
                      • robin4002
                        robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                        Ah ? J’utilise le 31, 30, 29, et 28, je n’ai pas de problème.

                        1 réponse Dernière réponse Répondre Citer 0
                        • mindany2
                          mindany2 dernière édition par

                          ​java.lang.IllegalArgumentException: Duplicate id value for 29!
                          at net.minecraft.entity.DataWatcher.addObject(DataWatcher.java:56)
                          at lmac.sonic.ExtendedEntityPropSonic.<init>(ExtendedEntityPropSonic.java:29)
                          at lmac.sonic.InfoOverlay.renderGameOverlay(InfoOverlay.java:67)
                          at cpw.mods.fml.common.eventhandler.ASMEventHandler_15_InfoOverlay_renderGameOverlay_Post.invoke(.dynamic)
                          at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
                          at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
                          at net.minecraftforge.client.GuiIngameForge.post(GuiIngameForge.java:901)
                          at net.minecraftforge.client.GuiIngameForge.renderHelmet(GuiIngameForge.java:263)
                          at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:120)
                          at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1122)
                          at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1025)
                          at net.minecraft.client.Minecraft.run(Minecraft.java:912)
                          at net.minecraft.client.main.Main.main(Main.java:112)
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                          at java.lang.reflect.Method.invoke(Unknown Source)
                          at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
                          at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
                          
                          

                          :s
                          Pas d’idée 😞 ?</init>

                          ^^

                          1 réponse Dernière réponse Répondre Citer 0
                          • isador
                            isador Moddeurs confirmés Modérateurs dernière édition par

                            deux mob qui on le même id

                            1 réponse Dernière réponse Répondre Citer 0
                            • mindany2
                              mindany2 dernière édition par

                              .<’
                              C’est pas de mobs qui ont le même id c’est deux DataWatcher qui ont le même id mais le problème c’est que c’est pareil avec tout les ids dispo :s

                              ^^

                              1 réponse Dernière réponse Répondre Citer 0
                              • robin4002
                                robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                                Tu as bien mit un id différent à chaque watcher ajouté ?

                                1 réponse Dernière réponse Répondre Citer 0
                                • mindany2
                                  mindany2 dernière édition par

                                  Bah apparemment non ._.

                                  public final static String EXT_PROP_NAME = "ExtPropSonic";
                                  
                                  private final EntityPlayer player;
                                  
                                  public int Descendre;
                                  public byte DoubleJump;
                                  public int Ring;
                                  int i = 28;
                                  public ExtendedEntityPropSonic(EntityPlayer player) {
                                  this.player = player;
                                  this.Descendre = 0;
                                  this.DoubleJump = 0;
                                  this.Ring = 0;
                                  
                                  this.player.getDataWatcher().addObject(i + 1, Descendre);
                                  this.player.getDataWatcher().addObject(i + 2, DoubleJump);
                                  this.player.getDataWatcher().addObject(i + 3, Ring);
                                  }
                                  
                                  @Override
                                  public void saveNBTData(NBTTagCompound compound) {
                                  compound.setInteger("Descendre", this.player.getDataWatcher().getWatchableObjectInt(i + 1));
                                  compound.setByte("DoubleJump", this.player.getDataWatcher().getWatchableObjectByte(i + 2));
                                  compound.setInteger("Ring", this.player.getDataWatcher().getWatchableObjectInt(i + 3));
                                  }
                                  
                                  @Override
                                  public void loadNBTData(NBTTagCompound compound) {
                                  this.player.getDataWatcher().updateObject(i + 1, compound.getInteger("Descendre"));
                                  this.player.getDataWatcher().updateObject(i + 2, compound.getByte("DoubleJump"));
                                  this.player.getDataWatcher().updateObject(i + 3, compound.getLong("Ring"));
                                  }
                                  
                                  @Override
                                  public void init(Entity entity, World world) {
                                  // TODO Auto-generated method stub
                                  
                                  }
                                  
                                  public static final void register(EntityPlayer player) {
                                  player.registerExtendedProperties(ExtendedEntityPropSonic.EXT_PROP_NAME,
                                  new ExtendedEntityPropSonic(player));
                                  }
                                  
                                  public static final ExtendedEntityPropSonic get(EntityPlayer player) {
                                  return (ExtendedEntityPropSonic) player.getExtendedProperties(EXT_PROP_NAME);
                                  }
                                  
                                  private static String getSaveKey(EntityPlayer player) {
                                  return player.getDisplayName() + ":" + EXT_PROP_NAME;
                                  }
                                  
                                  public static void saveProxyData(EntityPlayer player) {
                                  ExtendedEntityPropSonic playerData = ExtendedEntityPropSonic.get(player);
                                  NBTTagCompound savedData = new NBTTagCompound();
                                  
                                  playerData.saveNBTData(savedData);
                                  CommonProxy.storeEntityData(getSaveKey(player), savedData);
                                  }
                                  
                                  public int getDescendre() {
                                  return this.player.getDataWatcher().getWatchableObjectInt(i + 1);
                                  }
                                  
                                  public void setDescendre(int newDescendre) {
                                  this.player.getDataWatcher().updateObject(i + 1, newDescendre);
                                  }
                                  
                                  public boolean getDoubleJump() {
                                  if(this.player.getDataWatcher().getWatchableObjectInt(i + 2) == 0){
                                  return false;
                                  }
                                  else{
                                  return true;
                                  }
                                  }
                                  
                                  public void setDoubleJump(boolean newDoubleJump) {
                                  if(newDoubleJump){
                                  this.player.getDataWatcher().updateObject(i + 2, 0);
                                  }
                                  else{
                                  this.player.getDataWatcher().updateObject(i + 2, 1);
                                  }
                                  }
                                  
                                  public long getRing() {
                                  return this.player.getDataWatcher().getWatchableObjectInt(i + 3);
                                  }
                                  
                                  public void setRing(long newRing) {
                                  this.player.getDataWatcher().updateObject(i + 3, newRing);
                                  }
                                  

                                  Je me sentirais bête si ça viens de là >.<

                                  Edit: Je viens d’y penser mais le faite d’initialisé deux fois ExtendedEntityPropSonic doit être la cause du problème (je l’initialise dans l’event et dans un overlay)

                                  ^^

                                  1 réponse Dernière réponse Répondre Citer 0
                                  • robin4002
                                    robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                                    C’est en effet étrange, tu n’as pas d’autre mod sur ta workspace si ? Car c’est peut être un autre mod qui les utilisent déjà.
                                    Ou alors il y a vraiment un problème x)

                                    1 réponse Dernière réponse Répondre Citer 0
                                    • mindany2
                                      mindany2 dernière édition par

                                      Bah Glutils de (je ne vais pas citer le nom pour pas faire de faute, bon ok (jglrxavpok)) et FFTM

                                      ^^

                                      1 réponse Dernière réponse Répondre Citer 0
                                      • robin4002
                                        robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                                        Dans ce cas je ne vois pas pourquoi ça ne fonctionne pas 😕

                                        1 réponse Dernière réponse Répondre Citer 0
                                        • mindany2
                                          mindany2 dernière édition par

                                          Je crois avoir trouvé

                                          cf: mon édit d’hier

                                          Edit: Je viens d’y penser mais le faite d’initialisé deux fois ExtendedEntityPropSonic doit être la cause du problème (je l’initialise dans l’event et dans un overlay)

                                          Le constructeur de mon ExtendedEntityPropSonic n’arrête pas d’être chargé donc la première fois ça l’ajoute mais la seconde bah … ça peut que buguer maintenant faut savoir qu’elle bétise ai-je fais pour le charger plusieurs fois >.<’

                                          ^^

                                          1 réponse Dernière réponse Répondre Citer 0
                                          • robin4002
                                            robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                                            Ah oui en effet, c’est pas bon ça. Il faut seulement l’enregistrer dans l’event EntityConstructing
                                            Dans les autres event il faut juste le get.

                                            1 réponse Dernière réponse Répondre Citer 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            Contact / Mentions Légales

                                            MINECRAFT FORGE FRANCE © 2018

                                            Powered by NodeBB