mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
new y sitting limiter - #16
This commit is contained in:
parent
b46e10e835
commit
04d246a5bf
2 changed files with 90 additions and 6 deletions
|
@ -10,6 +10,7 @@ import net.minecraft.util.Hand;
|
|||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.file.ServerConfig;
|
||||
import one.oth3r.sit.file.SittingConfig;
|
||||
import one.oth3r.sit.file.HandSetting;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -27,6 +28,9 @@ public class Logic {
|
|||
if (!checkHands(player)) return false;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
|
@ -74,6 +78,25 @@ public class Logic {
|
|||
return canSit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
double playerEyeY = player.getEyeY();
|
||||
double blockY = blockPos.getY();
|
||||
// if the block is above the eye height
|
||||
boolean isAbove = playerEyeY < blockY;
|
||||
// get the height difference (positive)
|
||||
double heightDifference = Math.abs(playerEyeY - blockY);
|
||||
// get the config limits
|
||||
ServerConfig.YBounds yBounds = FileData.getServerConfig().getYBounds();
|
||||
|
||||
// debug
|
||||
Data.LOGGER.info("{} {} can sit? {}", heightDifference, isAbove ? "Above" : "Below", (isAbove? yBounds.getAbove(): yBounds.getBelow()) >= heightDifference);
|
||||
|
||||
return (isAbove? yBounds.getAbove(): yBounds.getBelow()) >= heightDifference;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the entity bound to the player from the game, using the player
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue