Search in sources :

Example 1 with WorldBorder

use of net.minecraft.world.level.border.WorldBorder in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method setWorldBorder.

@Override
public void setWorldBorder(Player player, Location center, double size, double currSize, long time, int warningDistance, int warningTime) {
    WorldBorder wb = new WorldBorder();
    wb.world = ((CraftWorld) player.getWorld()).getHandle();
    wb.setCenter(center.getX(), center.getZ());
    wb.setWarningBlocks(warningDistance);
    wb.setWarningTime(warningTime);
    if (time > 0) {
        wb.lerpSizeBetween(currSize, size, time);
    } else {
        wb.setSize(size);
    }
    send(player, new ClientboundInitializeBorderPacket(wb));
}
Also used : WorldBorder(net.minecraft.world.level.border.WorldBorder)

Example 2 with WorldBorder

use of net.minecraft.world.level.border.WorldBorder in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method resetWorldBorder.

@Override
public void resetWorldBorder(Player player) {
    WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();
    send(player, new ClientboundInitializeBorderPacket(wb));
}
Also used : WorldBorder(net.minecraft.world.level.border.WorldBorder)

Example 3 with WorldBorder

use of net.minecraft.world.level.border.WorldBorder in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method setWorldBorder.

@Override
public void setWorldBorder(Player player, Location center, double size, double currSize, long time, int warningDistance, int warningTime) {
    WorldBorder wb = new WorldBorder();
    wb.world = ((CraftWorld) player.getWorld()).getHandle();
    wb.setCenter(center.getX(), center.getZ());
    wb.setWarningBlocks(warningDistance);
    wb.setWarningTime(warningTime);
    if (time > 0) {
        wb.lerpSizeBetween(currSize, size, time);
    } else {
        wb.setSize(size);
    }
    send(player, new ClientboundInitializeBorderPacket(wb));
}
Also used : WorldBorder(net.minecraft.world.level.border.WorldBorder)

Example 4 with WorldBorder

use of net.minecraft.world.level.border.WorldBorder in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method resetWorldBorder.

@Override
public void resetWorldBorder(Player player) {
    WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();
    send(player, new ClientboundInitializeBorderPacket(wb));
}
Also used : WorldBorder(net.minecraft.world.level.border.WorldBorder)

Example 5 with WorldBorder

use of net.minecraft.world.level.border.WorldBorder in project SpongeCommon by SpongePowered.

the class SpongeTeleportHelper method getBlockLocations.

private Stream<Vector3i> getBlockLocations(ServerLocation 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.
    final WorldBorder.Settings worldBorder = (WorldBorder.Settings) worldLocation.world().properties().worldBorder();
    final double radius = worldBorder.getSize() / 2.0D;
    int worldBorderMinX = GenericMath.floor(worldBorder.getCenterX() - radius);
    int worldBorderMinZ = GenericMath.floor(worldBorder.getCenterZ() - radius);
    int worldBorderMaxX = GenericMath.floor(worldBorder.getCenterX() + radius);
    int worldBorderMaxZ = GenericMath.floor(worldBorder.getCenterZ() + radius);
    // Get the World and get the maximum Y value.
    int worldMaxY = worldLocation.world().max().y();
    Vector3i vectorLocation = worldLocation.blockPosition();
    // 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.y() - height, 0, worldMaxY);
    int maxY = GenericMath.clamp(vectorLocation.y() + height, 0, worldMaxY);
    int minX = GenericMath.clamp(vectorLocation.x() - width, worldBorderMinX, worldBorderMaxX);
    int maxX = GenericMath.clamp(vectorLocation.x() + width, worldBorderMinX, worldBorderMaxX);
    int minZ = GenericMath.clamp(vectorLocation.z() - width, worldBorderMinZ, worldBorderMaxZ);
    int maxZ = GenericMath.clamp(vectorLocation.z() + 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.y() - x.y())).thenComparing(x -> -x.y());
    // Sort them according to the distance to the provided worldLocation.
    return vectors.stream().sorted(c);
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) GenericMath(org.spongepowered.math.GenericMath) Collection(java.util.Collection) 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) TeleportHelper(org.spongepowered.api.world.teleport.TeleportHelper) TeleportHelperFilter(org.spongepowered.api.world.teleport.TeleportHelperFilter) List(java.util.List) Stream(java.util.stream.Stream) TeleportHelperFilters(org.spongepowered.api.world.teleport.TeleportHelperFilters) WorldBorder(net.minecraft.world.level.border.WorldBorder) World(org.spongepowered.api.world.World) Map(java.util.Map) SpongeConfigs(org.spongepowered.common.applaunch.config.core.SpongeConfigs) Optional(java.util.Optional) Comparator(java.util.Comparator) Singleton(com.google.inject.Singleton) ServerLocation(org.spongepowered.api.world.server.ServerLocation) Vector3i(org.spongepowered.math.vector.Vector3i) WorldBorder(net.minecraft.world.level.border.WorldBorder) Vector3i(org.spongepowered.math.vector.Vector3i) ArrayList(java.util.ArrayList)

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