MFF

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

    Elevator

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    36 Messages 5 Publieurs 7.9k 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.
    • AlgorythmisA Hors-ligne
      Algorythmis
      dernière édition par

      @‘XDoctorX’:

      package com.XDoctorX.main;
      
      import java.io.DataInput;
      import java.io.IOException;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.world.World;
      import net.minecraftforge.common.util.ForgeDirection;
      import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
      import com.XDoctorX.block.BlockElevator;
      import cpw.mods.fml.common.eventhandler.SubscribeEvent;
      
      public class ElevatorEvent {
         public EntityPlayer player;
         public World world;
         public PlayerMovementEvent.Type type;
      
         @SubscribeEvent
         public void onLivingJumpEvent(LivingJumpEvent event) {
             if (event.entity instanceof EntityPlayer) {
                 int[] positionBlocCible = BlockElevator.getTargetBlock(world, (int)player.posX, (int)player.posY, (int)player.posZ, true);
             }
         }
      }
      

      Rassure-moi, tu le fais exprès?
      Ce que je t’ai donné, c’est le code pour récupérer la position du prochain ascenseur au-dessus du joueur.
      Or, là :

      • Tu ne vérifies même pas si le joueur est sur un bloc ascenseur
      • Tu passes une variable membre non-initialisée en argument alors que la bonne variable est là, juste sous ton nez
      • Tu n’utilises même pas la valeur récupérée (bon, en même temps y’a pas grand chose à récupérer vu que ça crash. Mais pourquoi ça crash? Tout simplement parce que tu passes une variable non-initialisée en argument. T’étonne pas d’avoir des NullPointerException si la valeur est null).

      Tout ça ne me donne pas du tout envie de t’aider.
      Comme on te l’a sûrement déjà dit : Essaie de comprendre le code avant de l’utiliser.
      Apprends le Java, je sais pas, moi. Quand t’étais petit, fallait qu’on t’explique comment on empile des cubes en plastique ou bien?
      Désolé si j’emploie un ton agressif mais copier-coller un bout de code au hasard ça va bien 3 minutes, mais après faut pas être surpris si on a des crashs à tout bout de champ.
      T’as déjà trouvé comment récupérer la position du joueur. Ok, c’est assez facile, mais ça veut bien dire que tu peux réfléchir par toi-même et trouver une solution à partir de ce qu’on te propose. Sans créer des variables au hasard sans se demander à quoi peuvent servir celles qui existent déjà.

      Du coup je sais vraiment pas si je te fais la correction de ton code…
      Bon, allez, histoire d’essayer de t’apprendre quelque chose :

      package com.XDoctorX.main;
      
      import java.io.DataInput;
      import java.io.IOException;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.world.World;
      import net.minecraftforge.common.util.ForgeDirection;
      import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
      import com.XDoctorX.block.BlockElevator;
      import cpw.mods.fml.common.eventhandler.SubscribeEvent;
      
      public class ElevatorEvent {
         @SubscribeEvent
         public void onLivingJumpEvent(LivingJumpEvent event) {
             if (event.entity instanceof EntityPlayer && event.entity.worldObj.getBlock(event.entity.posX, event.entity.posY - 1, event.entity.posZ) == ClassePrincipale.*block_elevator*) {
                 EntityPlayer p = (EntityPlayer)(event.entity);
                 int[] posBlocCible = BlockElevator.getTargetBlock(world, (int)p.posX, (int)p.posY, (int)p.posZ, true);
                 p.setPosition(posBlocCible[0], posBlocCible[1]+1, posBlocCible[2]);
             }
         }
      }
      

      Mes mods :

      • Cookie Ore (1.7.10)

      Mod en cours : **E…

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

        sa marche pas c’est le meme crash report

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

          Toujours un NPE à la ligne 27 de ta classe ElevatorEvent ?

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

            Désolé, pourtant en théorie ce code marche très bien, on a remplacé les variables qui causaient l’erreur.

            Mes mods :

            • Cookie Ore (1.7.10)

            Mod en cours : **E…

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

              non je croit

              
              package com.XDoctorX.main;
              
              import java.io.DataInput;
              import java.io.IOException;
              import net.minecraft.entity.player.EntityPlayer;
              import net.minecraft.world.World;
              import net.minecraftforge.common.util.ForgeDirection;
              import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
              import com.XDoctorX.block.BlockElevator;
              import cpw.mods.fml.common.eventhandler.SubscribeEvent;
              
              public class ElevatorEvent {
              
              public World world;
              
              @SubscribeEvent
              public void onLivingJumpEvent(LivingJumpEvent event) {
              if (event.entity instanceof EntityPlayer && event.entity.worldObj.getBlock((int)event.entity.posX,(int) event.entity.posY - 1,(int) event.entity.posZ) == XDoctorX.Elevator) {
              EntityPlayer p = (EntityPlayer)(event.entity);
              int[] posBlocCible = BlockElevator.getTargetBlock(world, (int)p.posX, (int)p.posY, (int)p.posZ, true);
              p.setPosition(posBlocCible[0], posBlocCible[1]+1, posBlocCible[2]);
              }
              }
              }
              
              
              1 réponse Dernière réponse Répondre Citer 0
              • robin4002R En ligne
                robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                dernière édition par

                public World world; n’a rien à faire là.
                int[] posBlocCible = BlockElevator.getTargetBlock(world, (int)p.posX, (int)p.posY, (int)p.posZ, true);
                -> event.entity.worldObj à la place de world ici.

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

                  sa marche pas et il y a a pas de crash report

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

                    @‘robin4002’:

                    public World world; n’a rien à faire là.
                                    int[] posBlocCible = BlockElevator.getTargetBlock(world, (int)p.posX, (int)p.posY, (int)p.posZ, true);
                    -> event.entity.worldObj à la place de world ici.

                    Oups, merci Robin ^^’ Erreur d’inattention

                    Mes mods :

                    • Cookie Ore (1.7.10)

                    Mod en cours : **E…

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

                      je lais fait mais sa marche pas et il y a plus de crash report

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

                        marche pas = il se passe rien ? Tu as bien placé les blocs ? Renvoies également le code actuel.

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

                          Rien se passe.

                          code du Event :

                          
                          package com.XDoctorX.main;
                          
                          import java.io.DataInput;
                          import java.io.IOException;
                          import net.minecraft.entity.player.EntityPlayer;
                          import net.minecraft.world.World;
                          import net.minecraftforge.common.util.ForgeDirection;
                          import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
                          import com.XDoctorX.block.BlockElevator;
                          import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                          
                          public class ElevatorEvent {
                          
                          @SubscribeEvent
                          public void onLivingJumpEvent(LivingJumpEvent event) {
                          if (event.entity instanceof EntityPlayer && event.entity.worldObj.getBlock((int)event.entity.posX,(int) event.entity.posY - 1,(int) event.entity.posZ) == XDoctorX.Elevator) {
                          EntityPlayer p = (EntityPlayer)(event.entity);
                          int[] posBlocCible = BlockElevator.getTargetBlock(event.entity.worldObj, (int)p.posX, (int)p.posY, (int)p.posZ, true);
                          p.setPosition(posBlocCible[0], posBlocCible[1]+1, posBlocCible[2]);
                          }
                          }
                          }
                          
                          
                          1 réponse Dernière réponse Répondre Citer 0
                          • AlgorythmisA Hors-ligne
                            Algorythmis
                            dernière édition par

                            Tu essaies bien en te plaçant sur un bloc ascenseur?

                            Mes mods :

                            • Cookie Ore (1.7.10)

                            Mod en cours : **E…

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

                              Essayes avec p.setPositionAndUpdate(posBlocCible[0], posBlocCible[1]+1, posBlocCible[2]);

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

                                je suis sur le bloc, rien se passe j"ai mit

                                p.addChatComponentMessage(new ChatComponentTranslation(“test”));

                                sa marche une seul fois apres sa marche plus et le code est maintenant

                                
                                   package com.XDoctorX.main;
                                
                                   import java.io.DataInput;
                                import java.io.IOException;
                                
                                import net.minecraft.entity.player.EntityPlayer;
                                import net.minecraft.util.ChatComponentTranslation;
                                import net.minecraft.world.World;
                                import net.minecraftforge.common.util.ForgeDirection;
                                import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
                                
                                import com.XDoctorX.block.BlockElevator;
                                
                                import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                
                                   public class ElevatorEvent {
                                
                                       @SubscribeEvent
                                       public void onLivingJumpEvent(LivingJumpEvent event) {
                                           if (event.entity instanceof EntityPlayer && event.entity.worldObj.getBlock((int)event.entity.posX,(int) event.entity.posY - 1,(int) event.entity.posZ) == XDoctorX.Elevator) {
                                               EntityPlayer p = (EntityPlayer)(event.entity);
                                               p.addChatComponentMessage(new ChatComponentTranslation("test"));
                                               int[] posBlocCible = BlockElevator.getTargetBlock(event.entity.worldObj, (int)p.posX, (int)p.posY, (int)p.posZ, true);
                                               p.setPositionAndUpdate(posBlocCible[0], posBlocCible[1]+1, posBlocCible[2]);                
                                           }
                                       }
                                   }
                                
                                
                                1 réponse Dernière réponse Répondre Citer 0
                                • X Hors-ligne
                                  XDoctorX
                                  dernière édition par

                                  up up up up up up up up

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

                                    24h avant de up, merci de lire le règlement du forum …
                                    Envoies-moi un zip de ton dossier src je vais tester de mon côté.

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

                                      http://www.mediafire.com/download/0xeu8bbw2hvn1v2/Src+Elevator+by+XDoctorX.zip

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

                                        XDoctorX.java, fonction init, ajoute ça :
                                        FMLCommonHandler.instance().bus().register(new ElevatorEvent());
                                        En dessous de la ligne avec Forge.
                                        BlockElevator :

                                        package com.XDoctorX.block;
                                        
                                        import org.lwjgl.input.Keyboard;
                                        
                                        import com.XDoctorX.main.XDoctorX;
                                        
                                        import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                        import net.minecraft.block.Block;
                                        import net.minecraft.block.material.Material;
                                        import net.minecraft.entity.Entity;
                                        import net.minecraft.entity.player.EntityPlayer;
                                        import net.minecraft.world.World;
                                        import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
                                        
                                        public class BlockElevator extends Block
                                        {
                                        public EntityPlayer player;
                                        public World world;
                                        
                                        public BlockElevator()
                                        {
                                        super(Material.circuits);
                                        }
                                        
                                        public static int getTargetBlock(World w, int x, int y, int z, boolean up)
                                        {
                                        if(up)
                                        {
                                        for(int i = y; i <= 255; i++)
                                        {
                                        if(w.getBlock(x, i, z) == XDoctorX.Elevator)
                                        {
                                        return i;
                                        }
                                        }
                                        }
                                        else
                                        {
                                        for(int i = y; i >= 0; i–)
                                        {
                                        if(w.getBlock(x, i, z) == XDoctorX.Elevator)
                                        {
                                        return i;
                                        }
                                        }
                                        }
                                        return -1;
                                        }
                                        }
                                        

                                        ElevatorEvent :

                                        package com.XDoctorX.main;
                                        
                                        import com.XDoctorX.block.BlockElevator;
                                        
                                        import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                        import cpw.mods.fml.common.gameevent.TickEvent;
                                        import net.minecraft.entity.player.EntityPlayer;
                                        import net.minecraft.util.MathHelper;
                                        import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
                                        
                                        public class ElevatorEvent
                                        {
                                        @SubscribeEvent
                                        public void onLivingJumpEvent(LivingJumpEvent event)
                                        {
                                        if(event.entity instanceof EntityPlayer)
                                        {
                                        if(event.entity.worldObj.getBlock(MathHelper.floor_double(event.entity.posX), MathHelper.floor_double(event.entity.posY - 1), MathHelper.floor_double(event.entity.posZ)) == XDoctorX.Elevator)
                                        {
                                        EntityPlayer p = (EntityPlayer)event.entity;
                                        
                                        int posBlocCible = BlockElevator.getTargetBlock(event.entity.worldObj, MathHelper.floor_double(event.entity.posX), MathHelper.floor_double(event.entity.posY), MathHelper.floor_double(event.entity.posZ), true);
                                        if(posBlocCible != -1)
                                        {
                                        p.setPositionAndUpdate(event.entity.posX, posBlocCible + 1, event.entity.posZ);
                                        }
                                        }
                                        }
                                        }
                                        
                                        @SubscribeEvent
                                        public void onPlayerTick(TickEvent.PlayerTickEvent event)
                                        {
                                        if(event.phase == TickEvent.Phase.START)
                                        {
                                        if(event.player.isSneaking())
                                        {
                                        if(event.player.worldObj.getBlock(MathHelper.floor_double(event.player.posX), MathHelper.floor_double(event.player.posY - 1), MathHelper.floor_double(event.player.posZ)) == XDoctorX.Elevator)
                                        {
                                        int posBlocCible = BlockElevator.getTargetBlock(event.player.worldObj, MathHelper.floor_double(event.player.posX), MathHelper.floor_double(event.player.posY) - 2, MathHelper.floor_double(event.player.posZ), false);
                                        if(posBlocCible != -1)
                                        {
                                        event.player.setPositionAndUpdate(event.player.posX, posBlocCible + 1, event.player.posZ);
                                        event.player.setSneaking(false);
                                        }
                                        }
                                        }
                                        }
                                        }
                                        }
                                        
                                        
                                        1 réponse Dernière réponse Répondre Citer 0
                                        • X Hors-ligne
                                          XDoctorX
                                          dernière édition par

                                          merci

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

                                            Balise résolu ?

                                            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
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB