MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create a monster that attacks only when no player is looking at it"
/* This mod creates a monster that only attacks when no player is looking at it. */ public class ShyMonsterEntity extends MonsterEntity { public ShyMonsterEntity(EntityType<? extends MonsterEntity> type, World worldIn) { super(type, worldIn); } @Override public void tick() { super.tick(); List<PlayerEntity> players = this.level.getEntitiesOfClass(PlayerEntity.class, this.getBoundingBox().inflate(10.0D)); boolean playerIsLooking = players.stream().anyMatch(player -> player.canSee(this)); if (!playerIsLooking) { this.setAggressive(true); } else { this.setAggressive(false); } } /* Other necessary methods like registerAttributes, createSpawnPacket, etc. */ } /* This monster entity will only attack when no player within a 10 block radius is looking at it. */