178 lines
10 KiB
Diff
178 lines
10 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/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 24cc4a15731edcb701596fe7051e188637457e37..5440dc0fb8bccabb65fd9681ab368ef5028e2ca9 100644
|
|
--- a/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -268,7 +268,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;
|
|
} else {
|
|
@@ -345,7 +345,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) {
|
|
@@ -400,7 +406,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);
|
|
@@ -412,7 +425,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;
|
|
@@ -716,7 +729,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;
|
|
@@ -899,4 +912,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(EntityType.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, EntityType.RAVAGER)
|
|
+ || serverWorld.getBlockState(mutable.below()).is(net.minecraft.world.level.block.Blocks.SNOW)
|
|
+ && serverWorld.getBlockState(mutable).isAir())
|
|
+ ) {
|
|
+ return mutable.immutable();
|
|
+ }
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ private Optional<BlockPos> 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 bc2edc48ddefaab9022029f1a913a40b72e06024..1a51da9171c13711e106731c360051d183a40893 100644
|
|
--- a/net/minecraft/world/entity/raid/Raider.java
|
|
+++ b/net/minecraft/world/entity/raid/Raider.java
|
|
@@ -128,6 +128,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);
|