cn.nukkit.level.MovingObjectPosition Java Examples
The following examples show how to use
cn.nukkit.level.MovingObjectPosition.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityProjectile.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void onCollideWithEntity(Entity entity) { this.server.getPluginManager().callEvent(new ProjectileHitEvent(this, MovingObjectPosition.fromEntity(entity))); float damage = this.getResultDamage(); EntityDamageEvent ev; if (this.shootingEntity == null) { ev = new EntityDamageByEntityEvent(this, entity, DamageCause.PROJECTILE, damage); } else { ev = new EntityDamageByChildEntityEvent(this.shootingEntity, this, entity, DamageCause.PROJECTILE, damage); } if (entity.attack(ev)) { this.hadCollision = true; if (this.fireTicks > 0) { EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this, entity, 5); this.server.getPluginManager().callEvent(ev); if (!event.isCancelled()) { entity.setOnFire(event.getDuration()); } } } if (closeOnCollide) { this.close(); } }
Example #2
Source File: Block.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) { AxisAlignedBB bb = this.getBoundingBox(); if (bb == null) { return null; } Vector3 v1 = pos1.getIntermediateWithXValue(pos2, bb.getMinX()); Vector3 v2 = pos1.getIntermediateWithXValue(pos2, bb.getMaxX()); Vector3 v3 = pos1.getIntermediateWithYValue(pos2, bb.getMinY()); Vector3 v4 = pos1.getIntermediateWithYValue(pos2, bb.getMaxY()); Vector3 v5 = pos1.getIntermediateWithZValue(pos2, bb.getMinZ()); Vector3 v6 = pos1.getIntermediateWithZValue(pos2, bb.getMaxZ()); if (v1 != null && !bb.isVectorInYZ(v1)) { v1 = null; } if (v2 != null && !bb.isVectorInYZ(v2)) { v2 = null; } if (v3 != null && !bb.isVectorInXZ(v3)) { v3 = null; } if (v4 != null && !bb.isVectorInXZ(v4)) { v4 = null; } if (v5 != null && !bb.isVectorInXY(v5)) { v5 = null; } if (v6 != null && !bb.isVectorInXY(v6)) { v6 = null; } Vector3 vector = v1; if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) { vector = v2; } if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) { vector = v3; } if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) { vector = v4; } if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) { vector = v5; } if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) { vector = v6; } if (vector == null) { return null; } int f = -1; if (vector == v1) { f = 4; } else if (vector == v2) { f = 5; } else if (vector == v3) { f = 0; } else if (vector == v4) { f = 1; } else if (vector == v5) { f = 2; } else if (vector == v6) { f = 3; } return MovingObjectPosition.fromBlock((int) this.x, (int) this.y, (int) this.z, f, vector.add(this.x, this.y, this.z)); }
Example #3
Source File: ProjectileHitEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setMovingObjectPosition(MovingObjectPosition movingObjectPosition) { this.movingObjectPosition = movingObjectPosition; }
Example #4
Source File: ProjectileHitEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public MovingObjectPosition getMovingObjectPosition() { return movingObjectPosition; }
Example #5
Source File: ProjectileHitEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public ProjectileHitEvent(EntityProjectile entity, MovingObjectPosition movingObjectPosition) { this.entity = entity; this.movingObjectPosition = movingObjectPosition; }
Example #6
Source File: Block.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) { AxisAlignedBB bb = this.getBoundingBox(); if (bb == null) { return null; } Vector3 v1 = pos1.getIntermediateWithXValue(pos2, bb.getMinX()); Vector3 v2 = pos1.getIntermediateWithXValue(pos2, bb.getMaxX()); Vector3 v3 = pos1.getIntermediateWithYValue(pos2, bb.getMinY()); Vector3 v4 = pos1.getIntermediateWithYValue(pos2, bb.getMaxY()); Vector3 v5 = pos1.getIntermediateWithZValue(pos2, bb.getMinZ()); Vector3 v6 = pos1.getIntermediateWithZValue(pos2, bb.getMaxZ()); if (v1 != null && !bb.isVectorInYZ(v1)) { v1 = null; } if (v2 != null && !bb.isVectorInYZ(v2)) { v2 = null; } if (v3 != null && !bb.isVectorInXZ(v3)) { v3 = null; } if (v4 != null && !bb.isVectorInXZ(v4)) { v4 = null; } if (v5 != null && !bb.isVectorInXY(v5)) { v5 = null; } if (v6 != null && !bb.isVectorInXY(v6)) { v6 = null; } Vector3 vector = v1; if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) { vector = v2; } if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) { vector = v3; } if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) { vector = v4; } if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) { vector = v5; } if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) { vector = v6; } if (vector == null) { return null; } int f = -1; if (vector == v1) { f = 4; } else if (vector == v2) { f = 5; } else if (vector == v3) { f = 0; } else if (vector == v4) { f = 1; } else if (vector == v5) { f = 2; } else if (vector == v6) { f = 3; } return MovingObjectPosition.fromBlock((int) this.x, (int) this.y, (int) this.z, f, vector.add(this.x, this.y, this.z)); }
Example #7
Source File: AxisAlignedBB.java From Nukkit with GNU General Public License v3.0 | 4 votes |
default MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) { Vector3 v1 = pos1.getIntermediateWithXValue(pos2, this.getMinX()); Vector3 v2 = pos1.getIntermediateWithXValue(pos2, this.getMaxX()); Vector3 v3 = pos1.getIntermediateWithYValue(pos2, this.getMinY()); Vector3 v4 = pos1.getIntermediateWithYValue(pos2, this.getMaxY()); Vector3 v5 = pos1.getIntermediateWithZValue(pos2, this.getMinZ()); Vector3 v6 = pos1.getIntermediateWithZValue(pos2, this.getMaxZ()); if (v1 != null && !this.isVectorInYZ(v1)) { v1 = null; } if (v2 != null && !this.isVectorInYZ(v2)) { v2 = null; } if (v3 != null && !this.isVectorInXZ(v3)) { v3 = null; } if (v4 != null && !this.isVectorInXZ(v4)) { v4 = null; } if (v5 != null && !this.isVectorInXY(v5)) { v5 = null; } if (v6 != null && !this.isVectorInXY(v6)) { v6 = null; } Vector3 vector = null; //if (v1 != null && (vector == null || pos1.distanceSquared(v1) < pos1.distanceSquared(vector))) { if (v1 != null) { vector = v1; } if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) { vector = v2; } if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) { vector = v3; } if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) { vector = v4; } if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) { vector = v5; } if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) { vector = v6; } if (vector == null) { return null; } int face = -1; if (vector == v1) { face = 4; } else if (vector == v2) { face = 5; } else if (vector == v3) { face = 0; } else if (vector == v4) { face = 1; } else if (vector == v5) { face = 2; } else if (vector == v6) { face = 3; } return MovingObjectPosition.fromBlock(0, 0, 0, face, vector); }
Example #8
Source File: EntityProjectile.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { MovingObjectPosition movingObjectPosition = null; if (!this.isCollided) { this.motionY -= this.getGravity(); } Vector3 moveVector = new Vector3(this.x + this.motionX, this.y + this.motionY, this.z + this.motionZ); Entity[] list = this.getLevel().getCollidingEntities(this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1, 1, 1), this); double nearDistance = Integer.MAX_VALUE; Entity nearEntity = null; for (Entity entity : list) { if (/*!entity.canCollideWith(this) or */ (entity == this.shootingEntity && this.ticksLived < 5) ) { continue; } AxisAlignedBB axisalignedbb = entity.boundingBox.grow(0.3, 0.3, 0.3); MovingObjectPosition ob = axisalignedbb.calculateIntercept(this, moveVector); if (ob == null) { continue; } double distance = this.distanceSquared(ob.hitVector); if (distance < nearDistance) { nearDistance = distance; nearEntity = entity; } } if (nearEntity != null) { movingObjectPosition = MovingObjectPosition.fromEntity(nearEntity); } if (movingObjectPosition != null) { if (movingObjectPosition.entityHit != null) { onCollideWithEntity(movingObjectPosition.entityHit); return true; } } this.move(this.motionX, this.motionY, this.motionZ); if (this.isCollided && !this.hadCollision) { //collide with block this.hadCollision = true; this.motionX = 0; this.motionY = 0; this.motionZ = 0; this.server.getPluginManager().callEvent(new ProjectileHitEvent(this, MovingObjectPosition.fromBlock(this.getFloorX(), this.getFloorY(), this.getFloorZ(), -1, this))); return false; } else if (!this.isCollided && this.hadCollision) { this.hadCollision = false; } if (!this.hadCollision || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001) { double f = Math.sqrt((this.motionX * this.motionX) + (this.motionZ * this.motionZ)); this.yaw = Math.atan2(this.motionX, this.motionZ) * 180 / Math.PI; this.pitch = Math.atan2(this.motionY, f) * 180 / Math.PI; hasUpdate = true; } this.updateMovement(); } return hasUpdate; }
Example #9
Source File: ProjectileHitEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setMovingObjectPosition(MovingObjectPosition movingObjectPosition) { this.movingObjectPosition = movingObjectPosition; }
Example #10
Source File: ProjectileHitEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public MovingObjectPosition getMovingObjectPosition() { return movingObjectPosition; }
Example #11
Source File: ProjectileHitEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public ProjectileHitEvent(EntityProjectile entity, MovingObjectPosition movingObjectPosition) { this.entity = entity; this.movingObjectPosition = movingObjectPosition; }
Example #12
Source File: EntityProjectile.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { MovingObjectPosition movingObjectPosition = null; if (!this.isCollided) { this.motionY -= this.getGravity(); } Vector3 moveVector = new Vector3(this.x + this.motionX, this.y + this.motionY, this.z + this.motionZ); Entity[] list = this.getLevel().getCollidingEntities(this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1, 1, 1), this); double nearDistance = Integer.MAX_VALUE; Entity nearEntity = null; for (Entity entity : list) { if (/*!entity.canCollideWith(this) or */ (entity == this.shootingEntity && this.ticksLived < 5) ) { continue; } AxisAlignedBB axisalignedbb = entity.boundingBox.grow(0.3, 0.3, 0.3); MovingObjectPosition ob = axisalignedbb.calculateIntercept(this, moveVector); if (ob == null) { continue; } double distance = this.distanceSquared(ob.hitVector); if (distance < nearDistance) { nearDistance = distance; nearEntity = entity; } } if (nearEntity != null) { movingObjectPosition = MovingObjectPosition.fromEntity(nearEntity); } if (movingObjectPosition != null) { if (movingObjectPosition.entityHit != null) { onCollideWithEntity(movingObjectPosition.entityHit); return true; } } this.move(this.motionX, this.motionY, this.motionZ); if (this.isCollided && !this.hadCollision) { //collide with block this.hadCollision = true; this.motionX = 0; this.motionY = 0; this.motionZ = 0; this.server.getPluginManager().callEvent(new ProjectileHitEvent(this, MovingObjectPosition.fromBlock(this.getFloorX(), this.getFloorY(), this.getFloorZ(), -1, this))); return false; } else if (!this.isCollided && this.hadCollision) { this.hadCollision = false; } if (!this.hadCollision || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001) { double f = Math.sqrt((this.motionX * this.motionX) + (this.motionZ * this.motionZ)); this.yaw = Math.atan2(this.motionX, this.motionZ) * 180 / Math.PI; this.pitch = Math.atan2(this.motionY, f) * 180 / Math.PI; hasUpdate = true; } this.updateMovement(); } return hasUpdate; }
Example #13
Source File: AxisAlignedBB.java From Nukkit with GNU General Public License v3.0 | 4 votes |
default MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) { Vector3 v1 = pos1.getIntermediateWithXValue(pos2, this.getMinX()); Vector3 v2 = pos1.getIntermediateWithXValue(pos2, this.getMaxX()); Vector3 v3 = pos1.getIntermediateWithYValue(pos2, this.getMinY()); Vector3 v4 = pos1.getIntermediateWithYValue(pos2, this.getMaxY()); Vector3 v5 = pos1.getIntermediateWithZValue(pos2, this.getMinZ()); Vector3 v6 = pos1.getIntermediateWithZValue(pos2, this.getMaxZ()); if (v1 != null && !this.isVectorInYZ(v1)) { v1 = null; } if (v2 != null && !this.isVectorInYZ(v2)) { v2 = null; } if (v3 != null && !this.isVectorInXZ(v3)) { v3 = null; } if (v4 != null && !this.isVectorInXZ(v4)) { v4 = null; } if (v5 != null && !this.isVectorInXY(v5)) { v5 = null; } if (v6 != null && !this.isVectorInXY(v6)) { v6 = null; } Vector3 vector = null; //if (v1 != null && (vector == null || pos1.distanceSquared(v1) < pos1.distanceSquared(vector))) { if (v1 != null) { vector = v1; } if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) { vector = v2; } if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) { vector = v3; } if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) { vector = v4; } if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) { vector = v5; } if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) { vector = v6; } if (vector == null) { return null; } int face = -1; if (vector == v1) { face = 4; } else if (vector == v2) { face = 5; } else if (vector == v3) { face = 0; } else if (vector == v4) { face = 1; } else if (vector == v5) { face = 2; } else if (vector == v6) { face = 3; } return MovingObjectPosition.fromBlock(0, 0, 0, face, vector); }
Example #14
Source File: EntityProjectile.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { MovingObjectPosition movingObjectPosition = null; if (!this.isCollided) { this.motionY -= this.getGravity(); } Vector3 moveVector = new Vector3(this.x + this.motionX, this.y + this.motionY, this.z + this.motionZ); Entity[] list = this.getLevel().getCollidingEntities(this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1, 1, 1), this); double nearDistance = Integer.MAX_VALUE; Entity nearEntity = null; for (Entity entity : list) { if (/*!entity.canCollideWith(this) or */ (entity == this.shootingEntity && this.ticksLived < 5) ) { continue; } AxisAlignedBB axisalignedbb = entity.boundingBox.grow(0.3, 0.3, 0.3); MovingObjectPosition ob = axisalignedbb.calculateIntercept(this, moveVector); if (ob == null) { continue; } double distance = this.distanceSquared(ob.hitVector); if (distance < nearDistance) { nearDistance = distance; nearEntity = entity; } } if (nearEntity != null) { movingObjectPosition = MovingObjectPosition.fromEntity(nearEntity); } if (movingObjectPosition != null) { if (movingObjectPosition.entityHit != null) { onCollideWithEntity(movingObjectPosition.entityHit); return true; } } this.move(this.motionX, this.motionY, this.motionZ); if (this.isCollided && !this.hadCollision) { //collide with block this.hadCollision = true; this.motionX = 0; this.motionY = 0; this.motionZ = 0; this.server.getPluginManager().callEvent(new ProjectileHitEvent(this, MovingObjectPosition.fromBlock(this.getFloorX(), this.getFloorY(), this.getFloorZ(), -1, this))); return false; } else if (!this.isCollided && this.hadCollision) { this.hadCollision = false; } if (!this.hadCollision || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001) { double f = Math.sqrt((this.motionX * this.motionX) + (this.motionZ * this.motionZ)); this.yaw = Math.atan2(this.motionX, this.motionZ) * 180 / Math.PI; this.pitch = Math.atan2(this.motionY, f) * 180 / Math.PI; hasUpdate = true; } this.updateMovement(); } return hasUpdate; }
Example #15
Source File: ProjectileHitEvent.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public void setMovingObjectPosition(MovingObjectPosition movingObjectPosition) { this.movingObjectPosition = movingObjectPosition; }
Example #16
Source File: ProjectileHitEvent.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public MovingObjectPosition getMovingObjectPosition() { return movingObjectPosition; }
Example #17
Source File: ProjectileHitEvent.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public ProjectileHitEvent(EntityProjectile entity, MovingObjectPosition movingObjectPosition) { this.entity = entity; this.movingObjectPosition = movingObjectPosition; }
Example #18
Source File: Block.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) { AxisAlignedBB bb = this.getBoundingBox(); if (bb == null) { return null; } Vector3 v1 = pos1.getIntermediateWithXValue(pos2, bb.minX); Vector3 v2 = pos1.getIntermediateWithXValue(pos2, bb.maxX); Vector3 v3 = pos1.getIntermediateWithYValue(pos2, bb.minY); Vector3 v4 = pos1.getIntermediateWithYValue(pos2, bb.maxY); Vector3 v5 = pos1.getIntermediateWithZValue(pos2, bb.minZ); Vector3 v6 = pos1.getIntermediateWithZValue(pos2, bb.maxZ); if (v1 != null && !bb.isVectorInYZ(v1)) { v1 = null; } if (v2 != null && !bb.isVectorInYZ(v2)) { v2 = null; } if (v3 != null && !bb.isVectorInXZ(v3)) { v3 = null; } if (v4 != null && !bb.isVectorInXZ(v4)) { v4 = null; } if (v5 != null && !bb.isVectorInXY(v5)) { v5 = null; } if (v6 != null && !bb.isVectorInXY(v6)) { v6 = null; } Vector3 vector = v1; if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) { vector = v2; } if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) { vector = v3; } if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) { vector = v4; } if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) { vector = v5; } if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) { vector = v6; } if (vector == null) { return null; } int f = -1; if (vector == v1) { f = 4; } else if (vector == v2) { f = 5; } else if (vector == v3) { f = 0; } else if (vector == v4) { f = 1; } else if (vector == v5) { f = 2; } else if (vector == v6) { f = 3; } return MovingObjectPosition.fromBlock((int) this.x, (int) this.y, (int) this.z, f, vector.add(this.x, this.y, this.z)); }
Example #19
Source File: AxisAlignedBB.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) { Vector3 v1 = pos1.getIntermediateWithXValue(pos2, this.minX); Vector3 v2 = pos1.getIntermediateWithXValue(pos2, this.maxX); Vector3 v3 = pos1.getIntermediateWithYValue(pos2, this.minY); Vector3 v4 = pos1.getIntermediateWithYValue(pos2, this.maxY); Vector3 v5 = pos1.getIntermediateWithZValue(pos2, this.minZ); Vector3 v6 = pos1.getIntermediateWithZValue(pos2, this.maxZ); if (v1 != null && !this.isVectorInYZ(v1)) { v1 = null; } if (v2 != null && !this.isVectorInYZ(v2)) { v2 = null; } if (v3 != null && !this.isVectorInXZ(v3)) { v3 = null; } if (v4 != null && !this.isVectorInXZ(v4)) { v4 = null; } if (v5 != null && !this.isVectorInXY(v5)) { v5 = null; } if (v6 != null && !this.isVectorInXY(v6)) { v6 = null; } Vector3 vector = null; //if (v1 != null && (vector == null || pos1.distanceSquared(v1) < pos1.distanceSquared(vector))) { if (v1 != null) { vector = v1; } if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) { vector = v2; } if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) { vector = v3; } if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) { vector = v4; } if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) { vector = v5; } if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) { vector = v6; } if (vector == null) { return null; } int face = -1; if (vector == v1) { face = 4; } else if (vector == v2) { face = 5; } else if (vector == v3) { face = 0; } else if (vector == v4) { face = 1; } else if (vector == v5) { face = 2; } else if (vector == v6) { face = 3; } return MovingObjectPosition.fromBlock(0, 0, 0, face, vector); }