use of org.spongepowered.common.accessor.world.level.block.entity.BlockEntityAccessor in project SpongeCommon by SpongePowered.
the class VolumeStreamUtils method getBlockEntityOrCloneToBackingVolume.
@NonNull
public static BiConsumer<BlockPos, net.minecraft.world.level.block.entity.BlockEntity> getBlockEntityOrCloneToBackingVolume(final boolean shouldCarbonCopy, final ObjectArrayMutableBlockEntityBuffer backingVolume, @Nullable final Level level) {
return shouldCarbonCopy ? (pos, tile) -> {
final CompoundTag nbt = tile.save(new CompoundTag());
final net.minecraft.world.level.block.entity.@Nullable BlockEntity cloned = tile.getType().create();
final BlockState state = tile.getBlockState();
Objects.requireNonNull(cloned, () -> String.format("TileEntityType[%s] creates a null TileEntity!", BlockEntityType.getKey(tile.getType()))).load(state, nbt);
if (level != null) {
((BlockEntityAccessor) cloned).accessor$level(level);
}
backingVolume.addBlockEntity(pos.getX(), pos.getY(), pos.getZ(), (BlockEntity) cloned);
} : (pos, tile) -> {
};
}
Aggregations