check the block below if occupied

This commit is contained in:
Oth3r 2024-11-16 15:26:55 -06:00
commit 012778ba2b
2 changed files with 8 additions and 8 deletions

View file

@ -129,14 +129,17 @@ public class Logic {
// get the entity's block pos // get the entity's block pos
BlockPos pos = Utl.Entity.getBlockPos(entity); BlockPos pos = Utl.Entity.getBlockPos(entity);
// get the poses to check above the block // get the poses to check above the block
BlockPos pos1 = new BlockPos(pos).add(0,1,0), pos2 = new BlockPos(pos).add(0,2,0); BlockPos pos1 = new BlockPos(pos).add(0,1,0), pos2 = new BlockPos(pos).add(0,2,0), posBelow = new BlockPos(pos);
// doesn't check 2 blocks above if not sitting above .80 of the block // doesn't check 2 blocks above if not sitting above .80 of the block
if (pos.getY() > entity.getY() - .80) pos2 = pos2.add(0,-1,0); if (pos.getY() > entity.getY() - .80) {
pos2 = pos2.add(0,-1,0);
posBelow = posBelow.add(0,-1,0);
}
// check if both poses are obstructed or not // check if both poses are obstructed or not
return Utl.isNotObstructed(entity.getWorld(),pos1) && Utl.isNotObstructed(entity.getWorld(),pos2) return Utl.isNotObstructed(entity.getWorld(),pos1) && Utl.isNotObstructed(entity.getWorld(),pos2)
// also check if occupied // also check if occupied, checking below to make sure you cant sit directly on top of another sit entity
&& Utl.isNotOccupied(pos1) && Utl.isNotOccupied(pos2); && Utl.isNotOccupied(pos) && Utl.isNotOccupied(pos1) && Utl.isNotOccupied(pos2) && Utl.isNotOccupied(posBelow);
} }
/** /**

View file

@ -58,10 +58,7 @@ public class Utl {
* checks the list of sit entities and sees if any of them are occupying the block pos * checks the list of sit entities and sees if any of them are occupying the block pos
*/ */
public static boolean isNotOccupied(BlockPos pos) { public static boolean isNotOccupied(BlockPos pos) {
for (DisplayEntity.TextDisplayEntity entity : Data.getSitEntities().values()) { return Data.getSitEntities().values().stream().noneMatch(entity -> entity.getBlockPos().equals(pos));
if (entity.getBlockPos().equals(pos)) return false;
}
return true;
} }
public static class Num { public static class Num {