• 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 OnItemRightClick sur une entity.

1.7.x
1.7.10
8
125
19.5k
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.
  • Gabs
    Gabs dernière édition par 24 déc. 2015, 15:09

    Ouaip merci j’essaye ça je vous dis.

    1 réponse Dernière réponse Répondre Citer 0
    • Gabs
      Gabs dernière édition par 24 déc. 2015, 15:36

      Crash réglé mais quand un joueur boit et que j’interagi avec le clic droit sa m’indique 0 et quand on inverse c’est pareil 0 aussi.

      1 réponse Dernière réponse Répondre Citer 0
      • robin4002
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 24 déc. 2015, 15:52

        Tu as bien changé le code dans les autres items ?

        1 réponse Dernière réponse Répondre Citer 0
        • Gabs
          Gabs dernière édition par 25 déc. 2015, 17:05

          J’ai j’ai changer la class At qui permet de prendre le niveau d’alcool par contre j’ai pas touché a la class LIIT qui est la class pour les boissons d’alcool est donc normalement ajouté le niveau d’alcool .

          package com.AltisMine.mod;
          import net.minecraft.entity.player.EntityPlayer;
          import net.minecraft.item.EnumAction;
          import net.minecraft.item.ItemFood;
          import net.minecraft.item.ItemStack;
          import net.minecraft.potion.Potion;
          import net.minecraft.potion.PotionEffect;
          import net.minecraft.world.World;
          public class LIIT extends ItemFood {
           AT alcohol = new AT();
          public LIIT (int itemID, int i, boolean b)
           {
             super(itemID, i, b);
          }
           public EnumAction getItemUseAction(ItemStack itemstack)
           {
             return EnumAction.drink;
           }
             public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
             {
                 if (player.canEat(true))
                 {
                     player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
                 }
                 return stack;
             }
             public int getMaxItemUseDuration(ItemStack stack)
             {
                 return 32;
             }
             public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player)
             {
                 –stack.stackSize;
                 ExtendedEntityPropAlcool.alcoolvl = Math.abs(ExtendedEntityPropAlcool.alcoolvl +1);
                 player.getFoodStats().addStats(1, 2); // nombre de demi-gigots + saturation
                 world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
                 player.addPotionEffect(new PotionEffect(Potion.confusion.id, 315,0));
                 player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 315,0));
                 player.addPotionEffect(new PotionEffect(Potion.hunger.id, 315,0));
                 player.addPotionEffect(new PotionEffect(Potion.weakness.id, 315,0));
          return stack;
             }
             @Override
           public boolean hasEffect(ItemStack par1ItemStack){
            return true;
           }
          }
          1 réponse Dernière réponse Répondre Citer 0
          • BrokenSwing
            BrokenSwing Moddeurs confirmés Rédacteurs dernière édition par 25 déc. 2015, 17:42

            ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(player);
            prop.setAlcool(prop.getAlcool() + 1);
            1 réponse Dernière réponse Répondre Citer 1
            • robin4002
              robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 25 déc. 2015, 18:45

              Et la variable alcoolvl de la classe ExtendedEntityPropAlcool ne doit pas être static. Sinon ton ExtendedEntityPropAlcool n’a plus aucun intérêt (les instances ça fait partie de la base Java vivement que le tutoriel soit publié).

              1 réponse Dernière réponse Répondre Citer 0
              • BrokenSwing
                BrokenSwing Moddeurs confirmés Rédacteurs dernière édition par 25 déc. 2015, 19:05

                **Hors-Sujet : ** Oui mais est-ce-que ceux qui ne prenez même pas la peine d’apprendre le Java sur OpenClassroom prendront la peine de regarder des tutoriels de Java sur MFF ? C’est la question que je me pose …
                Vu que c’est du hors-sujet tu peux supprimer le message, je soulevais juste la question

                1 réponse Dernière réponse Répondre Citer 0
                • robin4002
                  robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 25 déc. 2015, 19:15

                  Une fois que le tutoriel sera disponible je ne vais plus m’embêter. Si quelqu’un demande de l’aide dans support pour les moddeurs et que je remarque que le minimum nécessaire pour coder en Java n’est pas acquis ça sera lock + lien vers le tutoriel.
                  À la base la description de la section c’est ça :

                  Il s’agit de la section de support pour ceux qui créent des mods avec Forge. L’aide au modding va ici, cependant, gardez à l’esprit que ce n’est pas une école de programmation Java. Vous êtes censé avoir au moins certaines base de Java avant de poster ici.

                  1 réponse Dernière réponse Répondre Citer 0
                  • Gabs
                    Gabs dernière édition par 25 déc. 2015, 21:34

                    J’ai fais comme vous avez dis mais j’ai un problème encore :
                    Detected ongoing potential memory leak. 4000 packets have leaked. Top offenders
                    [22:36:38] [Client thread/ERROR] [FML]: amm: : 4000
                    [22:36:38] [Client thread/ERROR] [FML]: Detected ongoing potential memory leak. 4100 packets have leaked. Top offenders
                    fuite de mémoire …
                    Class item:

                    public class LIIT extends ItemFood {
                     AT alcohol = new AT();
                    public LIIT (int itemID, int i, boolean b)
                     {
                       super(itemID, i, b);
                    }
                     public EnumAction getItemUseAction(ItemStack itemstack)
                     {
                       return EnumAction.drink;
                     }
                       public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
                       {
                           if (player.canEat(true))
                           {
                               player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
                           }
                           return stack;
                       }
                       public int getMaxItemUseDuration(ItemStack stack)
                       {
                           return 32;
                       }
                       public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player)
                       {
                           –stack.stackSize;
                           ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(player);
                           prop.setAlcool(prop.getAlcool() + 1);
                           player.getFoodStats().addStats(1, 2); // nombre de demi-gigots + saturation
                           world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
                           player.addPotionEffect(new PotionEffect(Potion.confusion.id, 315,0));
                           player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 315,0));
                           player.addPotionEffect(new PotionEffect(Potion.hunger.id, 315,0));
                           player.addPotionEffect(new PotionEffect(Potion.weakness.id, 315,0));
                    return stack;
                       }
                       @Override
                     public boolean hasEffect(ItemStack par1ItemStack){
                      return true;
                     }
                    }

                    class ExtendedEntity:

                    public class ExtendedEntityPropAlcool implements IExtendedEntityProperties {
                        public final static String EXT_PROP_NAME = "ExtPropAlcool";
                        private int alcool = 0;
                        private final EntityPlayer player;
                        public ExtendedEntityPropAlcool(EntityPlayer player) {
                                this.player = player;
                    }
                    @Override
                    public void saveNBTData(NBTTagCompound compound) {
                                NBTTagCompound properties = new NBTTagCompound();
                    properties.setInteger("alcool", this.alcool);
                    compound.setTag(EXT_PROP_NAME, properties);
                    }
                    @Override
                    public void loadNBTData(NBTTagCompound compound) {
                                NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
                    this.alcool = properties.getInteger("alcool");
                    }
                    @Override
                    public void init(Entity entity, World world) {
                    // TODO Auto-generated method stub
                    }
                        public static final void register(EntityPlayer player) {
                    player.registerExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME,
                    new ExtendedEntityPropAlcool(player));
                    }
                    public static final ExtendedEntityPropAlcool get(EntityPlayer player) {
                    return (ExtendedEntityPropAlcool) player.getExtendedProperties(EXT_PROP_NAME);
                    }
                        public final void sync() 
                        {
                    PacketAlcool packetAlcool = new PacketAlcool(this.alcool);
                          AltisMineMod.network.sendToServer(packetAlcool);
                    if (!player.worldObj.isRemote) 
                                {
                    EntityPlayerMP playerClient = (EntityPlayerMP) this.player;
                    AltisMineMod.network.sendTo(packetAlcool, playerClient);
                    }
                    }
                       private static String getSaveKey(EntityPlayer player) {
                    return player.getDisplayName() + ":" + EXT_PROP_NAME;
                    }
                    public static void saveProxyData(EntityPlayer player) {
                    ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player);
                    NBTTagCompound savedData = new NBTTagCompound();
                    playerData.saveNBTData(savedData);
                    CommonProxy.storeEntityData(getSaveKey(player), savedData);
                    }
                    public static void loadProxyData(EntityPlayer player) {
                    ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player);
                    NBTTagCompound savedData = CommonProxy
                    .getEntityData(getSaveKey(player));
                    if (savedData != null) {
                    playerData.loadNBTData(savedData);
                    }
                    playerData.sync();
                    }
                       public void setAlcool(int taux) {
                               this.alcool = taux;
                               this.sync();
                       }
                       public int getAlcool() {
                    this.alcool = 0;
                    if (alcool != 0)
                    alcool = Math.abs(alcool / 2);
                      else if (alcool == 0) {
                      alcool = Math.abs(alcool);
                      }
                               return this.alcool;
                       }
                    }
                    1 réponse Dernière réponse Répondre Citer 0
                    • robin4002
                      robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 25 déc. 2015, 22:35

                      public final void sync()
                      {
                          PacketAlcool packetAlcool = new PacketAlcool(this.alcool);
                          AltisMineMod.network.sendToServer(packetAlcool);
                          if (!player.worldObj.isRemote)
                          {
                              EntityPlayerMP playerClient = (EntityPlayerMP) this.player;
                              AltisMineMod.network.sendTo(packetAlcool, playerClient);
                          }
                      }

                      Change en :

                      public final void sync()
                      {
                         PacketAlcool packetAlcool = new PacketAlcool(this.alcool);
                         if (!player.worldObj.isRemote)
                         {
                             EntityPlayerMP playerClient = (EntityPlayerMP) this.player;
                             AltisMineMod.network.sendTo(packetAlcool, playerClient);
                         }
                         else
                         {
                             AltisMineMod.network.sendToServer(packetAlcool);
                         }
                      }
                      1 réponse Dernière réponse Répondre Citer 0
                      • Gabs
                        Gabs dernière édition par 25 déc. 2015, 23:13

                        Merci problème réglé par conte c’est exactement pareil 0 même lorsque on boit.

                        Edit:
                        Je suis sur que le problème vient d’ici:

                        public int getAlcool() {
                        this.alcool = 0;
                        if (alcool != 0)
                        alcool = Math.abs(alcool / 2);
                          else if (alcool == 0) {
                          alcool = Math.abs(alcool);
                          }
                                   return this.alcool;
                           }
                        }
                        1 réponse Dernière réponse Répondre Citer 0
                        • robin4002
                          robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 26 déc. 2015, 00:44

                          Mets directement return this.alcool;

                          1 réponse Dernière réponse Répondre Citer 0
                          • BrokenSwing
                            BrokenSwing Moddeurs confirmés Rédacteurs dernière édition par 26 déc. 2015, 00:52

                            "Je comprend pas pourquoi ça renvoie toujours 0 … : "
                            public int getAlcool() {
                            this.alcool = 0;

                            xD

                            1 réponse Dernière réponse Répondre Citer 0
                            • Gabs
                              Gabs dernière édition par 26 déc. 2015, 12:36

                              pareil marche toujours pas 😕

                              1 réponse Dernière réponse Répondre Citer -1
                              • Gabs
                                Gabs dernière édition par 27 déc. 2015, 17:17

                                Quelqu’un ?

                                1 réponse Dernière réponse Répondre Citer 0
                                • robin4002
                                  robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 27 déc. 2015, 18:17

                                  Renvoies ton code actuel.

                                  1 réponse Dernière réponse Répondre Citer 0
                                  • Gabs
                                    Gabs dernière édition par 27 déc. 2015, 22:33

                                    package com.AltisMine.mod;
                                    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                    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 net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
                                    public class ExtendedEntityPropAlcool implements IExtendedEntityProperties {
                                        public final static String EXT_PROP_NAME = "ExtPropAlcool";
                                        private int alcool = 0;
                                        private final EntityPlayer player;
                                        public ExtendedEntityPropAlcool(EntityPlayer player) {
                                                this.player = player;
                                    }
                                    @Override
                                    public void saveNBTData(NBTTagCompound compound) {
                                                NBTTagCompound properties = new NBTTagCompound();
                                    properties.setInteger("alcool", this.alcool);
                                    compound.setTag(EXT_PROP_NAME, properties);
                                    }
                                    @Override
                                    public void loadNBTData(NBTTagCompound compound) {
                                                NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
                                    this.alcool = properties.getInteger("alcool");
                                    }
                                    @Override
                                    public void init(Entity entity, World world) {
                                    // TODO Auto-generated method stub
                                    }
                                        public static final void register(EntityPlayer player) {
                                    player.registerExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME,
                                    new ExtendedEntityPropAlcool(player));
                                    }
                                    public static final ExtendedEntityPropAlcool get(EntityPlayer player) {
                                    return (ExtendedEntityPropAlcool) player.getExtendedProperties(EXT_PROP_NAME);
                                    }
                                    public final void sync() 
                                    {
                                       PacketAlcool packetAlcool = new PacketAlcool(this.alcool);
                                       if (!player.worldObj.isRemote) 
                                       {
                                           EntityPlayerMP playerClient = (EntityPlayerMP) this.player;
                                           AltisMineMod.network.sendTo(packetAlcool, playerClient);
                                       }
                                       else
                                       {
                                           AltisMineMod.network.sendToServer(packetAlcool);
                                       }
                                    }
                                       private static String getSaveKey(EntityPlayer player) {
                                    return player.getDisplayName() + ":" + EXT_PROP_NAME;
                                    }
                                    public static void saveProxyData(EntityPlayer player) {
                                    ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player);
                                    NBTTagCompound savedData = new NBTTagCompound();
                                    playerData.saveNBTData(savedData);
                                    CommonProxy.storeEntityData(getSaveKey(player), savedData);
                                    }
                                    public static void loadProxyData(EntityPlayer player) {
                                    ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player);
                                    NBTTagCompound savedData = CommonProxy
                                    .getEntityData(getSaveKey(player));
                                    if (savedData != null) {
                                    playerData.loadNBTData(savedData);
                                    }
                                    playerData.sync();
                                    }
                                       public void setAlcool(int taux) {
                                               this.alcool = taux;
                                               this.sync();
                                       }
                                       public int getAlcool() {
                                    this.alcool = 0;
                                    if (alcool != 0)
                                    alcool = Math.abs(alcool / 2);
                                      else if (alcool == 0) {
                                      alcool = Math.abs(alcool);
                                      }
                                      return this.alcool;
                                       }
                                    }

                                    Class bouteille d’alcool:

                                    package com.AltisMine.mod;
                                    import net.minecraft.entity.player.EntityPlayer;
                                    import net.minecraft.item.EnumAction;
                                    import net.minecraft.item.ItemFood;
                                    import net.minecraft.item.ItemStack;
                                    import net.minecraft.potion.Potion;
                                    import net.minecraft.potion.PotionEffect;
                                    import net.minecraft.world.World;
                                    public class LIIT extends ItemFood {
                                     AT alcohol = new AT();
                                    public LIIT (int itemID, int i, boolean b)
                                     {
                                       super(itemID, i, b);
                                    }
                                     public EnumAction getItemUseAction(ItemStack itemstack)
                                     {
                                       return EnumAction.drink;
                                     }
                                       public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
                                       {
                                           if (player.canEat(true))
                                           {
                                               player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
                                           }
                                           return stack;
                                       }
                                       public int getMaxItemUseDuration(ItemStack stack)
                                       {
                                           return 32;
                                       }
                                       public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player)
                                       {
                                           –stack.stackSize;
                                           ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(player);
                                           prop.setAlcool(prop.getAlcool() + 1);
                                           player.getFoodStats().addStats(1, 2); // nombre de demi-gigots + saturation
                                           world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
                                           player.addPotionEffect(new PotionEffect(Potion.confusion.id, 315,0));
                                           player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 315,0));
                                           player.addPotionEffect(new PotionEffect(Potion.hunger.id, 315,0));
                                           player.addPotionEffect(new PotionEffect(Potion.weakness.id, 315,0));
                                    return stack;
                                       }
                                       @Override
                                     public boolean hasEffect(ItemStack par1ItemStack){
                                      return true;
                                     }
                                    }
                                    1 réponse Dernière réponse Répondre Citer 0
                                    • Snowy_1803
                                      Snowy_1803 dernière édition par 27 déc. 2015, 23:20

                                      Le getAlcool tu mets juste return alcool, c’est tout ! Pourquoi tout ce code ?

                                      Moddeur 1.8

                                      Développeur Java

                                      1 réponse Dernière réponse Répondre Citer 0
                                      • Gabs
                                        Gabs dernière édition par 28 déc. 2015, 15:43

                                        J’essaye ça je vous dis

                                        1 réponse Dernière réponse Répondre Citer 0
                                        • BrokenSwing
                                          BrokenSwing Moddeurs confirmés Rédacteurs dernière édition par 28 déc. 2015, 17:07

                                          @‘Snowy_1803’:

                                          Le getAlcool tu mets juste return alcool, c’est tout ! Pourquoi tout ce code ?

                                          Surtout que Robin le lui a déjà dit de mettre return this.alcool (et il l’a pas fait)

                                          @‘robin4002’:

                                          Mets directement return this.alcool;

                                          1 réponse Dernière réponse Répondre Citer 0
                                          • 1
                                          • 2
                                          • 3
                                          • 4
                                          • 5
                                          • 6
                                          • 7
                                          • 4 / 7
                                          65 sur 125
                                          • Premier message
                                            65/125
                                            Dernier message
                                          Design by Woryk
                                          Contact / Mentions Légales

                                          MINECRAFT FORGE FRANCE © 2018

                                          Powered by NodeBB