Search in sources :

Example 1 with IntVector2

use of com.bergerkiller.bukkit.common.bases.IntVector2 in project BKCommonLib by bergerhealer.

the class MCSDBubbleFormat method writeSlice.

private void writeSlice(int z, BitOutputStream stream) throws IOException {
    // Split all found coordinates in edge points, intersections and lines
    // First optimize the order of rendering from the edge points
    // Then try to optimize the order of the remaining intersections
    // Then finally, try to optimize the order in which lines are drawn
    boolean[] cells = this.strands[z];
    List<IntVector2> edges = new ArrayList<IntVector2>();
    List<IntVector2> intersects = new ArrayList<IntVector2>();
    List<IntVector2> lines = new ArrayList<IntVector2>();
    {
        boolean[] data3x3 = new boolean[9];
        int index = 0;
        for (int y = 0; y < 256; y++) {
            for (int x = 0; x < 256; x++) {
                if (!cells[index++]) {
                    continue;
                }
                IntVector2 coord = new IntVector2(x, y);
                int n = 0;
                for (int dy = -1; dy <= 1; dy++) {
                    for (int dx = -1; dx <= 1; dx++) {
                        int mx = coord.x + dx;
                        int my = coord.z + dy;
                        if (mx < 0 || my < 0 || mx >= 256 || my >= 256) {
                            data3x3[n++] = false;
                        } else {
                            data3x3[n++] = cells[mx | (my << 8)];
                        }
                    }
                }
                if (MCSDWebbingCodec.EDGE_PATTERN.matches(data3x3)) {
                    edges.add(coord);
                } else if (MCSDWebbingCodec.LINE_PATTERN.matches(data3x3)) {
                    lines.add(coord);
                } else {
                    intersects.add(coord);
                }
            }
        }
    }
    Logging.LOGGER_MAPDISPLAY.info("Processing z=" + z + ", " + edges.size() + " edges, " + intersects.size() + " intersects, " + lines.size() + " lines");
    MCSDWebbingCodec codec = new MCSDWebbingCodec();
    codec.reset(cells, true);
    codec.processBest(edges, max_iterations);
    codec.processBest(intersects, max_iterations);
    codec.processBest(lines, max_iterations);
    codec.writePackets(stream);
}
Also used : ArrayList(java.util.ArrayList) IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2)

Example 2 with IntVector2

use of com.bergerkiller.bukkit.common.bases.IntVector2 in project BKCommonLib by bergerhealer.

the class RegionHandler_CubicChunks_1_12_2 method getRegions3.

@Override
public Set<IntVector3> getRegions3(World world) {
    // First try using the ICubicStorage API, if available
    {
        Object worldHandle = HandleConversion.toWorldHandle(world);
        Object chunkProviderServer = WorldServerHandle.T.getChunkProviderServer.raw.invoke(worldHandle);
        final Set<IntVector3> regionIndices = new HashSet<>();
        if (handle.forEachCube(chunkProviderServer, wrap(cubeCoordinate -> {
            regionIndices.add(new IntVector3(cubeCoordinate.x >> 5, cubeCoordinate.y >> 5, cubeCoordinate.z >> 5));
        }))) {
            return regionIndices;
        }
    }
    // Fallback for older CubicChunks versions
    // Obtain the coordinates using the files stored on disk
    Set<IntVector3> regionIndices = getWorldRegionFileCoordinates(world, c -> true);
    // Look at all loaded chunks and their cubes of the world and add the regions they are inside of
    for (Chunk chunk : world.getLoadedChunks()) {
        IntVector2 region = new IntVector2(chunk.getX() >> 5, chunk.getZ() >> 5);
        List<Integer> cubes_y = handle.getLoadedCubesY(HandleConversion.toChunkHandle(chunk));
        for (Integer y : cubes_y) {
            regionIndices.add(region.toIntVector3(y.intValue() >> 5));
        }
    }
    return regionIndices;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BitSet(java.util.BitSet) Chunk(org.bukkit.Chunk) IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

Example 3 with IntVector2

use of com.bergerkiller.bukkit.common.bases.IntVector2 in project BKCommonLib by bergerhealer.

the class RegionHandler_CubicChunks_1_12_2 method getRegions3ForXZ.

@Override
public Set<IntVector3> getRegions3ForXZ(World world, Set<IntVector2> regionXZCoordinates) {
    // First try using the ICubicStorage API, if available
    {
        Object worldHandle = HandleConversion.toWorldHandle(world);
        Object chunkProviderServer = WorldServerHandle.T.getChunkProviderServer.raw.invoke(worldHandle);
        final Set<IntVector3> regionIndices = new HashSet<>();
        if (handle.forEachCube(chunkProviderServer, wrap(cubeCoordinate -> {
            IntVector2 regionXZ = new IntVector2(cubeCoordinate.x >> 5, cubeCoordinate.z >> 5);
            if (regionXZCoordinates.contains(regionXZ)) {
                regionIndices.add(regionXZ.toIntVector3(cubeCoordinate.y >> 5));
            }
        }))) {
            return regionIndices;
        }
    }
    // Obtain the coordinates using the files stored on disk
    Set<IntVector3> regionIndices = getWorldRegionFileCoordinates(world, c -> {
        return regionXZCoordinates.contains(c.toIntVector2());
    });
    // Look at all loaded chunks and their cubes of the world and add the regions they are inside of
    for (Chunk chunk : world.getLoadedChunks()) {
        // Check region is filtered
        IntVector2 region = new IntVector2(chunk.getX() >> 5, chunk.getZ() >> 5);
        if (!regionXZCoordinates.contains(region)) {
            continue;
        }
        List<Integer> cubes_y = handle.getLoadedCubesY(HandleConversion.toChunkHandle(chunk));
        for (Integer y : cubes_y) {
            regionIndices.add(region.toIntVector3(y.intValue() >> 5));
        }
    }
    return regionIndices;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BitSet(java.util.BitSet) IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2) Chunk(org.bukkit.Chunk) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

Example 4 with IntVector2

use of com.bergerkiller.bukkit.common.bases.IntVector2 in project BKCommonLib by bergerhealer.

the class RegionHandler_Vanilla_1_15 method getRegions3.

@Override
public Set<IntVector3> getRegions3(World world) {
    HashSet<IntVector3> regionIndices = new HashSet<IntVector3>();
    // Add all RegionFile instances in the cache
    Object regionFileCache = findRegionFileCache.invoke(null, HandleConversion.toWorldHandle(world));
    regionIndices.addAll(findCacheRegionFileCoordinates.invoke(null, regionFileCache));
    // Figure out the minimum/maximum region y coordinate
    // Since Minecraft 1.17 there can be more than one region (32 chunks) vertically
    WorldHandle worldHandle = WorldHandle.fromBukkit(world);
    int minRegionY = worldHandle.getMinBuildHeight() >> 9;
    int maxRegionY = (worldHandle.getMaxBuildHeight() - 1) >> 9;
    // Obtain the region coordinates from all files in regions folder
    File regionFolder = Common.SERVER.getWorldRegionFolder(world.getName());
    if (regionFolder != null) {
        String[] regionFileNames = regionFolder.list();
        for (String regionFileName : regionFileNames) {
            File file = new File(regionFolder, regionFileName);
            if (file.isFile() && file.exists() && file.length() >= 4096) {
                IntVector2 coords = getRegionFileCoordinates(file);
                if (coords != null) {
                    for (int ry = minRegionY; ry <= maxRegionY; ry++) {
                        regionIndices.add(coords.toIntVector3(ry));
                    }
                }
            }
        }
    }
    // Look at all loaded chunks of the world and add the regions they are inside of
    for (Chunk chunk : world.getLoadedChunks()) {
        IntVector2 coords = new IntVector2(chunk.getX() >> 5, chunk.getZ() >> 5);
        for (int ry = minRegionY; ry <= maxRegionY; ry++) {
            regionIndices.add(coords.toIntVector3(ry));
        }
    }
    return regionIndices;
}
Also used : WorldHandle(com.bergerkiller.generated.net.minecraft.world.level.WorldHandle) IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2) Chunk(org.bukkit.Chunk) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with IntVector2

