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));
}
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());
}
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;
}
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;
}
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;
}
Aggregations