only be able to sit on bed with cookie in hand

This commit is contained in:
Virt 2025-04-04 11:26:43 +02:00
commit 0441f9644a
3 changed files with 36 additions and 10 deletions

View file

@ -2,11 +2,14 @@ package one.oth3r.sit.utl;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.entity.decoration.DisplayEntity; 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.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import one.oth3r.sit.file.FileData; import one.oth3r.sit.file.FileData;
@ -15,6 +18,9 @@ import one.oth3r.sit.file.HandSetting;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class Logic { public class Logic {
private static double BED_HEIGHT = 0.5625;
public static boolean sit(ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hitResult) { public static boolean sit(ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hitResult) {
// cant sit if crouching // cant sit if crouching
if (player.isSneaking()) return false; 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 sitting on a sit entity and sit while seated off, false
if (!FileData.getServerConfig().canSitWhileSeated() && Data.getSitEntity(player) != null) return false; if (!FileData.getServerConfig().canSitWhileSeated() && Data.getSitEntity(player) != null) return false;
ServerWorld serverWorld = player.getServerWorld();
BlockState blockState = serverWorld.getBlockState(blockPos);
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 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 (hitResult != null) {
if (!checkHands(player)) return false; if (!checkHands(player)) return false;
} }
ServerWorld serverWorld = player.getServerWorld(); sitHeight = Utl.getSittingHeight(blockState, player, blockPos, hitResult);
BlockState blockState = serverWorld.getBlockState(blockPos); }
Double sitHeight = Utl.getSittingHeight(blockState,player,blockPos,hitResult);
// if the sit height is null, its not a sittable block // if the sit height is null, its not a sittable block
if (sitHeight == null) return false; if (sitHeight == null) return false;

View file

@ -16,6 +16,7 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.consume.UseAction; import net.minecraft.item.consume.UseAction;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
@ -218,7 +219,7 @@ public class Utl {
// get the blockstate // get the blockstate
BlockState blockState = player.getWorld().getBlockState(blockPos); 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) // 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"))));
} }
/** /**

View file

@ -2,10 +2,11 @@
"schemaVersion": 1, "schemaVersion": 1,
"id": "sit-oth3r", "id": "sit-oth3r",
"version": "${version}", "version": "${version}",
"name": "Sit!", "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!", "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": [ "authors": [
"Oth3r" "Oth3r",
"Virt"
], ],
"contact": { "contact": {
"homepage": "https://modrinth.com/mod/sit!", "homepage": "https://modrinth.com/mod/sit!",