Compare commits

..

3 commits

4 changed files with 59 additions and 19 deletions

View file

@ -154,6 +154,8 @@ public class ServerConfig implements CustomFile<ServerConfig> {
}
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<ServerConfig> {
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() {

View file

@ -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;
@ -82,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
@ -92,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;
}

View file

@ -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"))));
}
/**

View file

@ -2,14 +2,15 @@
"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!",
"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",