From 426264336123b35256a760ff8448376b3793701b Mon Sep 17 00:00:00 2001 From: Oth3r <68134921+Oth3r@users.noreply.github.com> Date: Sun, 6 Aug 2023 13:07:53 -0500 Subject: [PATCH 01/35] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9cc9eb5..1422219 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Sit! -[![github](https://img.shields.io/github/v/release/oth3r/Sit?color=blueviolet&logo=github)](https://github.com/Oth3r/Sit/releases) [![discord](https://dcbadge.vercel.app/api/server/Mec6yNQ9B7?style=flat)](https://discord.gg/Mec6yNQ9B7) [![modrinth](https://img.shields.io/modrinth/dt/sit!?label=Modrinth&logo=modrinth)](https://modrinth.com/mod/sit!) [![curseforge](https://cf.way2muchnoise.eu/892424.svg)](https://www.curseforge.com/minecraft/mc-mods/Sit1) +[![github](https://img.shields.io/github/v/release/oth3r/Sit?color=blueviolet&logo=github)](https://github.com/Oth3r/Sit/releases) [![discord](https://dcbadge.vercel.app/api/server/Mec6yNQ9B7?style=flat)](https://discord.gg/Mec6yNQ9B7) [![modrinth](https://img.shields.io/modrinth/dt/sit!?label=Modrinth&logo=modrinth)](https://modrinth.com/mod/sit!) [![curseforge](https://cf.way2muchnoise.eu/892424.svg)](https://www.curseforge.com/minecraft/mc-mods/Sit1) [![Crowdin](https://badges.crowdin.net/oth3r-sit/localized.svg)](https://crowdin.com/project/oth3r-sit) **Sit!** is a minecraft mod that adds sitting in vanilla minecraft. Sit on **stairs**, **slabs**, **carpets** by default, and sit on everything else using the config! @@ -27,4 +27,4 @@ Configure to your hearts desire with the in-game config with **[ModMenu](https:/ ## Future Goals * Forge Port - * Client & Server sync to have custom hand restrictions per player \ No newline at end of file + * Client & Server sync to have custom hand restrictions per player From b0ae9940508219800f78be9a424f89fc39b99b8c Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 8 Aug 2023 21:35:05 -0500 Subject: [PATCH 02/35] 1.20.2 shifts everything down by .25 --- src/main/java/one/oth3r/sit/Events.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 78ed95a..0bd366f 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -113,23 +113,24 @@ public class Events { public static void setEntity(BlockPos pos, World world, Entity entity) { Block block = world.getBlockState(pos).getBlock(); entity.setCustomName(Text.of(Sit.ENTITY_NAME)); + double hitBoxY = 0.5; entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.47, pos.getZ() + 0.5, 0, 0); entity.setInvulnerable(true); if (block instanceof StairsBlock) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0); - entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5)); + hitBoxY = 2; } if (block instanceof SlabBlock) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0); - entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,1,1.5)); + hitBoxY = 1; } if (block instanceof CarpetBlock) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()-.17, pos.getZ() + 0.5, 0, 0); - entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,0.125,1.5)); + hitBoxY = 0.125; } if (world.getBlockState(pos).isFullCube(world,pos.add(0,1,0))) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.78, pos.getZ() + 0.5, 0, 0); - entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5)); + hitBoxY = 2; } if (config.customOn && config.customBlocks.size() != 0) { for (HashMap map:getCustomBlocks().values()) { @@ -137,12 +138,15 @@ public class Events { if (map.get("block").equals(blockID)) { double input = Math.max(Math.min(Double.parseDouble((String) map.get("height")),1),0); entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+input-.22, pos.getZ() + 0.5, 0, 0); - entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,Double.parseDouble((String) map.get("hitbox")),1.5)); + hitBoxY = Double.parseDouble((String) map.get("hitbox")); } } } + //1.20.2 mounting pos change (shifts everything down by .25) + entity.updatePositionAndAngles(entity.getX(),entity.getY()+.25,entity.getZ(),0,0); + entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,hitBoxY,1.5)); //change pitch based on if player is sitting below block height or not - if (entity.getY() <= pos.getY()+.35) entity.setPitch(90); + if (entity.getY() <= pos.getY()+.35+.25) entity.setPitch(90); else entity.setPitch(-90); } public static void register() { From 393605998b66d1bda7482dd74b14d7c4908be488 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Thu, 21 Sep 2023 12:19:25 -0500 Subject: [PATCH 03/35] v1.0.2+1.20.2 --- gradle.properties | 10 +++++----- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 05c46e0..7dfee91 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,16 +4,16 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.9 -loader_version=0.14.21 +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.1 +loader_version=0.14.22 # Mod Properties -mod_version=1.0.2+1.20-1.20.1 +mod_version=1.0.2+1.20.2 maven_group=one.oth3r archives_base_name=sit! # Dependencies -fabric_version=0.85.0+1.20.1 +fabric_version=0.89.0+1.20.2 modmenu_version=7.0.0 yacl_version=3.0.0+1.20 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 13a5a5e..6e25fb8 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ }, "depends": { "fabricloader": ">=0.14.21", - "minecraft": ">=1.20 <=1.20.1", + "minecraft": "=1.20.2", "java": ">=17", "fabric-api": "*" }, From 82cb2eebfe701f12eac8e1b584215486210d6eaa Mon Sep 17 00:00:00 2001 From: Oth3r Date: Fri, 13 Oct 2023 11:00:30 -0500 Subject: [PATCH 04/35] localization message --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1422219..cd73bd1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Sit!** is a minecraft mod that adds sitting in vanilla minecraft. Sit on **stairs**, **slabs**, **carpets** by default, and sit on everything else using the config! You can also customize hand restrictions to stop accidentally sitting down! - +## Help localize Sit! on [Crowdin](https://crowdin.com/project/oth3r-sit)! ![overview](https://github.com/Oth3r/Sit/blob/master/media/overview.gif?raw=true) ## Check out my other Projects! [![DirectionHUD badge](https://github.com/Oth3r/DirectionHUD/blob/master/media/mod-badge.png?raw=true)](https://modrinth.com/mod/directionhud) From 5518ccea825080cbd502cfd73212f0f194af4fd2 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 24 Oct 2023 18:16:36 -0500 Subject: [PATCH 05/35] change because deprecation --- src/main/java/one/oth3r/sit/ModMenu.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/one/oth3r/sit/ModMenu.java b/src/main/java/one/oth3r/sit/ModMenu.java index 1ee4e27..97b7fb9 100644 --- a/src/main/java/one/oth3r/sit/ModMenu.java +++ b/src/main/java/one/oth3r/sit/ModMenu.java @@ -98,7 +98,7 @@ public class ModMenu implements ModMenuApi { .append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED)))))) .binding(config.defaults.mainReq, () -> config.mainReq, n -> config.mainReq = n) .controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.HandRequirements.class) - .valueFormatter(v -> Text.translatable("config.sit."+v.name().toLowerCase()))) + .formatValue(v -> Text.translatable("config.sit."+v.name().toLowerCase()))) .build()) .group(OptionGroup.createBuilder() .name(lang("hand.restrictions")) @@ -150,7 +150,7 @@ public class ModMenu implements ModMenuApi { .append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED)))))) .binding(config.defaults.offReq, () -> config.offReq, n -> config.offReq = n) .controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.HandRequirements.class) - .valueFormatter(v -> Text.translatable("config.sit."+v.name().toLowerCase()))) + .formatValue(v -> Text.translatable("config.sit."+v.name().toLowerCase()))) .build()) .group(OptionGroup.createBuilder() .name(lang("hand.restrictions")) From a83fe5726da4ce85e0220900a73052c749dde62c Mon Sep 17 00:00:00 2001 From: Oth3r Date: Thu, 12 Oct 2023 22:20:06 -0500 Subject: [PATCH 06/35] test for a strict list of blocks allowed above a sit entity --- src/main/java/one/oth3r/sit/Events.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 0bd366f..ca13eb0 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -78,20 +78,22 @@ public class Events { } return map; } - @SuppressWarnings("deprecation") public static boolean checkBlocks(BlockPos pos, World world) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); BlockState blockStateAbove = world.getBlockState(pos.add(0,1,0)); Block blockAbove = blockStateAbove.getBlock(); - //not the biggest fan but ah well - if (blockStateAbove.isFullCube(world,pos.add(0,1,0)) && blockStateAbove.blocksMovement()) return false; - else if (blockAbove instanceof StairsBlock || blockAbove instanceof SlabBlock || blockAbove instanceof CarpetBlock) return false; + // todo strict checker option to check 2 blocks above?? + // set amount of blocks that can be above a chair + if (!(blockAbove instanceof SignBlock || blockAbove instanceof TrapdoorBlock || blockAbove instanceof BannerBlock)) return false; + //if there's already an entity at the block location or above it for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false; + // return for the 4 default types if (block instanceof StairsBlock && config.stairsOn) return blockState.get(StairsBlock.HALF) == BlockHalf.BOTTOM; if (block instanceof SlabBlock && config.slabsOn) return blockState.get(SlabBlock.TYPE) == SlabType.BOTTOM; if (block instanceof CarpetBlock && config.carpetsOn) return true; if (blockState.isFullCube(world,pos.add(0,1,0)) && config.fullBlocksOn) return true; + // custom checker if (config.customOn && config.customBlocks.size() != 0) { for (HashMap map:getCustomBlocks().values()) { String blockID = Registries.BLOCK.getId(block).toString(); From 745e76c02a359c07e9bd7e98b419ec8aba52b2b6 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Wed, 18 Oct 2023 13:02:57 -0500 Subject: [PATCH 07/35] fix the new blocklist --- src/main/java/one/oth3r/sit/Events.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index ca13eb0..70a8540 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -84,8 +84,9 @@ public class Events { BlockState blockStateAbove = world.getBlockState(pos.add(0,1,0)); Block blockAbove = blockStateAbove.getBlock(); // todo strict checker option to check 2 blocks above?? - // set amount of blocks that can be above a chair - if (!(blockAbove instanceof SignBlock || blockAbove instanceof TrapdoorBlock || blockAbove instanceof BannerBlock)) return false; + // set amount of blocks that can be above a chair & air + if (!(blockAbove instanceof WallSignBlock || blockAbove instanceof TrapdoorBlock || + blockAbove instanceof WallBannerBlock || blockAbove instanceof AirBlock)) return false; //if there's already an entity at the block location or above it for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false; // return for the 4 default types From 1686b3c1630c10e03370506401e1db21665cfa0a Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 24 Oct 2023 18:20:55 -0500 Subject: [PATCH 08/35] dependency version bump --- build.gradle | 10 +++++----- gradle.properties | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 243770a..2901a9d 100644 --- a/build.gradle +++ b/build.gradle @@ -23,11 +23,11 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" - modImplementation "dev.isxander.yacl:yet-another-config-lib-fabric:${project.yacl_version}" - - // Uncomment the following line to enable the deprecated Fabric API modules. - // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. - // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" + modImplementation ("dev.isxander.yacl:yet-another-config-lib-fabric:${project.yacl_version}") { + exclude(group: "org.quiltmc.parsers") + exclude(group: "com.twelvemonkeys.common") + exclude(group: "com.twelvemonkeys.imageio") + } } processResources { diff --git a/gradle.properties b/gradle.properties index 7dfee91..1b1a6df 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ archives_base_name=sit! # Dependencies fabric_version=0.89.0+1.20.2 -modmenu_version=7.0.0 -yacl_version=3.0.0+1.20 +modmenu_version=8.0.0 +yacl_version=3.2.1+1.20.2 From c72c32c5c5dc871bb6aa0709ecf96d7c764cad4a Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 24 Oct 2023 18:22:30 -0500 Subject: [PATCH 09/35] 1.20.3 prep --- src/main/java/one/oth3r/sit/LangReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/one/oth3r/sit/LangReader.java b/src/main/java/one/oth3r/sit/LangReader.java index e34692c..b6ae51b 100644 --- a/src/main/java/one/oth3r/sit/LangReader.java +++ b/src/main/java/one/oth3r/sit/LangReader.java @@ -61,7 +61,7 @@ public class LangReader { return txt; } } - return MutableText.of(TextContent.EMPTY).append(translated); + return Text.empty().append(translated); } public static LangReader of(String translationKey, Object... placeholders) { return new LangReader(translationKey, placeholders); From bca4dab9d42039823094f831634643201e952e43 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 24 Oct 2023 18:22:59 -0500 Subject: [PATCH 10/35] v1.0.3+1.20.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1b1a6df..952abc0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.1 loader_version=0.14.22 # Mod Properties -mod_version=1.0.2+1.20.2 +mod_version=1.0.3+1.20.2 maven_group=one.oth3r archives_base_name=sit! From f18872844067a2aad5f98c17a9c5098cbe77e14f Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 24 Oct 2023 18:34:53 -0500 Subject: [PATCH 11/35] 1.20.1 dependencies --- gradle.properties | 10 +++++----- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 952abc0..d41b7b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.2 -yarn_mappings=1.20.2+build.1 +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.10 loader_version=0.14.22 # Mod Properties @@ -14,6 +14,6 @@ maven_group=one.oth3r archives_base_name=sit! # Dependencies -fabric_version=0.89.0+1.20.2 -modmenu_version=8.0.0 -yacl_version=3.2.1+1.20.2 +fabric_version=0.90.4+1.20.1 +modmenu_version=7.0.0 +yacl_version=3.2.1+1.20 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6e25fb8..13a5a5e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ }, "depends": { "fabricloader": ">=0.14.21", - "minecraft": "=1.20.2", + "minecraft": ">=1.20 <=1.20.1", "java": ">=17", "fabric-api": "*" }, From ec261127756fbfb9394b97a669618bd2b5658577 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 24 Oct 2023 18:37:06 -0500 Subject: [PATCH 12/35] Revert "1.20.2 shifts everything down by .25" This reverts commit b0ae9940508219800f78be9a424f89fc39b99b8c. --- src/main/java/one/oth3r/sit/Events.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 70a8540..d136ebb 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -116,24 +116,23 @@ public class Events { public static void setEntity(BlockPos pos, World world, Entity entity) { Block block = world.getBlockState(pos).getBlock(); entity.setCustomName(Text.of(Sit.ENTITY_NAME)); - double hitBoxY = 0.5; entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.47, pos.getZ() + 0.5, 0, 0); entity.setInvulnerable(true); if (block instanceof StairsBlock) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0); - hitBoxY = 2; + entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5)); } if (block instanceof SlabBlock) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0); - hitBoxY = 1; + entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,1,1.5)); } if (block instanceof CarpetBlock) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()-.17, pos.getZ() + 0.5, 0, 0); - hitBoxY = 0.125; + entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,0.125,1.5)); } if (world.getBlockState(pos).isFullCube(world,pos.add(0,1,0))) { entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.78, pos.getZ() + 0.5, 0, 0); - hitBoxY = 2; + entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5)); } if (config.customOn && config.customBlocks.size() != 0) { for (HashMap map:getCustomBlocks().values()) { @@ -141,15 +140,12 @@ public class Events { if (map.get("block").equals(blockID)) { double input = Math.max(Math.min(Double.parseDouble((String) map.get("height")),1),0); entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+input-.22, pos.getZ() + 0.5, 0, 0); - hitBoxY = Double.parseDouble((String) map.get("hitbox")); + entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,Double.parseDouble((String) map.get("hitbox")),1.5)); } } } - //1.20.2 mounting pos change (shifts everything down by .25) - entity.updatePositionAndAngles(entity.getX(),entity.getY()+.25,entity.getZ(),0,0); - entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,hitBoxY,1.5)); //change pitch based on if player is sitting below block height or not - if (entity.getY() <= pos.getY()+.35+.25) entity.setPitch(90); + if (entity.getY() <= pos.getY()+.35) entity.setPitch(90); else entity.setPitch(-90); } public static void register() { From 213e041729038482243522a791ce47811bb4a14f Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 24 Oct 2023 18:39:03 -0500 Subject: [PATCH 13/35] v1.0.3+1.20-1.20.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d41b7b2..83bd8d8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10 loader_version=0.14.22 # Mod Properties -mod_version=1.0.3+1.20.2 +mod_version=1.0.3+1.20-1.20.1 maven_group=one.oth3r archives_base_name=sit! From 614fddb6bd6704661a1f8a87d074e93e2a53ac5b Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 21 Nov 2023 23:21:00 -0600 Subject: [PATCH 14/35] config 1.1, better version system & fixing config soft locking --- src/main/java/one/oth3r/sit/config.java | 164 ++++++++++-------- src/main/resources/assets/sit/lang/en_us.json | 1 + 2 files changed, 90 insertions(+), 75 deletions(-) diff --git a/src/main/java/one/oth3r/sit/config.java b/src/main/java/one/oth3r/sit/config.java index 409349b..4a49806 100644 --- a/src/main/java/one/oth3r/sit/config.java +++ b/src/main/java/one/oth3r/sit/config.java @@ -24,47 +24,31 @@ public class config { public static boolean fullBlocksOn = defaults.fullBlocksOn; public static boolean customOn = defaults.customOn; public static List customBlocks = defaults.customBlocks; - enum HandRequirements { + enum HandRequirement { empty, restrictive, - none + none; + public static HandRequirement get(String s) { + try { + return HandRequirement.valueOf(s); + + } catch (IllegalArgumentException e) { + return empty; + } + } } - public static HandRequirements mainReq = defaults.mainReq; + public static HandRequirement mainReq = defaults.mainReq; public static boolean mainBlock = defaults.mainBlock; public static boolean mainFood = defaults.mainFood; public static boolean mainUsable = defaults.mainUsable; public static List mainWhitelist = defaults.mainWhitelist; public static List mainBlacklist = defaults.mainBlacklist; - public static HandRequirements offReq = defaults.offReq; + public static HandRequirement offReq = defaults.offReq; public static boolean offBlock = defaults.offBlock; public static boolean offFood = defaults.offFood; public static boolean offUsable = defaults.offUsable; public static List offWhitelist = defaults.offWhitelist; public static List offBlacklist = defaults.offBlacklist; - public static void resetDefaults() { - lang = defaults.lang; - keepActive = defaults.keepActive; - sitWhileSeated = defaults.sitWhileSeated; - stairsOn = defaults.stairsOn; - slabsOn = defaults.slabsOn; - carpetsOn = defaults.carpetsOn; - fullBlocksOn = defaults.fullBlocksOn; - customOn = defaults.customOn; - customBlocks = defaults.customBlocks; - mainReq = defaults.mainReq; - mainBlock = defaults.mainBlock; - mainFood = defaults.mainFood; - mainUsable = defaults.mainUsable; - mainWhitelist = defaults.mainWhitelist; - mainBlacklist = defaults.mainBlacklist; - offReq = defaults.offReq; - offBlock = defaults.offBlock; - offFood = defaults.offFood; - offUsable = defaults.offUsable; - offWhitelist = defaults.offWhitelist; - offBlacklist = defaults.offBlacklist; - save(); - } public static File configFile() { return new File(FabricLoader.getInstance().getConfigDir().toFile()+"/Sit!.properties"); } @@ -77,43 +61,70 @@ public class config { try (FileInputStream fileStream = new FileInputStream(configFile())) { Properties properties = new Properties(); properties.load(fileStream); - loadVersion(properties,(String) properties.computeIfAbsent("version", a -> defaults.version)); + String ver = (String) properties.computeIfAbsent("version", a -> String.valueOf(defaults.version)); + // if the old version system (v1.0) remove "v: + if (ver.contains("v")) ver = ver.substring(1); + loadVersion(properties,Double.parseDouble(ver)); save(); } catch (Exception f) { //read fail f.printStackTrace(); - resetDefaults(); + save(); } } - public static void loadVersion(Properties properties, String version) { - Type mapType = new TypeToken>() {}.getType(); - lang = (String) properties.computeIfAbsent("lang", a -> defaults.lang); - //CONFIG - keepActive = Boolean.parseBoolean((String) properties.computeIfAbsent("keep-active", a -> String.valueOf(defaults.keepActive))); - sitWhileSeated = Boolean.parseBoolean((String) properties.computeIfAbsent("sit-while-seated", a -> String.valueOf(defaults.sitWhileSeated))); - stairsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("stairs", a -> String.valueOf(defaults.stairsOn))); - slabsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("slabs", a -> String.valueOf(defaults.slabsOn))); - carpetsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("carpets", a -> String.valueOf(defaults.carpetsOn))); - fullBlocksOn = Boolean.parseBoolean((String) properties.computeIfAbsent("full-blocks", a -> String.valueOf(defaults.fullBlocksOn))); - customOn = Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> String.valueOf(defaults.customOn))); - customBlocks = new Gson().fromJson((String) - properties.computeIfAbsent("custom-blocks", a -> String.valueOf(defaults.customBlocks)),mapType); - mainReq = HandRequirements.valueOf((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaults.mainReq))); - mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(defaults.mainBlock))); - mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> String.valueOf(defaults.mainFood))); - mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> String.valueOf(defaults.mainUsable))); - mainWhitelist = new Gson().fromJson((String) - properties.computeIfAbsent("main-hand-whitelist", a -> String.valueOf(defaults.mainWhitelist)),mapType); - mainBlacklist = new Gson().fromJson((String) - properties.computeIfAbsent("main-hand-blacklist", a -> String.valueOf(defaults.mainBlacklist)),mapType); - offReq = HandRequirements.valueOf((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaults.offReq))); - offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(defaults.offBlock))); - offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> String.valueOf(defaults.offFood))); - offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> String.valueOf(defaults.offUsable))); - offWhitelist = new Gson().fromJson((String) - properties.computeIfAbsent("off-hand-whitelist", a -> String.valueOf(defaults.offWhitelist)),mapType); - offBlacklist = new Gson().fromJson((String) - properties.computeIfAbsent("off-hand-blacklist", a -> String.valueOf(defaults.offBlacklist)),mapType); + public static void loadVersion(Properties properties, double version) { + try { + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + Type listType = new TypeToken>() {}.getType(); + lang = (String) properties.computeIfAbsent("lang", a -> defaults.lang); + //CONFIG + keepActive = Boolean.parseBoolean((String) properties.computeIfAbsent("keep-active", a -> String.valueOf(defaults.keepActive))); + sitWhileSeated = Boolean.parseBoolean((String) properties.computeIfAbsent("sit-while-seated", a -> String.valueOf(defaults.sitWhileSeated))); + stairsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("stairs", a -> String.valueOf(defaults.stairsOn))); + slabsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("slabs", a -> String.valueOf(defaults.slabsOn))); + carpetsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("carpets", a -> String.valueOf(defaults.carpetsOn))); + fullBlocksOn = Boolean.parseBoolean((String) properties.computeIfAbsent("full-blocks", a -> String.valueOf(defaults.fullBlocksOn))); + customOn = Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> String.valueOf(defaults.customOn))); + customBlocks = new Gson().fromJson((String) + properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType); + mainReq = HandRequirement.valueOf((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))); + mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.usable", a -> String.valueOf(defaults.mainUsable))); + mainWhitelist = new Gson().fromJson((String) + properties.computeIfAbsent("hand.main.whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType); + mainBlacklist = new Gson().fromJson((String) + properties.computeIfAbsent("hand.main.blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType); + offReq = HandRequirement.valueOf((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaults.offReq))); + offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.block", a -> String.valueOf(defaults.offBlock))); + offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.food", a -> String.valueOf(defaults.offFood))); + offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.usable", a -> String.valueOf(defaults.offUsable))); + offWhitelist = new Gson().fromJson((String) + properties.computeIfAbsent("hand.off.whitelist", a -> gson.toJson(defaults.offWhitelist)), listType); + offBlacklist = new Gson().fromJson((String) + properties.computeIfAbsent("hand.off.blacklist", a -> gson.toJson(defaults.offBlacklist)), listType); + if (version == 1.0) { + mainReq = HandRequirement.valueOf((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaults.mainReq))); + mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(defaults.mainBlock))); + mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> String.valueOf(defaults.mainFood))); + mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> String.valueOf(defaults.mainUsable))); + mainWhitelist = new Gson().fromJson((String) + properties.computeIfAbsent("main-hand-whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType); + mainBlacklist = new Gson().fromJson((String) + properties.computeIfAbsent("main-hand-blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType); + offReq = HandRequirement.valueOf((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaults.offReq))); + offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(defaults.offBlock))); + offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> String.valueOf(defaults.offFood))); + offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> String.valueOf(defaults.offUsable))); + offWhitelist = new Gson().fromJson((String) + properties.computeIfAbsent("off-hand-whitelist", a -> gson.toJson(defaults.offWhitelist)), listType); + offBlacklist = new Gson().fromJson((String) + properties.computeIfAbsent("off-hand-blacklist", a -> gson.toJson(defaults.offBlacklist)), listType); + } + } catch (Exception e) { + Sit.LOGGER.info("ERROR LOADING CONFIG - PLEASE REPORT WITH THE ERROR LOG"); + e.printStackTrace(); + } } public static MutableText lang(String key, Object... args) { LangReader.loadLanguageFile(); @@ -149,28 +160,31 @@ public class config { .append("\n# ").append(lang("general.sittable_blocks.description_7")) .append("\n# ").append(lang("general.sittable_blocks.description_8")).getString()).getBytes()); file.write(("\ncustom-blocks="+gson.toJson(customBlocks)).getBytes()); - file.write(("\n\n# "+lang("hand.requirements.description") + file.write(("\n\n# "+lang("hand")).getBytes()); + file.write(("\n# "+lang("hand.requirements.description") .append("\n# ").append(lang("hand.requirements.description_2")) .append("\n# ").append(lang("hand.requirements.description_3")) .append("\n# ").append(lang("hand.requirements.description_4")).getString()).getBytes()); - file.write(("\nmain-hand-requirement=" + mainReq).getBytes()); - file.write(("\nmain-hand-block=" + mainBlock).getBytes()); - file.write(("\nmain-hand-food=" + mainFood).getBytes()); - file.write(("\nmain-hand-usable=" + mainUsable).getBytes()); - file.write(("\nmain-hand-whitelist="+gson.toJson(mainWhitelist)).getBytes()); - file.write(("\nmain-hand-blacklist="+gson.toJson(mainBlacklist)).getBytes()); - file.write(("\noff-hand-requirement=" + offReq).getBytes()); - file.write(("\noff-hand-block=" + offBlock).getBytes()); - file.write(("\noff-hand-food=" + offFood).getBytes()); - file.write(("\noff-hand-usable=" + offUsable).getBytes()); - file.write(("\noff-hand-whitelist="+gson.toJson(offWhitelist)).getBytes()); - file.write(("\noff-hand-blacklist="+gson.toJson(offBlacklist)).getBytes()); + file.write(("\nhand.main.requirement=" + mainReq).getBytes()); + file.write(("\nhand.main.block=" + mainBlock).getBytes()); + file.write(("\nhand.main.food=" + mainFood).getBytes()); + file.write(("\nhand.main.usable=" + mainUsable).getBytes()); + file.write(("\nhand.main.whitelist="+gson.toJson(mainWhitelist)).getBytes()); + file.write(("\nhand.main.blacklist="+gson.toJson(mainBlacklist)).getBytes()); + file.write(("\nhand.off.requirement=" + offReq).getBytes()); + file.write(("\nhand.off.block=" + offBlock).getBytes()); + file.write(("\nhand.off.food=" + offFood).getBytes()); + file.write(("\nhand.off.usable=" + offUsable).getBytes()); + file.write(("\nhand.off.whitelist="+gson.toJson(offWhitelist)).getBytes()); + file.write(("\nhand.off.blacklist="+gson.toJson(offBlacklist)).getBytes()); + // send packets to update the settings on the server + if (SitClient.inGame) SitClient.sendPackets(); } catch (Exception e) { e.printStackTrace(); } } public static class defaults { - public static String version = "v1.0"; + public static double version = 1.1; public static String lang = "en_us"; public static boolean keepActive = true; public static boolean sitWhileSeated = true; @@ -180,13 +194,13 @@ 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"); - public static HandRequirements mainReq = HandRequirements.empty; + public static HandRequirement mainReq = HandRequirement.empty; public static boolean mainBlock = false; public static boolean mainFood = false; public static boolean mainUsable = false; public static List mainWhitelist = new ArrayList<>(); public static List mainBlacklist = new ArrayList<>(); - public static HandRequirements offReq = HandRequirements.restrictive; + public static HandRequirement offReq = HandRequirement.restrictive; public static boolean offBlock = true; public static boolean offFood = false; public static boolean offUsable = true; diff --git a/src/main/resources/assets/sit/lang/en_us.json b/src/main/resources/assets/sit/lang/en_us.json index cf40690..471d3be 100644 --- a/src/main/resources/assets/sit/lang/en_us.json +++ b/src/main/resources/assets/sit/lang/en_us.json @@ -33,6 +33,7 @@ "config.sit.general.sittable_blocks.description_6": "Third entry: hitbox size (where the player spawns above the entity when dismounting)", "config.sit.general.sittable_blocks.description_7": "Fourth entry (optional): required blockstate to sit (Put a \"!\" to exclude blockstates)", "config.sit.general.sittable_blocks.description_8": "Separate different entries with \"|\"!", + "config.sit.hand": "Hand Settings", "config.sit.hand.requirements": "Requirements", "config.sit.hand.requirements.description": "Hand requirements for sitting.", "config.sit.hand.requirements.description_2": "Empty = hand has to be empty", From 43c72ce1baa84462511dbb3ade53ac0d3f95c247 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Tue, 21 Nov 2023 23:21:47 -0600 Subject: [PATCH 15/35] per player hand restrictions * optimized code --- src/main/java/one/oth3r/sit/Events.java | 50 +++++++++++-------- src/main/java/one/oth3r/sit/ModMenu.java | 8 +-- .../java/one/oth3r/sit/PacketBuilder.java | 34 +++++++++++++ src/main/java/one/oth3r/sit/Sit.java | 19 +++++++ src/main/java/one/oth3r/sit/SitClient.java | 24 +++++++++ src/main/java/one/oth3r/sit/Utl.java | 45 +++++++++++++++++ src/main/resources/fabric.mod.json | 5 +- 7 files changed, 159 insertions(+), 26 deletions(-) create mode 100644 src/main/java/one/oth3r/sit/PacketBuilder.java create mode 100644 src/main/java/one/oth3r/sit/SitClient.java create mode 100644 src/main/java/one/oth3r/sit/Utl.java diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 70a8540..6060152 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -12,7 +12,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; @@ -23,6 +23,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import one.oth3r.sit.Utl.HandType; import java.util.*; @@ -36,31 +37,34 @@ public class Events { food.add(UseAction.DRINK); ArrayList notUsable = new ArrayList<>(food); notUsable.add(UseAction.NONE); - Item mainItem = player.getMainHandStack().getItem(); - Item offItem = player.getOffHandStack().getItem(); + HashMap itemMap = new HashMap<>(); + itemMap.put(HandType.main,player.getMainHandStack()); + itemMap.put(HandType.off,player.getOffHandStack()); + // if sneaking cant sit if (player.isSneaking()) return false; - if (config.mainReq.equals(config.HandRequirements.empty) && !player.getMainHandStack().isEmpty()) return false; - if (config.mainReq.equals(config.HandRequirements.restrictive)) { - if (checkList(config.mainBlacklist,mainItem)) return false; - if (!checkList(config.mainWhitelist,mainItem)) { - if (config.mainBlock && (mainItem instanceof BlockItem)) return false; - if (config.mainFood && food.contains(player.getMainHandStack().getUseAction())) return false; - if (config.mainUsable && !notUsable.contains(player.getMainHandStack().getUseAction())) return false; - } - } - if (config.offReq.equals(config.HandRequirements.empty) && !player.getOffHandStack().isEmpty()) return false; - if (config.offReq.equals(config.HandRequirements.restrictive)) { - if (checkList(config.offBlacklist,offItem)) return false; - if (!checkList(config.offWhitelist,offItem)) { - if (config.offBlock && (offItem instanceof BlockItem)) return false; - if (config.offFood && food.contains(player.getOffHandStack().getUseAction())) return false; - if (config.offUsable && !notUsable.contains(player.getOffHandStack().getUseAction())) return false; + // for both hands + for (HandType type:HandType.values()) { + ItemStack targetStack = itemMap.get(type); + // if req is empty and the item isn't empty, false + if (Utl.getReq(player,type).equals(config.HandRequirement.empty) && !targetStack.isEmpty()) return false; + // if req is restrictive + if (Utl.getReq(player,type).equals(config.HandRequirement.restrictive)) { + // if item is in blacklist, false + if (checkList(Utl.getList(player,type,"blacklist"),targetStack)) return false; + // if item is NOT in whitelist + if (!checkList(Utl.getList(player,type,"whitelist"),targetStack)) { + // if block is restricted and items is block, false, ect + if (Utl.getBool(player,type,"blocks") && (targetStack.getItem() instanceof BlockItem)) return false; + if (Utl.getBool(player,type,"food") && food.contains(targetStack.getUseAction())) return false; + if (Utl.getBool(player,type,"usable") && !notUsable.contains(targetStack.getUseAction())) return false; + } } } + // else true return true; } - public static boolean checkList(List list, Item item) { - String itemID = Registries.ITEM.getId(item).toString(); + public static boolean checkList(List list, ItemStack itemStack) { + String itemID = Registries.ITEM.getId(itemStack.getItem()).toString(); return list.contains(itemID); } public static HashMap> getCustomBlocks() { @@ -154,9 +158,12 @@ public class Events { } public static void register() { ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp)); + // PLAYER JOIN ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { ServerPlayerEntity player = handler.player; checkPlayers.put(player,2); + // put server settings in the player settings + Sit.playerSettings.put(player,Utl.getHandSettings()); }); ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> { ServerPlayerEntity player = handler.player; @@ -168,6 +175,7 @@ public class Events { entities.remove(player); } checkPlayers.remove(player); + Sit.playerSettings.remove(player); }); ServerLifecycleEvents.SERVER_STARTED.register(s -> { Sit.server = s; diff --git a/src/main/java/one/oth3r/sit/ModMenu.java b/src/main/java/one/oth3r/sit/ModMenu.java index 97b7fb9..401e672 100644 --- a/src/main/java/one/oth3r/sit/ModMenu.java +++ b/src/main/java/one/oth3r/sit/ModMenu.java @@ -90,14 +90,14 @@ public class ModMenu implements ModMenuApi { .category(ConfigCategory.createBuilder() .name(lang("category.main_hand")) .tooltip(lang("category.main_hand.tooltip")) - .option(Option.createBuilder() + .option(Option.createBuilder() .name(lang("hand.requirements")) .description(OptionDescription.of(lang("hand.requirements.description") .append("\n\n").append(lang("hand.requirements.description_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA)))) .append("\n").append(lang("hand.requirements.description_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN)))) .append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED)))))) .binding(config.defaults.mainReq, () -> config.mainReq, n -> config.mainReq = n) - .controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.HandRequirements.class) + .controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.HandRequirement.class) .formatValue(v -> Text.translatable("config.sit."+v.name().toLowerCase()))) .build()) .group(OptionGroup.createBuilder() @@ -142,14 +142,14 @@ public class ModMenu implements ModMenuApi { .category(ConfigCategory.createBuilder() .name(lang("category.off_hand")) .tooltip(lang("category.off_hand.tooltip")) - .option(Option.createBuilder() + .option(Option.createBuilder() .name(lang("hand.requirements")) .description(OptionDescription.of(lang("hand.requirements.description") .append("\n\n").append(lang("hand.requirements.description_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA)))) .append("\n").append(lang("hand.requirements.description_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN)))) .append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED)))))) .binding(config.defaults.offReq, () -> config.offReq, n -> config.offReq = n) - .controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.HandRequirements.class) + .controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.HandRequirement.class) .formatValue(v -> Text.translatable("config.sit."+v.name().toLowerCase()))) .build()) .group(OptionGroup.createBuilder() diff --git a/src/main/java/one/oth3r/sit/PacketBuilder.java b/src/main/java/one/oth3r/sit/PacketBuilder.java new file mode 100644 index 0000000..55bb0c1 --- /dev/null +++ b/src/main/java/one/oth3r/sit/PacketBuilder.java @@ -0,0 +1,34 @@ +package one.oth3r.sit; + +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.util.Identifier; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +public class PacketBuilder { + public static final String SETTINGS = "settings_v1.0"; + private final String message; + private PacketByteBuf packetByteBuf = PacketByteBufs.create(); + public PacketBuilder(PacketByteBuf buf) { + // Read any data sent in the packet + message = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(buf.array())).toString().trim(); + packetByteBuf = buf; + } + public PacketBuilder(String message) { + this.message = message; + packetByteBuf.writeBytes(ByteBuffer.wrap(message.getBytes(StandardCharsets.UTF_8)).array()); + } + public static Identifier getIdentifier() { + // only 1 packet rn + return new Identifier(Sit.MOD_ID, SETTINGS); + } + public void send() { + ClientPlayNetworking.send(getIdentifier(), packetByteBuf); + } + public String getMessage() { + return this.message; + } +} diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index ee4d704..e8c4d3e 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -1,16 +1,26 @@ package one.oth3r.sit; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.CommandManager; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.Type; +import java.util.HashMap; + public class Sit implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger("sit"); + public static final String MOD_ID = "oth3r-sit"; + public static HashMap> playerSettings = new HashMap<>(); public static final String ENTITY_NAME = "-sit!-entity-"; public static MinecraftServer server; public static CommandManager commandManager; @@ -23,6 +33,15 @@ public class Sit implements ModInitializer { // inner stair offset & custom support for that ig config.load(); Events.register(); + //PACKETS + ServerPlayNetworking.registerGlobalReceiver(PacketBuilder.getIdentifier(), + (server, player, handler, buf, responseSender) -> server.execute(() -> { + PacketBuilder packet = new PacketBuilder(buf); + Type hashMapToken = new TypeToken>() {}.getType(); + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken)); + System.out.println(playerSettings); + })); } public static MutableText lang(String key, Object... args) { if (isClient) return Text.translatable(key, args); diff --git a/src/main/java/one/oth3r/sit/SitClient.java b/src/main/java/one/oth3r/sit/SitClient.java new file mode 100644 index 0000000..a9cd769 --- /dev/null +++ b/src/main/java/one/oth3r/sit/SitClient.java @@ -0,0 +1,24 @@ +package one.oth3r.sit; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; + +public class SitClient implements ClientModInitializer { + public static boolean inGame = false; + @Override + public void onInitializeClient() { + ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { + inGame = true; + // send a data packet whenever joining a server + client.execute(SitClient::sendPackets); + }); + // reset inGame + ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> inGame = false); + } + public static void sendPackets() { + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + new PacketBuilder(gson.toJson(Utl.getHandSettings())).send(); + } +} diff --git a/src/main/java/one/oth3r/sit/Utl.java b/src/main/java/one/oth3r/sit/Utl.java new file mode 100644 index 0000000..3045ec1 --- /dev/null +++ b/src/main/java/one/oth3r/sit/Utl.java @@ -0,0 +1,45 @@ +package one.oth3r.sit; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import net.minecraft.server.network.ServerPlayerEntity; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class Utl { + enum HandType { + main, + off + } + public static HashMap getHandSettings() { + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + HashMap settings = new HashMap<>(); + settings.put("hand.main.requirement",String.valueOf(config.mainReq)); + settings.put("hand.main.block",String.valueOf(config.mainBlock)); + settings.put("hand.main.food",String.valueOf(config.mainFood)); + settings.put("hand.main.usable",String.valueOf(config.mainUsable)); + settings.put("hand.main.whitelist",gson.toJson(config.mainWhitelist)); + settings.put("hand.main.blacklist",gson.toJson(config.mainBlacklist)); + settings.put("hand.off.requirement",String.valueOf(config.offReq)); + settings.put("hand.off.block",String.valueOf(config.offBlock)); + settings.put("hand.off.food",String.valueOf(config.offFood)); + settings.put("hand.off.usable",String.valueOf(config.offUsable)); + settings.put("hand.off.whitelist",gson.toJson(config.offWhitelist)); + settings.put("hand.off.blacklist",gson.toJson(config.offBlacklist)); + return settings; + } + public static config.HandRequirement getReq(ServerPlayerEntity player, HandType type) { + return config.HandRequirement.get(Sit.playerSettings.get(player).get("hand."+type+".requirement")); + } + public static List getList(ServerPlayerEntity player, HandType type, String setting) { + Type listType = new TypeToken>() {}.getType(); + return new Gson().fromJson(Sit.playerSettings.get(player).get("hand."+type+"."+setting),listType); + } + public static boolean getBool(ServerPlayerEntity player, HandType type, String setting) { + return Boolean.parseBoolean(Sit.playerSettings.get(player).get("hand."+type+"."+setting)); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6e25fb8..2f29800 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "id": "sit", + "id": "oth3r-sit", "version": "${version}", "name": "Sit!", "description": "Adds sitting to minecraft! Endless customizability for hand restrictions and sittable blocks.", @@ -21,6 +21,9 @@ "server": [ "one.oth3r.sit.SitServer" ], + "client": [ + "one.oth3r.sit.SitClient" + ], "modmenu": [ "one.oth3r.sit.ModMenu" ] From 683956585f0a109f90176989adfccfe4e9d44528 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Wed, 22 Nov 2023 23:15:29 -0600 Subject: [PATCH 16/35] some changes --- gradle.properties | 2 +- src/main/java/one/oth3r/sit/Events.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 952abc0..c675dfa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.1 loader_version=0.14.22 # Mod Properties -mod_version=1.0.3+1.20.2 +mod_version=a1.1.0.0+1.20.2 maven_group=one.oth3r archives_base_name=sit! diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 6060152..71cc350 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -120,6 +120,7 @@ public class Events { public static void setEntity(BlockPos pos, World world, Entity entity) { Block block = world.getBlockState(pos).getBlock(); entity.setCustomName(Text.of(Sit.ENTITY_NAME)); + entity.setCustomNameVisible(false); double hitBoxY = 0.5; entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.47, pos.getZ() + 0.5, 0, 0); entity.setInvulnerable(true); @@ -192,6 +193,7 @@ public class Events { entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED); entities.remove(player); } + //interactions entity to make the hitbox? DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); setEntity(pos,world,entity); player.getServerWorld().spawnEntity(entity); From 05ed35e0ef5f4cb17ccc0f8480b92deb26c9fe01 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 10:35:51 -0600 Subject: [PATCH 17/35] console reload support --- src/main/java/one/oth3r/sit/SitCommand.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/one/oth3r/sit/SitCommand.java b/src/main/java/one/oth3r/sit/SitCommand.java index 8d59a80..88d8d2e 100644 --- a/src/main/java/one/oth3r/sit/SitCommand.java +++ b/src/main/java/one/oth3r/sit/SitCommand.java @@ -36,7 +36,6 @@ public class SitCommand { } private static int command(ServerCommandSource source, String arg) { ServerPlayerEntity player = source.getPlayer(); - if (player == null) return 1; //trim all the arguments before the command String keyword = "sit"; int index = Integer.MAX_VALUE; @@ -46,6 +45,14 @@ public class SitCommand { String[] args = arg.split(" "); if (args[0].equalsIgnoreCase("sit")) args = arg.replaceFirst("sit ", "").split(" "); + // if console + if (player == null) { + if (args[0].equalsIgnoreCase("reload")) { + config.load(); + Sit.LOGGER.info(Sit.lang("key.sit.command.reloaded").getString()); + } + return 1; + } if (args[0].equalsIgnoreCase("sit")) { BlockPos pos = player.getBlockPos(); if (!(player.getY() -((int) player.getY()) > 0.00)) { From 691eacb82ed7e2cea6a77faec8565d04f5eef43b Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 10:36:50 -0600 Subject: [PATCH 18/35] more comments --- src/main/java/one/oth3r/sit/SitCommand.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/one/oth3r/sit/SitCommand.java b/src/main/java/one/oth3r/sit/SitCommand.java index 88d8d2e..0fee18c 100644 --- a/src/main/java/one/oth3r/sit/SitCommand.java +++ b/src/main/java/one/oth3r/sit/SitCommand.java @@ -59,12 +59,12 @@ public class SitCommand { pos = pos.add(0,-1,0); } World world = player.getWorld(); - if (Events.checkBlocks(pos,world)) { - if (Events.entities.containsKey(player)) { - return 1; - } - DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); - Events.setEntity(pos,world,entity); + // if already sitting, ignore + if (Events.entities.containsKey(player)) return 1; + // make entity first to check the blocks + DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); + Events.setEntity(pos,world,entity); + if (Events.checkBlocks(pos,world,Events.isAboveBlockheight(entity))) { player.getServerWorld().spawnEntity(entity); player.startRiding(entity); Events.entities.put(player,entity); From eb65aacd4dbd4b07121f2756381ec2cc6921a0d6 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 10:37:07 -0600 Subject: [PATCH 19/35] fix block restriction not working --- src/main/java/one/oth3r/sit/Events.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 71cc350..0355445 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -54,7 +54,7 @@ public class Events { // if item is NOT in whitelist if (!checkList(Utl.getList(player,type,"whitelist"),targetStack)) { // if block is restricted and items is block, false, ect - if (Utl.getBool(player,type,"blocks") && (targetStack.getItem() instanceof BlockItem)) return false; + if (Utl.getBool(player,type,"block") && (targetStack.getItem() instanceof BlockItem)) return false; if (Utl.getBool(player,type,"food") && food.contains(targetStack.getUseAction())) return false; if (Utl.getBool(player,type,"usable") && !notUsable.contains(targetStack.getUseAction())) return false; } From 46f3c48e10ff136d86e2c80ea76750bcabc81c84 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 10:37:49 -0600 Subject: [PATCH 20/35] new isSitSafe() & isAboveBlockheight() --- src/main/java/one/oth3r/sit/Events.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 0355445..4d9da3a 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -82,7 +82,12 @@ public class Events { } return map; } - public static boolean checkBlocks(BlockPos pos, World world) { + public static boolean isSitSafe(Block block) { + // check if the block is sit safe (like a sign in the way) + return block instanceof WallSignBlock || block instanceof TrapdoorBlock || + block instanceof WallBannerBlock || block instanceof AirBlock; + } + public static boolean checkBlocks(BlockPos pos, World world, boolean isAbove) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); BlockState blockStateAbove = world.getBlockState(pos.add(0,1,0)); @@ -117,6 +122,9 @@ public class Events { } return false; } + public static boolean isAboveBlockheight(Entity entity) { + return entity.getPitch()<0; + } public static void setEntity(BlockPos pos, World world, Entity entity) { Block block = world.getBlockState(pos).getBlock(); entity.setCustomName(Text.of(Sit.ENTITY_NAME)); From c048dddbc29d457fdde8e13b40e0bbdb08ebd495 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 10:38:05 -0600 Subject: [PATCH 21/35] better checkBlocks() --- src/main/java/one/oth3r/sit/Events.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 4d9da3a..693b9a0 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -90,14 +90,13 @@ public class Events { public static boolean checkBlocks(BlockPos pos, World world, boolean isAbove) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); - BlockState blockStateAbove = world.getBlockState(pos.add(0,1,0)); - Block blockAbove = blockStateAbove.getBlock(); - // todo strict checker option to check 2 blocks above?? - // set amount of blocks that can be above a chair & air - if (!(blockAbove instanceof WallSignBlock || blockAbove instanceof TrapdoorBlock || - blockAbove instanceof WallBannerBlock || blockAbove instanceof AirBlock)) return false; - //if there's already an entity at the block location or above it + // make sure the block above the chair is safe + if (!isSitSafe(world.getBlockState(pos.add(0,1,0)).getBlock())) return false; + // if the player is above the block, (taller) check the next block above + if (isAbove && !isSitSafe(world.getBlockState(pos.add(0,2,0)).getBlock())) return false; + //if there's already an entity at the block location or one above it for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false; + // return for the 4 default types if (block instanceof StairsBlock && config.stairsOn) return blockState.get(StairsBlock.HALF) == BlockHalf.BOTTOM; if (block instanceof SlabBlock && config.slabsOn) return blockState.get(SlabBlock.TYPE) == SlabType.BOTTOM; From 618d1b9e6b73d0edddc3a4f4a919c0c63b668052 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 10:38:55 -0600 Subject: [PATCH 22/35] more comments and clarity, more to come --- src/main/java/one/oth3r/sit/Events.java | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/one/oth3r/sit/Events.java b/src/main/java/one/oth3r/sit/Events.java index 693b9a0..9fd9ef8 100644 --- a/src/main/java/one/oth3r/sit/Events.java +++ b/src/main/java/one/oth3r/sit/Events.java @@ -64,10 +64,12 @@ public class Events { return true; } public static boolean checkList(List list, ItemStack itemStack) { + // check if a list has an item String itemID = Registries.ITEM.getId(itemStack.getItem()).toString(); return list.contains(itemID); } public static HashMap> getCustomBlocks() { + // get a hashmap of custom blocks HashMap> map = new HashMap<>(); int i = 1; for (String s:config.customBlocks) { @@ -158,11 +160,12 @@ public class Events { } } //1.20.2 mounting pos change (shifts everything down by .25) - entity.updatePositionAndAngles(entity.getX(),entity.getY()+.25,entity.getZ(),0,0); + double oneTwentyTwo = .25; + entity.updatePositionAndAngles(entity.getX(),entity.getY()+oneTwentyTwo,entity.getZ(),0,0); entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,hitBoxY,1.5)); //change pitch based on if player is sitting below block height or not - if (entity.getY() <= pos.getY()+.35+.25) entity.setPitch(90); - else entity.setPitch(-90); + if (entity.getY() <= pos.getY()+.35+oneTwentyTwo) entity.setPitch(90); // below + else entity.setPitch(-90); // above } public static void register() { ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp)); @@ -194,19 +197,20 @@ public class Events { if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) { BlockPos pos = hitResult.getBlockPos(); if (!checkLogic(player)) return ActionResult.PASS; - if (checkBlocks(pos,world)) { + // todo interactions entity to make the hitbox? + // make the entity first before checking to make sure the blocks around are fine + DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); + setEntity(pos,world,entity); + if (checkBlocks(pos,world,isAboveBlockheight(entity))) { if (entities.containsKey(player)) { if (!config.sitWhileSeated) return ActionResult.PASS; entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED); entities.remove(player); } - //interactions entity to make the hitbox? - DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld()); - setEntity(pos,world,entity); player.getServerWorld().spawnEntity(entity); player.startRiding(entity); entities.put(player,entity); - return ActionResult.CONSUME; + return ActionResult.FAIL; } } return ActionResult.PASS; @@ -227,9 +231,12 @@ public class Events { entity.setRemoved(Entity.RemovalReason.DISCARDED); entityLoop.remove(); } else { - BlockPos pos = new BlockPos(entity.getBlockX(),(int) Math.floor(player.getY()),entity.getBlockZ()); - if (entity.getPitch() == 90) pos = new BlockPos(entity.getBlockX(),(int) Math.ceil(player.getY()),entity.getBlockZ()); + // if below the blockheight, round up the player pos + BlockPos pos = new BlockPos(entity.getBlockX(),(int)Math.ceil(player.getY()),entity.getBlockZ()); + // if above the block, round down the player pos + if (isAboveBlockheight(entity)) pos = new BlockPos(entity.getBlockX(),(int)Math.floor(player.getY()),entity.getBlockZ()); BlockState blockState = player.getWorld().getBlockState(pos); + // check if said block is still there if (blockState.isAir()) { player.teleport(player.getX(),player.getBlockY()+1,player.getZ()); entity.setRemoved(Entity.RemovalReason.DISCARDED); From 9829a2d0890d74c5b090753022f4e538240aa2f7 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 19:33:11 -0600 Subject: [PATCH 23/35] new readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cd73bd1..563f1a7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Sit! -[![github](https://img.shields.io/github/v/release/oth3r/Sit?color=blueviolet&logo=github)](https://github.com/Oth3r/Sit/releases) [![discord](https://dcbadge.vercel.app/api/server/Mec6yNQ9B7?style=flat)](https://discord.gg/Mec6yNQ9B7) [![modrinth](https://img.shields.io/modrinth/dt/sit!?label=Modrinth&logo=modrinth)](https://modrinth.com/mod/sit!) [![curseforge](https://cf.way2muchnoise.eu/892424.svg)](https://www.curseforge.com/minecraft/mc-mods/Sit1) [![Crowdin](https://badges.crowdin.net/oth3r-sit/localized.svg)](https://crowdin.com/project/oth3r-sit) +[![github](https://img.shields.io/github/issues/oth3r/Sit?logo=github?label=Issues)](https://github.com/Oth3r/Sit/releases) [![Crowdin](https://badges.crowdin.net/oth3r-sit/localized.svg)](https://crowdin.com/project/oth3r-sit) [![discord](https://dcbadge.vercel.app/api/server/Mec6yNQ9B7?style=flat)](https://discord.gg/Mec6yNQ9B7) + +[![modrinth](https://img.shields.io/modrinth/dt/sit!?label=Modrinth&logo=modrinth)](https://modrinth.com/mod/sit!) [![curseforge](https://cf.way2muchnoise.eu/892424.svg)](https://www.curseforge.com/minecraft/mc-mods/Sit1) **Sit!** is a minecraft mod that adds sitting in vanilla minecraft. Sit on **stairs**, **slabs**, **carpets** by default, and sit on everything else using the config! @@ -26,5 +28,5 @@ Configure to your hearts desire with the in-game config with **[ModMenu](https:/ ![custom blocks config](https://github.com/Oth3r/Sit/blob/master/media/custom-blocks-config.png?raw=true) ## Future Goals - * Forge Port - * Client & Server sync to have custom hand restrictions per player + * Forge Port (probably NeoForge 1.21) + * Custom dismounting logic From e924785faffcefad2655cb879e14f883d331e777 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sat, 25 Nov 2023 19:36:55 -0600 Subject: [PATCH 24/35] - Russian translations by adamadamich --- src/main/java/one/oth3r/sit/config.java | 2 +- src/main/resources/assets/sit/lang/ru_ru.json | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/assets/sit/lang/ru_ru.json diff --git a/src/main/java/one/oth3r/sit/config.java b/src/main/java/one/oth3r/sit/config.java index 4a49806..6149b85 100644 --- a/src/main/java/one/oth3r/sit/config.java +++ b/src/main/java/one/oth3r/sit/config.java @@ -135,7 +135,7 @@ public class config { Gson gson = new GsonBuilder().disableHtmlEscaping().create(); file.write("# Sit! Config\n".getBytes()); file.write(("version="+defaults.version).getBytes()); - file.write(("\n# all available languages: en_us").getBytes()); + file.write(("\n# all available languages: en_us, ru_ru").getBytes()); file.write(("\nlang=" + lang).getBytes()); file.write(("\n\n# "+lang("general.keep_active.description").getString()).getBytes()); file.write(("\nkeep-active=" + keepActive).getBytes()); diff --git a/src/main/resources/assets/sit/lang/ru_ru.json b/src/main/resources/assets/sit/lang/ru_ru.json new file mode 100644 index 0000000..d458dc1 --- /dev/null +++ b/src/main/resources/assets/sit/lang/ru_ru.json @@ -0,0 +1,55 @@ +{ + "config.sit.empty": "Пусто", + "config.sit.restrictive": "Ограничение", + "config.sit.none": "Нет", + "config.sit.category.general": "Общий", + "config.sit.category.general.tooltip": "Основные настройки", + "config.sit.category.main_hand": "Главная рука", + "config.sit.category.main_hand.tooltip": "Настройки главной руки", + "config.sit.category.off_hand": "Левая рука", + "config.sit.category.off_hand.tooltip": "Настройки левой руки", + "config.sit.general.keep_active": "Оставлять активным", + "config.sit.general.keep_active.description": "Оставлять сущности активными даже при выходе из системы / выключении", + "config.sit.general.sittable": "Блоки, для сидения", + "config.sit.general.sittable.description": "Вкл/выкл возможность сидеть на разных типах блоков.", + "config.sit.general.sit_while_seated": "Пересаживание на другой блок", + "config.sit.general.sit_while_seated.description": "Вкл/выкл возможность пересесть на другой блок, когда уже сидишь.", + "config.sit.general.sittable.stairs": "Ступени", + "config.sit.general.sittable.slabs": "Полублоки", + "config.sit.general.sittable.carpets": "Ковры", + "config.sit.general.sittable.full_blocks": "Полные блоки", + "config.sit.general.sittable.custom": "Другие блоки", + "config.sit.general.sittable.custom.description": "Позволяет добавить собственные блоки, на которые можно сесть.", + "config.sit.general.sittable_blocks": "Собственные блоки для сидения", + "config.sit.general.sittable_blocks.description": "Добавь свой блок для сидения!", + "config.sit.general.sittable_blocks.description_2": "Пример: ", + "config.sit.general.sittable_blocks.description_3": "\"%s|%s|%s|%s\"", + "config.sit.general.sittable_blocks.description_3_2": "minecraft:campfire", + "config.sit.general.sittable_blocks.description_3_3": ".255", + "config.sit.general.sittable_blocks.description_3_4": "1", + "config.sit.general.sittable_blocks.description_3_5": "lit=false", + "config.sit.general.sittable_blocks.description_4": "Первый вход: собственный блок", + "config.sit.general.sittable_blocks.description_5": "Второй вход: высота сидения (число от 0 до 1, например 0.52)", + "config.sit.general.sittable_blocks.description_6": "Третий вход: размер хитбокса (место, где игрок появляется над объектом при спешивании)", + "config.sit.general.sittable_blocks.description_7": "Четвертый вход (опционально): требуемое состояние блока для сидения (Вставьте \"!\" для исключения состояния блоков)", + "config.sit.general.sittable_blocks.description_8": "Разделяйте разные входы знаком \"|\"!", + "config.sit.hand.requirements": "Требования", + "config.sit.hand.requirements.description": "Что нужно, чтобы сесть.", + "config.sit.hand.requirements.description_2": "Пусто = рука должна быть пуста", + "config.sit.hand.requirements.description_3": "Ограниченный = установить ограничения для состояния руки", + "config.sit.hand.requirements.description_4": "Ничего = можно сеть когда угодно", + "config.sit.hand.restrictions": "Ограничения", + "config.sit.hand.restrictions.description": "Вкл/выкл пресет ограничений руки, для возможности сидеть.", + "config.sit.hand.restrictions.blocks": "Блоки", + "config.sit.hand.restrictions.food": "Еда", + "config.sit.hand.restrictions.usable": "Доступный", + "config.sit.hand.restrictions.usable.description": "например луки, трезубцы, щиты", + "config.sit.hand.whitelist": "Белый список", + "config.sit.hand.whitelist.description": "Создай свой белый список предметов, которые игрок может использовать, чтобы сесть.", + "config.sit.hand.blacklist": "Черный список", + "config.sit.hand.blacklist.description": "Создай свой черный список предметов, которые игрок не может использовать, чтобы сесть.", + "config.sit.hand.list.description": "Пример: ", + "config.sit.hand.list.description_2": "\"minecraft:torch\"", + "key.sit.command.reloaded": "Конфигурация перезагружена!", + "key.sit.command.purged": "Очищены все сущности-сидения!" +} \ No newline at end of file From 52117ea5c400c24c549c9c409145a7fef5cf7714 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 00:17:01 -0600 Subject: [PATCH 25/35] optimized and fixed LangReader for different languages --- src/main/java/one/oth3r/sit/LangReader.java | 30 +++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/one/oth3r/sit/LangReader.java b/src/main/java/one/oth3r/sit/LangReader.java index b6ae51b..0e3cdbd 100644 --- a/src/main/java/one/oth3r/sit/LangReader.java +++ b/src/main/java/one/oth3r/sit/LangReader.java @@ -1,11 +1,19 @@ package one.oth3r.sit; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TextContent; import java.io.InputStream; -import java.util.*; +import java.io.InputStreamReader; +import java.io.Reader; +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -75,21 +83,9 @@ public class LangReader { config.lang = config.defaults.lang; } if (inputStream == null) throw new IllegalArgumentException("CANT LOAD THE LANGUAGE FILE. DIRECTIONHUD WILL BREAK."); - Scanner scanner = new Scanner(inputStream); - String currentLine; - while (scanner.hasNextLine()) { - currentLine = scanner.nextLine().trim(); - if (currentLine.startsWith("{") || currentLine.startsWith("}")) { - continue; - } - String[] keyValue = currentLine.split(":", 2); - String key = keyValue[0].trim(); - key = key.substring(1,key.length()-1).replace("\\",""); - String value = keyValue[1].trim(); - if (value.endsWith(",")) value = value.substring(0, value.length() - 1); - value = value.substring(1,value.length()-1).replace("\\",""); - languageMap.put(key, value); - } + Type type = new TypeToken>(){}.getType(); + Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); + languageMap.putAll(new Gson().fromJson(reader, type)); } catch (Exception e) { e.printStackTrace(); } From 34bf49c62f65e05a32709638d782245de4e6e673 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 00:18:33 -0600 Subject: [PATCH 26/35] flip isClient boolean, and remove redundant SitServer --- src/main/java/one/oth3r/sit/Sit.java | 2 +- src/main/java/one/oth3r/sit/SitClient.java | 1 + src/main/java/one/oth3r/sit/SitServer.java | 12 ------------ src/main/resources/fabric.mod.json | 3 --- 4 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/one/oth3r/sit/SitServer.java diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index e8c4d3e..54d1ae9 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -24,7 +24,7 @@ public class Sit implements ModInitializer { public static final String ENTITY_NAME = "-sit!-entity-"; public static MinecraftServer server; public static CommandManager commandManager; - public static boolean isClient = true; + public static boolean isClient = false; @Override public void onInitialize() { diff --git a/src/main/java/one/oth3r/sit/SitClient.java b/src/main/java/one/oth3r/sit/SitClient.java index a9cd769..2a1d2e1 100644 --- a/src/main/java/one/oth3r/sit/SitClient.java +++ b/src/main/java/one/oth3r/sit/SitClient.java @@ -9,6 +9,7 @@ public class SitClient implements ClientModInitializer { public static boolean inGame = false; @Override public void onInitializeClient() { + Sit.isClient = true; ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { inGame = true; // send a data packet whenever joining a server diff --git a/src/main/java/one/oth3r/sit/SitServer.java b/src/main/java/one/oth3r/sit/SitServer.java deleted file mode 100644 index 199f5da..0000000 --- a/src/main/java/one/oth3r/sit/SitServer.java +++ /dev/null @@ -1,12 +0,0 @@ -package one.oth3r.sit; - -import net.fabricmc.api.DedicatedServerModInitializer; - -public class SitServer implements DedicatedServerModInitializer { - @Override - public void onInitializeServer() { - Sit.isClient = false; - config.load(); - LangReader.loadLanguageFile(); - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2f29800..963a042 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,9 +18,6 @@ "main": [ "one.oth3r.sit.Sit" ], - "server": [ - "one.oth3r.sit.SitServer" - ], "client": [ "one.oth3r.sit.SitClient" ], From 9bac78a08722055322ff137617b9867a13df0a65 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 00:39:58 -0600 Subject: [PATCH 27/35] fix file saving for utf-8 chars --- src/main/java/one/oth3r/sit/config.java | 78 +++++++++++++------------ 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/src/main/java/one/oth3r/sit/config.java b/src/main/java/one/oth3r/sit/config.java index 6149b85..2f67973 100644 --- a/src/main/java/one/oth3r/sit/config.java +++ b/src/main/java/one/oth3r/sit/config.java @@ -4,12 +4,12 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.text.MutableText; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -65,6 +65,7 @@ public class config { // if the old version system (v1.0) remove "v: if (ver.contains("v")) ver = ver.substring(1); loadVersion(properties,Double.parseDouble(ver)); + LangReader.loadLanguageFile(); save(); } catch (Exception f) { //read fail @@ -126,28 +127,28 @@ public class config { e.printStackTrace(); } } - public static MutableText lang(String key, Object... args) { - LangReader.loadLanguageFile(); - return LangReader.of("config.sit."+key, args).getTxT(); + public static String lang(String key, Object... args) { + return LangReader.of("config.sit."+key, args).getTxT().getString(); } public static void save() { - try (var file = new FileOutputStream(configFile(), false)) { + try (var file = Files.newBufferedWriter(configFile().toPath(), StandardCharsets.UTF_8)) { Gson gson = new GsonBuilder().disableHtmlEscaping().create(); - file.write("# Sit! Config\n".getBytes()); - file.write(("version="+defaults.version).getBytes()); - file.write(("\n# all available languages: en_us, ru_ru").getBytes()); - file.write(("\nlang=" + lang).getBytes()); - file.write(("\n\n# "+lang("general.keep_active.description").getString()).getBytes()); - file.write(("\nkeep-active=" + keepActive).getBytes()); - file.write(("\n# "+lang("general.sit_while_seated.description").getString()).getBytes()); - file.write(("\nsit-while-seated=" + sitWhileSeated).getBytes()); - file.write(("\n# "+lang("general.sittable.description").getString()).getBytes()); - file.write(("\nstairs=" + stairsOn).getBytes()); - file.write(("\nslabs=" + slabsOn).getBytes()); - file.write(("\ncarpets=" + carpetsOn).getBytes()); - file.write(("\nfull-blocks=" + fullBlocksOn).getBytes()); - file.write(("\ncustom=" + customOn).getBytes()); - file.write(("\n# "+lang("general.sittable_blocks.description") + file.write("# Sit! Config\n"); + file.write(("\nversion="+defaults.version)); + file.write(("\n# all available languages: en_us, ru_ru")); + file.write(("\nlang=" + lang)); + file.write(("\n\n# "+lang("general.keep_active.description"))); + file.write(("\nkeep-active=" + keepActive)); + file.write(("\n# "+lang("general.sit_while_seated.description"))); + file.write(("\nsit-while-seated=" + sitWhileSeated)); + file.write(("\n# "+lang("general.sittable.description"))); + file.write(("\nstairs=" + stairsOn)); + file.write(("\nslabs=" + slabsOn)); + file.write(("\ncarpets=" + carpetsOn)); + file.write(("\nfull-blocks=" + fullBlocksOn)); + file.write(("\ncustom=" + customOn)); + file.write(("\n# "+Sit.lang("config.sit."+ + "general.sittable_blocks.description") .append("\n# ").append(lang("general.sittable_blocks.description_2")) .append(lang("general.sittable_blocks.description_3", lang("general.sittable_blocks.description_3_2"), @@ -158,25 +159,26 @@ public class config { .append("\n# ").append(lang("general.sittable_blocks.description_5")) .append("\n# ").append(lang("general.sittable_blocks.description_6")) .append("\n# ").append(lang("general.sittable_blocks.description_7")) - .append("\n# ").append(lang("general.sittable_blocks.description_8")).getString()).getBytes()); - file.write(("\ncustom-blocks="+gson.toJson(customBlocks)).getBytes()); - file.write(("\n\n# "+lang("hand")).getBytes()); - file.write(("\n# "+lang("hand.requirements.description") + .append("\n# ").append(lang("general.sittable_blocks.description_8")))); + file.write(("\ncustom-blocks="+gson.toJson(customBlocks))); + file.write(("\n\n# "+lang("hand"))); + file.write(("\n# "+Sit.lang("config.sit."+ + "hand.requirements.description") .append("\n# ").append(lang("hand.requirements.description_2")) .append("\n# ").append(lang("hand.requirements.description_3")) - .append("\n# ").append(lang("hand.requirements.description_4")).getString()).getBytes()); - file.write(("\nhand.main.requirement=" + mainReq).getBytes()); - file.write(("\nhand.main.block=" + mainBlock).getBytes()); - file.write(("\nhand.main.food=" + mainFood).getBytes()); - file.write(("\nhand.main.usable=" + mainUsable).getBytes()); - file.write(("\nhand.main.whitelist="+gson.toJson(mainWhitelist)).getBytes()); - file.write(("\nhand.main.blacklist="+gson.toJson(mainBlacklist)).getBytes()); - file.write(("\nhand.off.requirement=" + offReq).getBytes()); - file.write(("\nhand.off.block=" + offBlock).getBytes()); - file.write(("\nhand.off.food=" + offFood).getBytes()); - file.write(("\nhand.off.usable=" + offUsable).getBytes()); - file.write(("\nhand.off.whitelist="+gson.toJson(offWhitelist)).getBytes()); - file.write(("\nhand.off.blacklist="+gson.toJson(offBlacklist)).getBytes()); + .append("\n# ").append(lang("hand.requirements.description_4")))); + file.write(("\nhand.main.requirement=" + mainReq)); + file.write(("\nhand.main.block=" + mainBlock)); + file.write(("\nhand.main.food=" + mainFood)); + file.write(("\nhand.main.usable=" + mainUsable)); + file.write(("\nhand.main.whitelist="+gson.toJson(mainWhitelist))); + file.write(("\nhand.main.blacklist="+gson.toJson(mainBlacklist))); + file.write(("\nhand.off.requirement=" + offReq)); + file.write(("\nhand.off.block=" + offBlock)); + file.write(("\nhand.off.food=" + offFood)); + file.write(("\nhand.off.usable=" + offUsable)); + file.write(("\nhand.off.whitelist="+gson.toJson(offWhitelist))); + file.write(("\nhand.off.blacklist="+gson.toJson(offBlacklist))); // send packets to update the settings on the server if (SitClient.inGame) SitClient.sendPackets(); } catch (Exception e) { From cf20a39c4ca21c8246151f336e0c4e52b5f47c4d Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 00:40:26 -0600 Subject: [PATCH 28/35] removing testing print --- src/main/java/one/oth3r/sit/Sit.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index 54d1ae9..d89f49d 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -40,7 +40,6 @@ public class Sit implements ModInitializer { Type hashMapToken = new TypeToken>() {}.getType(); Gson gson = new GsonBuilder().disableHtmlEscaping().create(); playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken)); - System.out.println(playerSettings); })); } public static MutableText lang(String key, Object... args) { From 3be4f289c7df59512117ea2fad6e62726c31e071 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 00:42:59 -0600 Subject: [PATCH 29/35] update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 563f1a7..ce74066 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ **Sit!** is a minecraft mod that adds sitting in vanilla minecraft. Sit on **stairs**, **slabs**, **carpets** by default, and sit on everything else using the config! -You can also customize hand restrictions to stop accidentally sitting down! +You can also customize hand restrictions to stop accidentally sitting down! +The mod also has full Geyser support! Enjoy sitting with everyone, weather they are on Bedrock or Java! ## Help localize Sit! on [Crowdin](https://crowdin.com/project/oth3r-sit)! ![overview](https://github.com/Oth3r/Sit/blob/master/media/overview.gif?raw=true) ## Check out my other Projects! From aadec761fbd11ab085a9b23c00e51ebb4826fff3 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 00:43:05 -0600 Subject: [PATCH 30/35] v1.1.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c675dfa..65f084f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.1 loader_version=0.14.22 # Mod Properties -mod_version=a1.1.0.0+1.20.2 +mod_version=1.1.0+1.20.2 maven_group=one.oth3r archives_base_name=sit! From ede8f290dcd72dce591869b27ec8378e4546aa28 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 10:16:36 -0600 Subject: [PATCH 31/35] 1.20-1.20.1 fix --- .../java/one/oth3r/sit/PacketBuilder.java | 2 +- src/main/java/one/oth3r/sit/Sit.java | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/one/oth3r/sit/PacketBuilder.java b/src/main/java/one/oth3r/sit/PacketBuilder.java index 55bb0c1..538609d 100644 --- a/src/main/java/one/oth3r/sit/PacketBuilder.java +++ b/src/main/java/one/oth3r/sit/PacketBuilder.java @@ -14,7 +14,7 @@ public class PacketBuilder { private PacketByteBuf packetByteBuf = PacketByteBufs.create(); public PacketBuilder(PacketByteBuf buf) { // Read any data sent in the packet - message = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(buf.array())).toString().trim(); + message = buf.toString(StandardCharsets.UTF_8); packetByteBuf = buf; } public PacketBuilder(String message) { diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index d89f49d..09bb4e3 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -3,6 +3,8 @@ package one.oth3r.sit; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import io.netty.buffer.ByteBuf; +import io.netty.util.ReferenceCountUtil; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -15,6 +17,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.HashMap; public class Sit implements ModInitializer { @@ -35,12 +39,15 @@ public class Sit implements ModInitializer { Events.register(); //PACKETS ServerPlayNetworking.registerGlobalReceiver(PacketBuilder.getIdentifier(), - (server, player, handler, buf, responseSender) -> server.execute(() -> { - PacketBuilder packet = new PacketBuilder(buf); - Type hashMapToken = new TypeToken>() {}.getType(); - Gson gson = new GsonBuilder().disableHtmlEscaping().create(); - playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken)); - })); + (server, player, handler, buf, responseSender) -> { + buf.retain(); + server.execute(() -> { + PacketBuilder packet = new PacketBuilder(buf); + Type hashMapToken = new TypeToken>() {}.getType(); + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken)); + }); + }); } public static MutableText lang(String key, Object... args) { if (isClient) return Text.translatable(key, args); From bf736d17a2d134d7a4e84811b692f292edde5c26 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 10:17:04 -0600 Subject: [PATCH 32/35] update 1.20.1 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 154df87..d90c86e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.parallel=true # check these on https://fabricmc.net/develop minecraft_version=1.20.1 yarn_mappings=1.20.1+build.10 -loader_version=0.14.22 +loader_version=0.14.24 # Mod Properties mod_version=1.1.0+1.20-1.20.1 @@ -14,6 +14,6 @@ maven_group=one.oth3r archives_base_name=sit! # Dependencies -fabric_version=0.90.4+1.20.1 +fabric_version=0.91.0+1.20.1 modmenu_version=7.0.0 yacl_version=3.2.1+1.20 From a1d651f2dd100eb44afda39391b0604862362b8d Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 10:19:34 -0600 Subject: [PATCH 33/35] make sure the buf is released --- src/main/java/one/oth3r/sit/Sit.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index 09bb4e3..420a028 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -47,6 +47,7 @@ public class Sit implements ModInitializer { Gson gson = new GsonBuilder().disableHtmlEscaping().create(); playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken)); }); + buf.release(); }); } public static MutableText lang(String key, Object... args) { From 41474091dca0747c798ff7112533e2287cc121c0 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Sun, 26 Nov 2023 10:35:49 -0600 Subject: [PATCH 34/35] the REAL 1.20-1.20.1 fix this time --- src/main/java/one/oth3r/sit/PacketBuilder.java | 7 ++++--- src/main/java/one/oth3r/sit/Sit.java | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/one/oth3r/sit/PacketBuilder.java b/src/main/java/one/oth3r/sit/PacketBuilder.java index 538609d..ac4bb96 100644 --- a/src/main/java/one/oth3r/sit/PacketBuilder.java +++ b/src/main/java/one/oth3r/sit/PacketBuilder.java @@ -1,5 +1,6 @@ package one.oth3r.sit; +import io.netty.buffer.ByteBuf; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.minecraft.network.PacketByteBuf; @@ -12,10 +13,10 @@ public class PacketBuilder { public static final String SETTINGS = "settings_v1.0"; private final String message; private PacketByteBuf packetByteBuf = PacketByteBufs.create(); - public PacketBuilder(PacketByteBuf buf) { + public PacketBuilder(ByteBuf buf) { // Read any data sent in the packet - message = buf.toString(StandardCharsets.UTF_8); - packetByteBuf = buf; + packetByteBuf.writeBytes(buf); + message = packetByteBuf.toString(StandardCharsets.UTF_8); } public PacketBuilder(String message) { this.message = message; diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index 420a028..cf985eb 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -8,6 +8,7 @@ import io.netty.util.ReferenceCountUtil; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.PacketByteBuf; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.CommandManager; import net.minecraft.server.network.ServerPlayerEntity; @@ -40,14 +41,13 @@ public class Sit implements ModInitializer { //PACKETS ServerPlayNetworking.registerGlobalReceiver(PacketBuilder.getIdentifier(), (server, player, handler, buf, responseSender) -> { - buf.retain(); + ByteBuf byteBuf = buf.copy(); server.execute(() -> { - PacketBuilder packet = new PacketBuilder(buf); + PacketBuilder packet = new PacketBuilder(byteBuf); Type hashMapToken = new TypeToken>() {}.getType(); Gson gson = new GsonBuilder().disableHtmlEscaping().create(); playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken)); }); - buf.release(); }); } public static MutableText lang(String key, Object... args) { From 70e43c515f5e44cec1fb46decde59f6668f1859b Mon Sep 17 00:00:00 2001 From: Oth3r Date: Thu, 30 Nov 2023 17:58:16 -0600 Subject: [PATCH 35/35] fix? --- src/main/java/one/oth3r/sit/PacketBuilder.java | 7 +++---- src/main/java/one/oth3r/sit/Sit.java | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/one/oth3r/sit/PacketBuilder.java b/src/main/java/one/oth3r/sit/PacketBuilder.java index ac4bb96..538609d 100644 --- a/src/main/java/one/oth3r/sit/PacketBuilder.java +++ b/src/main/java/one/oth3r/sit/PacketBuilder.java @@ -1,6 +1,5 @@ package one.oth3r.sit; -import io.netty.buffer.ByteBuf; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.minecraft.network.PacketByteBuf; @@ -13,10 +12,10 @@ public class PacketBuilder { public static final String SETTINGS = "settings_v1.0"; private final String message; private PacketByteBuf packetByteBuf = PacketByteBufs.create(); - public PacketBuilder(ByteBuf buf) { + public PacketBuilder(PacketByteBuf buf) { // Read any data sent in the packet - packetByteBuf.writeBytes(buf); - message = packetByteBuf.toString(StandardCharsets.UTF_8); + message = buf.toString(StandardCharsets.UTF_8); + packetByteBuf = buf; } public PacketBuilder(String message) { this.message = message; diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index cf985eb..d621a73 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -41,9 +41,8 @@ public class Sit implements ModInitializer { //PACKETS ServerPlayNetworking.registerGlobalReceiver(PacketBuilder.getIdentifier(), (server, player, handler, buf, responseSender) -> { - ByteBuf byteBuf = buf.copy(); + PacketBuilder packet = new PacketBuilder(buf); server.execute(() -> { - PacketBuilder packet = new PacketBuilder(byteBuf); Type hashMapToken = new TypeToken>() {}.getType(); Gson gson = new GsonBuilder().disableHtmlEscaping().create(); playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken));