forked from virt-mirrors/Sit
merge bed changes into 1.21.5
This commit is contained in:
commit
2f18f285ca
3 changed files with 38 additions and 12 deletions
|
@ -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;
|
||||
|
@ -16,6 +19,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;
|
||||
|
@ -23,19 +29,37 @@ 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 = 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);
|
||||
}
|
||||
|
||||
// check if the block is in the right y level limits from the config
|
||||
if (!checkYLimits(player, blockPos)) return false;
|
||||
|
||||
ServerWorld serverWorld = player.getServerWorld();
|
||||
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 (sitHeight == null) return false;
|
||||
|
||||
|
|
|
@ -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"))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue