Use constants for a few magic numbers in rules
This commit is contained in:
9 files changed
+19
-17
No files matched your search
@@ -24,6 +24,8 @@ import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.StructureBlockEntity;
|
||||
import net.minecraft.world.level.block.piston.PistonStructureResolver;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -52,12 +54,11 @@ public class CarpetSettings
|
||||
public static final Logger LOG = LoggerFactory.getLogger("carpet");
|
||||
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
|
||||
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
|
||||
public static final int VANILLA_FILL_LIMIT = 32768;
|
||||
public static int runPermissionLevel = 2;
|
||||
public static boolean doChainStone = false;
|
||||
public static boolean chainStoneStickToAll = false;
|
||||
public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID;
|
||||
public static final int vanillaStructureBlockLimit = 48;
|
||||
|
||||
private static class LanguageValidator extends Validator<String> {
|
||||
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
|
||||
if (!Translations.isValidLanguage(newValue))
|
||||
@@ -611,7 +612,7 @@ public class CarpetSettings
|
||||
strict = false,
|
||||
validate = PushLimitLimits.class
|
||||
)
|
||||
public static int pushLimit = 12;
|
||||
public static int pushLimit = PistonStructureResolver.MAX_PUSH_DEPTH;
|
||||
|
||||
@Rule(
|
||||
desc = "Customizable powered rail power range",
|
||||
@@ -636,7 +637,7 @@ public class CarpetSettings
|
||||
strict = false,
|
||||
validate = FillLimitLimits.class
|
||||
)
|
||||
public static int fillLimit = 32768;
|
||||
public static int fillLimit = VANILLA_FILL_LIMIT;
|
||||
|
||||
|
||||
@Rule(
|
||||
@@ -815,7 +816,7 @@ public class CarpetSettings
|
||||
options = {"0", "11"},
|
||||
validate = ChangeSpawnChunksValidator.class
|
||||
)
|
||||
public static int spawnChunksSize = 11;
|
||||
public static int spawnChunksSize = MinecraftServer.START_CHUNK_RADIUS;
|
||||
|
||||
public static class LightBatchValidator extends Validator<Integer> {
|
||||
public static void applyLightBatchSizes(int maxBatchSize)
|
||||
@@ -978,7 +979,7 @@ public class CarpetSettings
|
||||
public static class StructureBlockLimitValidator extends Validator<Integer> {
|
||||
|
||||
@Override public Integer validate(CommandSourceStack source, CarpetRule<Integer> currentRule, Integer newValue, String string) {
|
||||
return (newValue >= vanillaStructureBlockLimit) ? newValue : null;
|
||||
return (newValue >= StructureBlockEntity.MAX_SIZE_PER_AXIS) ? newValue : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -999,7 +1000,7 @@ public class CarpetSettings
|
||||
validate = StructureBlockLimitValidator.class,
|
||||
strict = false
|
||||
)
|
||||
public static int structureBlockLimit = vanillaStructureBlockLimit;
|
||||
public static int structureBlockLimit = StructureBlockEntity.MAX_SIZE_PER_AXIS;
|
||||
|
||||
public static class StructureBlockIgnoredValidator extends Validator<String> {
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@Mixin(CloneCommands.class)
|
||||
public abstract class CloneCommands_fillUpdatesMixin
|
||||
{
|
||||
@ModifyConstant(method = "clone", constant = @Constant(intValue = 32768))
|
||||
@ModifyConstant(method = "clone", constant = @Constant(intValue = CarpetSettings.VANILLA_FILL_LIMIT))
|
||||
private static int fillLimit(int original) {
|
||||
return CarpetSettings.fillLimit;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
@Mixin(FillBiomeCommand.class)
|
||||
public class FillBiomeCommandMixin
|
||||
{
|
||||
@ModifyConstant(method = "fill", constant = @Constant(intValue = 32768))
|
||||
@ModifyConstant(method = "fill", constant = @Constant(intValue = CarpetSettings.VANILLA_FILL_LIMIT))
|
||||
private static int fillLimit(int original)
|
||||
{
|
||||
return CarpetSettings.fillLimit;
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@Mixin(FillCommand.class)
|
||||
public abstract class FillCommandMixin
|
||||
{
|
||||
@ModifyConstant(method = "fillBlocks", constant = @Constant(intValue = 32768))
|
||||
@ModifyConstant(method = "fillBlocks", constant = @Constant(intValue = CarpetSettings.VANILLA_FILL_LIMIT))
|
||||
private static int fillLimit(int original)
|
||||
{
|
||||
return CarpetSettings.fillLimit;
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
@Mixin(value = PistonStructureResolver.class, priority = 420) // piston push limit is important for carpet
|
||||
public class PistonHandler_pushLimitMixin
|
||||
public class PistonStructureResolver_pushLimitMixin
|
||||
{
|
||||
@ModifyConstant(method = "addBlockLine", constant = @Constant(intValue = 12), expect = 3)
|
||||
@ModifyConstant(method = "addBlockLine", constant = @Constant(intValue = PistonStructureResolver.MAX_PUSH_DEPTH), expect = 3)
|
||||
private int pushLimit(int original)
|
||||
{
|
||||
return CarpetSettings.pushLimit;
|
||||
@@ -6,6 +6,8 @@ import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.game.ServerboundSetStructureBlockPacket;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.block.entity.StructureBlockEntity;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
@@ -39,7 +41,7 @@ public class ServerboundSetStructureBlockPacketMixin {
|
||||
)
|
||||
private void structureBlockLimitsWrite(FriendlyByteBuf buf, CallbackInfo ci) {
|
||||
//client method, only applicable if with carpet is on the server, or running locally
|
||||
if (CarpetSettings.structureBlockLimit != CarpetSettings.vanillaStructureBlockLimit)
|
||||
if (CarpetSettings.structureBlockLimit != StructureBlockEntity.MAX_SIZE_PER_AXIS)
|
||||
{
|
||||
buf.writeInt(this.offset.getX());
|
||||
buf.writeInt(this.offset.getY());
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.ServerLevelAccessor;
|
||||
import net.minecraft.world.level.block.entity.StructureBlockEntity;
|
||||
|
||||
@@ -14,7 +14,7 @@ public abstract class StructureBlockEntity_limitsMixin
|
||||
{
|
||||
@ModifyConstant(
|
||||
method = "load",
|
||||
constant = @Constant(intValue = 48)
|
||||
constant = @Constant(intValue = StructureBlockEntity.MAX_SIZE_PER_AXIS)
|
||||
)
|
||||
private int positiveLimit(int original) {
|
||||
return CarpetSettings.structureBlockLimit;
|
||||
@@ -22,7 +22,7 @@ public abstract class StructureBlockEntity_limitsMixin
|
||||
|
||||
@ModifyConstant(
|
||||
method = "load",
|
||||
constant = @Constant(intValue = -48)
|
||||
constant = @Constant(intValue = -StructureBlockEntity.MAX_SIZE_PER_AXIS)
|
||||
)
|
||||
private int negativeLimit(int original) {
|
||||
return -CarpetSettings.structureBlockLimit;
|
||||
|
||||
Reference in new issue
Block a user