| 1 | package net.minecraft.world.entity.monster.illager;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Direction;
|
| 6 | import net.minecraft.server.level.ServerLevel;
|
| 7 | import net.minecraft.sounds.SoundEvent;
|
| 8 | import net.minecraft.sounds.SoundEvents;
|
| 9 | import net.minecraft.util.Mth;
|
| 10 | import net.minecraft.world.damagesource.DamageSource;
|
| 11 | import net.minecraft.world.entity.Entity;
|
| 12 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 13 | import net.minecraft.world.entity.EntityType;
|
| 14 | import net.minecraft.world.entity.EntityTypes;
|
| 15 | import net.minecraft.world.entity.LivingEntity;
|
| 16 | import net.minecraft.world.entity.Mob;
|
| 17 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 18 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 19 | import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
|
| 20 | import net.minecraft.world.entity.ai.goal.FloatGoal;
|
| 21 | import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
|
| 22 | import net.minecraft.world.entity.ai.goal.RandomStrollGoal;
|
| 23 | import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
|
| 24 | import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
|
| 25 | import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
| 26 | import net.minecraft.world.entity.animal.golem.IronGolem;
|
| 27 | import net.minecraft.world.entity.animal.sheep.Sheep;
|
| 28 | import net.minecraft.world.entity.monster.Monster;
|
| 29 | import net.minecraft.world.entity.monster.Vex;
|
| 30 | import net.minecraft.world.entity.monster.creaking.Creaking;
|
| 31 | import net.minecraft.world.entity.npc.villager.AbstractVillager;
|
| 32 | import net.minecraft.world.entity.player.Player;
|
| 33 | import net.minecraft.world.entity.projectile.EvokerFangs;
|
| 34 | import net.minecraft.world.entity.raid.Raider;
|
| 35 | import net.minecraft.world.item.DyeColor;
|
| 36 | import net.minecraft.world.level.Level;
|
| 37 | import net.minecraft.world.level.block.state.BlockState;
|
| 38 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 39 | import net.minecraft.world.level.gamerules.GameRules;
|
| 40 | import net.minecraft.world.phys.Vec3;
|
| 41 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 42 | import net.minecraft.world.scores.PlayerTeam;
|
| 43 | import org.jspecify.annotations.Nullable;
|
| 44 |
|
| 45 | public class Evoker extends SpellcasterIllager {
|
| 46 | private @Nullable Sheep wololoTarget;
|
| 47 |
|
| 48 | public Evoker(final EntityType<? extends Evoker> type, final Level level) {
|
| 49 | super(type, level);
|
| 50 | this.xpReward = 10;
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | protected void registerGoals() {
|
| 55 | super.registerGoals();
|
| 56 | this.goalSelector.addGoal(0, new FloatGoal(this));
|
| 57 | this.goalSelector.addGoal(1, new Evoker.EvokerCastingSpellGoal());
|
| 58 | this.goalSelector.addGoal(2, new AvoidEntityGoal<>(this, Player.class, 8.0F, 0.6, 1.0));
|
| 59 | this.goalSelector.addGoal(3, new AvoidEntityGoal<>(this, Creaking.class, 8.0F, 0.6, 1.0));
|
| 60 | this.goalSelector.addGoal(4, new Evoker.EvokerSummonSpellGoal());
|
| 61 | this.goalSelector.addGoal(5, new Evoker.EvokerAttackSpellGoal());
|
| 62 | this.goalSelector.addGoal(6, new Evoker.EvokerWololoSpellGoal());
|
| 63 | this.goalSelector.addGoal(8, new RandomStrollGoal(this, 0.6));
|
| 64 | this.goalSelector.addGoal(9, new LookAtPlayerGoal(this, Player.class, 3.0F, 1.0F));
|
| 65 | this.goalSelector.addGoal(10, new LookAtPlayerGoal(this, Mob.class, 8.0F));
|
| 66 | this.targetSelector.addGoal(1, new HurtByTargetGoal(this, Raider.class).setAlertOthers());
|
| 67 | this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true).setUnseenMemoryTicks(300));
|
| 68 | this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, AbstractVillager.class, false).setUnseenMemoryTicks(300));
|
| 69 | this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, IronGolem.class, false));
|
| 70 | }
|
| 71 |
|
| 72 | public static AttributeSupplier.Builder createAttributes() {
|
| 73 | return Monster.createMonsterAttributes().add(Attributes.MOVEMENT_SPEED, 0.5).add(Attributes.FOLLOW_RANGE, 12.0).add(Attributes.MAX_HEALTH, 24.0);
|
| 74 | }
|
| 75 |
|
| 76 | @Override
|
| 77 | public SoundEvent getCelebrateSound() {
|
| 78 | return SoundEvents.EVOKER_CELEBRATE;
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | protected boolean considersEntityAsAlly(final Entity other) {
|
| 83 | if (other == this) {
|
| 84 | return true;
|
| 85 | }
|
| 86 |
|
| 87 | if (super.considersEntityAsAlly(other)) {
|
| 88 | return true;
|
| 89 | }
|
| 90 |
|
| 91 | if (other instanceof Vex vex) {
|
| 92 | LivingEntity rootOwner = vex.getRootOwner();
|
| 93 | if (rootOwner != null && (rootOwner == this || super.considersEntityAsAlly(rootOwner))) {
|
| 94 | return true;
|
| 95 | }
|
| 96 | }
|
| 97 |
|
| 98 | return false;
|
| 99 | }
|
| 100 |
|
| 101 | @Override
|
| 102 | protected SoundEvent getAmbientSound() {
|
| 103 | return SoundEvents.EVOKER_AMBIENT;
|
| 104 | }
|
| 105 |
|
| 106 | @Override
|
| 107 | protected SoundEvent getDeathSound() {
|
| 108 | return SoundEvents.EVOKER_DEATH;
|
| 109 | }
|
| 110 |
|
| 111 | @Override
|
| 112 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 113 | return SoundEvents.EVOKER_HURT;
|
| 114 | }
|
| 115 |
|
| 116 | private void setWololoTarget(final @Nullable Sheep wololoTarget) {
|
| 117 | this.wololoTarget = wololoTarget;
|
| 118 | }
|
| 119 |
|
| 120 | private @Nullable Sheep getWololoTarget() {
|
| 121 | return this.wololoTarget;
|
| 122 | }
|
| 123 |
|
| 124 | @Override
|
| 125 | protected SoundEvent getCastingSoundEvent() {
|
| 126 | return SoundEvents.EVOKER_CAST_SPELL;
|
| 127 | }
|
| 128 |
|
| 129 | @Override
|
| 130 | public void applyRaidBuffs(final ServerLevel level, final int wave, final boolean isCaptain) {
|
| 131 | }
|
| 132 |
|
| 133 | private class EvokerAttackSpellGoal extends SpellcasterIllager.SpellcasterUseSpellGoal {
|
| 134 | @Override
|
| 135 | protected int getCastingTime() {
|
| 136 | return 40;
|
| 137 | }
|
| 138 |
|
| 139 | @Override
|
| 140 | protected int getCastingInterval() {
|
| 141 | return 100;
|
| 142 | }
|
| 143 |
|
| 144 | @Override
|
| 145 | protected void performSpellCasting() {
|
| 146 | LivingEntity target = Evoker.this.getTarget();
|
| 147 | double minY = Math.min(target.getY(), Evoker.this.getY());
|
| 148 | double maxY = Math.max(target.getY(), Evoker.this.getY()) + 1.0;
|
| 149 | float angleTowardsTarget = (float)Mth.atan2(target.getZ() - Evoker.this.getZ(), target.getX() - Evoker.this.getX());
|
| 150 | if (Evoker.this.distanceToSqr(target) < 9.0) {
|
| 151 | for (int i = 0; i < 5; i++) {
|
| 152 | float angle = angleTowardsTarget + i * (float) Math.PI * 0.4F;
|
| 153 | this.createSpellEntity(Evoker.this.getX() + Mth.cos(angle) * 1.5, Evoker.this.getZ() + Mth.sin(angle) * 1.5, minY, maxY, angle, 0);
|
| 154 | }
|
| 155 |
|
| 156 | for (int i = 0; i < 8; i++) {
|
| 157 | float angle = angleTowardsTarget + i * (float) Math.PI * 2.0F / 8.0F + (float) (Math.PI * 2.0 / 5.0);
|
| 158 | this.createSpellEntity(Evoker.this.getX() + Mth.cos(angle) * 2.5, Evoker.this.getZ() + Mth.sin(angle) * 2.5, minY, maxY, angle, 3);
|
| 159 | }
|
| 160 | } else {
|
| 161 | for (int i = 0; i < 16; i++) {
|
| 162 | double reach = 1.25 * (i + 1);
|
| 163 | int spellSpeed = 1 * i;
|
| 164 | this.createSpellEntity(
|
| 165 | Evoker.this.getX() + Mth.cos(angleTowardsTarget) * reach,
|
| 166 | Evoker.this.getZ() + Mth.sin(angleTowardsTarget) * reach,
|
| 167 | minY,
|
| 168 | maxY,
|
| 169 | angleTowardsTarget,
|
| 170 | spellSpeed
|
| 171 | );
|
| 172 | }
|
| 173 | }
|
| 174 | }
|
| 175 |
|
| 176 | private void createSpellEntity(final double x, final double z, final double minY, final double maxY, final float angle, final int delayTicks) {
|
| 177 | BlockPos pos = BlockPos.containing(x, maxY, z);
|
| 178 | boolean success = false;
|
| 179 | double topOffset = 0.0;
|
| 180 |
|
| 181 | do {
|
| 182 | BlockPos below = pos.below();
|
| 183 | BlockState belowState = Evoker.this.level().getBlockState(below);
|
| 184 | if (belowState.isFaceSturdy(Evoker.this.level(), below, Direction.UP)) {
|
| 185 | if (!Evoker.this.level().isEmptyBlock(pos)) {
|
| 186 | BlockState blockState = Evoker.this.level().getBlockState(pos);
|
| 187 | VoxelShape shape = blockState.getCollisionShape(Evoker.this.level(), pos);
|
| 188 | if (!shape.isEmpty()) {
|
| 189 | topOffset = shape.max(Direction.Axis.Y);
|
| 190 | }
|
| 191 | }
|
| 192 |
|
| 193 | success = true;
|
| 194 | break;
|
| 195 | }
|
| 196 |
|
| 197 | pos = pos.below();
|
| 198 | } while (pos.getY() >= Mth.floor(minY) - 1);
|
| 199 |
|
| 200 | if (success) {
|
| 201 | Evoker.this.level().addFreshEntity(new EvokerFangs(Evoker.this.level(), x, pos.getY() + topOffset, z, angle, delayTicks, Evoker.this));
|
| 202 | Evoker.this.level().gameEvent(GameEvent.ENTITY_PLACE, new Vec3(x, pos.getY() + topOffset, z), GameEvent.Context.of(Evoker.this));
|
| 203 | }
|
| 204 | }
|
| 205 |
|
| 206 | @Override
|
| 207 | protected SoundEvent getSpellPrepareSound() {
|
| 208 | return SoundEvents.EVOKER_PREPARE_ATTACK;
|
| 209 | }
|
| 210 |
|
| 211 | @Override
|
| 212 | protected SpellcasterIllager.IllagerSpell getSpell() {
|
| 213 | return SpellcasterIllager.IllagerSpell.FANGS;
|
| 214 | }
|
| 215 | }
|
| 216 |
|
| 217 | private class EvokerCastingSpellGoal extends SpellcasterIllager.SpellcasterCastingSpellGoal {
|
| 218 | @Override
|
| 219 | public void tick() {
|
| 220 | if (Evoker.this.getTarget() != null) {
|
| 221 | Evoker.this.getLookControl().setLookAt(Evoker.this.getTarget(), Evoker.this.getMaxHeadYRot(), Evoker.this.getMaxHeadXRot());
|
| 222 | } else if (Evoker.this.getWololoTarget() != null) {
|
| 223 | Evoker.this.getLookControl().setLookAt(Evoker.this.getWololoTarget(), Evoker.this.getMaxHeadYRot(), Evoker.this.getMaxHeadXRot());
|
| 224 | }
|
| 225 | }
|
| 226 | }
|
| 227 |
|
| 228 | private class EvokerSummonSpellGoal extends SpellcasterIllager.SpellcasterUseSpellGoal {
|
| 229 | private final TargetingConditions vexCountTargeting = TargetingConditions.forNonCombat().range(16.0).ignoreLineOfSight().ignoreInvisibilityTesting();
|
| 230 |
|
| 231 | @Override
|
| 232 | public boolean canUse() {
|
| 233 | if (!super.canUse()) {
|
| 234 | return false;
|
| 235 | }
|
| 236 |
|
| 237 | int vexes = getServerLevel(Evoker.this.level())
|
| 238 | .getNearbyEntities(Vex.class, this.vexCountTargeting, Evoker.this, Evoker.this.getBoundingBox().inflate(16.0))
|
| 239 | .size();
|
| 240 | return Evoker.this.random.nextInt(8) + 1 > vexes;
|
| 241 | }
|
| 242 |
|
| 243 | @Override
|
| 244 | protected int getCastingTime() {
|
| 245 | return 100;
|
| 246 | }
|
| 247 |
|
| 248 | @Override
|
| 249 | protected int getCastingInterval() {
|
| 250 | return 340;
|
| 251 | }
|
| 252 |
|
| 253 | @Override
|
| 254 | protected void performSpellCasting() {
|
| 255 | ServerLevel serverLevel = (ServerLevel)Evoker.this.level();
|
| 256 | PlayerTeam evokerTeam = Evoker.this.getTeam();
|
| 257 |
|
| 258 | for (int i = 0; i < 3; i++) {
|
| 259 | BlockPos pos = Evoker.this.blockPosition().offset(-2 + Evoker.this.random.nextInt(5), 1, -2 + Evoker.this.random.nextInt(5));
|
| 260 | Vex vex = EntityTypes.VEX.create(Evoker.this.level(), EntitySpawnReason.MOB_SUMMONED);
|
| 261 | if (vex != null) {
|
| 262 | vex.snapTo(pos, 0.0F, 0.0F);
|
| 263 | vex.finalizeSpawn(serverLevel, serverLevel.getCurrentDifficultyAt(pos), EntitySpawnReason.MOB_SUMMONED, null);
|
| 264 | vex.setOwner(Evoker.this);
|
| 265 | vex.setBoundOrigin(pos);
|
| 266 | vex.setLimitedLife(20 * (30 + Evoker.this.random.nextInt(90)));
|
| 267 | if (evokerTeam != null) {
|
| 268 | serverLevel.getScoreboard().addPlayerToTeam(vex.getScoreboardName(), evokerTeam);
|
| 269 | }
|
| 270 |
|
| 271 | serverLevel.addFreshEntityWithPassengers(vex);
|
| 272 | serverLevel.gameEvent(GameEvent.ENTITY_PLACE, pos, GameEvent.Context.of(Evoker.this));
|
| 273 | }
|
| 274 | }
|
| 275 | }
|
| 276 |
|
| 277 | @Override
|
| 278 | protected SoundEvent getSpellPrepareSound() {
|
| 279 | return SoundEvents.EVOKER_PREPARE_SUMMON;
|
| 280 | }
|
| 281 |
|
| 282 | @Override
|
| 283 | protected SpellcasterIllager.IllagerSpell getSpell() {
|
| 284 | return SpellcasterIllager.IllagerSpell.SUMMON_VEX;
|
| 285 | }
|
| 286 | }
|
| 287 |
|
| 288 | public class EvokerWololoSpellGoal extends SpellcasterIllager.SpellcasterUseSpellGoal {
|
| 289 | private final TargetingConditions wololoTargeting = TargetingConditions.forNonCombat()
|
| 290 | .range(16.0)
|
| 291 | .selector((target, level) -> ((Sheep)target).getColor() == DyeColor.BLUE);
|
| 292 |
|
| 293 | @Override
|
| 294 | public boolean canUse() {
|
| 295 | if (Evoker.this.getTarget() != null) {
|
| 296 | return false;
|
| 297 | }
|
| 298 |
|
| 299 | if (Evoker.this.isCastingSpell()) {
|
| 300 | return false;
|
| 301 | }
|
| 302 |
|
| 303 | if (Evoker.this.tickCount < this.nextAttackTickCount) {
|
| 304 | return false;
|
| 305 | }
|
| 306 |
|
| 307 | ServerLevel level = getServerLevel(Evoker.this.level());
|
| 308 | if (!level.getGameRules().get(GameRules.MOB_GRIEFING)) {
|
| 309 | return false;
|
| 310 | }
|
| 311 |
|
| 312 | List<Sheep> entities = level.getNearbyEntities(Sheep.class, this.wololoTargeting, Evoker.this, Evoker.this.getBoundingBox().inflate(16.0, 4.0, 16.0));
|
| 313 | if (entities.isEmpty()) {
|
| 314 | return false;
|
| 315 | }
|
| 316 |
|
| 317 | Evoker.this.setWololoTarget(entities.get(Evoker.this.random.nextInt(entities.size())));
|
| 318 | return true;
|
| 319 | }
|
| 320 |
|
| 321 | @Override
|
| 322 | public boolean canContinueToUse() {
|
| 323 | return Evoker.this.getWololoTarget() != null && this.attackWarmupDelay > 0;
|
| 324 | }
|
| 325 |
|
| 326 | @Override
|
| 327 | public void stop() {
|
| 328 | super.stop();
|
| 329 | Evoker.this.setWololoTarget(null);
|
| 330 | }
|
| 331 |
|
| 332 | @Override
|
| 333 | protected void performSpellCasting() {
|
| 334 | Sheep wololoTarget = Evoker.this.getWololoTarget();
|
| 335 | if (wololoTarget != null && wololoTarget.isAlive()) {
|
| 336 | wololoTarget.setColor(DyeColor.RED);
|
| 337 | }
|
| 338 | }
|
| 339 |
|
| 340 | @Override
|
| 341 | protected int getCastWarmupTime() {
|
| 342 | return 40;
|
| 343 | }
|
| 344 |
|
| 345 | @Override
|
| 346 | protected int getCastingTime() {
|
| 347 | return 60;
|
| 348 | }
|
| 349 |
|
| 350 | @Override
|
| 351 | protected int getCastingInterval() {
|
| 352 | return 140;
|
| 353 | }
|
| 354 |
|
| 355 | @Override
|
| 356 | protected SoundEvent getSpellPrepareSound() {
|
| 357 | return SoundEvents.EVOKER_PREPARE_WOLOLO;
|
| 358 | }
|
| 359 |
|
| 360 | @Override
|
| 361 | protected SpellcasterIllager.IllagerSpell getSpell() {
|
| 362 | return SpellcasterIllager.IllagerSpell.WOLOLO;
|
| 363 | }
|
| 364 | }
|
| 365 | }
|
| 366 |
|