mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
Merge branch '1.21.3' into 1.21.1
# Conflicts: # gradle.properties
This commit is contained in:
commit
41abc4d361
10 changed files with 306 additions and 86 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,26 @@ 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 playerY = player.getBlockY();
|
||||
double blockY = blockPos.getY();
|
||||
// if the block is above the eye height
|
||||
boolean isAbove = playerY < blockY;
|
||||
|
||||
// return true if equal
|
||||
if (playerY == blockY) return true;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the entity bound to the player from the game, using the player
|
||||
*/
|
||||
|
@ -170,11 +194,11 @@ public class Logic {
|
|||
|
||||
|
||||
// get the message settings
|
||||
String messageKey = "sit!.chat.sit_toggle."+(config.getEnabled()?"on":"off");
|
||||
String messageKey = "sit!.chat.toggle_sit."+(config.getEnabled()?"on":"off");
|
||||
Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED;
|
||||
|
||||
// send the player the actionbar message
|
||||
return Utl.lang("sit!.chat.sit_toggle",
|
||||
return Utl.lang("sit!.chat.toggle_sit",
|
||||
Utl.lang(messageKey).formatted(messageColor));
|
||||
} else {
|
||||
// unsupported server message if not in a Sit! server
|
||||
|
|
|
@ -204,6 +204,10 @@ public class Utl {
|
|||
}
|
||||
|
||||
public static class Entity {
|
||||
/**
|
||||
* the customizable y height of the entity, as some versions have different sitting heights on the entity
|
||||
*/
|
||||
private static final double Y_ADJUSTMENT = 0;
|
||||
|
||||
/**
|
||||
* checks if the entity's block is still there, & is valid
|
||||
|
@ -220,8 +224,12 @@ public class Utl {
|
|||
* gets the bound block pos of the sit entity
|
||||
*/
|
||||
public static BlockPos getBlockPos(DisplayEntity.TextDisplayEntity entity) {
|
||||
// the entity Y level, adjusted
|
||||
// the adjustment - is the opposite of the offset applied in Entity.create()
|
||||
double entityY = entity.getY() + (Y_ADJUSTMENT*-1);
|
||||
|
||||
// get the block pos
|
||||
BlockPos pos = new BlockPos(entity.getBlockX(),entity.getBlockY(),entity.getBlockZ());
|
||||
BlockPos pos = new BlockPos(entity.getBlockX(),(int)entityY,entity.getBlockZ());
|
||||
// if above the block, subtract 1
|
||||
if (isAboveBlockHeight(entity)) {
|
||||
pos = pos.add(0,-1,0);
|
||||
|
@ -253,20 +261,20 @@ public class Utl {
|
|||
entity.setInvulnerable(true);
|
||||
entity.setInvisible(true);
|
||||
|
||||
/// make a double for adjusting the entity height if some versions change the player sit height on entities again
|
||||
double adjustmentY = 0;
|
||||
|
||||
// get the entities y level
|
||||
double entityY = blockPos.getY();
|
||||
entityY += sitHeight + adjustmentY;
|
||||
entityY += sitHeight;
|
||||
|
||||
// set the entities position
|
||||
entity.updatePositionAndAngles(blockPos.getX()+.5, entityY, blockPos.getZ()+.5, 0, 0);
|
||||
entity.updatePosition(blockPos.getX()+.5, entityY, blockPos.getZ()+.5);
|
||||
|
||||
// change pitch based on if player is sitting below block height or not (full block height only)
|
||||
if (entity.getY() == blockPos.getY() + 1) entity.setPitch(90); // below
|
||||
else entity.setPitch(-90); // above
|
||||
|
||||
// adjusting the entity height after doing the main calculations, for correct player visuals
|
||||
entity.updatePosition(entity.getX(),entityY+Y_ADJUSTMENT,entity.getZ());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue