217 lines
12 KiB
Diff
217 lines
12 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
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/79d9ef74c2684eb49060f07e1ab31c827326c9a5/leaves-server/minecraft-patches/features/0106-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 80f17f33f670018240c854df589cf90cdeab6e70..cbfb4ae2dc30c2ee98ef37f44a95434a7968e320 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 (fun.bm.lophine.config.modules.misc.OldFeatureConfig.oldRaidBehavior) {
|
|
+ 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 1910bff3f08147bfd63703097e30b9f88c84e337..5188ae86aff3051d45fe5e7d2fcc51233b7074d4 100644
|
|
--- a/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -263,7 +263,7 @@ public class Raid {
|
|
}
|
|
|
|
public boolean absorbRaidOmen(ServerPlayer player) {
|
|
- MobEffectInstance effect = player.getEffect(MobEffects.RAID_OMEN);
|
|
+ MobEffectInstance effect = player.getEffect(fun.bm.lophine.config.modules.misc.OldFeatureConfig.oldRaidBehavior ? MobEffects.BAD_OMEN : MobEffects.RAID_OMEN); // Leaves - old Raid Behavior
|
|
if (effect == null) {
|
|
return false;
|
|
} else {
|
|
@@ -340,7 +340,13 @@ public class Raid {
|
|
}
|
|
|
|
if (flag1) {
|
|
- this.waveSpawnPos = this.getValidSpawnPos(level);
|
|
+ // Leaves Start - old FindSpawnPosition
|
|
+ if (fun.bm.lophine.config.modules.misc.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) {
|
|
@@ -375,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 (fun.bm.lophine.config.modules.misc.OldFeatureConfig.oldRaidBehavior) {
|
|
+ blockPos = this.getRavagerSpawnLocation(level, i, 20);
|
|
+ } else {
|
|
+ blockPos = this.waveSpawnPos.orElseGet(() -> this.findRandomSpawnPos(level, 20));
|
|
+ }
|
|
+ // Leaves End - old FindSpawnPosition
|
|
if (blockPos != null) {
|
|
this.started = true;
|
|
this.spawnGroup(level, blockPos);
|
|
@@ -387,7 +400,7 @@ public class Raid {
|
|
i++;
|
|
}
|
|
|
|
- if (i > 5) {
|
|
+ if (i > (fun.bm.lophine.config.modules.misc.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;
|
|
@@ -683,7 +696,7 @@ public class Raid {
|
|
int i2 = this.center.getX() + Mth.floor(Mth.cos(f2) * 32.0F * f) + level.random.nextInt(3) * Mth.floor(f);
|
|
int i3 = this.center.getZ() + Mth.floor(Mth.sin(f2) * 32.0F * f) + level.random.nextInt(3) * Mth.floor(f);
|
|
int height = level.getHeight(Heightmap.Types.WORLD_SURFACE, i2, i3);
|
|
- if (Mth.abs(height - this.center.getY()) <= 96) {
|
|
+ if (fun.bm.lophine.config.modules.misc.OldFeatureConfig.oldRaidBehavior || Mth.abs(height - this.center.getY()) <= 96) { // Leaves - skippable
|
|
mutableBlockPos.set(i2, height, i3);
|
|
if (!level.isVillage(mutableBlockPos) || i <= 7) {
|
|
int i4 = 10;
|
|
@@ -702,6 +715,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<BlockPos> 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) {
|
|
// Folia start - make raids thread-safe
|
|
if (!this.ownsRaid(level)) {
|
|
@@ -864,4 +907,43 @@ public class Raid {
|
|
this.spawnsPerWaveBeforeBonus = spawnsPerWaveBeforeBonus;
|
|
}
|
|
}
|
|
+
|
|
+ // Leaves start - old FindSpawnPosition
|
|
+ private BlockPos getRavagerSpawnLocation(ServerLevel serverWorld, int proximity, int tries) {
|
|
+ int i = proximity == 0 ? 2 : 2 - proximity;
|
|
+ BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
|
|
+ SpawnPlacementType spawnLocation = SpawnPlacements.getPlacementType(EntityType.RAVAGER);
|
|
+
|
|
+ for (int j = 0; j < tries; j++) {
|
|
+ float f = serverWorld.random.nextFloat() * (float) (Math.PI * 2);
|
|
+ int k = this.center.getX() + Mth.floor(Mth.cos(f) * 32.0F * (float) i + serverWorld.random.nextInt(5));
|
|
+ int l = this.center.getZ() + Mth.floor(Mth.sin(f) * 32.0F * (float) i + serverWorld.random.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, EntityType.RAVAGER)
|
|
+ || serverWorld.getBlockState(mutable.below()).is(Blocks.SNOW)
|
|
+ && serverWorld.getBlockState(mutable).isAir())
|
|
+ ) {
|
|
+ return mutable;
|
|
+ }
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ private Optional<BlockPos> preCalcRavagerSpawnLocation(ServerLevel serverWorld, 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 3e30989c99cd11c8c94d6fd194d2969e3a7efda6..b1f1bcf7f5ac002550077d5e1d4efd5c67d18063 100644
|
|
--- a/net/minecraft/world/entity/raid/Raider.java
|
|
+++ b/net/minecraft/world/entity/raid/Raider.java
|
|
@@ -128,6 +128,43 @@ public abstract class Raider extends PatrollingMonster {
|
|
|
|
currentRaid.removeFromRaid(serverLevel, this, false);
|
|
}
|
|
+
|
|
+ // Leaves start - Revert raid changes
|
|
+ if (this.level() instanceof ServerLevel) {
|
|
+ if (fun.bm.lophine.config.modules.misc.OldFeatureConfig.oldRaidBehavior && !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);
|