Sync fillLimit rule with the equivalent gamerule

This commit is contained in:
altrisi authored and gnembon committed 2023-03-08 20:52:44 +01:00
1 parent 50470dd59a
commit 4801534229
6 files changed
+50 -53

No files matched your search

+12
View File
@@ -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<Integer> fillLimit = (CarpetRule<Integer>) settingsManager.getCarpetRule("fillLimit");
try
{
fillLimit.set(minecraftServer.createCommandSourceStack(), fillLimit.value());
} catch (InvalidRuleValueException e)
{
throw new AssertionError();
}
extensions.forEach(e -> {
if (e.extensionSettingsManager() != null)
{
+38 -6
View File
@@ -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<Integer> {
@Override public Integer validate(CommandSourceStack source, CarpetRule<Integer> currentRule, Integer newValue, String string) {
return (newValue>0 && newValue <= 20000000) ? newValue : null;
private static class FillLimitMigrator extends Validator<Integer>
{
@Override
public Integer validate(CommandSourceStack source, CarpetRule<Integer> 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<Integer>
{
@Override
public Integer validate(CommandSourceStack source, CarpetRule<Integer> 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;
@@ -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<GameRules.IntegerValue> 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"
@@ -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<GameRules.IntegerValue> key)
{
int vanilla = instance.getInt(key);
return Math.max(vanilla, CarpetSettings.fillLimit);
}
}
@@ -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<GameRules.IntegerValue> 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"
-1
View File
@@ -11,7 +11,6 @@
"PerfCommand_permissionMixin",
"FillCommandMixin",
"FillBiomeCommandMixin",
"CloneCommands_fillUpdatesMixin",
"SetBlockCommand_fillUpdatesMixin",
"ForceLoadCommand_forceLoadLimitMixin",