Search in sources :

Example 6 with IntVector3

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

the class DataWatcherTest method testEnderCrystalBeamTarget.

@Test
public void testEnderCrystalBeamTarget() {
    if (!EntityEnderCrystalHandle.T.isAvailable()) {
        return;
    }
    DataWatcher dataWatcher = new DataWatcher();
    // DATA_BEAM_TARGET
    dataWatcher.set(EntityEnderCrystalHandle.DATA_BEAM_TARGET, new IntVector3(5, 6, 7));
    assertEquals(new IntVector3(5, 6, 7), dataWatcher.get(EntityEnderCrystalHandle.DATA_BEAM_TARGET));
}
Also used : IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) DataWatcher(com.bergerkiller.bukkit.common.wrappers.DataWatcher) Test(org.junit.Test)

Example 7 with IntVector3

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

the class OctreeTest method testIteratorSelectSibling.

@Test
public void testIteratorSelectSibling() {
    // Tests a very specific edge case where, while trying to find a value,
    // it first runs into a direct sibling of the value. This causes the algorithm
    // to look for a sibling at depth=0 which has some interesting consequences.
    IntVector3 block = new IntVector3(1, 0, 0);
    Octree<String> tree = new Octree<String>();
    tree.put(block.x, block.y, block.z, "A");
    tree.put(block.x, block.y, block.z + 1, "B");
    tree.put(block.x, block.y + 1, block.z, "C");
    OctreeIterator<String> iter = tree.cuboid(block, block.add(1, 1, 0)).iterator();
    assertNext(iter, "A", block.x, block.y, block.z);
    assertNext(iter, "C", block.x, block.y + 1, block.z);
    assertFalse(iter.hasNext());
}
Also used : Octree(com.bergerkiller.bukkit.common.collections.octree.Octree) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) Test(org.junit.Test)

Example 8 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 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 9 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 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 10 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 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)

Aggregations

IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)27 HashSet (java.util.HashSet)9 IntVector2 (com.bergerkiller.bukkit.common.bases.IntVector2)6 Chunk (org.bukkit.Chunk)5 BlockFace (org.bukkit.block.BlockFace)4 Test (org.junit.Test)4 MapUUID (com.bergerkiller.bukkit.common.map.util.MapUUID)3 WorldHandle (com.bergerkiller.generated.net.minecraft.world.level.WorldHandle)3 File (java.io.File)3 UUID (java.util.UUID)3 World (org.bukkit.World)3 BlockLocation (com.bergerkiller.bukkit.common.BlockLocation)2 Octree (com.bergerkiller.bukkit.common.collections.octree.Octree)2 CommonTagCompound (com.bergerkiller.bukkit.common.nbt.CommonTagCompound)2 BlockData (com.bergerkiller.bukkit.common.wrappers.BlockData)2 EntityPlayerHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityPlayerHandle)2 BitSet (java.util.BitSet)2 Random (java.util.Random)2 Set (java.util.Set)2 ItemFrame (org.bukkit.entity.ItemFrame)2