From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: huanli233 <392352840@qq.com> Date: Wed, 23 Oct 2024 23:10:48 +0800 Subject: [PATCH] Revert raid changes diff --git a/net/minecraft/world/effect/BadOmenMobEffect.java b/net/minecraft/world/effect/BadOmenMobEffect.java index 80f17f33f670018240c854df589cf90cdeab6e70..4c6ce6a4a730033802651b0c0052fc46edeed4d6 100644 --- a/net/minecraft/world/effect/BadOmenMobEffect.java +++ b/net/minecraft/world/effect/BadOmenMobEffect.java @@ -22,6 +22,11 @@ class BadOmenMobEffect extends MobEffect { && !serverPlayer.isSpectator() && level.getDifficulty() != Difficulty.PEACEFUL && level.isVillage(serverPlayer.blockPosition())) { + // Leaves start - Revert raid changes + if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.raid.allowBadOmenTriggerRaid) { + return level.getRaids().createOrExtendRaid(serverPlayer, serverPlayer.blockPosition()) == null; + } + // Leaves end - Revert raid changes Raid raidAt = level.getRaidAt(serverPlayer.blockPosition()); if (raidAt == null || raidAt.getRaidOmenLevel() < raidAt.getMaxRaidOmenLevel()) { serverPlayer.addEffect(new MobEffectInstance(MobEffects.RAID_OMEN, 600, amplifier)); diff --git a/net/minecraft/world/entity/raid/Raid.java b/net/minecraft/world/entity/raid/Raid.java index 62a3a8d46e10e6f02e3f515bbce5d9ba1f6566b8..6a45e00490f0067d25010371f7c5fa40bbe7671c 100644 --- a/net/minecraft/world/entity/raid/Raid.java +++ b/net/minecraft/world/entity/raid/Raid.java @@ -333,7 +333,20 @@ public class Raid { } if (flag1) { - this.waveSpawnPos = this.getValidSpawnPos(level); + // Leaves Start - old FindSpawnPosition + if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.raid.useOldFindSpawnPosition) { + this.waveSpawnPos = this.getValidSpawnPos(level); + } else { + int n4 = 0; + if (this.raidCooldownTicks < 100) { + n4 = 1; + } + if (this.raidCooldownTicks < 40) { + n4 = 2; + } + this.waveSpawnPos = this.getValidSpawnPos(level, n4); + } + // Leaves End - old FindSpawnPosition } if (this.raidCooldownTicks == 300 || this.raidCooldownTicks % 20 == 0) { @@ -368,7 +381,14 @@ public class Raid { int i = 0; while (this.shouldSpawnGroup()) { - BlockPos blockPos = this.waveSpawnPos.orElseGet(() -> this.findRandomSpawnPos(level, 20)); + // Leaves Start - old FindSpawnPosition + BlockPos blockPos; + if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.raid.useOldFindSpawnPosition) { + blockPos = this.waveSpawnPos.orElseGet(() -> this.findRandomSpawnPos(level, 20)); + } else { + blockPos = this.waveSpawnPos.isPresent() ? this.waveSpawnPos.get() : this.findRandomSpawnPos(level, i, 20); + } + // Leaves End - old FindSpawnPosition if (blockPos != null) { this.started = true; this.spawnGroup(level, blockPos); @@ -380,7 +400,7 @@ public class Raid { i++; } - if (i > 5) { + if (i > (org.leavesmc.leaves.LeavesConfig.modify.oldMC.raid.useOldFindSpawnPosition ? 3 : 5)) { // Leaves - old FindSpawnPosition org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(level, this, org.bukkit.event.raid.RaidStopEvent.Reason.UNSPAWNABLE); // CraftBukkit this.stop(); break; @@ -686,6 +706,36 @@ public class Raid { return null; } + // Leaves Start - old FindSpawnPosition + @Nullable + private BlockPos findRandomSpawnPos(ServerLevel level, int n, int n2) { + int n3 = 2 - n; + BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); + SpawnPlacementType spawnPlacementType = SpawnPlacements.getPlacementType(EntityType.RAVAGER); + for (int i = 0; i < n2; ++i) { + float f = level.random.nextFloat() * ((float)Math.PI * 2); + int n4 = this.center.getX() + Mth.floor(Mth.cos(f) * 32.0f * (float)n3) + level.random.nextInt(5); + int n5 = this.center.getZ() + Mth.floor(Mth.sin(f) * 32.0f * (float)n3) + level.random.nextInt(5); + int n6 = level.getHeight(Heightmap.Types.WORLD_SURFACE, n4, n5); + mutableBlockPos.set(n4, n6, n5); + if (level.isVillage(mutableBlockPos) && n < 2) continue; + if (!level.hasChunksAt(mutableBlockPos.getX() - 10, mutableBlockPos.getZ() - 10, mutableBlockPos.getX() + 10, mutableBlockPos.getZ() + 10) || !level.isPositionEntityTicking(mutableBlockPos) || !spawnPlacementType.isSpawnPositionOk(level, mutableBlockPos, EntityType.RAVAGER) && (!level.getBlockState((BlockPos)mutableBlockPos.below()).is(Blocks.SNOW) || !level.getBlockState(mutableBlockPos).isAir())) continue; + return mutableBlockPos; + } + return null; + } + + private Optional getValidSpawnPos(ServerLevel level, int n) { + for (int i = 0; i < 3; ++i) { + BlockPos blockPos = this.findRandomSpawnPos(level, n, 1); + if (blockPos == null) continue; + return Optional.of(blockPos); + } + return Optional.empty(); + } + // Leaves End - old FindSpawnPosition + + private boolean addWaveMob(ServerLevel level, int wave, Raider raider) { return this.addWaveMob(level, wave, raider, true); } diff --git a/net/minecraft/world/entity/raid/Raider.java b/net/minecraft/world/entity/raid/Raider.java index 39a6a4579931d7edb7ab8c072d62cfc9b02791c8..23c0581ad4e3921f89070609ec7c01d8a5a9b2de 100644 --- a/net/minecraft/world/entity/raid/Raider.java +++ b/net/minecraft/world/entity/raid/Raider.java @@ -127,6 +127,43 @@ public abstract class Raider extends PatrollingMonster { currentRaid.removeFromRaid(serverLevel, this, false); } + + // Leaves start - Revert raid changes + if (this.level() instanceof ServerLevel) { + if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.raid.giveBadOmenWhenKillPatrolLeader && !this.hasRaid()) { + ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD); + net.minecraft.world.entity.player.Player entityhuman = null; + if (entity instanceof net.minecraft.world.entity.player.Player player) { + entityhuman = player; + } else if (entity instanceof net.minecraft.world.entity.animal.wolf.Wolf wolf) { + LivingEntity entityliving = wolf.getOwner(); + if (wolf.isTame() && entityliving instanceof net.minecraft.world.entity.player.Player player) { + entityhuman = player; + } + } + + if (entityhuman != null && !itemstack.isEmpty() && this.isCaptain()) { + net.minecraft.world.effect.MobEffectInstance mobeffect = entityhuman.getEffect(net.minecraft.world.effect.MobEffects.BAD_OMEN); + int i = 1; + + if (mobeffect != null) { + i += mobeffect.getAmplifier(); + entityhuman.removeEffectNoUpdate(net.minecraft.world.effect.MobEffects.BAD_OMEN); + } else { + --i; + } + + i = net.minecraft.util.Mth.clamp(i, 0, 4); + net.minecraft.world.effect.MobEffectInstance mobeffect1 = new net.minecraft.world.effect.MobEffectInstance(net.minecraft.world.effect.MobEffects.BAD_OMEN, 120000, i, false, false, true); + + if (!serverLevel.getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_DISABLE_RAIDS)) { + entityhuman.addEffect(mobeffect1, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.PATROL_CAPTAIN); // CraftBukkit + } + this.setPatrolLeader(false); + } + } + } + // Leaves end - Revert raid changes } super.die(cause);