Sync fillLimit rule with the equivalent gamerule
This commit is contained in:
1 parent
50470dd59a
commit
4801534229
6 files changed
+50
-53
No files matched your search
@@ -23,6 +23,8 @@ import carpet.helpers.HopperCounter;
|
|||||||
import carpet.helpers.TickSpeed;
|
import carpet.helpers.TickSpeed;
|
||||||
import carpet.logging.LoggerRegistry;
|
import carpet.logging.LoggerRegistry;
|
||||||
import carpet.script.CarpetScriptServer;
|
import carpet.script.CarpetScriptServer;
|
||||||
|
import carpet.api.settings.CarpetRule;
|
||||||
|
import carpet.api.settings.InvalidRuleValueException;
|
||||||
import carpet.api.settings.SettingsManager;
|
import carpet.api.settings.SettingsManager;
|
||||||
import carpet.logging.HUDController;
|
import carpet.logging.HUDController;
|
||||||
import carpet.script.external.Carpet;
|
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));
|
extensions.forEach(e -> e.onServerLoadedWorlds(minecraftServer));
|
||||||
// initialize scarpet rules after all extensions are loaded
|
// initialize scarpet rules after all extensions are loaded
|
||||||
settingsManager.initializeScarpetRules();
|
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 -> {
|
extensions.forEach(e -> {
|
||||||
if (e.extensionSettingsManager() != null)
|
if (e.extensionSettingsManager() != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import net.minecraft.server.level.ServerLevel;
|
|||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
|
import net.minecraft.world.level.GameRules;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
@@ -626,29 +627,60 @@ public class CarpetSettings
|
|||||||
)
|
)
|
||||||
public static int railPowerLimit = 9;
|
public static int railPowerLimit = 9;
|
||||||
|
|
||||||
private static class FillLimitLimits extends Validator<Integer> {
|
private static class FillLimitMigrator 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 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
|
@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(
|
@Rule(
|
||||||
desc = "[Deprecated] Customizable fill/fillbiome/clone volume limit",
|
desc = "[Deprecated] Customizable fill/fillbiome/clone volume limit",
|
||||||
extra = "Use vanilla gamerule instead. This setting will be removed in 1.20.0",
|
extra = "Use vanilla gamerule instead. This setting will be removed in 1.20.0",
|
||||||
options = {"32768", "250000", "1000000"},
|
options = {"32768", "250000", "1000000"},
|
||||||
category = CREATIVE,
|
category = CREATIVE,
|
||||||
strict = false,
|
strict = false,
|
||||||
validate = FillLimitLimits.class
|
validate = FillLimitMigrator.class
|
||||||
)
|
)
|
||||||
public static int fillLimit = 32768;
|
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(
|
@Rule(
|
||||||
desc = "Customizable forceload chunk limit",
|
desc = "Customizable forceload chunk limit",
|
||||||
options = {"256"},
|
options = {"256"},
|
||||||
category = CREATIVE,
|
category = CREATIVE,
|
||||||
strict = false,
|
strict = false,
|
||||||
validate = FillLimitLimits.class
|
validate = ForceloadLimitValidator.class
|
||||||
)
|
)
|
||||||
public static int forceloadLimit = 256;
|
public static int forceloadLimit = 256;
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,14 @@ import carpet.CarpetSettings;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.commands.CloneCommands;
|
import net.minecraft.server.commands.CloneCommands;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.GameRules;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
|
||||||
@Mixin(CloneCommands.class)
|
@Mixin(CloneCommands.class)
|
||||||
public abstract class CloneCommands_fillUpdatesMixin
|
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(
|
@Redirect(method = "clone", at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/level/ServerLevel;blockUpdated(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V"
|
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.core.BlockPos;
|
||||||
import net.minecraft.server.commands.FillCommand;
|
import net.minecraft.server.commands.FillCommand;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.GameRules;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -13,17 +12,6 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||||||
@Mixin(FillCommand.class)
|
@Mixin(FillCommand.class)
|
||||||
public abstract class FillCommandMixin
|
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(
|
@Redirect(method = "fillBlocks", at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/level/ServerLevel;blockUpdated(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V"
|
target = "Lnet/minecraft/server/level/ServerLevel;blockUpdated(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V"
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
"PerfCommand_permissionMixin",
|
"PerfCommand_permissionMixin",
|
||||||
"FillCommandMixin",
|
"FillCommandMixin",
|
||||||
"FillBiomeCommandMixin",
|
|
||||||
"CloneCommands_fillUpdatesMixin",
|
"CloneCommands_fillUpdatesMixin",
|
||||||
"SetBlockCommand_fillUpdatesMixin",
|
"SetBlockCommand_fillUpdatesMixin",
|
||||||
"ForceLoadCommand_forceLoadLimitMixin",
|
"ForceLoadCommand_forceLoadLimitMixin",
|
||||||
|
|||||||
Reference in new issue
Block a user