From 7b1766a1e7bdf3df344ef795143bd5fce0d01b5f Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 2 Dec 2024 12:51:43 -0600 Subject: [PATCH 1/7] method to save all files --- src/main/java/one/oth3r/sit/file/FileData.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/one/oth3r/sit/file/FileData.java b/src/main/java/one/oth3r/sit/file/FileData.java index 556e478..53b887d 100644 --- a/src/main/java/one/oth3r/sit/file/FileData.java +++ b/src/main/java/one/oth3r/sit/file/FileData.java @@ -69,6 +69,14 @@ public class FileData { } } + /** + * saves all config files + */ + public static void saveFiles() { + getSittingConfig().save(); + getServerConfig().save(); + } + public static class Defaults { public static final ArrayList SITTING_BLOCKS = new ArrayList<>(Arrays.asList( new SittingBlock(new ArrayList<>(),new ArrayList<>(Arrays.asList("#minecraft:campfires")), new ArrayList<>(Arrays.asList("lit=false")),.437), From 5b812720cefd58c17798998f57415cc589efcd12 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 2 Dec 2024 12:52:02 -0600 Subject: [PATCH 2/7] save files on mod load and reload --- src/main/java/one/oth3r/sit/Sit.java | 2 ++ src/main/java/one/oth3r/sit/utl/Logic.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index 8138f2a..b062269 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -10,6 +10,8 @@ public class Sit implements ModInitializer { @Override public void onInitialize() { FileData.loadFiles(); + // save the files to populate all missing config options + FileData.saveFiles(); Events.registerCommon(); } } \ No newline at end of file diff --git a/src/main/java/one/oth3r/sit/utl/Logic.java b/src/main/java/one/oth3r/sit/utl/Logic.java index 6063a58..62556b4 100644 --- a/src/main/java/one/oth3r/sit/utl/Logic.java +++ b/src/main/java/one/oth3r/sit/utl/Logic.java @@ -147,6 +147,7 @@ public class Logic { */ public static void reload() { FileData.loadFiles(); + FileData.saveFiles(); } /** From 40eb03c967b2bf8e473d5b43dc700560c1397211 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 2 Dec 2024 12:52:53 -0600 Subject: [PATCH 3/7] server config interaction block list + version bump --- .../java/one/oth3r/sit/file/FileData.java | 6 +++++ .../java/one/oth3r/sit/file/ServerConfig.java | 27 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/one/oth3r/sit/file/FileData.java b/src/main/java/one/oth3r/sit/file/FileData.java index 53b887d..1e7de3d 100644 --- a/src/main/java/one/oth3r/sit/file/FileData.java +++ b/src/main/java/one/oth3r/sit/file/FileData.java @@ -88,6 +88,12 @@ public class FileData { new CustomBlock(new ArrayList<>(),new ArrayList<>(Arrays.asList("#minecraft:shulker_boxes")),new ArrayList<>()) )); + public static final ArrayList INTERACTION_BLOCKS = new ArrayList<>(Arrays.asList( + new CustomBlock(new ArrayList<>(Arrays.asList("minecraft:crafter")),new ArrayList<>(Arrays.asList( + "#minecraft:shulker_boxes","#c:player_workstations/furnaces","#c:player_workstations/crafting_tables", + "#c:villager_job_sites","#minecraft:trapdoors","#c:chests")),new ArrayList<>()) + )); + public static final HandSetting MAIN_HAND = new HandSetting(HandSetting.SittingRequirement.EMPTY, new HandSetting.Filter( false,new HandSetting.Filter.Presets(), new CustomItem( diff --git a/src/main/java/one/oth3r/sit/file/ServerConfig.java b/src/main/java/one/oth3r/sit/file/ServerConfig.java index e61d0ee..05c604e 100644 --- a/src/main/java/one/oth3r/sit/file/ServerConfig.java +++ b/src/main/java/one/oth3r/sit/file/ServerConfig.java @@ -20,7 +20,7 @@ import java.util.Properties; public class ServerConfig implements CustomFile { @SerializedName("version") - private Double version = 2.0; + private Double version = 2.1; @SerializedName("lang") private String lang = "en_us"; @SerializedName("lang-options") @@ -37,6 +37,8 @@ public class ServerConfig implements CustomFile { private ArrayList sittingBlocks = FileData.Defaults.SITTING_BLOCKS; @SerializedName("blacklisted-blocks") private ArrayList blacklistedBlocks = FileData.Defaults.BLACKLISTED_BLOCKS; + @SerializedName("interaction-blocks") + private ArrayList interactionBlocks = FileData.Defaults.INTERACTION_BLOCKS; public ServerConfig() {} @@ -49,11 +51,13 @@ public class ServerConfig implements CustomFile { this.customEnabled = serverConfig.customEnabled; this.sittingBlocks = serverConfig.sittingBlocks; this.blacklistedBlocks = serverConfig.blacklistedBlocks; + this.interactionBlocks = serverConfig.interactionBlocks; } public ServerConfig(Double version, String lang, boolean keepActive, boolean sitWhileSeated, PresetBlocks presetBlocks, boolean customEnabled, - ArrayList sittingBlocks, ArrayList blacklistedBlocks) { + ArrayList sittingBlocks, ArrayList blacklistedBlocks, + ArrayList interactionBlocks) { this.version = version; this.lang = lang; this.keepActive = keepActive; @@ -62,6 +66,7 @@ public class ServerConfig implements CustomFile { this.customEnabled = customEnabled; this.sittingBlocks = sittingBlocks; this.blacklistedBlocks = blacklistedBlocks; + this.interactionBlocks = interactionBlocks; } public Double getVersion() { @@ -96,6 +101,10 @@ public class ServerConfig implements CustomFile { return blacklistedBlocks; } + public ArrayList getInteractionBlocks() { + return interactionBlocks; + } + public static class PresetBlocks { @SerializedName("stairs") @@ -135,7 +144,7 @@ public class ServerConfig implements CustomFile { @Override public void reset() { - updateToNewFile(new ServerConfig()); + loadFileData(new ServerConfig()); } @Override @@ -144,7 +153,7 @@ public class ServerConfig implements CustomFile { } @Override - public void updateToNewFile(ServerConfig newFile) { + public void loadFileData(ServerConfig newFile) { this.version = newFile.version; this.lang = newFile.lang; this.keepActive = newFile.keepActive; @@ -155,6 +164,14 @@ public class ServerConfig implements CustomFile { this.blacklistedBlocks = newFile.blacklistedBlocks; } + @Override + public void update() { + /// update to 2.1, just a new list, nothing to change + if (version == 2.0) { + version = 2.1; + } + } + @Override public String getFileName() { return "server-config.json"; @@ -283,7 +300,7 @@ public class ServerConfig implements CustomFile { Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> String.valueOf(defaultConfig.isCustomEnabled()))), getCustomBlocks(new Gson().fromJson((String) properties.computeIfAbsent("custom-blocks", a -> "[]"), listType)), - new ArrayList<>() + new ArrayList<>(), FileData.Defaults.INTERACTION_BLOCKS ); SittingConfig defaultSittingConfig = new SittingConfig(); From 6a471729d1b65af781b9837ecf92ea4c4c5e9d35 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 2 Dec 2024 12:54:42 -0600 Subject: [PATCH 4/7] remove method change checking --- src/main/java/one/oth3r/sit/utl/Utl.java | 58 ++---------------------- 1 file changed, 4 insertions(+), 54 deletions(-) diff --git a/src/main/java/one/oth3r/sit/utl/Utl.java b/src/main/java/one/oth3r/sit/utl/Utl.java index 7be286e..97dafec 100644 --- a/src/main/java/one/oth3r/sit/utl/Utl.java +++ b/src/main/java/one/oth3r/sit/utl/Utl.java @@ -199,63 +199,13 @@ public class Utl { } /** - * checks if a block has an interaction - * @param blockState the blockstate of the block to check - * @return if the block has an interaction or not + * checks if a blockstate is in the list provided + * @return */ - public static boolean hasInteraction(BlockState blockState) { - return isMethodOverridden(AbstractBlock.class, blockState.getBlock().getClass(), "onUse", BlockState.class, World.class, BlockPos.class, PlayerEntity.class, BlockHitResult.class); + public static boolean blockIsInList(ArrayList blockList, BlockState blockState) { + return blockList.stream().anyMatch(c -> c.isValid(blockState)); } - /** - * checks if an item has a use - * @param itemStack the itemstack to check - * @return if the item has a use or not - */ - public static boolean hasItemUse(ItemStack itemStack) { - return isMethodOverridden(Item.class, itemStack.getItem().getClass(), "use", World.class, PlayerEntity.class, Hand.class); - } - - /** - * checks if a method in the base class has been overridden in the subclass(es) by: - * checking the subclass and its supers till the original method is found or the original method is found - * @param baseClass the base class - * @param subclass the subclass to check - * @param methodName the method to check for - * @param parameterTypes the parameterTypes for the method, see {@link java.lang.Class#getDeclaredMethod(java.lang.String, java.lang.Class[])} - * @return if the method is overridden or not - */ - public static boolean isMethodOverridden(Class baseClass, Class subclass, String methodName, Class... parameterTypes) { - try { - // get the original method - Method superMethod = baseClass.getMethod(methodName, parameterTypes); - - // the current class to check, starting with the subclass - Class currentClass = subclass; - // while the class is null and the current class isn't the same as the baseclass. - while (currentClass != null && !currentClass.equals(baseClass)) { - try { - // get the submethod - Method subMethod = currentClass.getDeclaredMethod(methodName, parameterTypes); - - // check if the methods are different - if (!superMethod.equals(subMethod)) { - return true; - } - } catch (NoSuchMethodException ignored) { - // method isnt in this class, bump up a class and check that one - } - currentClass = currentClass.getSuperclass(); - } - } catch (NoSuchMethodException e) { - // method doesn't exist in the base class - return false; - } - // an override wasn't found - return false; - } - - public static class Entity { /** From 82d999c4c52ff71fe31a65ea9577a2341db10aa9 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 2 Dec 2024 12:55:07 -0600 Subject: [PATCH 5/7] fix hand usable check and add block interaction list checking --- src/main/java/one/oth3r/sit/utl/Utl.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/one/oth3r/sit/utl/Utl.java b/src/main/java/one/oth3r/sit/utl/Utl.java index 97dafec..25e82de 100644 --- a/src/main/java/one/oth3r/sit/utl/Utl.java +++ b/src/main/java/one/oth3r/sit/utl/Utl.java @@ -13,7 +13,6 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.consume.UseAction; import net.minecraft.registry.Registries; @@ -35,7 +34,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; @@ -139,7 +137,7 @@ public class Utl { // try the default conditions if (presets.isBlock() && itemStack.getItem() instanceof BlockItem) return TRUE; if (presets.isFood() && food.contains(itemStack.getUseAction())) return TRUE; - if (presets.isUsable() && hasItemUse(itemStack)) return TRUE; + if (presets.isUsable() && !notUsable.contains(itemStack.getUseAction())) return TRUE; // if nothing else is met, the item is filtered out return FALSE; @@ -166,14 +164,14 @@ public class Utl { Block block = blockState.getBlock(); // make sure that the block that is being sit on has no interaction when hand sitting - if (hit != null && hasInteraction(blockState)) { + if (hit != null && blockIsInList(config.getInteractionBlocks(), blockState)) { return null; } // only if custom is enabled if (config.isCustomEnabled()) { // if the block is on the blacklist, false - if (config.getBlacklistedBlocks().stream().anyMatch(c -> c.isValid(blockState))) return null; + if (blockIsInList(config.getBlacklistedBlocks(),blockState)) return null; for (SittingBlock sittingBlock : config.getSittingBlocks()) { // if the block is valid, true From 33271c4aea94b1c16f7215a518a0c3f907911bef Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 2 Dec 2024 12:55:55 -0600 Subject: [PATCH 6/7] add update file method to template and comment --- .../java/one/oth3r/sit/file/CustomBlock.java | 1 + .../java/one/oth3r/sit/file/CustomFile.java | 15 +++++++++++++-- .../java/one/oth3r/sit/file/SittingConfig.java | 17 ++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/one/oth3r/sit/file/CustomBlock.java b/src/main/java/one/oth3r/sit/file/CustomBlock.java index 0c4f5e7..6f8f0f7 100644 --- a/src/main/java/one/oth3r/sit/file/CustomBlock.java +++ b/src/main/java/one/oth3r/sit/file/CustomBlock.java @@ -51,6 +51,7 @@ public class CustomBlock { boolean blockType = checkBlockType(blockState); if (!blockType) return false; + /// BLOCK STATE CHECKER // now check if the state is one of the acceptable states for (String state : blockStates) { // if there is a NOT (!) blockstate diff --git a/src/main/java/one/oth3r/sit/file/CustomFile.java b/src/main/java/one/oth3r/sit/file/CustomFile.java index fb2d279..eab2d74 100644 --- a/src/main/java/one/oth3r/sit/file/CustomFile.java +++ b/src/main/java/one/oth3r/sit/file/CustomFile.java @@ -56,13 +56,24 @@ public interface CustomFile > { if (file == null) throw new NullPointerException(); // update the instance - updateToNewFile(file); + file.update(); + // load the file to the current object + loadFileData(file); } @NotNull Class getFileClass(); - void updateToNewFile(T newFile); + /** + * loads the data from the file object into the current object + * @param newFile the file to take the properties from + */ + void loadFileData(T newFile); + + /** + * updates the file based on the version number of the current instance + */ + void update(); /** * logic for the file not existing when loading, defaults to saving diff --git a/src/main/java/one/oth3r/sit/file/SittingConfig.java b/src/main/java/one/oth3r/sit/file/SittingConfig.java index c3409fe..d9e65e8 100644 --- a/src/main/java/one/oth3r/sit/file/SittingConfig.java +++ b/src/main/java/one/oth3r/sit/file/SittingConfig.java @@ -3,16 +3,8 @@ package one.oth3r.sit.file; import com.google.gson.annotations.SerializedName; import net.minecraft.util.Hand; import one.oth3r.sit.utl.Data; -import one.oth3r.sit.utl.Utl; import org.jetbrains.annotations.NotNull; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; - public class SittingConfig implements CustomFile { @SerializedName("version") @@ -37,7 +29,7 @@ public class SittingConfig implements CustomFile { } public SittingConfig(SittingConfig sittingConfig) { - updateToNewFile(sittingConfig); + loadFileData(sittingConfig); } public Double getVersion() { @@ -74,7 +66,7 @@ public class SittingConfig implements CustomFile { @Override public void reset() { - updateToNewFile(new SittingConfig()); + loadFileData(new SittingConfig()); } @Override @@ -83,7 +75,7 @@ public class SittingConfig implements CustomFile { } @Override - public void updateToNewFile(SittingConfig newFile) { + public void loadFileData(SittingConfig newFile) { this.version = newFile.version; this.enabled = newFile.enabled; this.handSitting = newFile.handSitting; @@ -91,6 +83,9 @@ public class SittingConfig implements CustomFile { this.offHand = newFile.offHand; } + @Override + public void update() {} + @Override public String getFileName() { return "sitting-config.json"; From 58469de16a89f1fca2ce1ad249f0af5fdbd29a38 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 2 Dec 2024 13:04:14 -0600 Subject: [PATCH 7/7] v1.2.1+1.21.3 --- changelog.md | 41 +++++++++-------------------------------- gradle.properties | 2 +- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/changelog.md b/changelog.md index 2793627..aef44e2 100644 --- a/changelog.md +++ b/changelog.md @@ -1,32 +1,9 @@ -# v1.2.0 - The Rewrite! -Hey yall, 1.2.0 is here! -Not too much to show in the changelog, as most of the changes were under the hood. -There is still some work that can be done, but I am happy where the mod is at currently. - -As always, leave suggestions / bugs in the discord or github, and help localize the mod on [Crowdin](https://crowdin.com/project/oth3r-sit)! - -Thank you for playing, and have a good day! - Oth3r 🦦 - -### Config -brand new config system for a better editing experience -* switch to json for all mod configuration -* split the config into 2, `server-config` & `sitting-config` -* block & item tag selection support -* select multiple block ids / tags per sitting height -* `sit-while-seated` config entry defaulted to false -* added a sitting block blacklist -* removed the YACL ModMenu config, as it is incompatible with the new system -* added a new custom config UI (full config control still WIP) - -### Dismounting -*fixed dismounting sit entities!* -* added a new custom dismounting system -* dismounts the player in the direction that they are looking in, instead of on top of the block every time - -### QOL -*im sure ive missed some things* -* interaction blocks now cannot be sat with the hand -* mod id is now `sit-oth3r` from `oth3r-sit` -* added keybinds -* sit toggle command -* `/sit` priorities target block over the block below the player +# v1.2.1 +Quick bugfix update. :) +### block interaction checker +now it actually works (based on config sadly) +* added `interaction-blocks` to the server config, any block added to this list will block sitting with the hand +### other changes +* added refreshes to the config files on startup and reload to write missing parts to disk +* bumped the `server-config.json` version +* fixed `usable` hand filter not working \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 90f6f01..e960c2d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ yarn_mappings=1.21.3+build.2 loader_version=0.16.7 # Mod Properties -mod_version=1.2.0+1.21.3 +mod_version=1.2.1+1.21.3 maven_group=one.oth3r file_name=sit!