MFF

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

    Encore problème onUpdate

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    104 Messages 8 Publieurs 18.1k 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.
    • DeletedD Hors-ligne
      Deleted
      dernière édition par

      Rajoute un null check pour ta variable stack, avant le setTagCompound

      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

        Si tu n’avais pas d’item en main c’est normal que cela crash (suffit de faire ce que plaigon t’a dis).
        Si tu avais un item en main, le crash vient surement de la ligne d’après, ce que tu fais n’a pas de sens.

        Je te conseille aussi de regarder la dernière vidéo de la chaine de mff, car rester bloquer sur un simple NPE ça ne devrait pas arriver …

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

          @‘robin4002’:

          Si tu n’avais pas d’item en main c’est normal que cela crash (suffit de faire ce que plaigon t’a dis).
          Si tu avais un item en main, le crash vient surement de la ligne d’après, ce que tu fais n’a pas de sens.

          Je te conseille aussi de regarder la dernière vidéo de la chaine de mff, car rester bloquer sur un simple NPE ça ne devrait pas arriver …

          J’avais un item dans la main oui, j’ai r’ajouter un null check pour évité le crash sans item.
          Maintenant c’est le NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag(“key”); qui pose soucis .
          Je sais que se que j’ai fais n’a pas de sens mais je vois pas comment le récupéré le nbt.

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

            stack.getTagCompound() quel est le problème ?

            Envoyé via mobile

            Si je vous ai aidé, n'oubliez pas d’être heureux, j'aiderai encore +

            AymericRed, moddeur expérimenté qui aide sur ce forum et qui peut accepter de faire un mod Forge rémunéré de temps en temps.

            Mes tutos : Table de craft, plugin NEI, plugin JEI, modifier l'overlay
            Je suis un membre apprécié et joueur, j'ai déjà obtenu 6 points de réputation.

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

              @‘AymericRed’:

              stack.getTagCompound() quel est le problème ?

              Envoyé via mobile

              J’ai essayer mais j’ai eu un crash je le refais je te glisse le crash 30 secondes 🙂

              edit:

              
              [20:39:06] [Server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception
              java.lang.NullPointerException
              at net.legacymod.packets.PacketKey$Handler.onMessage(PacketKey.java:40) ~[PacketKey$Handler.class:?]
              at net.legacymod.packets.PacketKey$Handler.onMessage(PacketKey.java:1) ~[PacketKey$Handler.class:?]
              at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[SimpleChannelHandlerWrapper.class:?]
              at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[SimpleChannelHandlerWrapper.class:?]
              at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?]
              at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
              at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
              at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]
              at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]
              at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
              at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
              at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]
              at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]
              at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]
              at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
              at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
              at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
              at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]
              at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [IntegratedServer.class:?]
              at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]
              at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
              
              

              ligne 40:      NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound();

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

                Ton ItemStack est null, envoi le code

                Site web contenant mes scripts : http://SCAREXgaming.github.io

                Pas de demandes de support par MP ni par skype SVP.
                Je n'accepte sur skype que l…

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

                  @‘SCAREX’:

                  Ton ItemStack est null, envoi le code

                  Encore ?!
                  mais what?
                  tien:

                  public static class Handler implements IMessageHandler <packetkey, imessage="">{
                  
                     public IMessage onMessage(PacketKey message, MessageContext ctx) {
                  
                      ItemStack stack = ctx.getServerHandler().playerEntity.inventory.getItemStack();
                      if(stack != null){
                      stack.setTagCompound(new NBTTagCompound());
                      }
                      NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound();
                      stack.getTagCompound().setTag("key", nbt);
                      return null;
                         }
                     }
                  

                  edit: my bad ^^

                  J’ai fais ça plus de crash:

                  
                  public static class Handler implements IMessageHandler <packetkey, imessage="">{
                  
                     public IMessage onMessage(PacketKey message, MessageContext ctx) {
                  
                      ItemStack stack = ctx.getServerHandler().playerEntity.inventory.getItemStack();
                      if(stack != null){
                      stack.setTagCompound(new NBTTagCompound());
                      NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound();
                      stack.getTagCompound().setTag("key", nbt);
                      }
                      return null;
                  
                         }
                     }
                  

                  Mais bon ça me lance une flèche normale au lieux d’une flèche en feu.

                  [21:25:20] [Server thread/INFO] [STDOUT]: [net.legacymod.items.FlameBow:onPlayerStoppedUsing:142]: flèche normale
                  
                  

                  Normalement ça doit exécute ça:

                   else if (!world.isRemote && stack.getTagCompound().hasKey("key"))
                             {
                              LegacyMod.network.sendToServer(new PacketArrow(f * 2.0F, 3));
                              System.out.println("flèche en feu");
                              //stack.getTagCompound().setInteger("timer2", 0);
                             }
                  ```</packetkey,></packetkey,>
                  1 réponse Dernière réponse Répondre Citer 0
                  • SCAREXS Hors-ligne
                    SCAREX
                    dernière édition par

                    Envoi le code du paquet, celui du ClientProxy et celui de la flèche

                    Site web contenant mes scripts : http://SCAREXgaming.github.io

                    Pas de demandes de support par MP ni par skype SVP.
                    Je n'accepte sur skype que l…

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

                      @‘SCAREX’:

                      Envoi le code du paquet, celui du ClientProxy et celui de la flèche

                      Paquet:

                      
                      package net.legacymod.packets;
                      
                      import io.netty.buffer.ByteBuf;
                      import net.legacymod.LegacyMod;
                      import net.legacymod.gui.ClassesGUI;
                      import net.minecraft.client.Minecraft;
                      import net.minecraft.item.ItemStack;
                      import net.minecraft.nbt.NBTTagCompound;
                      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 PacketKey implements IMessage {
                      
                      public PacketKey(){
                      
                      }
                      
                      @Override
                      public void fromBytes(ByteBuf buf) {
                      
                      }
                      
                      @Override
                      public void toBytes(ByteBuf buf) {
                      
                      }
                      
                      public static class Handler implements IMessageHandler <packetkey, imessage="">{
                      
                         public IMessage onMessage(PacketKey message, MessageContext ctx) {
                      
                          ItemStack stack = ctx.getServerHandler().playerEntity.inventory.getItemStack();
                          if(stack != null){
                          stack.setTagCompound(new NBTTagCompound());
                          NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound();
                          stack.getTagCompound().setTag("key", nbt);
                          }
                          return null;
                      
                             }
                         }
                      }
                      
                      

                      ClientProxy:

                      
                         @SubscribeEvent
                         public void onEvent2(KeyInputEvent event)
                         {
                             if(keyBindSortG1.isPressed())
                             {
                                 keyTestTyped2();
                             }
                         }
                      
                         private void keyTestTyped2()
                         {
                          LegacyMod.network.sendToServer(new PacketKey());   // c'est pas sendto ? il me semble que si mais j'ai du oublier de le modifier. 
                         }
                      
                      

                      Packet Arrow:

                      
                      package net.legacymod.packets;
                      
                      import io.netty.buffer.ByteBuf;
                      import net.minecraft.entity.player.EntityPlayer;
                      import net.minecraft.entity.projectile.EntityArrow;
                      import net.minecraft.util.Vec3;
                      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 PacketArrow implements IMessage{
                      
                      private float f1;
                      private int i;
                      
                          public PacketArrow(){ 
                      
                          }
                      
                          public PacketArrow(float f, int i) {
                          this.f1 = f;
                          this.i = i;
                          }
                      
                          @Override
                          public void fromBytes(ByteBuf buf) {
                          f1 = buf.readFloat();
                          i = buf.readInt();
                          }
                      
                          @Override
                          public void toBytes(ByteBuf buf) {
                          buf.writeFloat(f1);
                          buf.writeInt(i);
                          }
                      
                          public static class Handler implements IMessageHandler <packetarrow, imessage="">{
                      
                              @Override
                              public IMessage onMessage(PacketArrow message, MessageContext ctx) {
                              EntityArrow entityarrow = new EntityArrow(ctx.getServerHandler().playerEntity.worldObj, ctx.getServerHandler().playerEntity, message.f1 + message.i);
                              EntityArrow entityarrow2 = new EntityArrow(ctx.getServerHandler().playerEntity.worldObj, ctx.getServerHandler().playerEntity, message.f1 + message.i);
                              EntityArrow entityarrow3 = new EntityArrow(ctx.getServerHandler().playerEntity.worldObj, ctx.getServerHandler().playerEntity, message.f1 + message.i);
                              EntityArrow entityarrow4 = new EntityArrow(ctx.getServerHandler().playerEntity.worldObj, ctx.getServerHandler().playerEntity, message.f1 + message.i);
                              EntityArrow entityarrow5 = new EntityArrow(ctx.getServerHandler().playerEntity.worldObj, ctx.getServerHandler().playerEntity, message.f1 + message.i);
                              switch(message.i)
                              {
                              case 1:
                              {
                              entityarrow.getEntityData().setBoolean("isExplosive", true);
                              ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(entityarrow);
                              break;
                              }
                              case 2:
                              {
                              ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(entityarrow);
                                  ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(entityarrow2);
                                  ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(entityarrow3);
                                  ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(entityarrow4);
                                  ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(entityarrow5);
                      
                                  Vec3 look = ctx.getServerHandler().playerEntity.getLookVec();
                      
                                  entityarrow.setPosition(
                                  ctx.getServerHandler().playerEntity.posX + look.xCoord,
                                  ctx.getServerHandler().playerEntity.posY + 1 + look.yCoord,
                                  ctx.getServerHandler().playerEntity.posZ + look.zCoord);
                      
                                  entityarrow2.setPosition(
                                  ctx.getServerHandler().playerEntity.posX + 1 + look.xCoord,
                                  ctx.getServerHandler().playerEntity.posY + 1 + look.yCoord,
                                  ctx.getServerHandler().playerEntity.posZ + look.zCoord);
                      
                                  entityarrow3.setPosition(
                                  ctx.getServerHandler().playerEntity.posX + look.xCoord,
                                  ctx.getServerHandler().playerEntity.posY + 1 + look.yCoord,
                                  ctx.getServerHandler().playerEntity.posZ + 1 + look.zCoord);
                      
                                  entityarrow4.setPosition(
                                  ctx.getServerHandler().playerEntity.posX - 1 + look.xCoord,
                                  ctx.getServerHandler().playerEntity.posY + 1 + look.yCoord,
                                  ctx.getServerHandler().playerEntity.posZ + look.zCoord);
                      
                                  entityarrow5.setPosition(
                                  ctx.getServerHandler().playerEntity.posX + look.xCoord,
                                  ctx.getServerHandler().playerEntity.posY + 1 + look.yCoord,
                                  ctx.getServerHandler().playerEntity.posZ - 1 + look.zCoord);
                                  break;
                              }
                              case 3:
                              {
                              ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(entityarrow);
                                  entityarrow.setFire(2 * 5);
                                  break;
                              }
                              default:
                              break;
                              }
                      
                              return null;
                              }
                          }
                      
                      }
                      
                      ```</packetarrow,></packetkey,>
                      1 réponse Dernière réponse Répondre Citer 0
                      • SCAREXS Hors-ligne
                        SCAREX
                        dernière édition par

                        C’est bien sendToServeur puisque ça va vers le serveur. En revanche y’a un truc que je comprends pas : pourquoi envoyer un PacketKey et me donner la classe PacketArrow ?

                        Site web contenant mes scripts : http://SCAREXgaming.github.io

                        Pas de demandes de support par MP ni par skype SVP.
                        Je n'accepte sur skype que l…

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

                          @‘SCAREX’:

                          C’est bien sendToServeur puisque ça va vers le serveur. En revanche y’a un truc que je comprends pas : pourquoi envoyer un PacketKey et me donner la classe PacketArrow ?

                          Tu as le packetKey et le packetarrow ^^

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

                            Oui mais à quoi sert le PacketArrow alors ?

                            D’ailleurs je ne comprends pas ce que tu veux faire avec ce code :

                            if(stack != null){
                            stack.setTagCompound(new NBTTagCompound()); // Tu supprimes tous les tags de l'item
                            NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound(); // Ensuite tu récupères les tags (qui sont nuls désormais)
                            stack.getTagCompound().setTag("key", nbt); // et tu mets les tags de l'item (qui sont nuls) dans un tag "key" dans l'item
                            }
                            

                            Site web contenant mes scripts : http://SCAREXgaming.github.io

                            Pas de demandes de support par MP ni par skype SVP.
                            Je n'accepte sur skype que l…

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

                              @‘SCAREX’:

                              Oui mais à quoi sert le PacketArrow alors ?

                              D’ailleurs je ne comprends pas ce que tu veux faire avec ce code :

                              if(stack != null){
                                 stack.setTagCompound(new NBTTagCompound()); // Tu supprimes tous les tags de l'item
                                 NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound(); // Ensuite tu récupères les tags (qui sont nuls désormais)
                                 stack.getTagCompound().setTag("key", nbt); // et tu mets les tags de l'item (qui sont nuls) dans un tag "key" dans l'item
                                 }
                              

                              [font=Ubuntu, sans-serifCitation de SCAREX: Est-ce que ce ne serai pas plus simple de modifier le metadata lorsqu’on appuie sur une touche et ensuite récupérer le metadata afin de savoir quelle sorte de flèche tirer ?]

                              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

                                @‘robin4002’:

                                Avec un outil ce n’est pas bon car le metadata est déjà utilisé pour l’usure de l’item.

                                Au lieu de faire un setTag mets plutôt un integer qui correspond au mode de l’arc.

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

                                  @‘robin4002’:

                                  @‘robin4002’:

                                  Avec un outil ce n’est pas bon car le metadata est déjà utilisé pour l’usure de l’item.

                                  Au lieu de faire un setTag mets plutôt un integer qui correspond au mode de l’arc.

                                  un integer qui correspond au mode de l’arc c’est a dire ? c’est quoi le mode de l’arc ?

                                  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

                                    0 = normal
                                    1 = flèche de feu
                                    2 = autre truc
                                    etc …

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

                                      @‘robin4002’:

                                      0 = normal
                                      1 = flèche de feu
                                      2 = autre truc
                                      etc …

                                      Ok^^

                                      J’ai fais ça:

                                      
                                      package net.legacymod.packets;
                                      
                                      import io.netty.buffer.ByteBuf;
                                      import net.legacymod.LegacyMod;
                                      import net.legacymod.gui.ClassesGUI;
                                      import net.minecraft.client.Minecraft;
                                      import net.minecraft.item.ItemStack;
                                      import net.minecraft.nbt.NBTTagCompound;
                                      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 PacketKey implements IMessage {
                                      
                                      public PacketKey(){
                                      
                                      }
                                      
                                      @Override
                                      public void fromBytes(ByteBuf buf) {
                                      
                                      }
                                      
                                      @Override
                                      public void toBytes(ByteBuf buf) {
                                      
                                      }
                                      
                                      public static class Handler implements IMessageHandler <packetkey, imessage="">{
                                      
                                         public IMessage onMessage(PacketKey message, MessageContext ctx) {
                                      
                                          ItemStack stack = ctx.getServerHandler().playerEntity.inventory.getItemStack();
                                          if(stack != null){
                                          stack.setTagCompound(new NBTTagCompound());
                                          NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound();
                                          stack.getTagCompound().setInteger("key", 3);
                                          System.out.println("packet");
                                          }
                                          return null;
                                      
                                             }
                                         }
                                      }
                                      
                                      

                                      Arc:

                                      
                                                 else if (!world.isRemote && stack.getTagCompound().getInteger("key") == 3)
                                                 {
                                                  LegacyMod.network.sendToServer(new PacketArrow(f * 2.0F, 3));
                                                  System.out.println("flèche en feu");
                                                  //stack.getTagCompound().setInteger("timer2", 0);
                                                 }
                                      
                                      

                                      console:

                                      
                                      [00:54:44] [Server thread/INFO]: floriangabet a rejoint la partie
                                      [00:54:45] [Client thread/INFO] [STDOUT]: [net.legacymod.proxy.ClientProxy:keyTestTyped2:91]: num pad 6
                                      [00:54:47] [Server thread/INFO] [STDOUT]: [net.legacymod.items.FlameBow:onPlayerStoppedUsing:142]: flèche normale
                                      
                                      

                                      Marche pas.</packetkey,>

                                      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

                                        Pourquoi tu as encore PacketArrow ?
                                        Tu es déjà côté serveur, effectue directement le tire.

                                        Et on ne va pas avancer si tu donnes que des petits bouts de code …

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

                                          Ah oui exact.

                                          Marche toujours pas, donc tien:

                                          Arc:

                                          
                                          package net.legacymod.items;
                                          
                                          import cpw.mods.fml.relauncher.Side;
                                          import cpw.mods.fml.relauncher.SideOnly;
                                          import net.legacymod.LegacyMod;
                                          import net.legacymod.packets.PacketArrow;
                                          import net.legacymod.proxy.ClientProxy;
                                          import net.minecraft.client.renderer.texture.IIconRegister;
                                          import net.minecraft.creativetab.CreativeTabs;
                                          import net.minecraft.enchantment.Enchantment;
                                          import net.minecraft.enchantment.EnchantmentHelper;
                                          import net.minecraft.entity.Entity;
                                          import net.minecraft.entity.EntityLivingBase;
                                          import net.minecraft.entity.player.EntityPlayer;
                                          import net.minecraft.entity.projectile.EntityArrow;
                                          import net.minecraft.entity.projectile.EntityLargeFireball;
                                          import net.minecraft.init.Items;
                                          import net.minecraft.item.EnumAction;
                                          import net.minecraft.item.Item;
                                          import net.minecraft.item.ItemBow;
                                          import net.minecraft.item.ItemStack;
                                          import net.minecraft.nbt.NBTBase;
                                          import net.minecraft.nbt.NBTTagCompound;
                                          import net.minecraft.util.DamageSource;
                                          import net.minecraft.util.IIcon;
                                          import net.minecraft.util.Vec3;
                                          import net.minecraft.world.World;
                                          import net.minecraftforge.common.MinecraftForge;
                                          import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
                                          import net.minecraftforge.event.entity.player.ArrowLooseEvent;
                                          import net.minecraftforge.event.entity.player.ArrowNockEvent;
                                          
                                          public class FlameBow extends ItemBow {
                                          
                                          public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
                                             @SideOnly(Side.CLIENT)
                                             private IIcon[] iconArray;
                                          
                                             public boolean isExplosive;
                                          
                                             public FlameBow()
                                             {
                                                 this.maxStackSize = 1;
                                                 this.setMaxDamage(1000);
                                                 this.setFull3D();
                                                 this.setCreativeTab(CreativeTabs.tabCombat);
                                             }
                                          
                                             /**
                                              * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
                                              */
                                             public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int p_77615_4_)
                                             {
                                                 int j = this.getMaxItemUseDuration(stack) - p_77615_4_;
                                          
                                                 ArrowLooseEvent event = new ArrowLooseEvent(player, stack, j);
                                                 EntityLargeFireball fire = new EntityLargeFireball(world);
                                                 MinecraftForge.EVENT_BUS.post(event);
                                                 if (event.isCanceled())
                                                 {
                                                     return;
                                                 }
                                                 j = event.charge;
                                          
                                                 boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
                                          
                                                 if (flag || player.inventory.hasItem(Items.arrow))
                                                 {
                                                     float f = (float)j / 20.0F;
                                                     f = (f * f + f * 2.0F) / 3.0F;
                                          
                                                     if ((double)f < 0.1D)
                                                     {
                                                         return;
                                                     }
                                          
                                                     if (f > 1.0F)
                                                     {
                                                         f = 1.0F;
                                                     }
                                          
                                                     EntityArrow entityarrow = new EntityArrow(world, player, f * 2.0F);
                                                     EntityArrow entityarrow2 = new EntityArrow(world, player, f * 2.0F);
                                                     EntityArrow entityarrow3 = new EntityArrow(world, player, f * 2.0F);
                                                     EntityArrow entityarrow4 = new EntityArrow(world, player, f * 2.0F);
                                                     EntityArrow entityarrow5 = new EntityArrow(world, player, f * 2.0F);
                                          
                                                     if (f == 1.0F)
                                                     {
                                                         entityarrow.setIsCritical(true);
                                                     }
                                          
                                                     int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
                                          
                                                     if (k > 0)
                                                     {
                                                         entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
                                                     }
                                          
                                                     int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
                                          
                                                     if (l > 0)
                                                     {
                                                         entityarrow.setKnockbackStrength(l);
                                                     }
                                          
                                                     if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
                                                     {
                                                         entityarrow.setFire(100);
                                                     }
                                          
                                                     stack.damageItem(1, player);
                                                     world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                                          
                                                     if (flag)
                                                     {
                                                         entityarrow.canBePickedUp = 2;
                                                     }
                                                      if(ClientProxy.keyBindSortG2.isPressed() && stack.getTagCompound().getInteger("timer") >= 20 * 20)
                                                     {
                                                      LegacyMod.network.sendToServer(new PacketArrow(f * 2.0F, 1));
                                                      System.out.println("flèche explosive");
                                                      stack.getTagCompound().setInteger("timer", 0);
                                                     }
                                          
                                                     else if (!world.isRemote && stack.getTagCompound().getInteger("key") == 3) // c'est ici le reste des else if je m'en charge une fois celui-ci opérationnel.
                                                     {
                                                  world.spawnEntityInWorld(entityarrow);
                                                      entityarrow.setFire(2 * 5);
                                                      System.out.println("flèche en feu");
                                                      //stack.getTagCompound().setInteger("timer2", 0);
                                                     }
                                                     else if (player.isSneaking() && !world.isRemote)
                                                     {
                                                    System.out.println("5 flèches");
                                                  LegacyMod.network.sendToServer(new PacketArrow(2.0F, 2));
                                          
                                                      stack.getTagCompound().setInteger("timer3", 0);
                                          
                                                     }else if(!world.isRemote)
                                                     {
                                                      world.spawnEntityInWorld(entityarrow);
                                                      System.out.println("flèche normale");
                                                     }
                                                 }
                                             }
                                          
                                             public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_)
                                             {
                                                 return p_77654_1_;
                                             }
                                          
                                             /**
                                              * How long it takes to use or consume an item
                                              */
                                             public int getMaxItemUseDuration(ItemStack p_77626_1_)
                                             {
                                                 return 72000;
                                             }
                                          
                                             /**
                                              * returns the action that specifies what animation to play when the items is being used
                                              */
                                             public EnumAction getItemUseAction(ItemStack p_77661_1_)
                                             {
                                                 return EnumAction.bow;
                                             }
                                          
                                             /**
                                              * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
                                              */
                                             public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
                                             {
                                                 ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_);
                                                 MinecraftForge.EVENT_BUS.post(event);
                                                 if (event.isCanceled())
                                                 {
                                                     return event.result;
                                                 }
                                          
                                                 if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(Items.arrow))
                                                 {
                                                     p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
                                                 }
                                          
                                                 return p_77659_1_;
                                             }
                                          
                                             /**
                                              * Return the enchantability factor of the item, most of the time is based on material.
                                              */
                                             public int getItemEnchantability()
                                             {
                                                 return 1;
                                             }
                                          
                                             @SideOnly(Side.CLIENT)
                                             public void registerIcons(IIconRegister p_94581_1_)
                                             {
                                                 this.itemIcon = p_94581_1_.registerIcon(this.getIconString() + "_standby");
                                                 this.iconArray = new IIcon[bowPullIconNameArray.length];
                                          
                                                 for (int i = 0; i < this.iconArray.length; ++i)
                                                 {
                                                     this.iconArray* = p_94581_1_.registerIcon(this.getIconString() + "_" + bowPullIconNameArray*);
                                                 }
                                             }
                                          
                                             /**
                                              * used to cycle through icons based on their used duration, i.e. for the bow
                                              */
                                             @SideOnly(Side.CLIENT)
                                             public IIcon getItemIconForUseDuration(int p_94599_1_)
                                             {
                                                 return this.iconArray[p_94599_1_];
                                             }
                                          
                                          public void onUpdate(ItemStack item, World world, Entity player, int slotIndex, boolean inHand) {
                                          if(!item.hasTagCompound() && !world.isRemote) {
                                                item.setTagCompound(new NBTTagCompound());
                                          }
                                          if(world.isRemote){
                                          int timer = !item.getTagCompound().hasKey("timer") ? 0 : item.getTagCompound().getInteger("timer");
                                          timer++;
                                          item.getTagCompound().setInteger("timer", timer);
                                          
                                          int timer2 = !item.getTagCompound().hasKey("timer2") ? 0 : item.getTagCompound().getInteger("timer2");
                                          timer2++;
                                          item.getTagCompound().setInteger("timer2", timer2);
                                          
                                          int timer3 = !item.getTagCompound().hasKey("timer3") ? 0 : item.getTagCompound().getInteger("timer3");
                                          timer3++;
                                          item.getTagCompound().setInteger("timer3", timer3);
                                          
                                          super.onUpdate(item, world, player, slotIndex, inHand);
                                          }
                                          }
                                          
                                          @Override//Prob ici
                                             public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
                                             {
                                                 if(usingItem != null && usingItem.getItem() == LegacyMod.FlameBow)
                                                 {
                                                     int k = usingItem.getMaxItemUseDuration() - useRemaining;
                                                     if(k >= 18)
                                                         return iconArray[2];
                                                     if(k > 13)
                                                         return iconArray[1];
                                                     if(k > 0)
                                                         return iconArray[0];
                                                 }
                                                 return getIconIndex(stack);
                                          }
                                          
                                          }
                                          
                                          

                                          Proxy:

                                          
                                          package net.legacymod.proxy;
                                          
                                          import net.legacymod.LegacyMod;
                                          import net.legacymod.items.ItemEpee3D;
                                          import net.legacymod.mobs.EntityAlienMob;
                                          import net.legacymod.mobs.RenderAlienMob;
                                          import net.legacymod.mobs.alien;
                                          import net.legacymod.packets.PacketClassesGUI;
                                          import net.legacymod.packets.PacketKey;
                                          import net.minecraft.client.Minecraft;
                                          import net.minecraft.client.settings.KeyBinding;
                                          import net.minecraft.entity.player.EntityPlayer;
                                          import net.minecraft.item.ItemStack;
                                          import net.minecraft.nbt.NBTTagCompound;
                                          import net.minecraft.world.World;
                                          import net.minecraftforge.client.IItemRenderer;
                                          import net.minecraftforge.client.MinecraftForgeClient;
                                          
                                          import org.lwjgl.input.Keyboard;
                                          
                                          import cpw.mods.fml.client.registry.ClientRegistry;
                                          import cpw.mods.fml.client.registry.RenderingRegistry;
                                          import cpw.mods.fml.common.FMLCommonHandler;
                                          import cpw.mods.fml.common.event.FMLInitializationEvent;
                                          import cpw.mods.fml.common.event.FMLPreInitializationEvent;
                                          import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                          import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
                                          
                                          public class ClientProxy extends CommonProxy{
                                          
                                              private static KeyBinding keyBindGUI;
                                              public static KeyBinding keyBindSortG1;
                                              public static KeyBinding keyBindSortG2;
                                          
                                          @Override
                                             public void preInit(FMLPreInitializationEvent e)
                                             {
                                          
                                             }
                                          
                                          @Override
                                          public void init(FMLInitializationEvent e) {
                                          RenderingRegistry.registerEntityRenderingHandler(EntityAlienMob.class, new RenderAlienMob(new alien(), 0.5F));
                                          MinecraftForgeClient.registerItemRenderer(LegacyMod.epee, (IItemRenderer)new ItemEpee3D());
                                          }
                                          
                                             public ClientProxy(){
                                              FMLCommonHandler.instance().bus().register(this);
                                              keyBindGUI = new KeyBinding("Choix de grade!", Keyboard.KEY_NUMPAD5, "key.categories.gameplay");
                                                 ClientRegistry.registerKeyBinding(keyBindGUI);
                                          
                                                 keyBindSortG1 = new KeyBinding("Sort Guerrier 1", Keyboard.KEY_NUMPAD6, "key.categories.gameplay");
                                                 ClientRegistry.registerKeyBinding(keyBindSortG1);
                                          
                                                 keyBindSortG2 = new KeyBinding("Sort Guerrier 2", Keyboard.KEY_NUMPAD7, "key.categories.gameplay");
                                                 ClientRegistry.registerKeyBinding(keyBindSortG2);
                                             }
                                          
                                             @SubscribeEvent
                                             public void onEvent(KeyInputEvent event)
                                             {
                                                 if(keyBindGUI.isPressed())
                                                 {
                                                     keyTestTyped();
                                                 }
                                             }
                                          
                                             private void keyTestTyped()
                                             {
                                                 EntityPlayer player = Minecraft.getMinecraft().thePlayer;
                                                 World world = player.worldObj;
                                                 LegacyMod.network.sendToServer(new PacketClassesGUI());
                                          
                                             }
                                          
                                             @SubscribeEvent
                                             public void onEvent2(KeyInputEvent event)
                                             {
                                                 if(keyBindSortG1.isPressed())
                                                 {
                                                     keyTestTyped2();
                                                 }
                                             }
                                          
                                             private void keyTestTyped2()
                                             {
                                              LegacyMod.network.sendToServer(new PacketKey());   
                                              System.out.println("num pad 6");
                                             }
                                          
                                          }
                                          
                                          

                                          Packetkey:

                                          
                                          package net.legacymod.packets;
                                          
                                          import io.netty.buffer.ByteBuf;
                                          import net.legacymod.LegacyMod;
                                          import net.legacymod.gui.ClassesGUI;
                                          import net.minecraft.client.Minecraft;
                                          import net.minecraft.item.ItemStack;
                                          import net.minecraft.nbt.NBTTagCompound;
                                          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 PacketKey implements IMessage {
                                          
                                          public PacketKey(){
                                          
                                          }
                                          
                                          @Override
                                          public void fromBytes(ByteBuf buf) {
                                          
                                          }
                                          
                                          @Override
                                          public void toBytes(ByteBuf buf) {
                                          
                                          }
                                          
                                          public static class Handler implements IMessageHandler <packetkey, imessage="">{
                                          
                                             public IMessage onMessage(PacketKey message, MessageContext ctx) {
                                          
                                              ItemStack stack = ctx.getServerHandler().playerEntity.inventory.getItemStack();
                                              if(stack != null){
                                              stack.setTagCompound(new NBTTagCompound());
                                              NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound();
                                              stack.getTagCompound().setInteger("key", 3);
                                              System.out.println("packet");
                                              }
                                              return null;
                                          
                                                 }
                                             }
                                          }
                                          
                                          ```</packetkey,>
                                          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

                                            fais un print de stack.getTagCompound().getInteger(“key”) pour voir la valeur.

                                            Le reste de ton code est aussi un gros bordel, tu devrais le réorganiser.

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

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB