Search in sources :

Example 6 with BlockVector2

use of com.sk89q.worldedit.math.BlockVector2 in project FastAsyncWorldEdit by IntellectualSites.

the class TransformRegion method polygonize.

@Override
public List<BlockVector2> polygonize(int maxPoints) {
    List<BlockVector2> origPoints = region.polygonize(maxPoints);
    List<BlockVector2> transformedPoints = new ArrayList<>();
    for (BlockVector2 vector : origPoints) {
        transformedPoints.add(transform.apply(vector.toVector3(0)).toVector2().toBlockPoint());
    }
    return transformedPoints;
}
Also used : ArrayList(java.util.ArrayList) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 7 with BlockVector2

use of com.sk89q.worldedit.math.BlockVector2 in project FastAsyncWorldEdit by IntellectualSites.

the class Polygonal2DRegionSelector method learnChanges.

@Override
public void learnChanges() {
    BlockVector2 pt = region.getPoints().get(0);
    pos1 = BlockVector3.at(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ());
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 8 with BlockVector2

use of com.sk89q.worldedit.math.BlockVector2 in project FastAsyncWorldEdit by IntellectualSites.

the class Regenerator method getChunkCoordsRegen.

// algorithms
private List<Long> getChunkCoordsRegen(Region region, int border) {
    // needs to be square num of chunks
    BlockVector3 oldMin = region.getMinimumPoint();
    BlockVector3 newMin = BlockVector3.at((oldMin.getX() >> 4 << 4) - border * 16, oldMin.getY(), (oldMin.getZ() >> 4 << 4) - border * 16);
    BlockVector3 oldMax = region.getMaximumPoint();
    BlockVector3 newMax = BlockVector3.at((oldMax.getX() >> 4 << 4) + (border + 1) * 16 - 1, oldMax.getY(), (oldMax.getZ() >> 4 << 4) + (border + 1) * 16 - 1);
    Region adjustedRegion = new CuboidRegion(newMin, newMax);
    return adjustedRegion.getChunks().stream().map(c -> BlockVector2.at(c.getX(), c.getZ())).sorted(Comparator.comparingInt(BlockVector2::getZ).thenComparingInt(// needed for RegionLimitedWorldAccess
    BlockVector2::getX)).map(c -> MathMan.pairInt(c.getX(), c.getZ())).collect(Collectors.toList());
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Arrays(java.util.Arrays) SingleThreadQueueExtent(com.fastasyncworldedit.core.queue.implementation.SingleThreadQueueExtent) BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Future(java.util.concurrent.Future) WorldEditException(com.sk89q.worldedit.WorldEditException) RegenOptions(com.sk89q.worldedit.world.RegenOptions) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Map(java.util.Map) Region(com.sk89q.worldedit.regions.Region) ExecutorService(java.util.concurrent.ExecutorService) BlockPopulator(org.bukkit.generator.BlockPopulator) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) LogManagerCompat(com.sk89q.worldedit.internal.util.LogManagerCompat) Iterator(java.util.Iterator) IChunkCache(com.fastasyncworldedit.core.queue.IChunkCache) Settings(com.fastasyncworldedit.core.configuration.Settings) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) MathMan(com.fastasyncworldedit.core.util.MathMan) List(java.util.List) Logger(org.apache.logging.log4j.Logger) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Comparator(java.util.Comparator) Pattern(com.sk89q.worldedit.function.pattern.Pattern) IChunkGet(com.fastasyncworldedit.core.queue.IChunkGet) Extent(com.sk89q.worldedit.extent.Extent) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 9 with BlockVector2

use of com.sk89q.worldedit.math.BlockVector2 in project FastAsyncWorldEdit by IntellectualSites.

the class FileSystemSnapshotDatabaseTest method setUpStatic.