use of com.bergerkiller.bukkit.common.bases.IntVector2 in project BKCommonLib by bergerhealer.

the class RegionHandler_Vanilla_1_8 method getRegions3.

@Override
public Set<IntVector3> getRegions3(World world) {
    // Obtain the region file names
    Set<File> regionFiles = new HashSet<File>();
    File regionFolder = Common.SERVER.getWorldRegionFolder(world.getName());
    if (regionFolder != null) {
        String[] regionFileNames = regionFolder.list();
        for (String regionFileName : regionFileNames) {
            File file = new File(regionFolder, regionFileName);
            if (file.isFile() && file.exists() && file.length() >= 4096) {
                regionFiles.add(file);
            }
        }
    }
    // Synchronized, since we are going to iterate the files here...unsafe not to do so!
    synchronized (regionFileCacheType) {
        for (File regionFile : getCache().keySet()) {
            if (regionFile != null && regionFile.getParentFile().equals(regionFolder)) {
                regionFiles.add(regionFile);
            }
        }
    }
    // Parse all found files into the region x and z coordinates
    HashSet<IntVector3> regionIndices = new HashSet<IntVector3>();
    for (File file : regionFiles) {
        IntVector2 regionFileCoordinates = getRegionFileCoordinates(file);
        if (regionFileCoordinates == null) {
            continue;
        }
        IntVector3 coords = regionFileCoordinates.toIntVector3(0);
        if (coords != null) {
            regionIndices.add(coords);
        }
    }
    // Look at all loaded chunks of the world and add the regions they are inside of
    for (Chunk chunk : world.getLoadedChunks()) {
        IntVector3 coords = new IntVector3(chunk.getX() >> 5, 0, chunk.getZ() >> 5);
        regionIndices.add(coords);
    }
    return regionIndices;
}
Also used : IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2) Chunk(org.bukkit.Chunk) File(java.io.File) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) HashSet(java.util.HashSet)

Aggregations

IntVector2 (com.bergerkiller.bukkit.common.bases.IntVector2)13 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)6 HashSet (java.util.HashSet)6 Chunk (org.bukkit.Chunk)5 ArrayList (java.util.ArrayList)4 WorldHandle (com.bergerkiller.generated.net.minecraft.world.level.WorldHandle)2 File (java.io.File)2 BitSet (java.util.BitSet)2 Set (java.util.Set)2 BitOutputStream (com.bergerkiller.bukkit.common.io.BitOutputStream)1 BitPacket (com.bergerkiller.bukkit.common.io.BitPacket)1 ItemFrameInfo (com.bergerkiller.bukkit.common.map.binding.ItemFrameInfo)1 OfflineWorld (com.bergerkiller.bukkit.common.offline.OfflineWorld)1 IntHashMap (com.bergerkiller.bukkit.common.wrappers.IntHashMap)1 OutputTypeMap (com.bergerkiller.mountiplex.reflection.util.OutputTypeMap)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1