mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
fix entity y adjustment system
This commit is contained in:
parent
15fa69baa4
commit
abecde44c8
1 changed files with 14 additions and 6 deletions
|
@ -205,6 +205,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
|
||||
|
@ -221,8 +225,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);
|
||||
|
@ -254,20 +262,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