From 0441f9644a117853f69846a9685026fcf66a009c Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Fri, 4 Apr 2025 11:26:43 +0200 Subject: [PATCH 1/2] only be able to sit on bed with cookie in hand --- src/main/java/one/oth3r/sit/utl/Logic.java | 36 ++++++++++++++++++---- src/main/java/one/oth3r/sit/utl/Utl.java | 3 +- src/main/resources/fabric.mod.json | 7 +++-- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/main/java/one/oth3r/sit/utl/Logic.java b/src/main/java/one/oth3r/sit/utl/Logic.java index 62556b4..8626929 100644 --- a/src/main/java/one/oth3r/sit/utl/Logic.java +++ b/src/main/java/one/oth3r/sit/utl/Logic.java @@ -2,11 +2,14 @@ package one.oth3r.sit.utl; import net.minecraft.block.*; import net.minecraft.entity.decoration.DisplayEntity; +import net.minecraft.registry.Registries; +import net.minecraft.registry.tag.TagKey; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.MutableText; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import one.oth3r.sit.file.FileData; @@ -15,6 +18,9 @@ import one.oth3r.sit.file.HandSetting; import org.jetbrains.annotations.Nullable; public class Logic { + + private static double BED_HEIGHT = 0.5625; + public static boolean sit(ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hitResult) { // cant sit if crouching if (player.isSneaking()) return false; @@ -22,15 +28,33 @@ public class Logic { // if sitting on a sit entity and sit while seated off, false if (!FileData.getServerConfig().canSitWhileSeated() && Data.getSitEntity(player) != null) return false; - // if hit result isnt null (check the hands of the player) & the player hand checker returns false (can't sit with the items in the hand), quit - if (hitResult != null) { - if (!checkHands(player)) return false; - } - ServerWorld serverWorld = player.getServerWorld(); BlockState blockState = serverWorld.getBlockState(blockPos); - Double sitHeight = Utl.getSittingHeight(blockState,player,blockPos,hitResult); + Double sitHeight = null; + + // is a bed? + if (blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.tryParse("minecraft:beds")))) { + if (hitResult != null) { + + // is a cookie? + if (Registries.ITEM.getId(player.getStackInHand(Hand.MAIN_HAND).getItem()).toString().equals("minecraft:cookie")) + sitHeight = BED_HEIGHT; + else return false; + + } else { + sitHeight = BED_HEIGHT; + } + + // behave normally otherwise + } else { + // if hit result isnt null (check the hands of the player) & the player hand checker returns false (can't sit with the items in the hand), quit + if (hitResult != null) { + if (!checkHands(player)) return false; + } + + sitHeight = Utl.getSittingHeight(blockState, player, blockPos, hitResult); + } // if the sit height is null, its not a sittable block if (sitHeight == null) return false; diff --git a/src/main/java/one/oth3r/sit/utl/Utl.java b/src/main/java/one/oth3r/sit/utl/Utl.java index 4fd84bd..65b89df 100644 --- a/src/main/java/one/oth3r/sit/utl/Utl.java +++ b/src/main/java/one/oth3r/sit/utl/Utl.java @@ -16,6 +16,7 @@ import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.item.consume.UseAction; import net.minecraft.registry.Registries; +import net.minecraft.registry.tag.TagKey; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.MutableText; @@ -218,7 +219,7 @@ public class Utl { // get the blockstate BlockState blockState = player.getWorld().getBlockState(blockPos); // check if the block is still there & the block is a valid sit block (by checking if there is a sit height for the block) - return !blockState.isAir() && getSittingHeight(blockState,player,blockPos,null) != null; + return !blockState.isAir() && (getSittingHeight(blockState,player,blockPos,null) != null || blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.tryParse("minecraft:beds")))); } /** diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index dd81d2b..e1f4483 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -2,10 +2,11 @@ "schemaVersion": 1, "id": "sit-oth3r", "version": "${version}", - "name": "Sit!", - "description": "Adds sitting to minecraft! Endless customizability for hand restrictions and sittable blocks.\n Players can have their own sitting settings when using the Sit! client on the server!", + "name": "Sit! - Virt Edition", + "description": "Adds sitting to minecraft! Endless customizability for hand restrictions and sittable blocks.\n Players can have their own sitting settings when using the Sit! client on the server!\n Contains bed cookie patch.", "authors": [ - "Oth3r" + "Oth3r", + "Virt" ], "contact": { "homepage": "https://modrinth.com/mod/sit!", From 042b089712a9b8b85d37dcc626a37ee4fc76910b Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Fri, 4 Apr 2025 11:55:54 +0200 Subject: [PATCH 2/2] allow disabling of y limit (default disabled lol) --- src/main/java/one/oth3r/sit/file/ServerConfig.java | 14 +++++++++++++- src/main/java/one/oth3r/sit/utl/Logic.java | 8 +++++--- src/main/resources/fabric.mod.json | 6 +++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/one/oth3r/sit/file/ServerConfig.java b/src/main/java/one/oth3r/sit/file/ServerConfig.java index dd183c5..7f591ed 100644 --- a/src/main/java/one/oth3r/sit/file/ServerConfig.java +++ b/src/main/java/one/oth3r/sit/file/ServerConfig.java @@ -154,6 +154,8 @@ public class ServerConfig implements CustomFile { } public static class YDifferenceLimit { + @SerializedName("enabled") + private boolean enabled = false; @SerializedName("above") private Double above = 1.0; @SerializedName("below") @@ -162,14 +164,24 @@ public class ServerConfig implements CustomFile { public YDifferenceLimit() { } - public YDifferenceLimit(Double above, Double below) { + public YDifferenceLimit(Double above, Double below, boolean enabled) { this.above = above; this.below = below; + this.enabled = enabled; } public YDifferenceLimit(YDifferenceLimit yDifferenceLimit) { this.above = yDifferenceLimit.above; this.below = yDifferenceLimit.below; + this.enabled = yDifferenceLimit.enabled; + } + + public boolean isEnabled() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; } public Double getAbove() { diff --git a/src/main/java/one/oth3r/sit/utl/Logic.java b/src/main/java/one/oth3r/sit/utl/Logic.java index b5b9a21..eccafbd 100644 --- a/src/main/java/one/oth3r/sit/utl/Logic.java +++ b/src/main/java/one/oth3r/sit/utl/Logic.java @@ -106,6 +106,11 @@ public class Logic { * check if the Y-level of the block is within the limits of the player, bounds are set in the {@link ServerConfig} */ public static boolean checkYLimits(ServerPlayerEntity player, BlockPos blockPos) { + ServerConfig.YDifferenceLimit yDifferenceLimit = FileData.getServerConfig().getYDifferenceLimit(); + + // check if enabled + if (!yDifferenceLimit.isEnabled()) return true; + double playerY = player.getBlockY(); double blockY = blockPos.getY(); // if the block is above the eye height @@ -116,9 +121,6 @@ public class Logic { // get the height difference (positive) double heightDifference = Math.abs(playerY - blockY); - // get the config limits - ServerConfig.YDifferenceLimit yDifferenceLimit = FileData.getServerConfig().getYDifferenceLimit(); - return (isAbove? yDifferenceLimit.getAbove() : yDifferenceLimit.getBelow()) >= heightDifference; } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5c58928..75342bd 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -9,8 +9,8 @@ "Virt" ], "contact": { - "homepage": "https://modrinth.com/mod/sit!", - "sources": "https://github.com/Oth3r/Sit" + "homepage": "https://copeberg.org/virt/Sit", + "sources": "https://copeberg.org/virt/Sit" }, "license": "LGPL-3.0-only", "icon": "assets/sit-oth3r/icon.png", @@ -38,4 +38,4 @@ "mixins": [ "sit!.mixins.json" ] -} \ No newline at end of file +}