How can you make the piglin aggressive after breaking a block

Started by DarkCreeper208 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How can you make the piglin aggressive after breaking a block
Tue, 05/05/2026 - 04:32 (edited)

I'm working on a mod that add a ore in the nether and I want to know how to get piglin attack you after mining the ore.

I'm on version Mcreator 2026.1

Edited by DarkCreeper208 on Tue, 05/05/2026 - 04:32
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Use a trigger on the ore…
Tue, 05/05/2026 - 11:58

Use a trigger on the ore block broken, then use an entity iterator: get all entities in area 3 3 3 or whatever size you want. If entity iterator is type piglin: set attack target of entity iterator to event/target entity, may be source entity in this case so try both.

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I did what you said and it…
Tue, 05/05/2026 - 23:01

I did what you said and it didn't work.

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Show me your procedure?
Wed, 05/06/2026 - 09:07

Show me your procedure?

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I sent a screenshot of it. …
Wed, 05/06/2026 - 19:26

I sent a screenshot of it.

orebreakingprocedurse

 

 

 

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It won't let me send a…
Wed, 05/06/2026 - 19:33
It won't let me send a screenshot. I'm just going to send you the code.
@SubscribeEvent
	public static void onBlockBreak(BlockEvent.BreakEvent event) {
		execute(event, event.getLevel(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), event.getPlayer());
	}

	public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
		execute(null, world, x, y, z, entity);
	}

	private static void execute(@Nullable Event event, LevelAccessor world, double x, double y, double z, Entity entity) {
		if (entity == null)
			return;
		{
			final Vec3 _center = new Vec3(x, y, z);
			for (Entity entityiterator : world.getEntitiesOfClass(Entity.class, new AABB(_center, _center).inflate(16 / 2d), e -> true).stream().sorted(Comparator.comparingDouble(_entcnd -> _entcnd.distanceToSqr(_center))).toList()) {
				if (entityiterator instanceof Piglin) {
					if (entityiterator instanceof Mob _entity && entity instanceof LivingEntity _ent)
						_entity.setTarget(_ent);
				}
			}
		}
	}
}
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try using imgbox next time…
Wed, 05/06/2026 - 21:27

Try using imgbox next time. Code looks fine but I can’t tell for sure. Did you use entity iterator for everything other than the set target to?

Is the procedure selected in the block tab? What happens when you break the block? Did you try increasing the range of the iterator?

 

Joined May 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you go into "element tags…
Thu, 05/07/2026 - 00:16

If you go into "element tags", add a block tag with the namespace of minecraft and the tag name of guarded_by_piglins, then you can add your block to the list. I hope this works!

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
fr6_17 I put the iterator…
Sun, 05/10/2026 - 03:24

fr6_17 I put the iterator entity on the "set target to", and I tried to find the proceed to detect block, but couldn't find it. I added the procedure to my ore, but every time I tried to break the ore, the piglins didn't react to it; they just picked up the item instead.

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Jasonc_414, I don't see…
Sun, 05/10/2026 - 03:28

Jasonc_414, I don't see elemental tags on procedures. Can you send me the code for it?

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Use jasonc_414’s tag…
Sun, 05/10/2026 - 09:18

Use jasonc_414’s tag suggestion. Go to element tags on the left sidebar under resources (your textures). Then either locate guarded_by_piglins in common tags or add/create it yourself by doing: blocks,minecraft,guarded_by_piglins and adding your block to the list afterwards it should work without anything else needed

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It works thank you.
Tue, 05/12/2026 - 04:44

It works thank you.