diff --git a/src/main/java/twilightforest/entity/ai/goal/BreathAttackGoal.java b/src/main/java/twilightforest/entity/ai/goal/BreathAttackGoal.java index dc2333aabf..0043e1502d 100644 --- a/src/main/java/twilightforest/entity/ai/goal/BreathAttackGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/BreathAttackGoal.java @@ -1,5 +1,6 @@ package twilightforest.entity.ai.goal; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntitySelector; @@ -12,7 +13,9 @@ import org.jetbrains.annotations.Nullable; import twilightforest.entity.IBreathAttacker; +import java.awt.*; import java.util.*; +import java.util.List; public class BreathAttackGoal extends Goal { @@ -85,7 +88,7 @@ public void tick() { // anyhoo, deal damage Entity target = this.getHeadLookTarget(); if (target != null) { - this.entityHost.doBreathAttack(target); + this.entityHost.doBreathAttack(getServerLevel(target), target); this.entityHost.gameEvent(GameEvent.PROJECTILE_SHOOT); } } diff --git a/src/main/java/twilightforest/entity/ai/goal/ChargeAttackGoal.java b/src/main/java/twilightforest/entity/ai/goal/ChargeAttackGoal.java index 03935b4ab5..d98908403e 100644 --- a/src/main/java/twilightforest/entity/ai/goal/ChargeAttackGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/ChargeAttackGoal.java @@ -1,6 +1,7 @@ package twilightforest.entity.ai.goal; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -97,7 +98,7 @@ public void tick() { } } } else if (this.canBreak) { - if (!this.charger.level().isClientSide() && EventHooks.canEntityGrief(this.charger.level(), this.charger)) { + if (!this.charger.level().isClientSide() && EventHooks.canEntityGrief(getServerLevel(this.charger), this.charger)) { AABB bb = this.charger.getBoundingBox(); int minx = Mth.floor(bb.minX - 0.75D); @@ -126,7 +127,7 @@ public void tick() { if (this.charger.distanceToSqr(this.chargeTarget.getX(), this.chargeTarget.getBoundingBox().minY, this.chargeTarget.getZ()) <= rangeSq) { if (!this.hasAttacked) { this.hasAttacked = true; - this.charger.doHurtTarget(this.chargeTarget); + this.charger.doHurtTarget(getServerLevel(this.chargeTarget), this.chargeTarget); } } } diff --git a/src/main/java/twilightforest/entity/ai/goal/HoverBeamGoal.java b/src/main/java/twilightforest/entity/ai/goal/HoverBeamGoal.java index 6574ff16c9..4ff14c935d 100644 --- a/src/main/java/twilightforest/entity/ai/goal/HoverBeamGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/HoverBeamGoal.java @@ -1,8 +1,10 @@ package twilightforest.entity.ai.goal; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import twilightforest.entity.boss.SnowQueen; @@ -155,14 +157,14 @@ private void doRayAttack() { if (collisionBB.contains(srcVec)) { if (0.0D < hitDist || hitDist == 0.0D) { - this.attacker.doBreathAttack(possibleEntity); + this.attacker.doBreathAttack(getServerLevel(possibleEntity), possibleEntity); hitDist = 0.0D; } } else if (interceptPos.isPresent()) { double possibleDist = srcVec.distanceTo(interceptPos.get()); if (possibleDist < hitDist || hitDist == 0.0D) { - this.attacker.doBreathAttack(possibleEntity); + this.attacker.doBreathAttack(getServerLevel(possibleEntity), possibleEntity); hitDist = possibleDist; } } diff --git a/src/main/java/twilightforest/entity/ai/goal/HoverThenDropGoal.java b/src/main/java/twilightforest/entity/ai/goal/HoverThenDropGoal.java index 4dc9390878..5ba733a750 100644 --- a/src/main/java/twilightforest/entity/ai/goal/HoverThenDropGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/HoverThenDropGoal.java @@ -1,7 +1,9 @@ package twilightforest.entity.ai.goal; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.goal.Goal; import twilightforest.entity.boss.SnowQueen; import twilightforest.entity.boss.SnowQueen.Phase; @@ -114,7 +116,7 @@ public void tick() { // drop! this.dropTimer++; if (this.attacker.getY() > this.dropY) { - this.attacker.destroyBlocksInAABB(this.attacker.getBoundingBox().inflate(1, 0.5F, 1)); + this.attacker.destroyBlocksInAABB(getServerLevel(this.attacker), this.attacker.getBoundingBox().inflate(1, 0.5F, 1)); } } } diff --git a/src/main/java/twilightforest/entity/ai/goal/LichMinionsGoal.java b/src/main/java/twilightforest/entity/ai/goal/LichMinionsGoal.java index 838eddda29..a816e4d99e 100644 --- a/src/main/java/twilightforest/entity/ai/goal/LichMinionsGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/LichMinionsGoal.java @@ -9,6 +9,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.phys.Vec3; +import net.minecraft.server.level.ServerLevel; import net.neoforged.neoforge.event.EventHooks; import twilightforest.entity.boss.Lich; import twilightforest.entity.monster.LichMinion; @@ -88,14 +89,16 @@ public void tick() { } if (this.lich.getAttackCooldown() == 0) { + ServerLevel serverLevel = getServerLevel(this.lich); if (dist < 2.0F) { // melee attack - this.lich.doHurtTarget(targetedEntity); + this.lich.doHurtTarget(serverLevel, targetedEntity); + this.lich.swing(InteractionHand.MAIN_HAND); this.lich.setAttackCooldown(20); } else if (dist < ATTACK_RANGE && this.lich.getSensing().hasLineOfSight(targetedEntity)) { - if (this.lich.getNextAttackType() == 0) this.lich.launchProjectileAt(new LichBolt(this.lich.level(), this.lich)); - else this.lich.launchProjectileAt(new LichBomb(this.lich.level(), this.lich)); + if (this.lich.getNextAttackType() == 0) this.lich.launchProjectileAt(new LichBolt(serverLevel, this.lich)); + else this.lich.launchProjectileAt(new LichBomb(serverLevel, this.lich)); this.lich.swing(InteractionHand.MAIN_HAND); this.lich.setNextAttackType(this.lich.getRandom().nextBoolean() ? 0 : 1); @@ -129,7 +132,7 @@ private void spawnMinionAt() { // put a clone there LichMinion minion = new LichMinion(this.lich.level(), this.lich); minion.setPos(minionSpot.x(), minionSpot.y(), minionSpot.z()); - EventHooks.finalizeMobSpawn(minion, accessor, this.lich.level().getCurrentDifficultyAt(BlockPos.containing(minionSpot)), EntitySpawnReason.MOB_SUMMONED, null); + EventHooks.finalizeMobSpawn(minion, accessor, accessor.getCurrentDifficultyAt(BlockPos.containing(minionSpot)), EntitySpawnReason.MOB_SUMMONED, null); this.lich.level().addFreshEntity(minion); minion.setTarget(targetedEntity); diff --git a/src/main/java/twilightforest/entity/ai/goal/NagaMovementPattern.java b/src/main/java/twilightforest/entity/ai/goal/NagaMovementPattern.java index 36d9a0adb0..1cebe886ac 100644 --- a/src/main/java/twilightforest/entity/ai/goal/NagaMovementPattern.java +++ b/src/main/java/twilightforest/entity/ai/goal/NagaMovementPattern.java @@ -2,6 +2,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.goal.Goal; @@ -71,12 +72,13 @@ public void tick() { //the stunless charge has a higher chance to happen the lower the naga's health gets //difficulty is also factored in. The higher the difficulty the greater the chance float healthRatio = 1.0F - (this.naga.getHealth() / (this.naga.getMaxHealth())) - 0.25F; - float chance = Mth.clamp(healthRatio + (this.naga.level().getCurrentDifficultyAt(this.naga.blockPosition()).getDifficulty().getId() * 0.05F), 0.0F, 0.5F); + float chance = Mth.clamp(healthRatio + (getServerLevel(this.naga).getCurrentDifficultyAt(this.naga.blockPosition()).getDifficulty().getId() * 0.05F), 0.0F, 0.5F); float randChance = this.naga.getRandom().nextFloat() * 0.75F; boolean stunless = randChance < chance; this.naga.setStunlessCharging(stunless); this.stunCalculated = true; } + } case CRUMBLE -> { this.naga.getNavigation().stop(); @@ -176,7 +178,7 @@ private void doIntimidate() { } private void crumbleBelowTarget(int range) { - if (!EventHooks.canEntityGrief(this.naga.level(), this.naga) || naga.getTarget() == null) return; + if (!EventHooks.canEntityGrief(getServerLevel(this.naga), this.naga) || naga.getTarget() == null) return; int floor = (int) this.naga.getBoundingBox().minY; int targetY = (int) this.naga.getTarget().getBoundingBox().minY; @@ -247,4 +249,4 @@ public enum MovementState { CIRCLE, DAZE } -} \ No newline at end of file +} diff --git a/src/main/java/twilightforest/entity/ai/goal/NagaSmashGoal.java b/src/main/java/twilightforest/entity/ai/goal/NagaSmashGoal.java index 0c2a7b2406..d6216ce80d 100644 --- a/src/main/java/twilightforest/entity/ai/goal/NagaSmashGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/NagaSmashGoal.java @@ -1,6 +1,7 @@ package twilightforest.entity.ai.goal; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.tags.BlockTags; import net.minecraft.util.Mth; import net.minecraft.world.entity.ai.goal.Goal; @@ -20,7 +21,7 @@ public NagaSmashGoal(Naga naga) { @Override public boolean canUse() { - return this.naga.horizontalCollision && EventHooks.canEntityGrief(this.naga.level(), this.naga); + return this.naga.horizontalCollision && EventHooks.canEntityGrief(getServerLevel(this.naga), this.naga); } @Override diff --git a/src/main/java/twilightforest/entity/ai/goal/PhantomThrowWeaponGoal.java b/src/main/java/twilightforest/entity/ai/goal/PhantomThrowWeaponGoal.java index 3325a9e9c1..7686208ec3 100644 --- a/src/main/java/twilightforest/entity/ai/goal/PhantomThrowWeaponGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/PhantomThrowWeaponGoal.java @@ -5,6 +5,7 @@ import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.Vec3; import twilightforest.entity.boss.KnightPhantom; import twilightforest.entity.projectile.ThrownWep; import twilightforest.init.TFEntities; @@ -56,7 +57,7 @@ private void launchAxeAt(Entity targetedEntity) { projectile.shoot(tx, ty, tz, speed, 1.0F); - projectile.moveTo(sx, sy, sz, this.boss.getYRot(), this.boss.getXRot()); + projectile.snapTo(new Vec3(sx, sy, sz), this.boss.getYRot(), this.boss.getXRot()); this.boss.level().addFreshEntity(projectile); } @@ -76,11 +77,9 @@ private void launchPicks() { double vy = 0; double vz = Mth.sin(throwAngle); - ThrownWep projectile = new ThrownWep(TFEntities.THROWN_WEP.get(), this.boss.level(), this.boss).setDamage(3).setVelocity(0.015F).setItem(new ItemStack(TFItems.KNIGHTMETAL_PICKAXE.get())); - - projectile.moveTo(sx, sy, sz, i * 45F, this.boss.getXRot()); + projectile.snapTo(new Vec3(sx, sy, sz), i * 45, this.boss.getXRot()); float speed = 0.5F; diff --git a/src/main/java/twilightforest/entity/ai/goal/PhantomWatchAndAttackGoal.java b/src/main/java/twilightforest/entity/ai/goal/PhantomWatchAndAttackGoal.java index 55a0cd9ed9..870ae58edc 100644 --- a/src/main/java/twilightforest/entity/ai/goal/PhantomWatchAndAttackGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/PhantomWatchAndAttackGoal.java @@ -1,5 +1,6 @@ package twilightforest.entity.ai.goal; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.goal.Goal; @@ -34,7 +35,7 @@ public void tick() { if (this.boss.getSensing().hasLineOfSight(target)) { if (attackTime-- <= 0 && f1 < 2.0F && target.getBoundingBox().maxY > this.boss.getBoundingBox().minY && this.boss.getTarget().getBoundingBox().minY < this.boss.getBoundingBox().maxY) { attackTime = 20; - this.boss.doHurtTarget(target); + this.boss.doHurtTarget(getServerLevel(target), target); } } diff --git a/src/main/java/twilightforest/entity/ai/goal/RedcapLightTNTGoal.java b/src/main/java/twilightforest/entity/ai/goal/RedcapLightTNTGoal.java index d7c01ede11..9bf8031c5f 100644 --- a/src/main/java/twilightforest/entity/ai/goal/RedcapLightTNTGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/RedcapLightTNTGoal.java @@ -2,8 +2,10 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.gameevent.GameEvent; @@ -28,7 +30,7 @@ public RedcapLightTNTGoal(Redcap hostEntity, float speed) { @Override public boolean canUse() { - if (!EventHooks.canEntityGrief(this.redcap.level(), this.redcap)) { + if (!EventHooks.canEntityGrief(getServerLevel(this.redcap), this.redcap)) { return false; } diff --git a/src/main/java/twilightforest/entity/ai/goal/RedcapPlantTNTGoal.java b/src/main/java/twilightforest/entity/ai/goal/RedcapPlantTNTGoal.java index bb69f9e9cc..aced8c51c6 100644 --- a/src/main/java/twilightforest/entity/ai/goal/RedcapPlantTNTGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/RedcapPlantTNTGoal.java @@ -1,8 +1,10 @@ package twilightforest.entity.ai.goal; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.gameevent.GameEvent; import net.neoforged.neoforge.event.EventHooks; @@ -21,7 +23,7 @@ public boolean canUse() { && !this.redcap.heldTNT.isEmpty() && this.redcap.distanceToSqr(attackTarget) < 25 && !this.isTargetLookingAtMe(attackTarget) - && EventHooks.canEntityGrief(this.redcap.level(), this.redcap) + && EventHooks.canEntityGrief(getServerLevel(this.redcap), this.redcap) && !this.isLitTNTNearby(8) && this.findBlockTNTNearby(5) == null; } diff --git a/src/main/java/twilightforest/entity/ai/goal/SimplifiedAttackGoal.java b/src/main/java/twilightforest/entity/ai/goal/SimplifiedAttackGoal.java index bb03851ff7..5e15cd1150 100644 --- a/src/main/java/twilightforest/entity/ai/goal/SimplifiedAttackGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/SimplifiedAttackGoal.java @@ -1,5 +1,6 @@ package twilightforest.entity.ai.goal; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; @@ -53,7 +54,7 @@ protected void checkAndPerformAttack(LivingEntity entity) { if (this.attackTick <= 0 && this.mob.isWithinMeleeAttackRange(entity) && this.mob.hasLineOfSight(entity)) { this.attackTick = this.adjustedTickDelay(20); this.mob.swing(InteractionHand.MAIN_HAND); - this.mob.doHurtTarget(entity); + this.mob.doHurtTarget(getServerLevel(entity), entity); } } } \ No newline at end of file diff --git a/src/main/java/twilightforest/entity/ai/goal/ThrowRiderGoal.java b/src/main/java/twilightforest/entity/ai/goal/ThrowRiderGoal.java index d16cd22bfc..de76a941f5 100644 --- a/src/main/java/twilightforest/entity/ai/goal/ThrowRiderGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/ThrowRiderGoal.java @@ -11,10 +11,10 @@ import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.network.PacketDistributor; import twilightforest.components.entity.YetiThrowAttachment; -import twilightforest.tags.TFEntityTypeTags; import twilightforest.events.HostileMountEvents; import twilightforest.init.TFDataAttachments; import twilightforest.network.MovePlayerPacket; +import twilightforest.tags.TFEntityTypeTags; public class ThrowRiderGoal extends MeleeAttackGoal { @@ -65,7 +65,7 @@ protected void checkAndPerformAttack(LivingEntity victim) { // Pluck them from the boat, minecart, donkey, or whatever victim.stopRiding(); - victim.startRiding(this.mob, true); + victim.startRiding(this.mob, true, false); } } } @@ -74,7 +74,7 @@ protected void checkAndPerformAttack(LivingEntity victim) { @Override public void stop() { if (!this.mob.getPassengers().isEmpty()) { - Entity rider = this.mob.getPassengers().get(0); + Entity rider = this.mob.getPassengers().getFirst(); HostileMountEvents.hostileDismount(rider); Vec3 throwVec = new Vec3(this.mob.getLookAngle().x() * 2.0D, 0.9, this.mob.getLookAngle().z() * 2.0D); diff --git a/src/main/java/twilightforest/entity/ai/goal/YetiRampageGoal.java b/src/main/java/twilightforest/entity/ai/goal/YetiRampageGoal.java index e37a7fc691..675ecd0c2a 100644 --- a/src/main/java/twilightforest/entity/ai/goal/YetiRampageGoal.java +++ b/src/main/java/twilightforest/entity/ai/goal/YetiRampageGoal.java @@ -1,5 +1,6 @@ package twilightforest.entity.ai.goal; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3; @@ -72,11 +73,11 @@ public void tick() { this.yeti.gameEvent(GameEvent.HIT_GROUND); } - this.yeti.destroyBlocksInAABB(this.yeti.getBoundingBox().inflate(1, 2, 1).move(0, 2, 0)); + this.yeti.destroyBlocksInAABB(getServerLevel(this.yeti), this.yeti.getBoundingBox().inflate(1, 2, 1).move(0, 2, 0)); // regular falling blocks, twice a second if (this.currentDuration % 10 == 0) { - this.yeti.makeRandomBlockFall(30, 80); + this.yeti.makeRandomBlockFall(getServerLevel(this.yeti), 30, 80); } // blocks target players, one every second @@ -86,11 +87,11 @@ public void tick() { // blocks that fall close to the yeti, twice a second near the end of the rampage if (this.currentDuration < 40 && this.currentDuration % 10 == 0) { - this.yeti.makeRandomBlockFall(15, 40); + this.yeti.makeRandomBlockFall(getServerLevel(this.yeti), 15, 40); } if (this.currentDuration % 20 == 0) { - IceBomb ice = new IceBomb(TFEntities.THROWN_ICE.get(), this.yeti.level(), this.yeti); + IceBomb ice = new IceBomb(TFEntities.THROWN_ICE.get(), this.yeti.level()); Vec3 vec = new Vec3(0.5F + this.yeti.getRandom().nextFloat() * 0.5F, 0.5F + this.yeti.getRandom().nextFloat() * 0.3F, 0).yRot(this.yeti.getRandom().nextFloat() * 360F); ice.shoot(vec.x(), vec.y(), vec.z(), 0.4F + yeti.getRandom().nextFloat() * 0.3F, 0); this.yeti.playSound(TFSounds.ALPHA_YETI_ICE.get(), 1.0F, 1.0F / (this.yeti.getRandom().nextFloat() * 0.4F + 0.8F));