I need help fixing my code to make mobs attack me when I right click on them.

Started by zommer500 on Wed, 07/06/2022 - 19:16

Topic category: Help with modding (Java Edition)

Last seen on 02:03, 26. Jul 2022
Joined May 2020

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I need help fixing my code to make mobs attack me when I right click on them.
Wed, 07/06/2022 - 19:16

Hey guys, I am trying to make passive mobs attack me when I right click on them, But I have bugs in my code when I export my mod.

The problem is a import function called net.minecraft.entity.EntityLiving is not working. There is bugs that say causes build errors and stuff like that.

I also need to know how the entityliving.setattacktarget() code work, but I don't have a way to fix this.

Here's the code:

import net.minecraft.entity.EntityLiving;

public class MobbattleProcedure {
    private static class GlobalTrigger {
        public static void onRightClickEntity(PlayerInteractEvent.EntityInteract event) {
            EntityLiving entity = event.getTarget();
            PlayerEntity sourceentity = event.getPlayer();
            if (event.getHand() != sourceentity.getActiveHand()) {
            double i = event.getPos().getX();
            double j = event.getPos().getY();
            double k = event.getPos().getZ();
            IWorld world = event.getWorld();
            Map<String, Object> dependencies = new HashMap<>();
            dependencies.put("x", i);
            dependencies.put("y", j);
            dependencies.put("z", k);
            dependencies.put("world", world);
            dependencies.put("entity", entity);
            dependencies.put("sourceentity", sourceentity);
            dependencies.put("event", event);