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!",