Compare commits

..

No commits in common. "458333d347c2e7486ce6917c21f72103776ba194" and "9d6881d9f5102a38af05d14bd1255b2dbb30e781" have entirely different histories.

11 changed files with 94 additions and 93 deletions

View file

@ -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 **just** the hand? Use a keybind or type a command to sit instead!
Don't want to sit with the **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)

View file

@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version "1.11-SNAPSHOT"
id 'fabric-loom' version "1.10-SNAPSHOT"
id 'maven-publish'
id "me.modmuss50.mod-publish-plugin" version "0.8.4"
id 'co.uzzu.dotenv.gradle' version '4.0.0'

View file

@ -1,6 +1,26 @@
# v1.2.5.0
New allowed-above-seat config option!
# v1.2.4.5
* bumped OtterLib version to `0.2.1.0`
* fixed default languages files not being able to be loaded
* 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
# 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

View file

@ -4,23 +4,23 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
min_minecraft_version=1.21.6
max_minecraft_version=1.21.8
minecraft_versions=1.21.6,1.21.7,1.21.8
min_minecraft_version=1.21.7
max_minecraft_version=1.21.7
minecraft_versions=1.21.7
minecraft_version=1.21.8
yarn_mappings=1.21.8+build.1
minecraft_version=1.21.7
yarn_mappings=1.21.7+build.1
loader_version=0.16.14
# Mod Properties
mod_version=1.2.5.0+1.21.8
mod_version=1.2.4.5+1.21.7
maven_group=one.oth3r
file_name=sit!
# Dependencies
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
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
modmenu_version=15.0.0-beta.1
devauth_version=1.2.1

View file

@ -2,31 +2,13 @@ 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();

View file

