Search in sources :

Example 6 with WorldBorder

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);
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) WorldBorder(net.minecraft.world.level.border.WorldBorder) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Aggregations

WorldBorder (net.minecraft.world.level.border.WorldBorder)6 Sets (com.google.common.collect.Sets)1 Singleton (com.google.inject.Singleton)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 BlockState (org.spongepowered.api.block.BlockState)1 Tristate (org.spongepowered.api.util.Tristate)1 World (org.spongepowered.api.world.World)1 ServerLocation (org.spongepowered.api.world.server.ServerLocation)1 ServerWorld (org.spongepowered.api.world.server.ServerWorld)1