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