From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: AlphaKR93 Date: Fri, 29 Sep 2023 21:10:26 +0900 Subject: [PATCH] Implement FixMySpawnR diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java index 64d911bee1607880514061c75116d8672df8bb8f..7868590696f620cc5f0785125c9573d7494d8477 100644 --- a/src/main/java/net/minecraft/world/level/BaseSpawner.java +++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java @@ -46,6 +46,8 @@ public abstract class BaseSpawner { public int requiredPlayerRange = 16; public int spawnRange = 4; private int tickDelay = 0; // Paper + private int blockExistsTick = 0; // Plazma - Implement FixMySpawnR + private boolean blockLockedByTime = false; // Plazma - Implement FixMySpawnR public BaseSpawner() {} @@ -81,6 +83,17 @@ public abstract class BaseSpawner { } public void serverTick(ServerLevel world, BlockPos pos) { + // Plazma start - Implement FixMySpawnR + if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().gameMechanics.spawning.deadlockTimer.enabled) { + if (!this.blockLockedByTime) { + if (this.blockExistsTick > org.plazmamc.plazma.configurations.GlobalConfiguration.get().gameMechanics.spawning.deadlockTimer.timerTimeout) + blockLockedByTime = true; + else blockExistsTick++; + } + + if (blockLockedByTime && world.getBestNeighborSignal(pos) > 0) return; + } + // Plazma end if (spawnCount <= 0 || maxNearbyEntities <= 0) return; // Paper - Ignore impossible spawn tick // Paper start - Configurable mob spawner tick rate if (spawnDelay > 0 && --tickDelay > 0) return; @@ -286,6 +299,14 @@ public abstract class BaseSpawner { this.spawnRange = nbt.getShort("SpawnRange"); } + // Plazma start - Implement FixMySpawnR + if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().gameMechanics.spawning.deadlockTimer.enabled + && nbt.contains("Plazma.SpawnerTicks", 99)) { + this.blockExistsTick = nbt.getInt("Plazma.SpawnerTicks"); + this.blockLockedByTime = nbt.getBoolean("Plazma.SpawnerLocked"); + } + // Plazma end + this.displayEntity = null; } @@ -314,6 +335,9 @@ public abstract class BaseSpawner { })); } + nbt.putInt("Plazma.SpawnerTicks", this.blockExistsTick); // Plazma - Implement FixMySpawnR + nbt.putBoolean("Plazma.SpawnerLocked", this.blockLockedByTime); // Plazma - Implement FixMySpawnR + nbt.put("SpawnPotentials", (Tag) SpawnData.LIST_CODEC.encodeStart(NbtOps.INSTANCE, this.spawnPotentials).result().orElseThrow()); return nbt; } diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java index 989aa0aeb05a878945849adc6fb6663027e15927..d17df5621717b1c8d1d9a5549feb73c3600ecf3d 100644 --- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java +++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java @@ -40,6 +40,24 @@ public class GlobalConfiguration extends ConfigurationPart { } + public GameMechanics gameMechanics; + public class GameMechanics extends ConfigurationPart { + + public Spawning spawning; + public class Spawning extends ConfigurationPart { + + public DeadlockTimer deadlockTimer; + public class DeadlockTimer extends ConfigurationPart { + + public boolean enabled = DO_OPTIMIZE; + public int timerTimeout = 0; + + } + + } + + } + public Player player; public class Player extends ConfigurationPart {