use of net.minecraft.world.level.border.WorldBorder in project SpongeCommon by SpongePowered.
the class PortalHelper method generateNetherPortal.
// see Teleporter#createPortal
public static void generateNetherPortal(final ServerLevel world, final int x, final int y, final int z, final Direction.Axis axis, final boolean placePortalBlocks) {
final BlockPos portalPos = new BlockPos(x, y, z);
final Direction direction = Direction.get(Direction.AxisDirection.POSITIVE, axis);
double d0 = -1.0D;
BlockPos blockpos = null;
double d1 = -1.0D;
BlockPos blockpos1 = null;
final WorldBorder worldborder = world.getWorldBorder();
final int i = world.getHeight() - 1;
final BlockPos.MutableBlockPos blockpos$mutable = portalPos.mutable();
for (final BlockPos.MutableBlockPos blockpos$mutable1 : BlockPos.spiralAround(portalPos, 16, Direction.EAST, Direction.SOUTH)) {
final int j = Math.min(i, world.getHeight(Heightmap.Types.MOTION_BLOCKING, blockpos$mutable1.getX(), blockpos$mutable1.getZ()));
final int k = 1;
if (worldborder.isWithinBounds(blockpos$mutable1) && worldborder.isWithinBounds(blockpos$mutable1.move(direction, 1))) {
blockpos$mutable1.move(direction.getOpposite(), 1);
for (int l = j; l >= 0; --l) {
blockpos$mutable1.setY(l);
if (world.isEmptyBlock(blockpos$mutable1)) {
final int i1;
for (i1 = l; l > 0 && world.isEmptyBlock(blockpos$mutable1.move(Direction.DOWN)); --l) {
}
if (l + 4 <= i) {
final int j1 = i1 - l;
if (j1 <= 0 || j1 >= 3) {
blockpos$mutable1.setY(l);
if (PortalHelper.canHostFrame(world, blockpos$mutable1, blockpos$mutable, direction, 0)) {
final double d2 = portalPos.distSqr(blockpos$mutable1);
if (PortalHelper.canHostFrame(world, blockpos$mutable1, blockpos$mutable, direction, -1) && PortalHelper.canHostFrame(world, blockpos$mutable1, blockpos$mutable, direction, 1) && (d0 == -1.0D || d0 > d2)) {
d0 = d2;
blockpos = blockpos$mutable1.immutable();
}
if (d0 == -1.0D && (d1 == -1.0D || d1 > d2)) {
d1 = d2;
blockpos1 = blockpos$mutable1.immutable();
}
}
}
}
}
}
}
}
if (d0 == -1.0D && d1 != -1.0D) {
blockpos = blockpos1;
d0 = d1;
}
if (d0 == -1.0D) {
blockpos = (new BlockPos(portalPos.getX(), Mth.clamp(portalPos.getY(), 70, world.getHeight() - 10), portalPos.getZ())).immutable();
final Direction direction1 = direction.getClockWise();
if (!worldborder.isWithinBounds(blockpos)) {
return;
}
for (int l1 = -1; l1 < 2; ++l1) {
for (int k2 = 0; k2 < 2; ++k2) {
for (int i3 = -1; i3 < 3; ++i3) {
final BlockState blockstate1 = i3 < 0 ? Blocks.OBSIDIAN.defaultBlockState() : Blocks.AIR.defaultBlockState();
blockpos$mutable.setWithOffset(blockpos, k2 * direction.getStepX() + l1 * direction1.getStepX(), i3, k2 * direction.getStepZ() + l1 * direction1.getStepZ());
world.setBlockAndUpdate(blockpos$mutable, blockstate1);
}
}
}
}
for (int k1 = -1; k1 < 3; ++k1) {
for (int i2 = -1; i2 < 4; ++i2) {
if (k1 == -1 || k1 == 2 || i2 == -1 || i2 == 3) {
blockpos$mutable.setWithOffset(blockpos, k1 * direction.getStepX(), i2, k1 * direction.getStepZ());
world.setBlock(blockpos$mutable, Blocks.OBSIDIAN.defaultBlockState(), 3);
}
}
}
if (placePortalBlocks) {
final BlockState blockstate = Blocks.NETHER_PORTAL.defaultBlockState().setValue(NetherPortalBlock.AXIS, axis);
for (int j2 = 0; j2 < 2; ++j2) {
for (int l2 = 0; l2 < 3; ++l2) {
blockpos$mutable.setWithOffset(blockpos, j2 * direction.getStepX(), l2, j2 * direction.getStepZ());
world.setBlock(blockpos$mutable, blockstate, 18);
}
}
}
}
Aggregations