use of net.minecraft.world.border.WorldBorder in project SpongeCommon by SpongePowered.
the class SpongeTeleportHelper method getBlockLocations.
private Stream<Vector3i> getBlockLocations(Location<World> worldLocation, int height, int width) {
// We don't want to warp outside of the world border, so we want to check that we're within it.
WorldBorder worldBorder = (WorldBorder) worldLocation.getExtent().getWorldBorder();
int worldBorderMinX = GenericMath.floor(worldBorder.minX());
int worldBorderMinZ = GenericMath.floor(worldBorder.minZ());
int worldBorderMaxX = GenericMath.floor(worldBorder.maxX());
int worldBorderMaxZ = GenericMath.floor(worldBorder.maxZ());
// Get the World and get the maximum Y value.
int worldMaxY = worldLocation.getExtent().getBlockMax().getY();
Vector3i vectorLocation = worldLocation.getBlockPosition();
// We use clamp to remain within the world confines, so we don't waste time checking blocks outside of the
// world border and the world height.
int minY = GenericMath.clamp(vectorLocation.getY() - height, 0, worldMaxY);
int maxY = GenericMath.clamp(vectorLocation.getY() + height, 0, worldMaxY);
int minX = GenericMath.clamp(vectorLocation.getX() - width, worldBorderMinX, worldBorderMaxX);
int maxX = GenericMath.clamp(vectorLocation.getX() + width, worldBorderMinX, worldBorderMaxX);
int minZ = GenericMath.clamp(vectorLocation.getZ() - width, worldBorderMinZ, worldBorderMaxZ);
int maxZ = GenericMath.clamp(vectorLocation.getZ() + width, worldBorderMinZ, worldBorderMaxZ);
// We now iterate over all possible x, y and z positions to get all possible vectors.
List<Vector3i> vectors = new ArrayList<>();
for (int y = minY; y <= maxY; y++) {
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
vectors.add(new Vector3i(x, y, z));
}
}
}
Comparator<Vector3i> c = Comparator.comparingInt(vectorLocation::distanceSquared);
// The compiler seems to need this to be a new line.
// We check to see what the y location is, preferring changes in Y over X and Z, and higher over lower locations.
c = c.thenComparing(x -> -Math.abs(vectorLocation.getY() - x.getY())).thenComparing(x -> -x.getY());
// Sort them according to the distance to the provided worldLocation.
return vectors.stream().sorted(c);
}
use of net.minecraft.world.border.WorldBorder in project ImmersiveEngineering by BluSunrize.
the class SkylineHelper method getBlockCollisionBoxes.
public static void getBlockCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB aabb, @Nonnull List<AxisAlignedBB> outList, World w, Collection<BlockPos> ignored) {
int minX = MathHelper.floor(aabb.minX) - 1;
int maxX = MathHelper.ceil(aabb.maxX) + 1;
int minY = MathHelper.floor(aabb.minY) - 1;
int maxY = MathHelper.ceil(aabb.maxY) + 1;
int minZ = MathHelper.floor(aabb.minZ) - 1;
int maxZ = MathHelper.ceil(aabb.maxZ) + 1;
WorldBorder worldborder = w.getWorldBorder();
boolean outsideWorld = entityIn != null && entityIn.isOutsideBorder();
boolean insideWorld = entityIn != null && w.isInsideWorldBorder(entityIn);
IBlockState outsideState = Blocks.STONE.getDefaultState();
BlockPos.PooledMutableBlockPos mutPos = BlockPos.PooledMutableBlockPos.retain();
try {
for (int x = minX; x < maxX; ++x) {
for (int z = minZ; z < maxZ; ++z) {
boolean xBorder = x == minX || x == maxX - 1;
boolean zBorder = z == minZ || z == maxZ - 1;
if ((!xBorder || !zBorder) && w.isBlockLoaded(mutPos.setPos(x, 64, z))) {
for (int y = minY; y < maxY; ++y) {
if (!xBorder && !zBorder || y != maxY - 1) {
if (entityIn != null && outsideWorld == insideWorld) {
entityIn.setOutsideBorder(!insideWorld);
}
mutPos.setPos(x, y, z);
if (!ignored.contains(mutPos)) {
IBlockState currState;
if (!worldborder.contains(mutPos) && insideWorld)
currState = outsideState;
else
currState = w.getBlockState(mutPos);
currState.addCollisionBoxToList(w, mutPos, aabb, outList, entityIn, false);
}
}
}
}
}
}
} finally {
mutPos.release();
}
}
Aggregations