Merge branch 'refs/heads/1.20.6' into 1.20.4

# Conflicts:
#	gradle.properties
#	src/main/java/one/oth3r/sit/packet/CustomPayloads.java
This commit is contained in:
Oth3r 2024-07-22 10:41:05 -05:00
commit f019b89647
3 changed files with 22 additions and 1 deletions

View file

@ -211,6 +211,7 @@ public class Events {
Sit.server = s; Sit.server = s;
Sit.commandManager = s.getCommandManager(); Sit.commandManager = s.getCommandManager();
UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> { UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> {
if (!Config.handSitting) return ActionResult.PASS;
ServerPlayerEntity player = Sit.server.getPlayerManager().getPlayer(pl.getUuid()); ServerPlayerEntity player = Sit.server.getPlayerManager().getPlayer(pl.getUuid());
if (player == null) return ActionResult.PASS; if (player == null) return ActionResult.PASS;
if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) { if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) {

View file

@ -13,17 +13,24 @@ import net.minecraft.util.Formatting;
import one.oth3r.sit.file.Config; import one.oth3r.sit.file.Config;
public class ModMenu implements ModMenuApi { public class ModMenu implements ModMenuApi {
private static MutableText lang(String key) { private static MutableText lang(String key) {
return Text.translatable("config.sit."+key); return Text.translatable("config.sit."+key);
} }
private static MutableText lang(String key, Object... args) { private static MutableText lang(String key, Object... args) {
return Text.translatable("config.sit."+key,args); return Text.translatable("config.sit."+key,args);
} }
@Override @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() { public ConfigScreenFactory<?> getModConfigScreenFactory() {
// return null if YACL isn't installed to not throw an error // return null if YACL isn't installed to not throw an error
if (!yaclCheck()) return screen -> null; 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!")) .title(Text.of("Sit!"))
.category(ConfigCategory.createBuilder() .category(ConfigCategory.createBuilder()
.name(lang("category.general")) .name(lang("category.general"))
@ -40,6 +47,12 @@ public class ModMenu implements ModMenuApi {
.binding(Config.defaults.sitWhileSeated, () -> Config.sitWhileSeated, n -> Config.sitWhileSeated = n) .binding(Config.defaults.sitWhileSeated, () -> Config.sitWhileSeated, n -> Config.sitWhileSeated = n)
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter()) .controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
.build()) .build())
.option(Option.<Boolean>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() .group(OptionGroup.createBuilder()
.name(lang("general.sittable")) .name(lang("general.sittable"))
.description(OptionDescription.of(lang("general.sittable.description"))) .description(OptionDescription.of(lang("general.sittable.description")))

View file

@ -42,6 +42,7 @@ public class Config {
} }
} }
} }
public static boolean handSitting = defaults.handSitting;
public static HandRequirement mainReq = defaults.mainReq; public static HandRequirement mainReq = defaults.mainReq;
public static boolean mainBlock = defaults.mainBlock; public static boolean mainBlock = defaults.mainBlock;
public static boolean mainFood = defaults.mainFood; public static boolean mainFood = defaults.mainFood;
@ -113,6 +114,8 @@ public class Config {
customBlocks = validateCustomBlocks(new Gson().fromJson((String) customBlocks = validateCustomBlocks(new Gson().fromJson((String)
properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType)); properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType));
} catch (JsonSyntaxException ignore) {} } 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))); 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))); 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))); mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.food", a -> String.valueOf(defaults.mainFood)));
@ -164,9 +167,11 @@ public class Config {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static String lang(String key, Object... args) { public static String lang(String key, Object... args) {
return LangReader.of("config.sit."+key, args).getTxT().getString(); return LangReader.of("config.sit."+key, args).getTxT().getString();
} }
public static void save() { public static void save() {
try (var file = Files.newBufferedWriter(configFile().toPath(), StandardCharsets.UTF_8)) { try (var file = Files.newBufferedWriter(configFile().toPath(), StandardCharsets.UTF_8)) {
Gson gson = new GsonBuilder().disableHtmlEscaping().create(); Gson gson = new GsonBuilder().disableHtmlEscaping().create();
@ -195,6 +200,7 @@ public class Config {
.append("\n# ").append(lang("general.sittable_blocks.description_8")).getString()); .append("\n# ").append(lang("general.sittable_blocks.description_8")).getString());
file.write("\ncustom-blocks="+gson.toJson(customBlocks)); file.write("\ncustom-blocks="+gson.toJson(customBlocks));
file.write("\n\n# "+lang("hand")); file.write("\n\n# "+lang("hand"));
file.write("\nhand.sitting=" + handSitting);
file.write("\n# "+Sit.lang("config.sit."+ file.write("\n# "+Sit.lang("config.sit."+
"hand.requirements.description") "hand.requirements.description")
.append("\n# ").append(lang("hand.requirements.description_2")) .append("\n# ").append(lang("hand.requirements.description_2"))
@ -229,6 +235,7 @@ public class Config {
public static boolean fullBlocksOn = false; public static boolean fullBlocksOn = false;
public static boolean customOn = false; public static boolean customOn = false;
public static List<String> customBlocks = List.of("minecraft:campfire|.46|1|lit=false","minecraft:soul_campfire|.46|1|lit=false,waterlogged=false"); public static List<String> 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 HandRequirement mainReq = HandRequirement.empty;
public static boolean mainBlock = false; public static boolean mainBlock = false;
public static boolean mainFood = false; public static boolean mainFood = false;