diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 61a4c39..7371e3b 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -211,6 +211,7 @@ public class Events { Sit.server = s; Sit.commandManager = s.getCommandManager(); UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> { + if (!Config.handSitting) return ActionResult.PASS; ServerPlayerEntity player = Sit.server.getPlayerManager().getPlayer(pl.getUuid()); if (player == null) return ActionResult.PASS; if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) { diff --git a/src/main/java/one/oth3r/sit/ModMenu.java b/src/main/java/one/oth3r/sit/ModMenu.java index 189c77f..be74779 100644 --- a/src/main/java/one/oth3r/sit/ModMenu.java +++ b/src/main/java/one/oth3r/sit/ModMenu.java @@ -13,17 +13,24 @@ import net.minecraft.util.Formatting; import one.oth3r.sit.file.Config; public class ModMenu implements ModMenuApi { + private static MutableText lang(String key) { return Text.translatable("config.sit."+key); } + private static MutableText lang(String key, Object... args) { return Text.translatable("config.sit."+key,args); } + @Override public ConfigScreenFactory getModConfigScreenFactory() { // return null if YACL isn't installed to not throw an error if (!yaclCheck()) return screen -> null; - return parent -> YetAnotherConfigLib.createBuilder().save(Config::save) + return parent -> YetAnotherConfigLib.createBuilder().save(() -> { + // save and load to get rid of bad data + Config.save(); + Config.load(); + }) .title(Text.of("Sit!")) .category(ConfigCategory.createBuilder() .name(lang("category.general")) @@ -40,6 +47,12 @@ public class ModMenu implements ModMenuApi { .binding(Config.defaults.sitWhileSeated, () -> Config.sitWhileSeated, n -> Config.sitWhileSeated = n) .controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter()) .build()) + .option(Option.createBuilder() + .name(Text.of("Sitting with Hand")) + .description(OptionDescription.of(Text.of("Toggles the player's ability to sit with their hand."))) + .binding(Config.defaults.handSitting,()-> Config.handSitting, n -> Config.handSitting = n) + .controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter()) + .build()) .group(OptionGroup.createBuilder() .name(lang("general.sittable")) .description(OptionDescription.of(lang("general.sittable.description"))) diff --git a/src/main/java/one/oth3r/sit/file/Config.java b/src/main/java/one/oth3r/sit/file/Config.java index 5c5c802..994d89c 100644 --- a/src/main/java/one/oth3r/sit/file/Config.java +++ b/src/main/java/one/oth3r/sit/file/Config.java @@ -42,6 +42,7 @@ public class Config { } } } + public static boolean handSitting = defaults.handSitting; public static HandRequirement mainReq = defaults.mainReq; public static boolean mainBlock = defaults.mainBlock; public static boolean mainFood = defaults.mainFood; @@ -113,6 +114,8 @@ public class Config { customBlocks = validateCustomBlocks(new Gson().fromJson((String) properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType)); } catch (JsonSyntaxException ignore) {} + + handSitting = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.sitting", a -> String.valueOf(defaults.handSitting))); mainReq = HandRequirement.get((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaults.mainReq))); mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.block", a -> String.valueOf(defaults.mainBlock))); mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.food", a -> String.valueOf(defaults.mainFood))); @@ -164,9 +167,11 @@ public class Config { e.printStackTrace(); } } + public static String lang(String key, Object... args) { return LangReader.of("config.sit."+key, args).getTxT().getString(); } + public static void save() { try (var file = Files.newBufferedWriter(configFile().toPath(), StandardCharsets.UTF_8)) { Gson gson = new GsonBuilder().disableHtmlEscaping().create(); @@ -195,6 +200,7 @@ public class Config { .append("\n# ").append(lang("general.sittable_blocks.description_8")).getString()); file.write("\ncustom-blocks="+gson.toJson(customBlocks)); file.write("\n\n# "+lang("hand")); + file.write("\nhand.sitting=" + handSitting); file.write("\n# "+Sit.lang("config.sit."+ "hand.requirements.description") .append("\n# ").append(lang("hand.requirements.description_2")) @@ -229,6 +235,7 @@ public class Config { public static boolean fullBlocksOn = false; public static boolean customOn = false; public static List customBlocks = List.of("minecraft:campfire|.46|1|lit=false","minecraft:soul_campfire|.46|1|lit=false,waterlogged=false"); + public static boolean handSitting = true; public static HandRequirement mainReq = HandRequirement.empty; public static boolean mainBlock = false; public static boolean mainFood = false;