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

Résolu Une aide pour des events.

1.7.x
1.7.10
8
46
6.7k
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.
  • Y
    yveslefou dernière édition par 30 juin 2016, 20:52

    @‘robin4002’:

    Étrange qu’il n’y ait pas Ca lance version 2 dans les logs ni l’effet 😕

    Je sais je ne comprend moi aussi l’erreur mais je pense contourner le probléme avec un event de forge playerEvent.PlayerRespawnEvent. Le soucie est que je ne sais pas comment l’exploiter.

    1 réponse Dernière réponse Répondre Citer 0
    • RedRelay
      RedRelay Moddeurs confirmés dernière édition par 1 juil. 2016, 02:21

      @‘BrokenSwing’:

      public String transformation(){
      if (this.LevelV == 0){this.Lv = "0";}
      if (this.LevelV == 1){this.Lv = "1";}
      if (this.LevelV == 2){this.Lv = "2";}
      if (this.LevelV == 3){this.Lv = "3";}
      if (this.LevelV == 4){this.Lv = "4";}
      if (this.LevelV == 5){this.Lv = "5";}
      if (this.LevelV == 6){this.Lv = "6";}
      if (this.LevelV == 7){this.Lv = "7";}
      if (this.LevelV == 8){this.Lv = "8";}
      if (this.LevelV == 9){this.Lv = "9";}
      if (this.LevelV == 10){this.Lv = "10";}
      if (this.LevelV == 11){this.Lv = "11";}
      if (this.LevelV == 12){this.Lv = "12";}
      if (this.LevelV == 13){this.Lv = "13";}
      if (this.LevelV == 14){this.Lv = "14";}
      if (this.LevelV == 15){this.Lv = "15";}
      if (this.LevelV == 16){this.Lv = "16";}
      if (this.LevelV == 17){this.Lv = "17";}
      if (this.LevelV == 18){this.Lv = "18";}
      if (this.LevelV == 19){this.Lv = "19";}
      if (this.LevelV == 20){this.Lv = "20";}
      return Lv;}

      Devient :

      public String transformation() {
      this.Lv = new String(this.LevelV);
      return Lv;
      }

      Ça a rien avoir ton problème mais faut pas abuser

      J’ai pas tout lu, mais la non plus faut pas abuser :

      public String transformation() {
      this.Lv = new String(this.LevelV);
      return Lv;
      }

      Devient

      public void transformation() {
      this.Lv = Integer.toString(this.LevelV);
      }

      On n’appel jamais “new” quand on utilise une chaîne de caractères.
      Tout ça pour une fonction transformation() qui n’a pas lieu d’être car les attributs de tes objets n’ont aucun sens, tu dupliques les valeurs en fonction de leur type, ça va créer des incohérences dans ton objet
      Tu n’a besoin que de this.lv (oui une petite relecture des conventions de nommage, ça pourrait t’être utile 😉 )

      Pour comprendre ton erreur, met des breakpoints et utilise le debugger d’eclipse 😉

      –------------------------------------------------------------------------------------
      Si tu trouves mon intervention pertinente, n'hésite pas a m…

      1 réponse Dernière réponse Répondre Citer 0
      • Y
        yveslefou dernière édition par 3 juil. 2016, 12:28

        J’ais compris l’erreur mais je ne la comprend pas.
        En faite la variable LevelV vaut 0 lorsque le joueur meurt.

        Les code lorsque le joueur change de monde (qui marche trés bien) :

        [14:18:50] [Server thread/INFO] [STDOUT]: [Channel.ExtendVieLv:Lv:155]: Ca lance
        10
        [14:18:50] [Server thread/INFO] [STDOUT]: [Channel.ExtendVieLv:Lv:158]: Le if passe
        [14:18:50] [Server thread/INFO] [STDOUT]: [Channel.ExtendVieLv:Lv:160]: Le if passe 2
        [14:18:50] [Server thread/INFO] [STDOUT]: [Channel.ExtendVieLv:Lv:162]: Le if passe 3
        [14:18:50] [Server thread/INFO] [STDOUT]: [Channel.ExtendVieLv:Lv:165]: Ca lance version 2
        [14:18:50] [Server thread/INFO] [STDOUT]: [Channel.ExtendVieLv:Lv:169]: Effet de potion passé
        

        mais lorsqu’il meurt on a :

        [14:18:52] [Server thread/INFO] [STDOUT]: [Channel.ExtendVieLv:Lv:155]: Ca lance
        0
        

        La fonction lorsque le joueur change de monde ou meurt :

        public void Lv(){
        System.out.println("Ca lance");
        System.out.println(LevelV);
        if (this.LevelV > 0){
        System.out.println("Le if passe");
        AttributeModifier moreHealth = new AttributeModifier(player.getPersistentID(), "Test",4*LevelV, 0).setSaved(true); 
        System.out.println("Le if passe 2");
        IAttributeInstance attributeinstance = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
        System.out.println("Le if passe 3");
        attributeinstance.removeModifier(moreHealth);
        attributeinstance.applyModifier(moreHealth);
        System.out.println("Ca lance version 2");
        player.addPotionEffect(new PotionEffect(6,1));
        player.addPotionEffect(new PotionEffect(7,1));
        player.addPotionEffect(new PotionEffect(10,800,1));
        System.out.println("Effet de potion passé");}}

        La classe compléte :

        package Channel;
        import com.google.common.base.Strings;
        import cpw.mods.fml.common.network.simpleimpl.IMessage;
        import fr.extazilia.extaziliamod.common.Main;
        import fr.extazilia.extaziliamod.proxy.CommonProxy;
        import io.netty.buffer.ByteBuf;
        import io.netty.channel.ChannelHandlerContext;
        import net.minecraft.entity.Entity;
        import net.minecraft.entity.SharedMonsterAttributes;
        import net.minecraft.entity.ai.attributes.AttributeModifier;
        import net.minecraft.entity.ai.attributes.IAttributeInstance;
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.entity.player.EntityPlayerMP;
        import net.minecraft.nbt.NBTTagCompound;
        import net.minecraft.potion.PotionEffect;
        import net.minecraft.util.ChatComponentText;
        import net.minecraft.world.World;
        import net.minecraftforge.common.IExtendedEntityProperties;
        public class ExtendVieLv implements IExtendedEntityProperties{
        public final static String EXT_Vie = "PropVie";
        private EntityPlayer player;
        public String Lv;
        public long LevelV;
        public static long LLv;
        public ExtendVieLv(EntityPlayer player) {
        this.player = player;
        this.Lv = "";
        this.LevelV = 0;
        }
            public static final void register(EntityPlayer player) {
            player.registerExtendedProperties(ExtendVieLv.EXT_Vie,new ExtendVieLv(player));}
            public static final ExtendVieLv get(EntityPlayer player) {
            return (ExtendVieLv) player.getExtendedProperties(EXT_Vie);
            }
        @Override
        public void saveNBTData(NBTTagCompound compound) {
        NBTTagCompound properties = new NBTTagCompound();
        properties.setLong("NiveauxVie", this.LevelV);
        compound.setTag(EXT_Vie, properties);
        }
        @Override
        public void loadNBTData(NBTTagCompound compound) {
        NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_Vie);
        this.LevelV = properties.getLong("NiveauxVie");
        }
        public final void sync() {
        transformation();
        MyMessage packetMoney = new MyMessage(this.Lv);
                Main.network.sendToServer(packetMoney);
        if (!player.worldObj.isRemote) {
        EntityPlayerMP player1 = (EntityPlayerMP) player;
        Main.network.sendTo(packetMoney, player1);
        }
        transformation2();
        return;
        }
        private static String getSaveKey(EntityPlayer player) {
        return player.getDisplayName() + ":" + EXT_Vie;
        }
        public static void saveProxyData(EntityPlayer player) {
        ExtendVieLv playerData = ExtendVieLv.get(player);
        NBTTagCompound savedData = new NBTTagCompound();
        playerData.saveNBTData(savedData);
        CommonProxy.storeEntityData(getSaveKey(player), savedData);
        }
        public static void loadProxyData(EntityPlayer player) {
        ExtendVieLv playerData = ExtendVieLv.get(player);
        NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player));
        if (savedData != null) {
        playerData.loadNBTData(savedData);
        }
        playerData.sync();
        }
        public String transformation(){
        if (this.LevelV == 0){this.Lv = "0";}
        if (this.LevelV == 1){this.Lv = "1";}
        if (this.LevelV == 2){this.Lv = "2";}
        if (this.LevelV == 3){this.Lv = "3";}
        if (this.LevelV == 4){this.Lv = "4";}
        if (this.LevelV == 5){this.Lv = "5";}
        if (this.LevelV == 6){this.Lv = "6";}
        if (this.LevelV == 7){this.Lv = "7";}
        if (this.LevelV == 8){this.Lv = "8";}
        if (this.LevelV == 9){this.Lv = "9";}
        if (this.LevelV == 10){this.Lv = "10";}
        if (this.LevelV == 11){this.Lv = "11";}
        if (this.LevelV == 12){this.Lv = "12";}
        if (this.LevelV == 13){this.Lv = "13";}
        if (this.LevelV == 14){this.Lv = "14";}
        if (this.LevelV == 15){this.Lv = "15";}
        if (this.LevelV == 16){this.Lv = "16";}
        if (this.LevelV == 17){this.Lv = "17";}
        if (this.LevelV == 18){this.Lv = "18";}
        if (this.LevelV == 19){this.Lv = "19";}
        if (this.LevelV == 20){this.Lv = "20";}
        return Lv;}
        public Long transformation2(){
        if(this.Lv=="0"){this.LevelV=0;};
        if(this.Lv=="1"){this.LevelV=1;};
        if(this.Lv=="2"){this.LevelV=2;};
        if(this.Lv=="3"){this.LevelV=3;};
        if(this.Lv=="4"){this.LevelV=4;};
        if(this.Lv=="5"){this.LevelV=5;};
        if(this.Lv=="6"){this.LevelV=6;};
        if(this.Lv=="7"){this.LevelV=7;};
        if(this.Lv=="8"){this.LevelV=8;};
        if(this.Lv=="9"){this.LevelV=9;};
        if(this.Lv=="10"){this.LevelV=10;};
        if(this.Lv=="11"){this.LevelV=11;};
        if(this.Lv=="12"){this.LevelV=12;};
        if(this.Lv=="13"){this.LevelV=13;};
        if(this.Lv=="14"){this.LevelV=14;};
        if(this.Lv=="15"){this.LevelV=15;};
        if(this.Lv=="16"){this.LevelV=16;};
        if(this.Lv=="17"){this.LevelV=17;};
        if(this.Lv=="18"){this.LevelV=18;};
        if(this.Lv=="19"){this.LevelV=19;};
        if(this.Lv=="20"){this.LevelV=20;};
        return LevelV;
        }
        public boolean LvUp() {
        System.out.println(player);
        if (LevelV < 10 ){
        this.LevelV += 1;
        AttributeModifier moreHealth = new AttributeModifier(player.getPersistentID(), "Test",4*LevelV, 0).setSaved(true); 
        IAttributeInstance attributeinstance = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
        attributeinstance.removeModifier(moreHealth);
        attributeinstance.applyModifier(moreHealth);
        this.sync();
        return true;}
        else{
        return false;}
        }
        public void Lv(){
        System.out.println("Ca lance");
        System.out.println(LevelV);
        if (this.LevelV > 0){
        System.out.println("Le if passe");
        AttributeModifier moreHealth = new AttributeModifier(player.getPersistentID(), "Test",4*LevelV, 0).setSaved(true); 
        System.out.println("Le if passe 2");
        IAttributeInstance attributeinstance = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
        System.out.println("Le if passe 3");
        attributeinstance.removeModifier(moreHealth);
        attributeinstance.applyModifier(moreHealth);
        System.out.println("Ca lance version 2");
        player.addPotionEffect(new PotionEffect(6,1));
        player.addPotionEffect(new PotionEffect(7,1));
        player.addPotionEffect(new PotionEffect(10,800,1));
        System.out.println("Effet de potion passé");}}
        public void Check(){
        this.transformation();
        System.out.println(Lv);
        player.addChatMessage(new ChatComponentText(Lv));
        }
        private void Lv1() {
        // TODO Auto-generated method stub
        }
        @Override
        public void init(Entity entity, World world) {}
        }

        La classe d’event :

        public class EventHardler {
        public EntityPlayer player;
        @SubscribeEvent
        public void onEntityConstructing(EntityConstructing event) {
        if (event.entity instanceof EntityPlayer&& ExtendVieLv.get((EntityPlayer) event.entity) == null)
        ExtendVieLv.register((EntityPlayer) event.entity);}
        @SubscribeEvent
        public void onLivingDeathEvent(LivingDeathEvent event) {
        if (!event.entity.worldObj.isRemote&& event.entity instanceof EntityPlayer) {
        ExtendVieLv props = ExtendVieLv.get((EntityPlayer) event.entity);
        props.Lv();
        NBTTagCompound playerData = new NBTTagCompound();
        ((ExtendVieLv) (event.entity.getExtendedProperties(ExtendVieLv.EXT_Vie))).saveNBTData(playerData);
        CommonProxy.storeEntityData(((EntityPlayer) event.entity).getDisplayName(), playerData);
        ExtendVieLv.saveProxyData((EntityPlayer) event.entity);} else {}
        }
        @SubscribeEvent
        public void onEntityJoinWorld(EntityJoinWorldEvent event) {
        if (!event.entity.worldObj.isRemote&& event.entity instanceof EntityPlayer) {
        ExtendVieLv props = ExtendVieLv.get((EntityPlayer) event.entity);
        props.Lv();
        NBTTagCompound playerData = CommonProxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
        if (playerData != null) {
        ((ExtendVieLv) (event.entity.getExtendedProperties(ExtendVieLv.EXT_Vie))).loadNBTData(playerData);}
        ((ExtendVieLv) (event.entity.getExtendedProperties(ExtendVieLv.EXT_Vie))).sync();}}}

        PS : pour ceux qui mon conseillé de modifié transformation, les solutions qui mon était donné sont détecté comme des erreurs néanmoins merci quand même cela me permettras de savoir quoi rechercher.

        1 réponse Dernière réponse Répondre Citer 0
        • BrokenSwing
          BrokenSwing Moddeurs confirmés Rédacteurs dernière édition par 3 juil. 2016, 12:42

          Ou il y a encore

          chaineCaractere = "" + nombre;
          1 réponse Dernière réponse Répondre Citer 0
          • Y
            yveslefou dernière édition par 3 juil. 2016, 13:24

            @‘BrokenSwing’:

            Ou il y a encore

            chaineCaractere = "" + nombre;

            Je vais essayer et sinon aurais tu une idée pourquoi lorsque le joueur LevelV tombe à zero mais a bien sa valeur lorsqu’il change de monde ?

            1 réponse Dernière réponse Répondre Citer 0
            • RedRelay
              RedRelay Moddeurs confirmés dernière édition par 5 juil. 2016, 01:48

              @‘BrokenSwing’:

              Ou il y a encore

              chaineCaractere = "" + nombre;

              Ce qui après compilation revient a new StringBuilder(“”).append(Integer.toString(nombre)).toString().
              Donc méthode de crado moins performante

              –------------------------------------------------------------------------------------
              Si tu trouves mon intervention pertinente, n'hésite pas a m…

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

              MINECRAFT FORGE FRANCE © 2018

              Powered by NodeBB