@BeforeAll
static void setUpStatic() throws IOException, DataException {
    try (InputStream in = Resources.getResource("world_region.mca.gzip").openStream();
        GZIPInputStream gzIn = new GZIPInputStream(in)) {
        REGION_DATA = ByteStreams.toByteArray(gzIn);
    }
    McRegionReader reader = new McRegionReader(new ByteArrayInputStream(REGION_DATA));
    try {
        // Find the single chunk
        BlockVector2 chunkPos = IntStream.range(0, 32).mapToObj(x -> IntStream.range(0, 32).filter(z -> reader.hasChunk(x, z)).mapToObj(z -> BlockVector2.at(x, z))).flatMap(Function.identity()).findAny().orElseThrow(() -> new AssertionError("No chunk in region file."));
        ByteArrayOutputStream cap = new ByteArrayOutputStream();
        try (InputStream in = reader.getChunkInputStream(chunkPos);
            GZIPOutputStream gzOut = new GZIPOutputStream(cap)) {
            ByteStreams.copy(in, gzOut);
        }
        CHUNK_DATA = cap.toByteArray();
        CHUNK_TAG = ChunkStoreHelper.readCompoundTag(() -> new GZIPInputStream(new ByteArrayInputStream(CHUNK_DATA)));
        CHUNK_POS = chunkPos.toBlockVector3();
    } finally {
        reader.close();
    }
    TEMP_DIR = Files.createTempDirectory("worldedit-fs-snap-dbs").toRealPath();
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) IntStream(java.util.stream.IntStream) ChunkStoreHelper(com.sk89q.worldedit.world.storage.ChunkStoreHelper) GZIPInputStream(java.util.zip.GZIPInputStream) BlockVector2(com.sk89q.worldedit.math.BlockVector2) TestFactory(org.junit.jupiter.api.TestFactory) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ZonedDateTime(java.time.ZonedDateTime) DynamicNode(org.junit.jupiter.api.DynamicNode) Function(java.util.function.Function) AfterAll(org.junit.jupiter.api.AfterAll) ByteArrayInputStream(java.io.ByteArrayInputStream) BeforeAll(org.junit.jupiter.api.BeforeAll) DynamicContainer.dynamicContainer(org.junit.jupiter.api.DynamicContainer.dynamicContainer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) DataException(com.sk89q.worldedit.world.DataException) McRegionReader(com.sk89q.worldedit.world.storage.McRegionReader) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) ArchiveNioSupport(com.sk89q.worldedit.util.io.file.ArchiveNioSupport) Resources(com.google.common.io.Resources) Files(java.nio.file.Files) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Instant(java.time.Instant) ZoneId(java.time.ZoneId) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) UncheckedIOException(java.io.UncheckedIOException) ArchiveNioSupports(com.sk89q.worldedit.util.io.file.ArchiveNioSupports) FileVisitResult(java.nio.file.FileVisitResult) Stream(java.util.stream.Stream) DateTimeFormatter(java.time.format.DateTimeFormatter) ByteStreams(com.google.common.io.ByteStreams) CompoundTag(com.sk89q.jnbt.CompoundTag) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipArchiveNioSupport(com.sk89q.worldedit.util.io.file.ZipArchiveNioSupport) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) McRegionReader(com.sk89q.worldedit.world.storage.McRegionReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BlockVector2(com.sk89q.worldedit.math.BlockVector2) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with BlockVector2

use of com.sk89q.worldedit.math.BlockVector2 in project FastAsyncWorldEdit by IntellectualSites.

the class AsyncPreloader method run.

@Override
public void run() {
    FaweTimer timer = Fawe.instance().getTimer();
    if (cancelled.get()) {
        return;
    }
    if (update.isEmpty()) {
        TaskManager.taskManager().laterAsync(this, 1);
        return;
    }
    Iterator<Map.Entry<UUID, MutablePair<World, Set<BlockVector2>>>> plrIter = update.entrySet().iterator();
    while (timer.getTPS() > 18 && plrIter.hasNext()) {
        if (cancelled.get()) {
            return;
        }
        Map.Entry<UUID, MutablePair<World, Set<BlockVector2>>> entry = plrIter.next();
        MutablePair<World, Set<BlockVector2>> pair = entry.getValue();
        World world = pair.getKey();
        Set<BlockVector2> chunks = pair.getValue();
        if (chunks != null) {
            Iterator<BlockVector2> chunksIter = chunks.iterator();
            while (chunksIter.hasNext() && pair.getValue() == chunks) {
                // Ensure the queued load is still valid
                BlockVector2 chunk = chunksIter.next();
                queueLoad(world, chunk);
            }
        }
        plrIter.remove();
    }
    if (cancelled.get()) {
        return;
    }
    TaskManager.taskManager().laterAsync(this, 20);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) FaweTimer(com.fastasyncworldedit.core.util.FaweTimer) World(com.sk89q.worldedit.world.World) BlockVector2(com.sk89q.worldedit.math.BlockVector2) MutablePair(com.fastasyncworldedit.core.util.collection.MutablePair) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Aggregations

BlockVector2 (com.sk89q.worldedit.math.BlockVector2)55 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)19 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)9 Map (java.util.Map)9 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)7 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)6 LinkedHashMap (java.util.LinkedHashMap)6 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)5 Path (java.nio.file.Path)5 Iterator (java.util.Iterator)5 Set (java.util.Set)5 JsonIOException (com.google.gson.JsonIOException)4 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4 Location (com.sk89q.worldedit.util.Location)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)3 Region (com.sk89q.worldedit.regions.Region)3