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 je vais essayer ça :)___```java
      @SubscribeEvent
         public void onPlayerTrade(EntityInteractEvent event)
         {
             if(event.target instanceof EntityPlayer)
                 if(event.entityPlayer.worldObj != null && event.entityPlayer != null)
                  if (lvl != 0)
                     lvl2 = Math.abs(lvl / 2);
                   else if (lvl == 0) {
                     lvl2 = Math.abs(lvl);
                   }
                   this.lvlS = Integer.toString(lvl2);
                     System.out.println(“Interaction avec un joueur réussie !”);
         }

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

        C’est normal, le problème d’interaction est résolu, ce qu’il faut c’est enregistré le taux d’alcoolémie :

        Classe du ExtendedEntityProperties :

        
        public class ExtendedEntityPropAlcool implements IExtendedEntityProperties {
        
        public final static String EXT_PROP_NAME = "ExtPropAlcool";
        private int alcool;
        private final EntityPlayer player;
        
        public ExtendedEntityPropAlcool(EntityPlayer player) {
        this.alcool = 0
        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);
        AltisMine.tonNetworkPourLesPackets.sendToServer(packetAlcool);
        
        if (!player.worldObj.isRemote)
        {
        EntityPlayerMP playerClient = (EntityPlayerMP) this.player;
        AltisMine.tonNetworkPourLesPackets.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() {
        return this.alcool;
        }
        
        }
        
        

        Voilà, je pense que tu aurait pu faire ça en suivant le tuto

        Maintenant dans ton event handler :

        
        @SubscribeEvent
        public void onEntityConstructing(EntityConstructing event) {
        
        if (event.entity instanceof EntityPlayer
        && ExtendedEntityPropAlcool.get((EntityPlayer) event.entity) == null)
        
        ExtendedEntityPropAlcool.register((EntityPlayer) event.entity);
        }
        
        @SubscribeEvent
        public void onEntityJoinWorld(EntityJoinWorldEvent event) {
        if (!event.entity.worldObj.isRemote
        && event.entity instanceof EntityPlayer) {
        NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
        if (playerData != null) {
        ((ExtendedEntityPropAlcool) (event.entity.getExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME))).loadNBTData(playerData);
        }
        
        ((ExtendedEntityPropAlcool) (event.entity.getExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME))).sync();
        }
        }
        
        

        La classe du packet :

        
        public class PacketAlcool implements IMessage, IMessageHandler <packettrafficchannel, imessage="">{
        
        private int alcool;
        
        public PacketAlcool() {}
        
        public PacketAlcool(int alcool) {
        this.alcool = alcool;
        }
        
        @Override
        public IMessage onMessage(PacketAlcool message, MessageContext ctx) {
        EntityPlayerMP player = ctx.getServerHandler().playerEntity;
        ExtendedEntityPropAlcool props = ExtendedEntityPropAlcool
        .get(player);
        props.setAlcool(message.alcool);
        }
        
        @Override
        public void fromBytes(ByteBuf buf) {
        this.alcool = buf.readInt();
        }
        
        @Override
        public void toBytes(ByteBuf buf) {
        buf.writeInt(this.alcool);
        }
        
        }
        
        

        Je pense que pour le CommonProxy tu va y arriver (j’espère du moins) et tu doit enregistrer ton packet pour qu’il puisse aller vers les deux sides

        Il y a sûrement des erreurs, j’ai rien testé, ça correspond à un copié-collé du tuto plus ou moins adapté à ta situation, si avec ça tu n’y arrive pas bah on t’aidera

        Et regarde bien comment fonctionne le code, c’est très simple, il faudra que tu récupère le taux d’alcoolémie du joueur sur lequel tu fait clique droit avec la fonction get</packettrafficchannel,>

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

          Yep merci juste un petit prob sur le commonProxy.

          Code:

          private static final Map <string, nbttagcompound="">extendedEntityData = new HashMap<string, nbttagcompound="">();
          
          public static NBTTagCompound getEntityData(String displayName) {
          return extendedEntityData.remove(**name**);
          return null;
          }
          
          public static void storeEntityData(String saveKey, NBTTagCompound savedData) {
          extendedEntityData.put(**name**, **compound**);
          
          }
          
          

          Je dois mettre quoi a la place de (**name **et compound) ?</string,></string,>

          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

            …
            Faut apprendre la programmation en Java. Car franchement c’est évidant. Regardes les arguments de la fonction.

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

              yep thx jsuis con

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

                J’ai une petite erreur sur le network.registerMessage
                Screen:
                http://puu.sh/m5g7X/80ea7371c8.PNG

                Class (PackerAlcool):

                package com.AltisMine.mod;
                
                import io.netty.buffer.ByteBuf;
                import net.minecraft.entity.player.EntityPlayer;
                import net.minecraft.entity.player.EntityPlayerMP;
                import net.minecraft.nbt.NBTTagCompound;
                import net.minecraftforge.event.entity.EntityJoinWorldEvent;
                import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
                import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                import cpw.mods.fml.common.network.simpleimpl.IMessage;
                import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
                import cpw.mods.fml.common.network.simpleimpl.MessageContext;
                
                public class PacketAlcool implements IMessage, IMessageHandler <packettrafficchannel, imessage="">{
                
                public class Handler {
                
                @SubscribeEvent
                public void onEntityConstructing(EntityConstructing event) {
                
                if (event.entity instanceof EntityPlayer
                && ExtendedEntityPropAlcool.get((EntityPlayer) event.entity) == null)
                
                ExtendedEntityPropAlcool.register((EntityPlayer) event.entity);
                }
                
                       @SubscribeEvent
                public void onEntityJoinWorld(EntityJoinWorldEvent event) {
                if (!event.entity.worldObj.isRemote
                && event.entity instanceof EntityPlayer) {
                NBTTagCompound playerData = AltisMineMod.proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
                if (playerData != null) {
                ((ExtendedEntityPropAlcool) (event.entity.getExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME))).loadNBTData(playerData);
                }
                
                ((ExtendedEntityPropAlcool) (event.entity.getExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME))).sync();
                }
                       }
                }
                
                private int alcool;
                
                public PacketAlcool() {}
                
                public PacketAlcool(int alcool) {
                this.alcool = alcool;
                }
                
                public IMessage onMessage(PacketAlcool message, MessageContext ctx) {
                EntityPlayerMP player = ctx.getServerHandler().playerEntity;
                ExtendedEntityPropAlcool props = ExtendedEntityPropAlcool
                .get(player);
                props.setAlcool(message.alcool);
                return message;
                }
                
                @Override
                public void fromBytes(ByteBuf buf) {
                                this.alcool = buf.readInt();
                }
                
                @Override
                public void toBytes(ByteBuf buf) {
                                buf.writeInt(this.alcool);
                }
                
                @Override
                public IMessage onMessage(PacketTrafficChannel message, MessageContext ctx) {
                // TODO Auto-generated method stub
                return null;
                }
                
                }
                
                ```</packettrafficchannel,>
                1 réponse Dernière réponse Répondre Citer 0
                • BrokenSwingB Hors-ligne
                  BrokenSwing Moddeurs confirmés Rédacteurs
                  dernière édition par

                  Fait comme ça :

                  network.registerMessage(PacketAlcool.class, PacketAlcool.class, 1, Side.SERVER);
                  
                  1 réponse Dernière réponse Répondre Citer 0
                  • GabsG Hors-ligne
                    Gabs
                    dernière édition par

                    J’ai la même érreur

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

                      Envoie ta classe principale et ton packet

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

                        Class Principale:

                        Class Packet:

                        package com.AltisMine.mod;
                        
                        import io.netty.buffer.ByteBuf;
                        import net.minecraft.entity.player.EntityPlayer;
                        import net.minecraft.entity.player.EntityPlayerMP;
                        import net.minecraft.nbt.NBTTagCompound;
                        import net.minecraftforge.event.entity.EntityJoinWorldEvent;
                        import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
                        import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                        import cpw.mods.fml.common.network.simpleimpl.IMessage;
                        import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
                        import cpw.mods.fml.common.network.simpleimpl.MessageContext;
                        
                        public class PacketAlcool implements IMessage, IMessageHandler <packettrafficchannel, imessage="">{
                        
                        public class Handler {
                        
                        @SubscribeEvent
                        public void onEntityConstructing(EntityConstructing event) {
                        
                        if (event.entity instanceof EntityPlayer
                        && ExtendedEntityPropAlcool.get((EntityPlayer) event.entity) == null)
                        
                        ExtendedEntityPropAlcool.register((EntityPlayer) event.entity);
                        }
                        
                               @SubscribeEvent
                        public void onEntityJoinWorld(EntityJoinWorldEvent event) {
                        if (!event.entity.worldObj.isRemote
                        && event.entity instanceof EntityPlayer) {
                        NBTTagCompound playerData = AltisMineMod.proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
                        if (playerData != null) {
                        ((ExtendedEntityPropAlcool) (event.entity.getExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME))).loadNBTData(playerData);
                        }
                        
                        ((ExtendedEntityPropAlcool) (event.entity.getExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME))).sync();
                        }
                               }
                        }
                        
                        private int alcool;
                        
                        public PacketAlcool() {}
                        
                        public PacketAlcool(int alcool) {
                        this.alcool = alcool;
                        }
                        
                        public IMessage onMessage(PacketAlcool message, MessageContext ctx) {
                        EntityPlayerMP player = ctx.getServerHandler().playerEntity;
                        ExtendedEntityPropAlcool props = ExtendedEntityPropAlcool
                        .get(player);
                        props.setAlcool(message.alcool);
                        return message;
                        }
                        
                        @Override
                        public void fromBytes(ByteBuf buf) {
                                        this.alcool = buf.readInt();
                        }
                        
                        @Override
                        public void toBytes(ByteBuf buf) {
                                        buf.writeInt(this.alcool);
                        }
                        
                        @Override
                        public IMessage onMessage(PacketTrafficChannel message, MessageContext ctx) {
                        // TODO Auto-generated method stub
                        return null;
                        }
                        
                        }
                        
                        ```</packettrafficchannel,>
                        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

                          La classe de ton paquet est complètement fausse.
                          Je t’invite à aller voir le tutoriel sur les paquets du site.

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

                            Ouais merci prob résolu je vais essayé ça je vous dis la réponse .
                            Class packet ( ou cas ou si j’aurai oublier quelques trucs ) :

                            public class PacketAlcool implements IMessage{
                            
                            private int alcool;
                            
                            public PacketAlcool() {}
                            
                            public PacketAlcool(int alcool) {
                            this.alcool = alcool;
                            }
                            
                            @Override
                            public void fromBytes(ByteBuf buf) {
                                            this.alcool = buf.readInt();
                            }
                            
                            @Override
                            public void toBytes(ByteBuf buf) {
                                            buf.writeInt(this.alcool);
                            }
                            
                             public static class Handler implements IMessageHandler <packetalcool, imessage="">{
                            
                            @Override
                            public IMessage onMessage(PacketAlcool message, MessageContext ctx) {
                            EntityPlayerMP player = ctx.getServerHandler().playerEntity;
                            ExtendedEntityPropAlcool props = ExtendedEntityPropAlcool
                            .get(player);
                            props.setAlcool(message.alcool);
                            return message;
                            }
                             }
                            
                            }
                            
                            ```</packetalcool,>
                            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

                              C’est en effet mieux comme ça.
                              Ça ne fonctionne toujours pas ?

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

                                sisi c’est bon l’erreur est réglée il manque juste que je l’essaye sur mon serveur

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

                                  Marche pas je crois que vous avez pas compris se que je voulais faire.
                                  Je veux faire que l’osque que on clic droit sur un joueur on obtient son niveau d’alcoolémie .
                                  //EDIT:
                                  Les codes marches mais le problème c’est que ça prend mon niveau d’alcoolémie l’osque je fais clic droit sur un joueur et pas celui du joueur …

                                  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

                                    Envoies un .zip de ton dossier src je vais regarder de mon côté.

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

                                      J’ai pas pu te le mettre en pièce jointe c’est trop lourd du coup tien:
                                      http://armacraft.net/Flow/src.zip
                                      Attend encore quelques minutes c’est en upload d’ici 2min c’est bon

                                      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

                                        Au pire je me serai passé des 25 mo de son x)

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

                                          C’est vrai ^^ j’avais la flemme 🙂

                                          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

                                            Ho putain le truc horrible que tu as fait x)
                                            En plus ça ne risque pas du tout de fonctionner car tu utilises la même instance pour tout et en plus qui sort de nul part. En gros là si un joueur bois ça va augmenter le niveau d’alcool de tout le monde …
                                            Voila un truc plus propre :

                                            package com.AltisMine.mod;
                                            
                                            import ibxm.Player;
                                            
                                            import java.util.List;
                                            
                                            import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                            import net.minecraft.client.renderer.texture.IIconRegister;
                                            import net.minecraft.entity.Entity;
                                            import net.minecraft.entity.EntityLivingBase;
                                            import net.minecraft.entity.player.EntityPlayer;
                                            import net.minecraft.item.Item;
                                            import net.minecraft.item.ItemStack;
                                            import net.minecraft.nbt.NBTTagCompound;
                                            import net.minecraft.util.ChatComponentText;
                                            import net.minecraft.world.World;
                                            import net.minecraftforge.common.util.Constants;
                                            import net.minecraftforge.event.entity.player.EntityInteractEvent;
                                            
                                            public class AT extends Item
                                            {
                                            public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity)
                                            {
                                            if(entity instanceof EntityPlayer)
                                            {
                                            EntityPlayer target = (EntityPlayer)entity;
                                            if(!stack.hasTagCompound())
                                            {
                                            stack.setTagCompound(new NBTTagCompound());
                                            }
                                            ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(target);
                                            stack.getTagCompound().setInteger("level", prop.getAlcool());
                                            }
                                            return true;
                                            }
                                            
                                            public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
                                            {
                                            if(!stack.hasTagCompound())
                                            {
                                            stack.setTagCompound(new NBTTagCompound());
                                            }
                                            if(stack.getTagCompound().hasKey("level", Constants.NBT.TAG_INT))
                                            {
                                            list.add("le niveau d'alcoolemie de la personne est de : " + stack.getTagCompound().getInteger("level"));
                                            }
                                            else
                                            {
                                            list.add("Faite clic droit sur le joueur pour ");
                                            list.add("obtenir son niveau d'alcoolemie.");
                                            }
                                            }
                                            }
                                            

                                            Et du-coup dans tes items comme IMF tu vires ça :
                                            AT alcohol = new AT();
                                            public int Fixlvl = 0;
                                            Et tu définie le niveau d’alcool dans ExtendedEntityPropAlcool

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

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB