MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    OnItemRightClick sur une entity.

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    125 Messages 8 Publieurs 21.6k Vues 1 Watching
    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.
    • BrokenSwingB Hors-ligne
      BrokenSwing Moddeurs confirmés Rédacteurs
      dernière édition par

      ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(player);
      prop.setAlcool(prop.getAlcool() + 1);
      
      1 réponse Dernière réponse Répondre Citer 1
      • robin4002R Hors-ligne
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
        dernière édition par

        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
        • BrokenSwingB Hors-ligne
          BrokenSwing Moddeurs confirmés Rédacteurs
          dernière édition par

          **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
          • robin4002R Hors-ligne
            robin4002 Moddeurs confirmés Rédacteurs Administrateurs
            dernière édition par

            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
            • GabsG Hors-ligne
              Gabs
              dernière édition par

              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
              • robin4002R Hors-ligne
                robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                dernière édition par

                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
                • GabsG Hors-ligne
                  Gabs
                  dernière édition par

                  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
                  • robin4002R Hors-ligne
                    robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                    dernière édition par

                    Mets directement return this.alcool;

                    1 réponse Dernière réponse Répondre Citer 0
                    • BrokenSwingB Hors-ligne
                      BrokenSwing Moddeurs confirmés Rédacteurs
                      dernière édition par

                      "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
                      • GabsG Hors-ligne
                        Gabs
                        dernière édition par

                        pareil marche toujours pas 😕

                        1 réponse Dernière réponse Répondre Citer -1
                        • GabsG Hors-ligne
                          Gabs
                          dernière édition par

                          Quelqu’un ?

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

                            Renvoies ton code actuel.

                            1 réponse Dernière réponse Répondre Citer 0
                            • GabsG Hors-ligne
                              Gabs
                              dernière édition par

                              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_1803S Hors-ligne
                                Snowy_1803
                                dernière édition par

                                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
                                • GabsG Hors-ligne
                                  Gabs
                                  dernière édition par

                                  J’essaye ça je vous dis

                                  1 réponse Dernière réponse Répondre Citer 0
                                  • BrokenSwingB Hors-ligne
                                    BrokenSwing Moddeurs confirmés Rédacteurs
                                    dernière édition par

                                    @‘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
                                    • GabsG Hors-ligne
                                      Gabs
                                      dernière édition par

                                      Niquel merci

                                      1 réponse Dernière réponse Répondre Citer 0
                                      • GabsG Hors-ligne
                                        Gabs
                                        dernière édition par

                                        Juste une dernière question si je veux faire baisser le niveau d’alcoolémie de 1 au bout de 15 minutes je dois faire comment ?

                                        1 réponse Dernière réponse Répondre Citer 0
                                        • DeletedD Hors-ligne
                                          Deleted
                                          dernière édition par

                                          TickHandler avec la variable getTotalWorldTime() + modulo

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

                                            TickEvent.PlayerTickEvent*
                                            L’interface ITickHandler n’existe plus depuis la 1.7

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

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB