Savoir quelle entity regarde le joueur
-
if(par2World.getEntitiesWithinAABB(CoeMob.Mob.MobtestEntity.class, player.boundingBox.expand(32.0D, 32.0D, 32.0D)) != null)
-
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)
-
Essaie de voir de quelle partie ça viens
-
ca vient du .getEntitiesWithinAABB
-
Dans ce cas ton objet world est null, envoie toute ta classe.
-
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>
-
private World par2World;
Forcement il est null si tu fais ça …
Vire se truc et remplace par2World par player.worldObj -
car crash plus mais target est toujours null