@ -1,23 +1,41 @@
package one.oth3r.sit.file;
import net.minecraft.server.network.ServerPlayerEntity;
import one.oth3r.otterlib.registry.CustomFileReg;
import one.oth3r.otterlib.file.LanguageReader;
import one.oth3r.otterlib.file.ResourceReader;
import one.oth3r.sit.Sit;
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 {
/// getters for Sit! config files
/**
* Sit! config file
*/
private static ServerConfig serverConfig = new ServerConfig();
public static ServerConfig getServerConfig() {
return (ServerConfig) CustomFileReg.getFile(Data.MOD_ID,ServerConfig.ID);
return serverConfig;
}
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) CustomFileReg.getFile(Data.MOD_ID,SittingConfig.ID);
return sittingConfig;
}
public static void setSittingConfig(SittingConfig newSittingConfig) {
sittingConfig = new SittingConfig(newSittingConfig);
}
/**
@ -38,7 +56,16 @@ public class FileData {
}
public static SittingConfig getPlayerSetting(ServerPlayerEntity player) {
return playerSettings.getOrDefault(player, getSittingConfig());
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;
}
/**
@ -46,6 +73,9 @@ 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()) {
@ -65,14 +95,14 @@ public class FileData {
public static final ArrayList<SittingBlock> 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<>(), new ArrayList<>(Arrays.asList("#minecraft:beds")), new ArrayList<>(Arrays.asList("part=foot","occupied=false")),.5625)
new SittingBlock(new ArrayList<>(Arrays.asList()), new ArrayList<>(Arrays.asList("#minecraft:beds")), new ArrayList<>(Arrays.asList("part=foot","occupied=false")),.5625)
));
public static final ArrayList<CustomBlock> BLACKLISTED_BLOCKS = new ArrayList<>(List.of(
new CustomBlock(new ArrayList<>(), new ArrayList<>(List.of("#minecraft:shulker_boxes")), new ArrayList<>())
public static final ArrayList<CustomBlock> BLACKLISTED_BLOCKS = new ArrayList<>(Arrays.asList(
new CustomBlock(new ArrayList<>(),new ArrayList<>(Arrays.asList("#minecraft:shulker_boxes")),new ArrayList<>())
));
public static final ArrayList<CustomBlock> INTERACTION_BLOCKS = new ArrayList<>(List.of(
public static final ArrayList<CustomBlock> INTERACTION_BLOCKS = new ArrayList<>(Arrays.asList(
new CustomBlock(new ArrayList<>(Arrays.asList(
"minecraft:crafter","minecraft:repeating_command_block","minecraft:chain_command_block","minecraft:command_block")),
new ArrayList<>(Arrays.asList(
@ -81,18 +111,6 @@ public class FileData {
new ArrayList<>())
));
public static final ArrayList<CustomBlock> 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(

View file

@ -8,7 +8,6 @@ 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;
@ -25,7 +24,6 @@ import java.util.Properties;
import java.util.stream.Collectors;
public class ServerConfig implements CustomFile<ServerConfig> {
public static final String ID = "server-config";
@SerializedName("version")
private Double version = 2.3;
@ -54,8 +52,6 @@ public class ServerConfig implements CustomFile<ServerConfig> {
private ArrayList<CustomBlock> blacklistedBlocks = FileData.Defaults.BLACKLISTED_BLOCKS;
@SerializedName("interaction-blocks")
private ArrayList<CustomBlock> interactionBlocks = FileData.Defaults.INTERACTION_BLOCKS;
@SerializedName("allowed-above-seat")
private ArrayList<CustomBlock> allowedAboveSeat = FileData.Defaults.ALLOWED_ABOVE_SEAT;
public ServerConfig() {}
@ -66,7 +62,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
public ServerConfig(Double version, String lang, boolean keepActive, boolean sitWhileSeated,
PresetBlocks presetBlocks, boolean customEnabled,
ArrayList<SittingBlock> sittingBlocks, ArrayList<CustomBlock> blacklistedBlocks,
ArrayList<CustomBlock> interactionBlocks, ArrayList<CustomBlock> allowedAboveSeat) {
ArrayList<CustomBlock> interactionBlocks) {
this.version = version;
this.lang = lang;
this.keepActive = keepActive;
@ -76,7 +72,6 @@ public class ServerConfig implements CustomFile<ServerConfig> {
this.sittingBlocks = sittingBlocks;
this.blacklistedBlocks = blacklistedBlocks;
this.interactionBlocks = interactionBlocks;
this.allowedAboveSeat = allowedAboveSeat;
}
public Double getVersion() {
@ -119,10 +114,6 @@ public class ServerConfig implements CustomFile<ServerConfig> {
return interactionBlocks;
}
public ArrayList<CustomBlock> getAllowedAboveSeat() {
return allowedAboveSeat;
}
public static class PresetBlocks {
@SerializedName("stairs")
@ -270,7 +261,6 @@ public class ServerConfig implements CustomFile<ServerConfig> {
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
@ -285,9 +275,6 @@ public class ServerConfig implements CustomFile<ServerConfig> {
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
@ -311,17 +298,14 @@ public class ServerConfig implements CustomFile<ServerConfig> {
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) && Objects.equals(allowedAboveSeat, that.allowedAboveSeat);
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);
}
@Override
public int hashCode() {
return Objects.hash(version, lang, langOptions, keepActive, sitWhileSeated, presetBlocks, yDifferenceLimit, customEnabled, sittingBlocks, blacklistedBlocks, interactionBlocks, allowedAboveSeat);
return Objects.hash(version, lang, langOptions, keepActive, sitWhileSeated, presetBlocks, yDifferenceLimit, customEnabled, sittingBlocks, blacklistedBlocks, interactionBlocks);
}
/**
* legacy updater
*/
protected static class Legacy {
/**
* gets the legacy file, from the old directory for fabric, and the same one for spigot
@ -361,8 +345,6 @@ public class ServerConfig implements CustomFile<ServerConfig> {
} catch (Exception e) {
Data.LOGGER.error("Failed to delete the old Sit! config.");
}
// continue loading as normal...
}
/**
@ -432,7 +414,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
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, FileData.Defaults.ALLOWED_ABOVE_SEAT
new ArrayList<>(), FileData.Defaults.INTERACTION_BLOCKS
);
SittingConfig defaultSittingConfig = new SittingConfig();
@ -510,12 +492,10 @@ public class ServerConfig implements CustomFile<ServerConfig> {
} catch (JsonSyntaxException ignored) {}
}
// update and save the new files
FileData.getServerConfig().copyFileData(serverConfig);
FileData.getServerConfig().save();
FileData.getSittingConfig().copyFileData(sittingConfig);
FileData.getSittingConfig().save();
FileData.setServerConfig(serverConfig);
FileData.setSittingConfig(sittingConfig);
serverConfig.save();
sittingConfig.save();
} catch (Exception e) {
Data.LOGGER.error("Error loading legacy config: %s", e.getMessage());
}

View file

@ -1,6 +1,7 @@
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;
@ -12,7 +13,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
public class SittingConfig implements CustomFile<SittingConfig> {
public static final String ID = "sitting-config";
@SerializedName("version")
private Double version = 1.0;

View file

@ -1,7 +1,7 @@
package one.oth3r.sit.utl;
import one.oth3r.otterlib.chat.CTxT;
import one.oth3r.otterlib.registry.LanguageReg;
import one.oth3r.sit.file.FileData;
import java.awt.*;
@ -11,6 +11,6 @@ public class Chat {
}
public static CTxT lang(String key, Object... args) {
return LanguageReg.getLang(Data.MOD_ID).dynamicTranslatable(key, args);
return FileData.getLangReader().dynamicTranslatable(key, args);
}
}

View file

@ -204,7 +204,7 @@ public class Logic {
}
/**
* toggles the sit ability config option
* toggles the sit ablity config option
* @return returns a message, that can be sent to the player
*/
public static MutableText toggleSiting() {
@ -213,6 +213,9 @@ 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

View file

@ -49,8 +49,6 @@ 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();
}