9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00

Remove Force peaceful mode switch (#265) (#579)

This commit is contained in:
violetc
2025-06-26 16:42:03 +08:00
committed by GitHub
parent f33f5feac7
commit 6c07912dd2
74 changed files with 9 additions and 275 deletions

View File

@@ -1,23 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 3 Aug 2023 14:21:55 +0800
Subject: [PATCH] Force peaceful mode switch
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index a8b64f78bf3c453094074b4b4d3c8fd07b9eb273..ed2bcc30cec91d3266c3d184b89b96bac6fb1f67 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -4358,6 +4358,12 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
void setSendViewDistance(int viewDistance);
// Paper end - view distance api
+ // Leaves start - unsupported settings
+ public void setPeacefulModeSwitchTick(int tick);
+
+ public int getPeacefulModeSwitchTick();
+ // Leaves end - unsupported settings
+
/**
* Gets all generated structures that intersect the chunk at the given
* coordinates. <br>

View File

@@ -1,100 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 3 Aug 2023 14:21:47 +0800
Subject: [PATCH] Force peaceful mode switch
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 59e8a5e1b35c81883c9b1ca00c6e55d77584d8cc..1e6f7c0997efdeb06dbf1450b3d7f5f4ecc4072c 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -184,6 +184,12 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
// Paper end - chunk tick iteration optimisations
+ // Leaves start - peaceful mode switch
+ public int peacefulModeSwitchTick = org.leavesmc.leaves.LeavesConfig.modify.peacefulModeSwitch.tick;
+ public Set<Class<? extends Entity>> peacefulModeSwitchEntityTypes = org.leavesmc.leaves.LeavesConfig.modify.peacefulModeSwitch.classTypes;
+ public int peacefulModeSwitchCount = -1;
+ // Leaves end - peaceful mode switch
+
public ServerChunkCache(
ServerLevel level,
@@ -512,6 +518,20 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
this.lastInhabitedUpdate = gameTime;
if (!this.level.isDebug()) {
ProfilerFiller profilerFiller = Profiler.get();
+ // Leaves start - peaceful mode switch
+ if (peacefulModeSwitchTick > 0) {
+ if (this.level.getLevelData().getGameTime() % peacefulModeSwitchTick == 0) {
+ peacefulModeSwitchCount = 0;
+ this.level.getAllEntities().forEach(entity -> {
+ if (peacefulModeSwitchEntityTypes.contains(entity.getClass())) {
+ peacefulModeSwitchCount++;
+ }
+ });
+ }
+ } else {
+ peacefulModeSwitchCount = -1;
+ }
+ // Leaves end - peaceful mode switch
profilerFiller.push("pollingChunks");
if (this.level.tickRateManager().runsNormally()) {
profilerFiller.push("tickingChunks");
@@ -568,6 +588,14 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
boolean _boolean = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
int _int = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
List<MobCategory> filteredSpawningCategories;
+ // Leaves start - peaceful mode switch
+ boolean peacefulModeSwitch = false;
+ if (lastSpawnState != null && peacefulModeSwitchCount != -1) {
+ if (peacefulModeSwitchCount >= NaturalSpawner.globalLimitForCategory(level, net.minecraft.world.entity.MobCategory.MONSTER, lastSpawnState.getSpawnableChunkCount())) {
+ peacefulModeSwitch = true;
+ }
+ }
+ // Leaves end - peaceful mode switch
if (_boolean && (this.spawnEnemies || this.spawnFriendlies)) {
// Paper start - PlayerNaturallySpawnCreaturesEvent
for (ServerPlayer entityPlayer : this.level.players()) {
@@ -578,7 +606,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
// Paper end - PlayerNaturallySpawnCreaturesEvent
boolean flag = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
- filteredSpawningCategories = NaturalSpawner.getFilteredSpawningCategories(spawnState, this.spawnFriendlies, this.spawnEnemies, flag, this.level); // CraftBukkit
+ filteredSpawningCategories = NaturalSpawner.getFilteredSpawningCategories(spawnState, this.spawnFriendlies, this.spawnEnemies, flag, this.level, peacefulModeSwitch); // CraftBukkit Leaves start - peaceful mode switch
} else {
filteredSpawningCategories = List.of();
}
diff --git a/net/minecraft/world/level/NaturalSpawner.java b/net/minecraft/world/level/NaturalSpawner.java
index 5427f5e1f0416a8dfa3e9c38c3ce69d6e2bd37a6..acfecf37c6e3efc21d7f2194d9efed79146b1f1d 100644
--- a/net/minecraft/world/level/NaturalSpawner.java
+++ b/net/minecraft/world/level/NaturalSpawner.java
@@ -116,16 +116,26 @@ public final class NaturalSpawner {
static Biome getRoughBiome(BlockPos pos, ChunkAccess chunk) {
return chunk.getNoiseBiome(QuartPos.fromBlock(pos.getX()), QuartPos.fromBlock(pos.getY()), QuartPos.fromBlock(pos.getZ())).value();
}
-
+ // Leaves start - peaceful mode switch
// CraftBukkit start - add server
public static List<MobCategory> getFilteredSpawningCategories(
NaturalSpawner.SpawnState spawnState, boolean spawnFriendlies, boolean spawnEnemies, boolean spawnPassives, ServerLevel level
) {
+ return getFilteredSpawningCategories(spawnState, spawnFriendlies, spawnEnemies, spawnPassives, level, false);
+ }
+
+ public static List<MobCategory> getFilteredSpawningCategories(NaturalSpawner.SpawnState spawnState, boolean spawnFriendlies, boolean spawnEnemies, boolean spawnPassives, ServerLevel level, boolean peacefulModeSwitch) {
+ // Leaves end - peaceful mode switch
net.minecraft.world.level.storage.LevelData worlddata = level.getLevelData(); // CraftBukkit - Other mob type spawn tick rate
// CraftBukkit end
List<MobCategory> list = new ArrayList<>(SPAWNING_CATEGORIES.length);
for (MobCategory mobCategory : SPAWNING_CATEGORIES) {
+ // Leaves start - peaceful mode switch
+ if (mobCategory == MobCategory.MONSTER && peacefulModeSwitch) {
+ continue;
+ }
+ // Leaves end - peaceful mode switch
// CraftBukkit start - Use per-world spawn limits
boolean spawnThisTick = true;
int limit = mobCategory.getMaxInstancesPerChunk();

View File

@@ -119,7 +119,7 @@ index 70cc20483905d3877e2ffb51afb4902bd59f0cd0..066d18609f7f8aa5c14e95e09b454cb7
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} else { } else {
diff --git a/net/minecraft/world/inventory/MerchantMenu.java b/net/minecraft/world/inventory/MerchantMenu.java diff --git a/net/minecraft/world/inventory/MerchantMenu.java b/net/minecraft/world/inventory/MerchantMenu.java
index d59f67ffe34201c63e3d9706a4434f33b6732edb..bee1d5c30a6ee9b14a23fbcf1c479417f1776ddb 100644 index 1bf2a015fa35981328c098f2fec363c84b85b2a7..8aa4079e7fb5fb81f33859d106a425d0183f13df 100644
--- a/net/minecraft/world/inventory/MerchantMenu.java --- a/net/minecraft/world/inventory/MerchantMenu.java
+++ b/net/minecraft/world/inventory/MerchantMenu.java +++ b/net/minecraft/world/inventory/MerchantMenu.java
@@ -25,7 +25,7 @@ public class MerchantMenu extends AbstractContainerMenu { @@ -25,7 +25,7 @@ public class MerchantMenu extends AbstractContainerMenu {

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Disable offline warn if use proxy
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 8ed391f61b0eb50d26ce8250c652433e896d5ae4..46eabb498758052cc1ce1b4f46d9c033df14b8ef 100644 index 12c8486ff2a5a7140fde40babc4388f311a6401e..6846570f8e669341662b86cd9b693aa5fffc897e 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java --- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -246,7 +246,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface @@ -246,7 +246,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface

View File

@@ -18,7 +18,7 @@ index c6e4f72825c868b416ce2e81fc6d9b5bfdbd85f2..5c4d0a9297387503f48cb4c1d6db6aed
.encodeStart(provider.createSerializationContext(JsonOps.INSTANCE), component) .encodeStart(provider.createSerializationContext(JsonOps.INSTANCE), component)
.getOrThrow(JsonParseException::new); .getOrThrow(JsonParseException::new);
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index e33776c039e36f55f0579b51b147d7be087839cf..28456eab6d5c31cf33fd9918d7306b078a97bd41 100644 index 0dee4945feb6d4cb2f520d346bf8be4fa36fb868..df58e2cd1a8be7c4b24a747ca40d0e79bf40f976 100644
--- a/net/minecraft/server/players/PlayerList.java --- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java
@@ -377,6 +377,13 @@ public abstract class PlayerList { @@ -377,6 +377,13 @@ public abstract class PlayerList {

View File

@@ -762,7 +762,7 @@ index bbb1abfbfe7afd7b631cf269c1e338697cd016d2..768e5c6f1c0ce7d4bec41c37668249e7
this.getBlock().affectNeighborsAfterRemoval(this.asState(), level, pos, movedByPiston); this.getBlock().affectNeighborsAfterRemoval(this.asState(), level, pos, movedByPiston);
} }
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index 7fca1659bd85b1a737355fb9a8377dff64a7fe17..d1b25a1e698253e1dfaf203536e4f10d8705be0f 100644 index 845319dd3e355f739cce70b7df3172dd146601b1..d0ae0a73f2a635c008e2d60374d5b85a10216c96 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java --- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java +++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -394,20 +394,26 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p @@ -394,20 +394,26 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Do not prevent block entity and entity crash at LevelChunk
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index d1b25a1e698253e1dfaf203536e4f10d8705be0f..bea00fb701cbd11aa73188f8e3aa9a5163f2f157 100644 index d0ae0a73f2a635c008e2d60374d5b85a10216c96..90888df3fb4ee72c02815322b4b1d643c1d1420e 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java --- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java +++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -945,12 +945,14 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p @@ -945,12 +945,14 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p

View File

@@ -1,29 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 3 Aug 2023 14:21:47 +0800
Subject: [PATCH] Force peaceful mode switch
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 6773681bfaf0edb03cc17bcdfa43b98c8b7c9c20..f1b018774473b52fe3dee56dc78cf5def9030c43 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2383,6 +2383,18 @@ public class CraftWorld extends CraftRegionAccessor implements World {
// Paper - replace feature flag API
+ // Leaves start - unsupported settings
+ @Override
+ public void setPeacefulModeSwitchTick(int tick) {
+ this.getHandle().chunkSource.peacefulModeSwitchTick = tick;
+ }
+
+ @Override
+ public int getPeacefulModeSwitchTick() {
+ return this.getHandle().chunkSource.peacefulModeSwitchTick;
+ }
+ // Leaves end - unsupported settings
+
public void storeBukkitValues(CompoundTag c) {
if (!this.persistentDataContainer.isEmpty()) {
c.put("BukkitValues", this.persistentDataContainer.toTagCompound());

View File

@@ -583,42 +583,6 @@ public final class LeavesConfig {
} }
} }
public ForcePeacefulModeSwitchConfig peacefulModeSwitch = new ForcePeacefulModeSwitchConfig();
@GlobalConfigCategory("force-peaceful-mode-switch")
public static class ForcePeacefulModeSwitchConfig {
@RemovedConfig(name = "force-peaceful-mode", category = "modify", transform = true)
@GlobalConfig(value = "tick", validator = TickValidator.class)
public int tick = -1;
private static class TickValidator extends IntConfigValidator {
@Override
public void verify(Integer old, Integer value) throws IllegalArgumentException {
for (ServerLevel level : MinecraftServer.getServer().getAllLevels()) {
level.chunkSource.peacefulModeSwitchTick = value;
}
}
}
@GlobalConfig(value = "types", validator = TypeValidator.class)
public List<ForcePeacefulModeSwitchType> types = List.of(ForcePeacefulModeSwitchType.BLAZE, ForcePeacefulModeSwitchType.WITHER, ForcePeacefulModeSwitchType.SHULKER, ForcePeacefulModeSwitchType.WARDEN);
public Set<Class<? extends Entity>> classTypes = new HashSet<>();
private static class TypeValidator extends ListConfigValidator.ENUM<ForcePeacefulModeSwitchType> {
@Override
public void verify(List<ForcePeacefulModeSwitchType> old, @NotNull List<ForcePeacefulModeSwitchType> value) throws IllegalArgumentException {
Set<Class<? extends Entity>> classes = new HashSet<>();
for (ForcePeacefulModeSwitchType type : value) {
classes.add(type.getEntityClass());
}
LeavesConfig.modify.peacefulModeSwitch.classTypes = classes;
for (ServerLevel level : MinecraftServer.getServer().getAllLevels()) {
level.chunkSource.peacefulModeSwitchEntityTypes = classes;
}
}
}
}
@GlobalConfig("disable-vault-blacklist") @GlobalConfig("disable-vault-blacklist")
public boolean disableVaultBlacklist = false; public boolean disableVaultBlacklist = false;
@@ -642,6 +606,10 @@ public final class LeavesConfig {
} }
} }
@RemovedConfig(name = "tick", category = {"modify", "force-peaceful-mode-switch"})
@RemovedConfig(name = "types", category = {"modify", "force-peaceful-mode-switch"})
@RemovedConfig(name = "force-peaceful-mode-switch", category = "modify")
@RemovedConfig(name = "force-peaceful-mode", category = "modify")
@RemovedConfig(name = "tick-command", category = "modify") @RemovedConfig(name = "tick-command", category = "modify")
@RemovedConfig(name = "player-can-edit-sign", category = "modify") @RemovedConfig(name = "player-can-edit-sign", category = "modify")
@RemovedConfig(name = "mending-compatibility-infinity", category = {"modify", "minecraft-old"}) @RemovedConfig(name = "mending-compatibility-infinity", category = {"modify", "minecraft-old"})

View File

@@ -4,7 +4,6 @@ import net.minecraft.Util;
import org.leavesmc.leaves.command.subcommands.BlockUpdateCommand; import org.leavesmc.leaves.command.subcommands.BlockUpdateCommand;
import org.leavesmc.leaves.command.subcommands.ConfigCommand; import org.leavesmc.leaves.command.subcommands.ConfigCommand;
import org.leavesmc.leaves.command.subcommands.CounterCommand; import org.leavesmc.leaves.command.subcommands.CounterCommand;
import org.leavesmc.leaves.command.subcommands.PeacefulModeSwitchCommand;
import org.leavesmc.leaves.command.subcommands.ReloadCommand; import org.leavesmc.leaves.command.subcommands.ReloadCommand;
import org.leavesmc.leaves.command.subcommands.ReportCommand; import org.leavesmc.leaves.command.subcommands.ReportCommand;
import org.leavesmc.leaves.command.subcommands.UpdateCommand; import org.leavesmc.leaves.command.subcommands.UpdateCommand;
@@ -23,7 +22,6 @@ public final class LeavesCommand extends LeavesRootCommand {
final Map<Set<String>, LeavesSubcommand> commands = new HashMap<>(); final Map<Set<String>, LeavesSubcommand> commands = new HashMap<>();
commands.put(Set.of("config"), new ConfigCommand()); commands.put(Set.of("config"), new ConfigCommand());
commands.put(Set.of("update"), new UpdateCommand()); commands.put(Set.of("update"), new UpdateCommand());
commands.put(Set.of("peaceful"), new PeacefulModeSwitchCommand());
commands.put(Set.of("counter"), new CounterCommand()); commands.put(Set.of("counter"), new CounterCommand());
commands.put(Set.of("reload"), new ReloadCommand()); commands.put(Set.of("reload"), new ReloadCommand());
commands.put(Set.of("report"), new ReportCommand()); commands.put(Set.of("report"), new ReportCommand());

View File

@@ -1,80 +0,0 @@
package org.leavesmc.leaves.command.subcommands;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.NaturalSpawner;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.command.LeavesCommandUtil;
import org.leavesmc.leaves.command.LeavesSubcommand;
import org.leavesmc.leaves.command.LeavesSuggestionBuilder;
public class PeacefulModeSwitchCommand implements LeavesSubcommand {
@Override
public void execute(CommandSender sender, String subCommand, String[] args) {
World world;
if (args.length == 0) {
if (sender instanceof Player player) {
world = player.getWorld();
} else {
sender.sendMessage(Component.text("Must specify a world! ex: '/leaves peaceful world'", NamedTextColor.RED));
return;
}
} else {
final String input = args[0];
final World inputWorld = Bukkit.getWorld(input);
if (inputWorld == null) {
sender.sendMessage(Component.text("'" + input + "' is not a valid world!", NamedTextColor.RED));
return;
} else {
world = inputWorld;
}
}
final ServerLevel level = ((CraftWorld) world).getHandle();
int chunks = 0;
if (level.chunkSource.getLastSpawnState() != null) {
chunks = level.chunkSource.getLastSpawnState().getSpawnableChunkCount();
}
sender.sendMessage(Component.join(JoinConfiguration.noSeparators(),
Component.text("Peaceful Mode Switch for world: "),
Component.text(world.getName(), NamedTextColor.AQUA)
));
sender.sendMessage(Component.join(JoinConfiguration.noSeparators(),
Component.text("Refuses per "),
Component.text(level.chunkSource.peacefulModeSwitchTick, level.chunkSource.peacefulModeSwitchTick > 0 ? NamedTextColor.AQUA : NamedTextColor.GRAY),
Component.text(" tick")
));
int count = level.chunkSource.peacefulModeSwitchCount;
int limit = NaturalSpawner.globalLimitForCategory(level, MobCategory.MONSTER, chunks);
NamedTextColor color = count >= limit ? NamedTextColor.AQUA : NamedTextColor.GRAY;
sender.sendMessage(Component.join(JoinConfiguration.noSeparators(),
Component.text("Now count "),
Component.text(count, color),
Component.text("/", color),
Component.text(limit, color)
));
}
@Override
public void suggest(@NotNull CommandSender sender, @NotNull String alias, @NotNull String @NotNull [] args, @Nullable Location location, LeavesSuggestionBuilder builder) throws IllegalArgumentException {
if (args.length > 1) {
return;
}
LeavesCommandUtil.getListMatchingLast(sender, args, Bukkit.getWorlds().stream().map(World::getName).toList()).forEach(builder::suggest);
}
}