qxjl1010 Posted July 8, 2016 Posted July 8, 2016 Hi there, I'm a newbie here. I wanna build an entity that when I right click him, the entity moves to the certain position. How can I make it? Thx! Quote
qxjl1010 Posted July 9, 2016 Author Posted July 9, 2016 I tried to build an AI class, but it doesn't work :'( package com.practise.ai; import com.practise.NPC.EscortRequestNPC; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.ai.EntityAIBase; import net.minecraft.entity.ai.EntityAIMoveToBlock; import net.minecraft.util.BlockPos; import net.minecraft.world.World; public class EscortRequestNPCai extends EntityAIBase{ private final EscortRequestNPC entity; public EscortRequestNPCai(EscortRequestNPC entity){ this.entity = entity; } @Override public boolean shouldExecute() { if(entity.ifTrigger == true) return true; else return false; } @Override public void startExecuting() { BlockPos NPCpos = entity.getPosition(); int posX = NPCpos.getX(); int posY = NPCpos.getY(); int posZ = NPCpos.getZ(); posX += 200; posY += 200; entity.getNavigator().tryMoveToXYZ(posX, posY, posZ, 2); } } Quote
qxjl1010 Posted July 10, 2016 Author Posted July 10, 2016 Thanks buddy! package com.practise.NPC; import com.practise.ai.EscortRequestNPCai; import net.minecraft.entity.ai.EntityAIMoveToBlock; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class EscortRequestNPC extends EntityVillager{ public EscortRequestNPC(World worldIn) { super(worldIn); this.tasks.addTask(0, new EscortRequestNPCai(this)); } public boolean ifTrigger = false; @Override public boolean interact(EntityPlayer player) { ifTrigger = true; return true; } } Quote
qxjl1010 Posted July 10, 2016 Author Posted July 10, 2016 errr, I've already posX+=200, posY+=200. Quote
qxjl1010 Posted July 10, 2016 Author Posted July 10, 2016 Ok, the problem is, I can enter the method startExcuting, but it doesn't work. I've changed my code to this: package com.practise.ai; import com.practise.NPC.EscortRequestNPC; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.ai.EntityAIBase; import net.minecraft.entity.ai.EntityAIMoveToBlock; import net.minecraft.util.BlockPos; import net.minecraft.world.World; public class EscortRequestNPCai extends EntityAIBase{ private final EscortRequestNPC entity; BlockPos NPCpos; int posX; int posY; int posZ; public EscortRequestNPCai(EscortRequestNPC entity){ this.entity = entity; NPCpos = entity.getPosition(); posX = NPCpos.getX(); posY = NPCpos.getY(); posZ = NPCpos.getZ(); posX += 200; posY += 200; } @Override public boolean shouldExecute() { if(entity.ifTrigger == true) return true; else return false; } @Override public void startExecuting() { for(int i=0;i !=10;i++) System.out.println("enter startExecuting!!!"); entity.getNavigator().tryMoveToXYZ(posX, posY, posZ, 0.5); } } When I right click the entity, the console gave me this: [13:03:53] [server thread/INFO]: Player98 joined the game [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:57] [server thread/INFO] [sTDOUT]: [com.practise.ai.EscortRequestNPCai:startExecuting:42]: enter startExecuting!!! [13:03:58] [server thread/INFO]: Saving and pausing game... So, it seems the "tryMoveToXYZ" method did not work. Quote
qxjl1010 Posted July 10, 2016 Author Posted July 10, 2016 Changed to posX += 5; posY += 5; Still didn't work :'( Quote
qxjl1010 Posted July 11, 2016 Author Posted July 11, 2016 I changed my code to this: package com.practise.ai; import com.practise.NPC.EscortRequestNPC; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.ai.EntityAIBase; import net.minecraft.entity.ai.EntityAIMoveToBlock; import net.minecraft.util.BlockPos; import net.minecraft.world.World; public class EscortRequestNPCai extends EntityAIBase{ private final EscortRequestNPC entity; BlockPos NPCpos; int posX; int posY; int posZ; public EscortRequestNPCai(EscortRequestNPC entity){ this.entity = entity; NPCpos = entity.getPosition(); posX = NPCpos.getX(); posY = NPCpos.getY(); posZ = NPCpos.getZ(); posX += 5; posY += 5; } @Override public boolean shouldExecute() { if(entity.ifTrigger == true) return true; else return false; } @Override public void startExecuting() { System.out.println(entity.getNavigator().tryMoveToXYZ((double)posX, (double)posY, (double)posZ, 2)); } } And the console gave me "false" result. So I guess there must be something wrong with parameters? :'( Quote
jeffryfisher Posted July 11, 2016 Posted July 11, 2016 BTW, In class EscortRequestNPC, is interact being called when it should be? Do you ever clear ifTrigger to false? Does anything ever test for being at the XYZ so you can stop executing? Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
qxjl1010 Posted July 12, 2016 Author Posted July 12, 2016 is interact being called when it should be? I believe so, with other classes I made, I used it a bunch of times, they work perfectly. Do you ever clear ifTrigger to false? Oh, I forgot about it, I'll definitely add this when the entity moves to certain position. But the problem is: it doesn't even move now. Does anything ever test for being at the XYZ so you can stop executing? The same answer with last one, it doesn't move now. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.