Jump to content

[1.7.10] set attack target of zombies


knokko

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.