Use enum for chainstone setting

And very minor cleanup in `CarpetSettings`
This commit is contained in:
altrisi committed 2023-01-18 22:44:12 +01:00
1 parent b81ce06beb
commit e924477558
2 files changed
+13 -35

No files matched your search

+10 -33
View File
@@ -32,7 +32,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Iterator;
import java.util.Locale;
import java.util.Optional;
import static carpet.api.settings.RuleCategory.BUGFIX;
@@ -56,8 +55,6 @@ public class CarpetSettings
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
public static int runPermissionLevel = 2;
public static boolean doChainStone = false;
public static boolean chainStoneStickToAll = false;
public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID;
private static class LanguageValidator extends Validator<String> {
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
@@ -386,13 +383,10 @@ public class CarpetSettings
@Rule( desc = "Pistons can push block entities, like hoppers, chests etc.", category = {EXPERIMENTAL, FEATURE} )
public static boolean movableBlockEntities = false;
private static class ChainStoneSetting extends Validator<String> {
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
CarpetSettings.doChainStone = !newValue.toLowerCase(Locale.ROOT).equals("false");
CarpetSettings.chainStoneStickToAll = newValue.toLowerCase(Locale.ROOT).equals("stick_to_all");
return newValue;
public enum ChainStoneMode {
TRUE, FALSE, STICK_TO_ALL;
public boolean enabled() {
return this != FALSE;
}
}
@@ -402,11 +396,9 @@ public class CarpetSettings
"and will stick to other blocks that connect to them directly.",
"With stick_to_all: it will stick even if not visually connected"
},
category = {EXPERIMENTAL, FEATURE},
options = {"true", "false", "stick_to_all"},
validate = ChainStoneSetting.class
category = {EXPERIMENTAL, FEATURE}
)
public static String chainStone = "false";
public static ChainStoneMode chainStone = ChainStoneMode.FALSE;
@Rule( desc = "Saplings turn into dead shrubs in hot climates and no water access", category = FEATURE )
public static boolean desertShrubs = false;
@@ -487,18 +479,10 @@ public class CarpetSettings
private static class ModulePermissionLevel extends Validator<String> {
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
int permissionLevel = switch (newValue) {
case "false":
yield 0;
case "true":
case "ops":
yield 2;
case "0":
case "1":
case "2":
case "3":
case "4":
yield Integer.parseInt(newValue);
default: throw new IllegalArgumentException();
case "false" -> 0;
case "true", "ops" -> 2;
case "0", "1", "2", "3", "4" -> Integer.parseInt(newValue);
default -> throw new IllegalArgumentException(); // already checked by previous validator
};
if (source != null && !source.hasPermission(permissionLevel))
return null;
@@ -591,13 +575,6 @@ public class CarpetSettings
)
public static boolean smoothClientAnimations;
//@Rule(
// desc="Fixes mining ghost blocks by trusting clients with block breaking",
// extra="Increases player allowed mining distance to 32 blocks",
// category = SURVIVAL
//)
//public static boolean miningGhostBlockFix = false;
private static class PushLimitLimits extends Validator<Integer> {
@Override public Integer validate(CommandSourceStack source, CarpetRule<Integer> currentRule, Integer newValue, String string) {
return (newValue>0 && newValue <= 1024) ? newValue : null;
@@ -3,6 +3,7 @@ package carpet.mixins;
import org.spongepowered.asm.mixin.Mixin;
import carpet.CarpetSettings;
import carpet.CarpetSettings.ChainStoneMode;
import carpet.fakes.BlockBehaviourInterface;
import net.minecraft.core.BlockPos;
@@ -20,7 +21,7 @@ public class ChainBlock_customStickyMixin implements BlockBehaviourInterface {
@Override
public boolean isSticky(BlockState state) {
return CarpetSettings.doChainStone;
return CarpetSettings.chainStone.enabled();
}
@Override
@@ -31,7 +32,7 @@ public class ChainBlock_customStickyMixin implements BlockBehaviourInterface {
return false;
}
if (CarpetSettings.chainStoneStickToAll) {
if (CarpetSettings.chainStone == ChainStoneMode.STICK_TO_ALL) {
return true;
}
if (neighborState.is((Block)(Object)this)) {