Jump to content

[1.16.5] Help with making an entity attack if the player gets hurt


TheMajorN

Recommended Posts

Heya,

I'm trying to make it so that my entity, the Quipper, becomes hostile and attacks everything nearby if anything gets hurt near it.  At the moment, I'm not worried about actually making them hostile, but triggering the event itself, and notifying myself with a console message.

Here is the code I used:

@Mod.EventBusSubscriber(modid = FeyWild.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class QuipperEvents {

    @SubscribeEvent
    public void attackEntitiesTrigger(LivingHurtEvent event) {
      	// Establish living entity, and its block position
        LivingEntity entity = event.getEntityLiving();
        BlockPos pos = event.getEntityLiving().blockPosition();
        World world = event.getEntityLiving().level;

        // Create a 20x20x20 block radius from where the entity is hurt
        AxisAlignedBB blockAABB = new AxisAlignedBB(pos).inflate(20, 20, 20);

        assert world != null;
      	// Checking for the amount of quippers in that radius
        List<QuipperEntity> entities = world.getEntities
                (EntityInit.QUIPPER.get(), blockAABB, dryadEntity -> true);
	// If there are more than 0 quippers in the radius, display message
        if (entities.size() > 0) {
            FeyWild.LOGGER.info("You've frenzied the quippers!");
        }
    }
}

I assume it's not working because I'm misinterpreting LivingEntityHurtEvent to mean something else, but if anyone could steer me in the right direction, that would be much appreciated.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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