Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.