From 480153422914ee202248f84a51fc96ea99757fe3 Mon Sep 17 00:00:00 2001 From: altrisi Date: Wed, 8 Mar 2023 19:11:43 +0100 Subject: [PATCH] Sync `fillLimit` rule with the equivalent gamerule --- src/main/java/carpet/CarpetServer.java | 12 +++++ src/main/java/carpet/CarpetSettings.java | 44 ++++++++++++++++--- .../CloneCommands_fillUpdatesMixin.java | 12 ----- .../carpet/mixins/FillBiomeCommandMixin.java | 22 ---------- .../java/carpet/mixins/FillCommandMixin.java | 12 ----- src/main/resources/carpet.mixins.json | 1 - 6 files changed, 50 insertions(+), 53 deletions(-) delete mode 100644 src/main/java/carpet/mixins/FillBiomeCommandMixin.java diff --git a/src/main/java/carpet/CarpetServer.java b/src/main/java/carpet/CarpetServer.java index 27fa84e1..861ba61d 100644 --- a/src/main/java/carpet/CarpetServer.java +++ b/src/main/java/carpet/CarpetServer.java @@ -23,6 +23,8 @@ import carpet.helpers.HopperCounter; import carpet.helpers.TickSpeed; import carpet.logging.LoggerRegistry; import carpet.script.CarpetScriptServer; +import carpet.api.settings.CarpetRule; +import carpet.api.settings.InvalidRuleValueException; import carpet.api.settings.SettingsManager; import carpet.logging.HUDController; import carpet.script.external.Carpet; @@ -104,6 +106,16 @@ public class CarpetServer // static for now - easier to handle all around the co extensions.forEach(e -> e.onServerLoadedWorlds(minecraftServer)); // initialize scarpet rules after all extensions are loaded settingsManager.initializeScarpetRules(); + // run fillLimit rule migration now that gamerules are available + @SuppressWarnings("unchecked") + CarpetRule fillLimit = (CarpetRule) settingsManager.getCarpetRule("fillLimit"); + try + { + fillLimit.set(minecraftServer.createCommandSourceStack(), fillLimit.value()); + } catch (InvalidRuleValueException e) + { + throw new AssertionError(); + } extensions.forEach(e -> { if (e.extensionSettingsManager() != null) { diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 97b144a0..1fabb02e 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -22,6 +22,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -626,29 +627,60 @@ public class CarpetSettings ) public static int railPowerLimit = 9; - private static class FillLimitLimits extends Validator { - @Override public Integer validate(CommandSourceStack source, CarpetRule currentRule, Integer newValue, String string) { - return (newValue>0 && newValue <= 20000000) ? newValue : null; + private static class FillLimitMigrator extends Validator + { + @Override + public Integer validate(CommandSourceStack source, CarpetRule changingRule, Integer newValue, String userInput) + { + if (source != null && source.getServer().overworld() != null) + { + GameRules.IntegerValue gamerule = source.getServer().getGameRules().getRule(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT); + if (gamerule.get() != newValue) + { + if (newValue == 32768 && changingRule.value() == newValue) // migration call, gamerule is different, update rule + { + Messenger.m(source, "g Syncing fillLimit rule with gamerule"); + newValue = gamerule.get(); + } else if (newValue != 32768 && gamerule.get() == 32768) + { + Messenger.m(source, "g Migrated value of fillLimit carpet rule to commandModificationBlockLimit gamerule"); + gamerule.set(newValue, source.getServer()); + } + } + } + return newValue; } @Override - public String description() { return "You must choose a value from 1 to 20M";} + public String description() { return "The value of this rule will be migrated to the gamerule";} } + @Rule( desc = "[Deprecated] Customizable fill/fillbiome/clone volume limit", extra = "Use vanilla gamerule instead. This setting will be removed in 1.20.0", options = {"32768", "250000", "1000000"}, category = CREATIVE, strict = false, - validate = FillLimitLimits.class + validate = FillLimitMigrator.class ) public static int fillLimit = 32768; + private static class ForceloadLimitValidator extends Validator + { + @Override + public Integer validate(CommandSourceStack source, CarpetRule currentRule, Integer newValue, String string) + { + return (newValue > 0 && newValue <= 20000000) ? newValue : null; + } + + @Override + public String description() { return "You must choose a value from 1 to 20M";} + } @Rule( desc = "Customizable forceload chunk limit", options = {"256"}, category = CREATIVE, strict = false, - validate = FillLimitLimits.class + validate = ForceloadLimitValidator.class ) public static int forceloadLimit = 256; diff --git a/src/main/java/carpet/mixins/CloneCommands_fillUpdatesMixin.java b/src/main/java/carpet/mixins/CloneCommands_fillUpdatesMixin.java index 3f9ba1df..7a172441 100644 --- a/src/main/java/carpet/mixins/CloneCommands_fillUpdatesMixin.java +++ b/src/main/java/carpet/mixins/CloneCommands_fillUpdatesMixin.java @@ -4,26 +4,14 @@ import carpet.CarpetSettings; import net.minecraft.core.BlockPos; import net.minecraft.server.commands.CloneCommands; import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.GameRules; import net.minecraft.world.level.block.Block; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; - @Mixin(CloneCommands.class) public abstract class CloneCommands_fillUpdatesMixin { - @Redirect(method = "clone", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/GameRules;getInt(Lnet/minecraft/world/level/GameRules$Key;)I" - )) - private static int redirectCloneGameRuleInt(GameRules instance, GameRules.Key key) - { - int vanilla = instance.getInt(key); - return Math.max(vanilla, CarpetSettings.fillLimit); - } - @Redirect(method = "clone", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;blockUpdated(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V" diff --git a/src/main/java/carpet/mixins/FillBiomeCommandMixin.java b/src/main/java/carpet/mixins/FillBiomeCommandMixin.java deleted file mode 100644 index cd4402a7..00000000 --- a/src/main/java/carpet/mixins/FillBiomeCommandMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package carpet.mixins; - -import carpet.CarpetSettings; -import net.minecraft.server.commands.FillBiomeCommand; -import net.minecraft.world.level.GameRules; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(FillBiomeCommand.class) -public class FillBiomeCommandMixin -{ - @Redirect(method = "fill", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/GameRules;getInt(Lnet/minecraft/world/level/GameRules$Key;)I" - )) - private static int redirectCloneGameRuleInt(GameRules instance, GameRules.Key key) - { - int vanilla = instance.getInt(key); - return Math.max(vanilla, CarpetSettings.fillLimit); - } -} diff --git a/src/main/java/carpet/mixins/FillCommandMixin.java b/src/main/java/carpet/mixins/FillCommandMixin.java index ab1e0a40..344f5ff3 100644 --- a/src/main/java/carpet/mixins/FillCommandMixin.java +++ b/src/main/java/carpet/mixins/FillCommandMixin.java @@ -4,7 +4,6 @@ import carpet.CarpetSettings; import net.minecraft.core.BlockPos; import net.minecraft.server.commands.FillCommand; import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.GameRules; import net.minecraft.world.level.block.Block; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -13,17 +12,6 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(FillCommand.class) public abstract class FillCommandMixin { - - @Redirect(method = "fillBlocks", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/GameRules;getInt(Lnet/minecraft/world/level/GameRules$Key;)I" - )) - private static int redirectCloneGameRuleInt(GameRules instance, GameRules.Key key) - { - int vanilla = instance.getInt(key); - return Math.max(vanilla, CarpetSettings.fillLimit); - } - @Redirect(method = "fillBlocks", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;blockUpdated(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V" diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 5b0bd9eb..79ef3e0c 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -11,7 +11,6 @@ "PerfCommand_permissionMixin", "FillCommandMixin", - "FillBiomeCommandMixin", "CloneCommands_fillUpdatesMixin", "SetBlockCommand_fillUpdatesMixin", "ForceLoadCommand_forceLoadLimitMixin",