diff --git a/gradle.properties b/gradle.properties index 217b323..c7de4bc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_build=3 loader_version=0.15.11 # Mod Properties -mod_version=1.4.1 +mod_version=1.5.0 maven_group=net.mcbrawls mod_id=blueprint diff --git a/src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt b/src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt index 8279c77..20c7d14 100644 --- a/src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt +++ b/src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt @@ -7,6 +7,8 @@ import net.minecraft.block.BlockState import net.minecraft.server.world.ServerWorld import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3i +import java.util.concurrent.CompletableFuture +import java.util.concurrent.atomic.AtomicReference import java.util.function.BiConsumer /** @@ -38,6 +40,11 @@ data class Blueprint( */ val center: Vec3i = Vec3i(size.x / 2, size.y / 2, size.z / 2) + /** + * The total amount of blocks placed from this blueprint. + */ + val totalBlocks: Int = palettedBlockStates.size + /** * Places this blueprint in the world at the given position. * @return a placed blueprint @@ -50,6 +57,28 @@ data class Blueprint( return PlacedBlueprint(this, position) } + /** + * Launches a completable future placing this blueprint in the world at the given position. + * @return a placed blueprint future and a progress provider + */ + fun placeWithProgress(world: ServerWorld, position: BlockPos): Pair, ProgressProvider> { + val progress = AtomicReference(0.0f) + + val future: CompletableFuture = CompletableFuture.supplyAsync { + var i = 0 + forEach { offset, state -> + world.setBlockState(position.add(offset), state) + i++ + } + + progress.set(i.toFloat() / totalBlocks) + + PlacedBlueprint(this, position) + } + + return future to ProgressProvider(progress::get) + } + /** * Performs the given action for every position in the blueprint. */ diff --git a/src/main/kotlin/net/mcbrawls/blueprint/structure/ProgressProvider.kt b/src/main/kotlin/net/mcbrawls/blueprint/structure/ProgressProvider.kt new file mode 100644 index 0000000..ab83775 --- /dev/null +++ b/src/main/kotlin/net/mcbrawls/blueprint/structure/ProgressProvider.kt @@ -0,0 +1,5 @@ +package net.mcbrawls.blueprint.structure + +fun interface ProgressProvider { + fun getProgress(): Float +}