Posted November 19, 201410 yr hello, I am creating an item that has to "control" zombies. I am trying methods of EntityZombie for setting attack targets, but none of them seems to work. Now the strange thing is: The item works great on zombie pigmans, but zombies to not react at all. here is the important part of the code: Line line = Line.fromRaytrace(player, 100).toNearestBlock(world, false, 1); EntityLivingBase entity = (EntityLivingBase) line.getNearestEntity(world, EntityLivingBase.class, line.getPosition(1), player); System.out.println("entity = " + entity); if(entity != null){ double distance = Math.min(spirit * 5, 40); List zombies = world.getEntitiesWithinAABB(EntityZombie.class, AxisAlignedBB.getBoundingBox(player.posX - distance, player.posY - distance, player.posZ - distance, player.posX + distance, player.posY + distance, player.posZ + distance)); System.out.println("zombies = " + zombies); int times = 0; while(times < zombies.size()){ EntityZombie zombie = (EntityZombie) zombies.get(times); if(zombie != entity){ zombie.setTarget(entity); zombie.setAttackTarget(entity); zombie.setRevengeTarget(entity); System.out.println("target is set."); } ++times; } } Does anybody know a way to set the target of a zombie? And does anybody know why it works on zombie pigmans, but not on normal zombies?
November 20, 201410 yr Author I have edited the code to work on any undead mobs, but now the Zombie is the only entity I can't control. Here is my new code: Line line = Line.fromRaytrace(player, 100).toNearestBlock(world, false, 1); EntityLivingBase entity = (EntityLivingBase) line.getNearestEntity(world, EntityLivingBase.class, line.getPosition(1), player); System.out.println("entity = " + entity); if(entity != null){ double distance = Math.min(spirit * 5, 40); distance = 50; List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(player.posX - distance, player.posY - distance, player.posZ - distance, player.posX + distance, player.posY + distance, player.posZ + distance)); System.out.println("entities = " + entities); int times = 0; while(times < entities.size()){ EntityLivingBase living = (EntityLivingBase) entities.get(times); if(living != entity && living.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD){ living.setRevengeTarget(entity); if(living instanceof EntityCreature){ ((EntityCreature) living).setTarget(entity); } System.out.println("target is set."); } ++times; } } I can even control withers, but no zombies. EDIT: I can't control wither skeletons too. Why is target control different for every mob? Has anybody ever controlled zombies?
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.