Search in sources :

Example 1 with WorldBorder

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);
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Location(org.spongepowered.api.world.Location) Collection(java.util.Collection) GenericMath(com.flowpowered.math.GenericMath) WorldBorder(net.minecraft.world.border.WorldBorder) Set(java.util.Set) HashMap(java.util.HashMap) Sets(com.google.common.collect.Sets) Tristate(org.spongepowered.api.util.Tristate) ArrayList(java.util.ArrayList) BlockState(org.spongepowered.api.block.BlockState) TeleportHelperFilter(org.spongepowered.api.world.teleport.TeleportHelperFilter) List(java.util.List) Stream(java.util.stream.Stream) TeleportHelperFilters(org.spongepowered.api.world.teleport.TeleportHelperFilters) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) Map(java.util.Map) Optional(java.util.Optional) Comparator(java.util.Comparator) TeleportHelper(org.spongepowered.api.world.TeleportHelper) Singleton(com.google.inject.Singleton) WorldBorder(net.minecraft.world.border.WorldBorder) Vector3i(com.flowpowered.math.vector.Vector3i) ArrayList(java.util.ArrayList)

Example 2 with WorldBorder

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();
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) WorldBorder(net.minecraft.world.border.WorldBorder) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

WorldBorder (net.minecraft.world.border.WorldBorder)2 GenericMath (com.flowpowered.math.GenericMath)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 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 IBlockState (net.minecraft.block.state.IBlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockState (org.spongepowered.api.block.BlockState)1 Tristate (org.spongepowered.api.util.Tristate)1 Location (org.spongepowered.api.world.Location)1 TeleportHelper (org.spongepowered.api.world.TeleportHelper)1