MFF

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

    Savoir quelle entity regarde le joueur

    Planifier Épinglé Verrouillé Déplacé Sans suite
    28 Messages 4 Publieurs 6.5k 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.
    • GuguG Hors-ligne
      Gugu
      dernière édition par

      Fais un check que la méthode ne return pas null

      "If you have a comprehensive explanation for everything then it decreases uncertainty and anxiety and reduces your cognitive load. And if you can use that simplifying algorithm to put yourself on the side of moral virtue then you’re constantly a good person with a minimum of effort."
      ― Jordan B. Peterson

      1 réponse Dernière réponse Répondre Citer 0
      • isadorI Hors-ligne
        isador Moddeurs confirmés Modérateurs
        dernière édition par

        comment ca?

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

          if(par2World.getEntitiesWithinAABB(CoeMob.Mob.MobtestEntity.class, player.boundingBox.expand(32.0D, 32.0D, 32.0D)) != null)

          "If you have a comprehensive explanation for everything then it decreases uncertainty and anxiety and reduces your cognitive load. And if you can use that simplifying algorithm to put yourself on the side of moral virtue then you’re constantly a good person with a minimum of effort."
          ― Jordan B. Peterson

          1 réponse Dernière réponse Répondre Citer 0
          • isadorI Hors-ligne
            isador Moddeurs confirmés Modérateurs
            dernière édition par

            par contre si je veux check avec plusieurs entity comment faire?

            edit: j’ai un NPE sur if(par2World.getEntitiesWithinAABB(CoeMob.Mob.MobtestEntity.class, player.boundingBox.expand(32.0D, 32.0D, 32.0D)) != null)

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

              Essaie de voir de quelle partie ça viens

              "If you have a comprehensive explanation for everything then it decreases uncertainty and anxiety and reduces your cognitive load. And if you can use that simplifying algorithm to put yourself on the side of moral virtue then you’re constantly a good person with a minimum of effort."
              ― Jordan B. Peterson

              1 réponse Dernière réponse Répondre Citer 0
              • isadorI Hors-ligne
                isador Moddeurs confirmés Modérateurs
                dernière édition par

                ca vient du .getEntitiesWithinAABB

                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

                  Dans ce cas ton objet world est null, envoie toute ta classe.

                  1 réponse Dernière réponse Répondre Citer 0
                  • isadorI Hors-ligne
                    isador Moddeurs confirmés Modérateurs
                    dernière édition par

                    
                    package CoeQuest;
                    
                    import java.util.EnumSet;
                    import java.util.List;
                    
                    import net.minecraft.client.Minecraft;
                    import net.minecraft.client.settings.KeyBinding;
                    import net.minecraft.entity.Entity;
                    import net.minecraft.entity.EntityLivingBase;
                    import net.minecraft.entity.player.EntityPlayer;
                    import net.minecraft.util.MovingObjectPosition;
                    import net.minecraft.util.Vec3;
                    import net.minecraft.world.World;
                    
                    import org.lwjgl.input.Keyboard;
                    
                    import cpw.mods.fml.client.FMLClientHandler;
                    import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
                    import cpw.mods.fml.common.TickType;
                    import cpw.mods.fml.common.network.FMLNetworkHandler;
                    
                    public class KeyBindQuest extends KeyHandler
                    {
                    public static KeyBinding questKey = new KeyBinding("key.button.interactKey", Keyboard.KEY_I);
                    private EntityLivingBase entityTarget;
                    private World par2World;
                    
                    private String Newligne = System.getProperty("line.separator");
                    
                    public KeyBindQuest()
                    {
                    
                    super(new KeyBinding[] {questKey}, new boolean[] {false});
                    }
                    
                    @Override
                    public String getLabel()
                    {
                    return "Intéragir";
                    }
                    
                    @Override
                    public void keyDown(EnumSet <ticktype>types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
                    {}
                    
                    @Override
                    public void keyUp(EnumSet <ticktype>types, KeyBinding kb, boolean tickEnd)
                    {
                    
                    EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
                    Minecraft mc = Minecraft.getMinecraft();
                    
                    MovingObjectPosition mouseOver = player.rayTrace(100D, 1F);
                    /*
                    * if(mouseOver != null && mouseOver.typeOfHit ==
                    * EnumMovingObjectType.ENTITY) { if(mouseOver.entityHit instanceof
                    * MobtestEntity) { System.out.println(mouseOver.typeOfHit.name());
                    * if(kb.keyCode == questKey.keyCode && mc.currentScreen == null &&
                    * player.getCurrentEquippedItem() != null &&
                    * player.getCurrentEquippedItem().getItem() == CoeQuestMain.quest)//
                    * ADMIN { FMLNetworkHandler.openGui(player, CoeQuestMain.instance, 2,
                    * player.worldObj, (int)Math.floor(player.posX),
                    * (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); }
                    *
                    * else if(kb.keyCode == questKey.keyCode && mc.currentScreen == null) {
                    * FMLNetworkHandler.openGui(player, CoeQuestMain.instance, 1,
                    * player.worldObj, (int)Math.floor(player.posX),
                    * (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); } } }
                    */
                    if(kb.keyCode == questKey.keyCode && mc.currentScreen == null)
                    // && player.getCurrentEquippedItem() != null &&
                    // player.getCurrentEquippedItem().getItem() == CoeQuestMain.quest)ADMIN
                    {
                    System.out.println("test 0");
                    // FMLNetworkHandler.openGui(player, CoeQuestMain.instance, 2,
                    // player.worldObj, (int)Math.floor(player.posX),
                    // (int)Math.floor(player.posY), (int)Math.floor(player.posZ));
                    if(player instanceof EntityPlayer)
                    {
                    System.out.println("test 1");
                    player = (EntityPlayer)player;
                    Entity target = null;
                    System.out.println("test 1 bis");
                    if(par2World
                    .getEntitiesWithinAABB
                    (CoeMob.Mob.MobtestEntity.class,
                    player
                    .boundingBox
                    .expand
                    (32.0D,
                    32.0D,
                    32.0D))
                    != null)
                    {
                    List entityTagetList = par2World.getEntitiesWithinAABB(CoeMob.Mob.MobtestEntity.class, player.boundingBox.expand(32.0D, 32.0D, 32.0D));
                    System.out.println("test 1 tris");
                    for(int i = 0; i < entityTagetList.size(); i++)
                    {
                    System.out.println("test 2");
                    Entity entityTarget = (Entity)entityTagetList.get(i);
                    if(entityTarget != player && entityTarget instanceof EntityLivingBase)
                    {
                    EntityLivingBase entityLivingTarget = (EntityLivingBase)entityTarget;
                    Vec3 vec3 = player.getLook(1.0F).normalize();
                    Vec3 vec31 = entityLivingTarget.worldObj.getWorldVec3Pool().getVecFromPool(entityLivingTarget.posX - player.posX, entityLivingTarget.boundingBox.minY + (double)(entityLivingTarget.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), entityLivingTarget.posZ - player.posZ);
                    double d0 = vec31.lengthVector();
                    vec31 = vec31.normalize();
                    double d1 = vec3.dotProduct(vec31);
                    if(d1 > 1.0D - 0.025D / d0 && player.canEntityBeSeen(entityLivingTarget))
                    {
                    System.out.println("test 3");
                    target = entityLivingTarget;
                    }
                    else
                    {
                    System.out.println("test 4");
                    target = null;
                    }
                    }
                    }
                    }
                    }
                    System.out.println("team: " + (Minecraft.getMinecraft().thePlayer.getTeam()) + Newligne);
                    System.out.println("target: " + entityTarget + Newligne);
                    System.out.println("MouseOver" + mouseOver);
                    }
                    
                    /*
                    * else if(kb.keyCode == questKey.keyCode && mc.currentScreen == null) {
                    * FMLNetworkHandler.openGui(player, CoeQuestMain.instance, 1,
                    * player.worldObj, (int)Math.floor(player.posX),
                    * (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); }
                    */
                    }
                    
                    @Override
                    public EnumSet <ticktype>ticks()
                    {
                    return EnumSet.allOf(TickType.class);
                    }
                    }
                    
                    ```</ticktype></ticktype></ticktype>
                    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

                      private World par2World;
                      Forcement il est null si tu fais ça …
                      Vire se truc et remplace par2World par player.worldObj

                      1 réponse Dernière réponse Répondre Citer 0
                      • isadorI Hors-ligne
                        isador Moddeurs confirmés Modérateurs
                        dernière édition par

                        car crash plus mais target est toujours null

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

                        MINECRAFT FORGE FRANCE © 2024

                        Powered by NodeBB