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

                                  J’ai trouvais ça sur internet je dois définir le nombre de tick comment?

                                  @SubscribeEvent
                                  public void onPlayerTickEvent(TickEvent.PlayerTickEvent event) {
                                      if (event.phase == TickEvent.Phase.START && !event.player.worldObj.isRemote) {
                                          IExtendedEntityProperties properties = event.player.getExtendedProperties(PlayerExtendedProperties.ID);
                                          if (properties instanceof PlayerExtendedProperties) {
                                              PlayerExtendedProperties playerExtendedProperties = (PlayerExtendedProperties) properties;
                                              playerExtendedProperties.tick();
                                          }
                                          properties = event.player.getExtendedProperties(PlayerPreferencesProperties.ID);
                                          if (properties instanceof PlayerPreferencesProperties) {
                                              PlayerPreferencesProperties preferencesProperties = (PlayerPreferencesProperties) properties;
                                              preferencesProperties.tick(RFToolsMessages.INSTANCE);
                                          }
                                      }
                                  }
                                  
                                  1 réponse Dernière réponse Répondre Citer 0
                                  • DeletedD Hors-ligne
                                    Deleted
                                    dernière édition par

                                    Le nombre de tick à la seconde est déjà défini.
                                    Ton code va logiquement crash car worldObj sera null lorsque le menu principal sera ouvert.
                                    Du coup null-check pour le world et pour faire vérifier un code tous les x nbre de tick, c’est comme ça

                                    
                                    if(event.player.worldObj.getTotalWorldTime() % (nbreDeSecondes * 20) == 0
                                    {
                                    System.out.println("ton code à exécuter avec ton ExtProp");
                                    }
                                    
                                    
                                    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

                                      PlayerTickEvent n’est que appelé en jeu, donc normalement event.player.worldObj ne sera jamais nul. Pas besoin de null check.

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

                                        Ok je reverrai mes sources la prochaine fois 😉

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

                                          J’ai fais sa je suis pas trop sur que ça marche…

                                            @SubscribeEvent
                                            public void onPlayerTickEvent(TickEvent.PlayerTickEvent event) {
                                          
                                            if(event.player.worldObj.getTotalWorldTime() % (60 * 20) == 0)
                                            {
                                            ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(event.player);
                                                 prop.setAlcool(prop.getAlcool() - 1);
                                            System.out.println("Test!");
                                            }
                                            }
                                          
                                          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

                                            Normalement ça devrait être bon.
                                            Regardes en jeu si Test ! s’affiche. Si ce n’est pas le cas c’est surement car ta classe n’est pas enregistré avec FMLCommonHandler.instance().bus().register(new NomDeTaClasseD’event());

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

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB