From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Fri, 11 Apr 2025 16:53:57 +0800 Subject: [PATCH] Leaves: Old raid behavior Co-authored by: huanli233 <392352840@qq.com> As a part of : Leaves (https://github.com/LeavesMC/Leaves/blob/bda7e406b995290234e33283a181e33467ceda38/leaves-server/minecraft-patches/features/0114-Old-raid-behavior.patch) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) diff --git a/net/minecraft/world/effect/BadOmenMobEffect.java b/net/minecraft/world/effect/BadOmenMobEffect.java index f58b10c7dec0d2b7dc2b3d1198539b74d13038f3..0a838a2015526dde2cb8d9006a71610e0bf5e9dc 100644 --- a/net/minecraft/world/effect/BadOmenMobEffect.java +++ b/net/minecraft/world/effect/BadOmenMobEffect.java @@ -22,6 +22,11 @@ class BadOmenMobEffect extends MobEffect { && !player.isSpectator() && level.getDifficulty() != Difficulty.PEACEFUL && level.isVillage(player.blockPosition())) { + // Leaves start - Revert raid changes + if (fun.bm.lophine.config.modules.function.OldFeatureConfig.oldRaidBehavior) { + return level.getRaids().createOrExtendRaid(player, player.blockPosition()) == null; + } + // Leaves end - Revert raid changes Raid raid = level.getRaidAt(player.blockPosition()); if (raid == null || raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel()) { player.addEffect(new MobEffectInstance(MobEffects.RAID_OMEN, 600, amplification)); diff --git a/net/minecraft/world/entity/raid/Raid.java b/net/minecraft/world/entity/raid/Raid.java index 32e20979b9343efa6b5903c7b6baf351205654a0..4ddc34822e88b011f58c70ca4f14e7a17912b714 100644 --- a/net/minecraft/world/entity/raid/Raid.java +++ b/net/minecraft/world/entity/raid/Raid.java @@ -269,7 +269,7 @@ public class Raid { } public boolean absorbRaidOmen(final ServerPlayer player) { - MobEffectInstance effect = player.getEffect(MobEffects.RAID_OMEN); + MobEffectInstance effect = player.getEffect(fun.bm.lophine.config.modules.function.OldFeatureConfig.oldRaidBehavior ? MobEffects.BAD_OMEN : MobEffects.RAID_OMEN); // Leaves - old Raid Behavior if (effect == null) { return false; } @@ -346,7 +346,13 @@ public class Raid { } if (shouldTryToFindSpawnPos) { - this.waveSpawnPos = this.getValidSpawnPos(level); + // Leaves Start - old FindSpawnPosition + if (fun.bm.lophine.config.modules.function.OldFeatureConfig.oldRaidBehavior) { + this.waveSpawnPos = this.preCalcRavagerSpawnLocation(level, this.raidCooldownTicks < 100 ? 1 : 0); + } else { + this.waveSpawnPos = this.getValidSpawnPos(level); + } + // Leaves End - old FindSpawnPosition } if (this.raidCooldownTicks == 300 || this.raidCooldownTicks % 20 == 0) { @@ -401,7 +407,14 @@ public class Raid { int attempt = 0; while (this.shouldSpawnGroup()) { - BlockPos spawnPos = this.waveSpawnPos.orElseGet(() -> this.findRandomSpawnPos(level, 20)); + // Leaves Start - old FindSpawnPosition + BlockPos spawnPos; + if (fun.bm.lophine.config.modules.function.OldFeatureConfig.oldRaidBehavior) { + spawnPos = this.getRavagerSpawnLocation(level, attempt, 20); + } else { + spawnPos = this.waveSpawnPos.orElseGet(() -> this.findRandomSpawnPos(level, 20)); + } + // Leaves End - old FindSpawnPosition if (spawnPos != null) { this.started = true; this.spawnGroup(level, spawnPos); @@ -413,7 +426,7 @@ public class Raid { attempt++; } - if (attempt > 5) { + if (attempt > (fun.bm.lophine.config.modules.function.OldFeatureConfig.oldRaidBehavior ? 3 : 5)) { // Leaves - old FindSpawnPosition org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(level, this, org.bukkit.event.raid.RaidStopEvent.Reason.UNSPAWNABLE); // CraftBukkit this.stop(); break; @@ -717,7 +730,7 @@ public class Raid { int spawnX = this.center.getX() + Mth.floor(Mth.cos(angle) * 32.0F * howFar) + this.random.nextInt(3) * Mth.floor(howFar); int spawnZ = this.center.getZ() + Mth.floor(Mth.sin(angle) * 32.0F * howFar) + this.random.nextInt(3) * Mth.floor(howFar); int spawnY = level.getHeight(Heightmap.Types.WORLD_SURFACE, spawnX, spawnZ); - if (Mth.abs(spawnY - this.center.getY()) <= 96) { + if (fun.bm.lophine.config.modules.function.OldFeatureConfig.oldRaidBehavior || Mth.abs(spawnY - this.center.getY()) <= 96) { // Leaves - skippable spawnPos.set(spawnX, spawnY, spawnZ); if (!level.isVillage(spawnPos) || secondsRemaining <= 7) { int delta = 10; @@ -900,4 +913,42 @@ public class Raid { this.spawnsPerWaveBeforeBonus = spawnsPerWaveBeforeBonus; } } + + // Leaves start - old FindSpawnPosition + @Nullable + private BlockPos getRavagerSpawnLocation(final ServerLevel serverWorld, final int proximity, final int tries) { + int i = proximity == 0 ? 2 : 2 - proximity; + BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos(); + net.minecraft.world.entity.SpawnPlacementType spawnLocation = net.minecraft.world.entity.SpawnPlacements.getPlacementType(EntityTypes.RAVAGER); + for (int j = 0; j < tries; j++) { + float f = serverWorld.getRandom().nextFloat() * (float) (Math.PI * 2); + int k = this.center.getX() + Mth.floor(Mth.cos(f) * 32.0F * (float) i + serverWorld.getRandom().nextInt(5)); + int l = this.center.getZ() + Mth.floor(Mth.sin(f) * 32.0F * (float) i + serverWorld.getRandom().nextInt(5)); + int m = serverWorld.getHeight(Heightmap.Types.WORLD_SURFACE, k, l); + mutable.set(k, m, l); + if (serverWorld.isVillage(mutable) && proximity < 2) { + continue; + } + if (serverWorld.hasChunksAt(mutable.getX() - 10, mutable.getZ() - 10, mutable.getX() + 10, mutable.getZ() + 10) + && serverWorld.isPositionEntityTicking(mutable) + && (spawnLocation.isSpawnPositionOk(serverWorld, mutable, EntityTypes.RAVAGER) + || serverWorld.getBlockState(mutable.below()).is(net.minecraft.world.level.block.Blocks.SNOW) + && serverWorld.getBlockState(mutable).isAir()) + ) { + return mutable.immutable(); + } + } + return null; + } + + private Optional preCalcRavagerSpawnLocation(final ServerLevel serverWorld, final int proximity) { + for (int i = 0; i < 3; i++) { + BlockPos blockPos = this.getRavagerSpawnLocation(serverWorld, proximity, 1); + if (blockPos != null) { + return Optional.of(blockPos); + } + } + return Optional.empty(); + } + // Leaves end - old FindSpawnPosition } diff --git a/net/minecraft/world/entity/raid/Raider.java b/net/minecraft/world/entity/raid/Raider.java index 7e969cd81d2ac788515f4d9ad7584ade4c684a42..7555f0c5edf6a5419018203487cf8941e8095cb5 100644 --- a/net/minecraft/world/entity/raid/Raider.java +++ b/net/minecraft/world/entity/raid/Raider.java @@ -129,6 +129,42 @@ public abstract class Raider extends PatrollingMonster { raidWhenKilled.removeFromRaid(serverLevel, this, false); } + + // Leaves start - Revert raid changes + Entity killerEntity = source.getEntity(); + if (fun.bm.lophine.config.modules.function.OldFeatureConfig.oldRaidBehavior && !this.hasActiveRaid()) { + ItemStack itemstack = this.getItemBySlot(net.minecraft.world.entity.EquipmentSlot.HEAD); + net.minecraft.world.entity.player.Player entityhuman = null; + if (killerEntity instanceof net.minecraft.world.entity.player.Player player) { + entityhuman = player; + } else if (killerEntity 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.isPatrolLeader()) { + net.minecraft.world.effect.MobEffectInstance mobeffect = entityhuman.getEffect(net.minecraft.world.effect.MobEffects.BAD_OMEN); + int amp = 1; + + if (mobeffect != null) { + amp += mobeffect.getAmplifier(); + entityhuman.removeEffectNoUpdate(net.minecraft.world.effect.MobEffects.BAD_OMEN); + } else { + --amp; + } + + amp = net.minecraft.util.Mth.clamp(amp, 0, 4); + net.minecraft.world.effect.MobEffectInstance mobeffect1 = new net.minecraft.world.effect.MobEffectInstance(net.minecraft.world.effect.MobEffects.BAD_OMEN, 120000, amp, false, false, true); + + if (serverLevel.getGameRules().get(net.minecraft.world.level.gamerules.GameRules.RAIDS)) { + entityhuman.addEffect(mobeffect1, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.PATROL_CAPTAIN); // CraftBukkit + } + this.setPatrolLeader(false); + } + } + // Leaves end - Revert raid changes } super.die(source);