diff --git a/src/main/java/one/oth3r/sit/file/FileData.java b/src/main/java/one/oth3r/sit/file/FileData.java index 0eb0baa..f3cb229 100644 --- a/src/main/java/one/oth3r/sit/file/FileData.java +++ b/src/main/java/one/oth3r/sit/file/FileData.java @@ -10,6 +10,7 @@ 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 { /** @@ -111,6 +112,13 @@ public class FileData { 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<>()) + )); + 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 660c14c..ce416b7 100644 --- a/src/main/java/one/oth3r/sit/file/ServerConfig.java +++ b/src/main/java/one/oth3r/sit/file/ServerConfig.java @@ -52,6 +52,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 +64,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 +74,7 @@ public class ServerConfig implements CustomFile { this.sittingBlocks = sittingBlocks; this.blacklistedBlocks = blacklistedBlocks; this.interactionBlocks = interactionBlocks; + this.allowedAboveSeat = allowedAboveSeat; } public Double getVersion() { @@ -114,6 +117,10 @@ public class ServerConfig implements CustomFile { return interactionBlocks; } + public ArrayList getAllowedAboveSeat() { + return allowedAboveSeat; + } + public static class PresetBlocks { @SerializedName("stairs") @@ -261,6 +268,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 @@ -298,12 +306,12 @@ 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); } protected static class Legacy { @@ -419,7 +427,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(); 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(); }