Search in sources :

Example 26 with IntVector3

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

the class RegionHandler_Vanilla_1_14 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));
    // 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) {
                IntVector3 coords = getRegionFileCoordinates(file).toIntVector3(0);
                if (coords != null && !regionIndices.contains(coords)) {
                    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 : Chunk(org.bukkit.Chunk) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) File(java.io.File) HashSet(java.util.HashSet)

Example 27 with IntVector3

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

the class ChunkBlockStateChangeConverter method convertInput.

@Override
public BlockStateChange convertInput(Object value) {
    final ClientboundLevelChunkPacketDataHandle.BlockEntityDataHandle handle;
    handle = ClientboundLevelChunkPacketDataHandle.BlockEntityDataHandle.createHandle(value);
    // Deferred readout of metadata for performance, as we're using reflection
    IntVector3 position = handle.getPosition(this.chunkX, this.chunkZ);
    BlockStateType type = handle.getType();
    CommonTagCompound initialMetadata = handle.getTag();
    if (initialMetadata != null) {
        // Constant value
        return BlockStateChange.deferred(position, type, LogicUtil.constantSupplier(initialMetadata), () -> true);
    } else {
        // Initialize when first called
        final DeferredSupplier<CommonTagCompound> metadataSupplier = DeferredSupplier.of(() -> {
            CommonTagCompound metadata = new CommonTagCompound();
            handle.setTag(metadata);
            return metadata;
        });
        return BlockStateChange.deferred(position, type, metadataSupplier, metadataSupplier::isInitialized);
    }
}
Also used : BlockStateType(com.bergerkiller.bukkit.common.resources.BlockStateType) CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) ClientboundLevelChunkPacketDataHandle(com.bergerkiller.generated.net.minecraft.network.protocol.game.ClientboundLevelChunkPacketDataHandle) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

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