Savoir quelle entity regarde le joueur
-
Salut a tous je suis en train de bosser sur un système de quête et j’ai besoin de deux/trois chose:
la première:
if(kb.keyCode == questKey.keyCode && mc.currentScreen == null) { FMLNetworkHandler.openGui(player, CoeQuestMain.instance, 2, player.worldObj, (int)Math.floor(player.posX), (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); }
voila ce code permet d’ouvrir le GUI d’id 2, mais j’aimerai qu’il check aussi quelle entité le joueur regarde, ce sera utile pour le deuxième problème:
je veut via le check de l’entity écrire dans le NBT de la dite entité un String (via un l8nString), pour ensuite rebondir sur le 3ème problème:
dans le panel de création de quête j’ai 4 élément (pour l’instant)
textBox1
textBox2
button1
button2
la première textBox sert a écrire la quête, la seconde a attribuer un id a la quête.
la premier bouton serai la pour enregistrer le contenu de textBox1 dans le fichier lang FR et le second bouton dans le lang EN
cependant je ne sais pas comment faire.en résumé:
-faire une condition pour check quelle entité je regarde
-écrire dans le NBT de l’entité vue
-écrire dans un fichier lang automatiquementje précise que dans le mod chaque entité est unique, c’est à dire qu’il y en aura une seule dans toute la map
-
Je fais la setup de Forge et je te dis
-
merci
-
Je n’ai vraiment pas le temps en ce moment, je finirais ça demain mais j’ai des pistes à te donner:
- Le Vec3 du player
- Le world.getEntitiesWithinBoundingBox()
Essaie de trouver quelque chose avec ça et bonne nuit
-
merci je vais chercher
-
Alors t’as trouvé ?
-
non car je vient de me reveiller et je me suis coucher après toi ^^
-
Dans le onUpdate, y’a une fonction qui fait exactement ça;
-
merci je regarde ca
si je copie colle ca code:if (par5 && par3Entity instanceof EntityPlayer && !par2World.isRemote) { if (par3Entity.getEntityData().getBoolean("devastatorFired")) { EntityPlayer player = (EntityPlayer) par3Entity; Entity target = null; List entityTagetList = par2World.getEntitiesWithinAABB( Entity.class, player.boundingBox.expand(32.0D, 32.0D, 32.0D)); for (int i = 0; i < entityTagetList.size(); i++) { 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)) { target = entityLivingTarget; } else { target = null; } } }
je peut faire après un
if(target == entityTarget) { //mon code }
?
-
Bah, target = l’entité visée.
Après, tu en fais ce que tu veux. -
dans tout les cas target sera egal a entityLivingTarget non?
-
Oui
-
J’aime bien ton message + ta signature.
ça fait
Oui ! Non !
On peut limite compléter avec : en fait je ne sais pas. xD(Ceci était un message inutile de robin4002)
-
merci de ta participation robin
du coup gugu avec ton code on peut récup l’entité visé?
-
Petit up car je comprend pas trop le code de gugu
-
Oui, l’entité Target est la cible.
-
Donc en fait si je veux écrire un nbt dans l’entity visé faudrat utiliser la variable Target ?
EDIT:
problème: target renvoi toujours nullif(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)); if(par5 && par3Entity instanceof EntityPlayer && !par2World.isRemote) { player = (EntityPlayer)par3Entity; Entity target = null; List entityTagetList = par2World.getEntitiesWithinAABB(Entity.class, player.boundingBox.expand(32.0D, 32.0D, 32.0D)); for(int i = 0; i < entityTagetList.size(); i++) { 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)) { target = entityLivingTarget; } else { target = null; } } } } } 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)); } System.out.println("target: " + entityTarget); System.out.println(mouseOver); }
-
bon pour le problème de null c’était moi, tromper de condition
maintenant ca crash au niveau du .getEntitiesWithinAABB deList entityTagetList = par2World.getEntitiesWithinAABB(CoeMob.Mob.MobtestEntity.class, player.boundingBox.expand(32.0D, 32.0D, 32.0D));
le crash report:
:::–-- Minecraft Crash Report ---- // Why is it breaking :( Time: 30/06/14 13:15 Description: Unexpected error java.lang.NullPointerException at CoeQuest.KeyBindQuest.keyUp(KeyBindQuest.java:84) at cpw.mods.fml.client.registry.KeyBindingRegistry$KeyHandler.keyTick(KeyBindingRegistry.java:129) at cpw.mods.fml.client.registry.KeyBindingRegistry$KeyHandler.tickStart(KeyBindingRegistry.java:102) at cpw.mods.fml.common.SingleIntervalHandler.tickStart(SingleIntervalHandler.java:28) at cpw.mods.fml.common.FMLCommonHandler.tickStart(FMLCommonHandler.java:122) at cpw.mods.fml.common.FMLCommonHandler.onRenderTickStart(FMLCommonHandler.java:372) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:944) at net.minecraft.client.Minecraft.run(Minecraft.java:838) at net.minecraft.client.main.Main.main(Main.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) at net.minecraft.launchwrapper.Launch.main(Launch.java:27) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at CoeQuest.KeyBindQuest.keyUp(KeyBindQuest.java:84) at cpw.mods.fml.client.registry.KeyBindingRegistry$KeyHandler.keyTick(KeyBindingRegistry.java:129) at cpw.mods.fml.client.registry.KeyBindingRegistry$KeyHandler.tickStart(KeyBindingRegistry.java:102) at cpw.mods.fml.common.SingleIntervalHandler.tickStart(SingleIntervalHandler.java:28) at cpw.mods.fml.common.FMLCommonHandler.tickStart(FMLCommonHandler.java:122) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['isador34'/4, l='MpServer', x=1143,30, y=5,62, z=223,68]] Chunk stats: MultiplayerChunkCache: 275 Level seed: 0 Level generator: ID 01 - flat, ver 0\. Features enabled: false Level generator options: Level spawn location: World: (1121,4,239), Chunk: (at 1,0,15 in 70,14; contains blocks 1120,0,224 to 1135,255,239), Region: (2,0; contains chunks 64,0 to 95,31, blocks 1024,0,0 to 1535,255,511) Level time: 375011 game time, 107102 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 5 total; [MobtestEntity['entity.Testmob.name'/0, l='MpServer', x=1141,31, y=4,00, z=223,69], EntityClientPlayerMP['isador34'/4, l='MpServer', x=1143,30, y=5,62, z=223,68], MobtestEntity['entity.Testmob.name'/1, l='MpServer', x=1151,31, y=4,00, z=226,69], MobtestEntity['entity.Testmob.name'/2, l='MpServer', x=1151,69, y=4,00, z=226,69], MobtestEntity['entity.Testmob.name'/3, l='MpServer', x=1151,69, y=4,00, z=226,69]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:440) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2312) at net.minecraft.client.Minecraft.run(Minecraft.java:863) at net.minecraft.client.main.Main.main(Main.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) at net.minecraft.launchwrapper.Launch.main(Launch.java:27) – System Details -- Details: Minecraft Version: 1.6.4 Operating System: Windows 8 (amd64) version 6.2 Java Version: 1.7.0_45, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 661595768 bytes (630 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 19636 (1099616 bytes; 1 MB) allocated, 1 (56 bytes; 0 MB) used Suspicious classes: FML and Forge are installed IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v8.11 FML v6.4.45.953 Minecraft Forge 9.11.1.953 15 mods loaded, 15 mods active mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{6.4.45.953} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{9.11.1.953} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coebiome{1.0.0} [CoeBiome] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coeblock{1.0.0} [Coe Block] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coebordure{1.0.0} [Coe Bordure] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coecore{1.0.0} [CoeCore] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coelevel{1.0.0} [CoeLevel] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coemob{1.0.0} [Coemob] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coequest{1.0.0} [CoeQuest] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coespell{1.0.0} [CoeSpell] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available coeweapon{1.0.0} [CoeWeapon] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available crusadegui{2.0.0} [COE gui] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available mineralherb{1.0.1} [Mineralherb] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available PM{V.1.0.0} [Portal WoW] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Launched Version: 1.6 LWJGL: 2.9.0 OpenGL: GeForce GTX 660/PCIe/SSE2 GL version 4.4.0, NVIDIA Corporation Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Pack: Default Current Language: English (US) Profiler Position: N/A (disabled) Vec3 Pool Size: 292 (16352 bytes; 0 MB) allocated, 14 (784 bytes; 0 MB) used
:::
le code: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 team; 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; List entityTagetList = par2World .getEntitiesWithinAABB (CoeMob.Mob.MobtestEntity.class , player.boundingBox.expand(32.0D, 32.0D, 32.0D)); 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; } } } } } /*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)); }*/ team = Minecraft.getMinecraft().thePlayer.getTeam().toString(); System.out.println("team: "+team+Newligne); System.out.println("target: " + entityTarget+Newligne); System.out.println("MouseOver"+mouseOver); } @Override public EnumSet <ticktype>ticks() { return EnumSet.allOf(TickType.class); } } ```</ticktype></ticktype></ticktype>
-
Fais un check que la méthode ne return pas null
-
comment ca?