diff --git a/README.md b/README.md index 22fec77..fb8170b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ With the new config system, block tags and custom blockstates can be used to mas ![players sitting on a vast range of blocks](https://github.com/Oth3r/oth3r.github.io/blob/main/mod_data/Sit!/media/desc/custom_blocks.gif?raw=true) ### ⌨️ Keybinds -Don't want to sit with the **just** the hand? Use a keybind or type a command to sit instead! +Don't want to sit with **just** the hand? Use a keybind or type a command to sit instead! ![setting keybinds for the sit mod, and sitting by using them](https://github.com/Oth3r/oth3r.github.io/blob/main/mod_data/Sit!/media/desc/keybinds.gif?raw=true) diff --git a/build.gradle b/build.gradle index ba352c7..f77bf8c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version "1.10-SNAPSHOT" + id 'fabric-loom' version "1.11-SNAPSHOT" id 'maven-publish' id "me.modmuss50.mod-publish-plugin" version "0.8.4" id 'co.uzzu.dotenv.gradle' version '4.0.0' diff --git a/changelog.md b/changelog.md index 1601ba7..7a97995 100644 --- a/changelog.md +++ b/changelog.md @@ -1,26 +1,6 @@ -# v1.2.4.5 -* bumped OtterLib version to `0.2.1.0` - * fixed default languages files not being able to be loaded +# v1.2.5.0 +New allowed-above-seat config option! -# v1.2.4.4 -* bumped OtterLib version to `0.2.0.0` - * now relies on OtterLib Language Reader - -# v1.2.4.3 -* added a max OtterLib version as the beta will have breaking changes between major versions - -# v1.2.4.2 -* fixed language file not loading (reverted uppercase locales) -* fixed block checking having a hardcoded player reach - now uses player reach (1.20.6+) -* fixed block and item tag check logic for cases with only not(!) tags - -# v1.2.4.1 -* removed unused assets -* enabled file logging for easier debugging - -# v1.2.4.0 -Small changelog but big update! -\ -Switching to OtterLib will allow for a simplified main mod and lead to more unified mod development across my projects! Download OtterLib today: [Link](https://modrinth.com/mod/otterlib) -* make sitting via hand execute the `/sit` command, to allow for universal sitting permission control -* switch to using OtterLib for file management, config screen management, and more to come \ No newline at end of file +* added new config option `allowed-above-seat` to allow certain blocks to be above the seat block +* switched to OtterLib for language file loading +* switched to OtterLib for config file loading \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index fda1a3e..2a62c1c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,23 +4,23 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -min_minecraft_version=1.21.7 -max_minecraft_version=1.21.7 -minecraft_versions=1.21.7 +min_minecraft_version=1.21.6 +max_minecraft_version=1.21.8 +minecraft_versions=1.21.6,1.21.7,1.21.8 -minecraft_version=1.21.7 -yarn_mappings=1.21.7+build.1 +minecraft_version=1.21.8 +yarn_mappings=1.21.8+build.1 loader_version=0.16.14 # Mod Properties -mod_version=1.2.4.5+1.21.7 +mod_version=1.2.5.0+1.21.8 maven_group=one.oth3r file_name=sit! # Dependencies -fabric_version=0.128.1+1.21.7 -otterlib_version=0.2.1.0+1.21.7-fabric -otterlib_max_version=0.3.0.0+1.21.7-fabric +fabric_version=0.129.0+1.21.8 +otterlib_version=0.2.2.0+1.21.8-fabric +otterlib_max_version=0.3.0.0+1.21.8-fabric modmenu_version=15.0.0-beta.1 devauth_version=1.2.1 diff --git a/src/main/java/one/oth3r/sit/Sit.java b/src/main/java/one/oth3r/sit/Sit.java index b062269..831c7ad 100644 --- a/src/main/java/one/oth3r/sit/Sit.java +++ b/src/main/java/one/oth3r/sit/Sit.java @@ -2,13 +2,31 @@ package one.oth3r.sit; import net.fabricmc.api.ModInitializer; +import one.oth3r.otterlib.file.LanguageReader; +import one.oth3r.otterlib.file.ResourceReader; +import one.oth3r.otterlib.registry.CustomFileReg; +import one.oth3r.otterlib.registry.LanguageReg; import one.oth3r.sit.file.FileData; +import one.oth3r.sit.file.ServerConfig; +import one.oth3r.sit.file.SittingConfig; +import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Events; public class Sit implements ModInitializer { @Override public void onInitialize() { + LanguageReg.registerLang(Data.MOD_ID, new LanguageReader( + new ResourceReader("assets/sit-oth3r/lang/",Sit.class.getClassLoader()), + new ResourceReader(Data.CONFIG_DIR),"en_us","en_us")); + + /// autoload is off, we will handle loading and saving manually + CustomFileReg.registerFile(Data.MOD_ID,new CustomFileReg.FileEntry( + ServerConfig.ID,new ServerConfig(),false,false)); + CustomFileReg.registerFile(Data.MOD_ID,new CustomFileReg.FileEntry( + SittingConfig.ID,new SittingConfig(),false,false)); + + FileData.loadFiles(); // save the files to populate all missing config options FileData.saveFiles(); diff --git a/src/main/java/one/oth3r/sit/file/FileData.java b/src/main/java/one/oth3r/sit/file/FileData.java index 0eb0baa..fd77520 100644 --- a/src/main/java/one/oth3r/sit/file/FileData.java +++ b/src/main/java/one/oth3r/sit/file/FileData.java @@ -1,41 +1,23 @@ package one.oth3r.sit.file; import net.minecraft.server.network.ServerPlayerEntity; -import one.oth3r.otterlib.file.LanguageReader; -import one.oth3r.otterlib.file.ResourceReader; -import one.oth3r.sit.Sit; +import one.oth3r.otterlib.registry.CustomFileReg; import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Utl; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; public class FileData { - /** - * Sit! config file - */ - private static ServerConfig serverConfig = new ServerConfig(); - + /// getters for Sit! config files public static ServerConfig getServerConfig() { - return serverConfig; + return (ServerConfig) CustomFileReg.getFile(Data.MOD_ID,ServerConfig.ID); } - public static void setServerConfig(ServerConfig newServerConfig) { - serverConfig = new ServerConfig(newServerConfig); - } - - /** - * The default sitting config for all new players - */ - private static SittingConfig sittingConfig = new SittingConfig(); - public static SittingConfig getSittingConfig() { - return sittingConfig; - } - - public static void setSittingConfig(SittingConfig newSittingConfig) { - sittingConfig = new SittingConfig(newSittingConfig); + return (SittingConfig) CustomFileReg.getFile(Data.MOD_ID,SittingConfig.ID); } /** @@ -56,16 +38,7 @@ public class FileData { } public static SittingConfig getPlayerSetting(ServerPlayerEntity player) { - return playerSettings.getOrDefault(player, sittingConfig); - } - - /// the language / text system for the mod - private static final LanguageReader langReader = new LanguageReader( - new ResourceReader("assets/sit-oth3r/lang/",Sit.class.getClassLoader()), - new ResourceReader(Data.CONFIG_DIR),"en_us","en_us"); - - public static LanguageReader getLangReader() { - return langReader; + return playerSettings.getOrDefault(player, getSittingConfig()); } /** @@ -73,9 +46,6 @@ public class FileData { */ public static void loadFiles() { getServerConfig().load(); - // load the language reader - langReader.updateLanguage(getServerConfig().getLang()); - getSittingConfig().load(); // if loading file and is on supported server on client, send the new settings over if (Data.isClient() && Data.isSupportedServer()) { @@ -95,22 +65,34 @@ public class FileData { 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), new SittingBlock(new ArrayList<>(Arrays.asList("!minecraft:crimson_stem","!minecraft:warped_stem","minecraft:polished_basalt")), new ArrayList<>(Arrays.asList("#minecraft:logs","!#minecraft:oak_logs")), new ArrayList<>(Arrays.asList("!axis=y")),1.0), - new SittingBlock(new ArrayList<>(Arrays.asList()), new ArrayList<>(Arrays.asList("#minecraft:beds")), new ArrayList<>(Arrays.asList("part=foot","occupied=false")),.5625) + new SittingBlock(new ArrayList<>(), new ArrayList<>(Arrays.asList("#minecraft:beds")), new ArrayList<>(Arrays.asList("part=foot","occupied=false")),.5625) )); - public static final ArrayList BLACKLISTED_BLOCKS = new ArrayList<>(Arrays.asList( - new CustomBlock(new ArrayList<>(),new ArrayList<>(Arrays.asList("#minecraft:shulker_boxes")),new ArrayList<>()) + public static final ArrayList BLACKLISTED_BLOCKS = new ArrayList<>(List.of( + new CustomBlock(new ArrayList<>(), new ArrayList<>(List.of("#minecraft:shulker_boxes")), new ArrayList<>()) )); - public static final ArrayList INTERACTION_BLOCKS = new ArrayList<>(Arrays.asList( + public static final ArrayList INTERACTION_BLOCKS = new ArrayList<>(List.of( new CustomBlock(new ArrayList<>(Arrays.asList( - "minecraft:crafter","minecraft:repeating_command_block","minecraft:chain_command_block","minecraft:command_block")), + "minecraft:crafter", "minecraft:repeating_command_block", "minecraft:chain_command_block", "minecraft:command_block")), new ArrayList<>(Arrays.asList( - "#minecraft:shulker_boxes","#c:player_workstations/furnaces","#c:player_workstations/crafting_tables", - "#c:villager_job_sites","#minecraft:trapdoors","#c:chests")), + "#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 ArrayList ALLOWED_ABOVE_SEAT = new ArrayList<>(List.of( + new CustomBlock( + new ArrayList<>(), + new ArrayList<>(List.of("#minecraft:trapdoors")), + new ArrayList<>(List.of("open=true"))), + new CustomBlock( + new ArrayList<>(), + new ArrayList<>(List.of("#minecraft:doors")), + 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 8a36ad3..990c244 100644 --- a/src/main/java/one/oth3r/sit/file/ServerConfig.java +++ b/src/main/java/one/oth3r/sit/file/ServerConfig.java @@ -8,6 +8,7 @@ import net.minecraft.util.Hand; import one.oth3r.otterlib.base.Num; import one.oth3r.otterlib.file.CustomFile; import one.oth3r.otterlib.file.FileSettings; +import one.oth3r.otterlib.registry.LanguageReg; import one.oth3r.sit.utl.Data; import org.jetbrains.annotations.NotNull; @@ -24,6 +25,7 @@ import java.util.Properties; import java.util.stream.Collectors; public class ServerConfig implements CustomFile { + public static final String ID = "server-config"; @SerializedName("version") private Double version = 2.3; @@ -52,6 +54,8 @@ public class ServerConfig implements CustomFile { private ArrayList blacklistedBlocks = FileData.Defaults.BLACKLISTED_BLOCKS; @SerializedName("interaction-blocks") private ArrayList interactionBlocks = FileData.Defaults.INTERACTION_BLOCKS; + @SerializedName("allowed-above-seat") + private ArrayList allowedAboveSeat = FileData.Defaults.ALLOWED_ABOVE_SEAT; public ServerConfig() {} @@ -62,7 +66,7 @@ public class ServerConfig implements CustomFile { public ServerConfig(Double version, String lang, boolean keepActive, boolean sitWhileSeated, PresetBlocks presetBlocks, boolean customEnabled, ArrayList sittingBlocks, ArrayList blacklistedBlocks, - ArrayList interactionBlocks) { + ArrayList interactionBlocks, ArrayList allowedAboveSeat) { this.version = version; this.lang = lang; this.keepActive = keepActive; @@ -72,6 +76,7 @@ public class ServerConfig implements CustomFile { this.sittingBlocks = sittingBlocks; this.blacklistedBlocks = blacklistedBlocks; this.interactionBlocks = interactionBlocks; + this.allowedAboveSeat = allowedAboveSeat; } public Double getVersion() { @@ -114,6 +119,10 @@ public class ServerConfig implements CustomFile { return interactionBlocks; } + public ArrayList getAllowedAboveSeat() { + return allowedAboveSeat; + } + public static class PresetBlocks { @SerializedName("stairs") @@ -261,6 +270,7 @@ public class ServerConfig implements CustomFile { this.sittingBlocks = newFile.sittingBlocks.stream().map(SittingBlock::new).collect(Collectors.toCollection(ArrayList::new)); this.blacklistedBlocks = newFile.blacklistedBlocks.stream().map(CustomBlock::new).collect(Collectors.toCollection(ArrayList::new)); this.interactionBlocks = newFile.interactionBlocks.stream().map(CustomBlock::new).collect(Collectors.toCollection(ArrayList::new)); + this.allowedAboveSeat = newFile.allowedAboveSeat.stream().map(CustomBlock::new).collect(Collectors.toCollection(ArrayList::new)); } @Override @@ -275,6 +285,9 @@ public class ServerConfig implements CustomFile { version = 2.3; this.lang = this.lang.substring(0,3)+this.lang.substring(3).toLowerCase(); } + + // update the language reader + LanguageReg.getLang(Data.MOD_ID).updateLanguage(lang); } @Override @@ -298,14 +311,17 @@ public class ServerConfig implements CustomFile { public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; ServerConfig that = (ServerConfig) o; - return Objects.equals(version, that.version) && Objects.equals(lang, that.lang) && Objects.equals(keepActive, that.keepActive) && Objects.equals(sitWhileSeated, that.sitWhileSeated) && Objects.equals(presetBlocks, that.presetBlocks) && Objects.equals(yDifferenceLimit, that.yDifferenceLimit) && Objects.equals(customEnabled, that.customEnabled) && Objects.equals(sittingBlocks, that.sittingBlocks) && Objects.equals(blacklistedBlocks, that.blacklistedBlocks) && Objects.equals(interactionBlocks, that.interactionBlocks); + return Objects.equals(version, that.version) && Objects.equals(lang, that.lang) && Objects.equals(keepActive, that.keepActive) && Objects.equals(sitWhileSeated, that.sitWhileSeated) && Objects.equals(presetBlocks, that.presetBlocks) && Objects.equals(yDifferenceLimit, that.yDifferenceLimit) && Objects.equals(customEnabled, that.customEnabled) && Objects.equals(sittingBlocks, that.sittingBlocks) && Objects.equals(blacklistedBlocks, that.blacklistedBlocks) && Objects.equals(interactionBlocks, that.interactionBlocks) && Objects.equals(allowedAboveSeat, that.allowedAboveSeat); } @Override public int hashCode() { - return Objects.hash(version, lang, langOptions, keepActive, sitWhileSeated, presetBlocks, yDifferenceLimit, customEnabled, sittingBlocks, blacklistedBlocks, interactionBlocks); + return Objects.hash(version, lang, langOptions, keepActive, sitWhileSeated, presetBlocks, yDifferenceLimit, customEnabled, sittingBlocks, blacklistedBlocks, interactionBlocks, allowedAboveSeat); } + /** + * legacy updater + */ protected static class Legacy { /** * gets the legacy file, from the old directory for fabric, and the same one for spigot @@ -345,6 +361,8 @@ public class ServerConfig implements CustomFile { } catch (Exception e) { Data.LOGGER.error("Failed to delete the old Sit! config."); } + + // continue loading as normal... } /** @@ -414,7 +432,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<>(), FileData.Defaults.INTERACTION_BLOCKS + new ArrayList<>(), FileData.Defaults.INTERACTION_BLOCKS, FileData.Defaults.ALLOWED_ABOVE_SEAT ); SittingConfig defaultSittingConfig = new SittingConfig(); @@ -492,10 +510,12 @@ public class ServerConfig implements CustomFile { } catch (JsonSyntaxException ignored) {} } - FileData.setServerConfig(serverConfig); - FileData.setSittingConfig(sittingConfig); - serverConfig.save(); - sittingConfig.save(); + // update and save the new files + FileData.getServerConfig().copyFileData(serverConfig); + FileData.getServerConfig().save(); + + FileData.getSittingConfig().copyFileData(sittingConfig); + FileData.getSittingConfig().save(); } catch (Exception e) { Data.LOGGER.error("Error loading legacy config: %s", e.getMessage()); } diff --git a/src/main/java/one/oth3r/sit/file/SittingConfig.java b/src/main/java/one/oth3r/sit/file/SittingConfig.java index 2e7337b..c60a41c 100644 --- a/src/main/java/one/oth3r/sit/file/SittingConfig.java +++ b/src/main/java/one/oth3r/sit/file/SittingConfig.java @@ -1,7 +1,6 @@ package one.oth3r.sit.file; import com.google.common.base.Objects; -import com.google.gson.JsonElement; import com.google.gson.annotations.SerializedName; import net.minecraft.util.Hand; import one.oth3r.otterlib.file.CustomFile; @@ -13,6 +12,7 @@ import java.nio.file.Path; import java.nio.file.Paths; public class SittingConfig implements CustomFile { + public static final String ID = "sitting-config"; @SerializedName("version") private Double version = 1.0; diff --git a/src/main/java/one/oth3r/sit/utl/Chat.java b/src/main/java/one/oth3r/sit/utl/Chat.java index 6dc2867..57f8536 100644 --- a/src/main/java/one/oth3r/sit/utl/Chat.java +++ b/src/main/java/one/oth3r/sit/utl/Chat.java @@ -1,7 +1,7 @@ package one.oth3r.sit.utl; import one.oth3r.otterlib.chat.CTxT; -import one.oth3r.sit.file.FileData; +import one.oth3r.otterlib.registry.LanguageReg; import java.awt.*; @@ -11,6 +11,6 @@ public class Chat { } public static CTxT lang(String key, Object... args) { - return FileData.getLangReader().dynamicTranslatable(key, args); + return LanguageReg.getLang(Data.MOD_ID).dynamicTranslatable(key, args); } } diff --git a/src/main/java/one/oth3r/sit/utl/Logic.java b/src/main/java/one/oth3r/sit/utl/Logic.java index e5d8387..ae8bcf7 100644 --- a/src/main/java/one/oth3r/sit/utl/Logic.java +++ b/src/main/java/one/oth3r/sit/utl/Logic.java @@ -204,7 +204,7 @@ public class Logic { } /** - * toggles the sit ablity config option + * toggles the sit ability config option * @return returns a message, that can be sent to the player */ public static MutableText toggleSiting() { @@ -213,9 +213,6 @@ public class Logic { SittingConfig config = FileData.getSittingConfig(); // toggle the setting config.setEnabled(!config.getEnabled()); - - // set the sitting config to the new value - FileData.setSittingConfig(config); // save the changes to the file config.save(); // send the changes to the server diff --git a/src/main/java/one/oth3r/sit/utl/Utl.java b/src/main/java/one/oth3r/sit/utl/Utl.java index 8e766ce..ecfdffb 100644 --- a/src/main/java/one/oth3r/sit/utl/Utl.java +++ b/src/main/java/one/oth3r/sit/utl/Utl.java @@ -49,6 +49,8 @@ public class Utl { public static boolean isNotObstructed(World world, BlockPos blockPos) { // get the block state at the blockPos BlockState state = world.getBlockState(blockPos); + // if block is allowed to be above seat, return true + if (blockIsInList(FileData.getServerConfig().getAllowedAboveSeat(), state)) return true; // make sure it doesn't have a collision return state.getCollisionShape(world,blockPos).isEmpty(); }