diff --git a/gradle.properties b/gradle.properties index 389fea7..32ccc9b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_build=7 loader_version=0.15.11 # Mod Properties -mod_version=1.5.3 +mod_version=1.5.4 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 51fe167..0433a1a 100644 --- a/src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt +++ b/src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt @@ -69,10 +69,8 @@ data class Blueprint( var i = 0 forEach { offset, state -> world.setBlockState(position.add(offset), state) - i++ + progress.set(++i / totalBlocks.toFloat()) } - - progress.set(i / totalBlocks.toFloat()) } PlacedBlueprint(this, position) diff --git a/src/test/kotlin/net/mcbrawls/blueprint/test/BlueprintTest.kt b/src/test/kotlin/net/mcbrawls/blueprint/test/BlueprintTest.kt index ba8588e..bbde79b 100644 --- a/src/test/kotlin/net/mcbrawls/blueprint/test/BlueprintTest.kt +++ b/src/test/kotlin/net/mcbrawls/blueprint/test/BlueprintTest.kt @@ -1,8 +1,44 @@ package net.mcbrawls.blueprint.test +import dev.andante.audience.AudienceInitializer.server import net.fabricmc.api.ModInitializer +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents +import net.mcbrawls.blueprint.BlueprintMod +import net.mcbrawls.blueprint.resource.BlueprintManager +import net.mcbrawls.blueprint.structure.ProgressProvider +import net.minecraft.server.command.CommandManager +import net.minecraft.text.Text +import net.minecraft.util.Identifier +import net.minecraft.util.math.BlockPos object BlueprintTest : ModInitializer { + private var displayedProgress: ProgressProvider? = null + override fun onInitialize() { + CommandRegistrationCallback.EVENT.register { dispatcher, _, _ -> + dispatcher.register( + CommandManager.literal("blueprint-test") + .executes { context -> + val pos = context.source.position + val blockPos = BlockPos.ofFloored(pos) + val (future, progress) = BlueprintManager[Identifier.of(BlueprintMod.MOD_ID, "test")]!!.placeWithProgress(context.source.world, blockPos) + if (displayedProgress == null) { + displayedProgress = progress + } + future.thenRun { + if (displayedProgress === progress) { + displayedProgress = null + } + } + 1 + } + ) + } + ServerTickEvents.END_SERVER_TICK.register { server -> + server.playerManager.playerList.forEach { player -> + player.actionBar(Text.literal("${displayedProgress?.getProgress()}")) + } + } } } diff --git a/src/test/resources/data/blueprint/blueprints/test.nbt b/src/test/resources/data/blueprint/blueprints/test.nbt new file mode 100644 index 0000000..a1dc86d Binary files /dev/null and b/src/test/resources/data/blueprint/blueprints/test.nbt differ