Search in sources :

Example 1 with BlockStateType

use of com.bergerkiller.bukkit.common.resources.BlockStateType 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)1 CommonTagCompound (com.bergerkiller.bukkit.common.nbt.CommonTagCompound)1 BlockStateType (com.bergerkiller.bukkit.common.resources.BlockStateType)1 ClientboundLevelChunkPacketDataHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.ClientboundLevelChunkPacketDataHandle)1