Skip to content

Commit

Permalink
Block state processor
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jul 6, 2024
1 parent fffaa16 commit c8a238d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_build=7
loader_version=0.15.11

# Mod Properties
mod_version=1.5.4
mod_version=1.5.5
maven_group=net.mcbrawls
mod_id=blueprint

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.mcbrawls.blueprint.structure

import net.minecraft.block.BlockState

/**
* Processes a block state.
*/
fun interface BlockStateProcessor {
/**
* Processes a block state.
* @return the output block state
*/
fun process(
/**
* The input block state.
*/
state: BlockState
): BlockState
}
10 changes: 6 additions & 4 deletions src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ data class Blueprint(
* Places this blueprint in the world at the given position.
* @return a placed blueprint
*/
fun place(world: ServerWorld, position: BlockPos): PlacedBlueprint {
fun place(world: ServerWorld, position: BlockPos, processor: BlockStateProcessor? = null): PlacedBlueprint {
forEach { offset, state ->
world.setBlockState(position.add(offset), state)
val trueState = processor?.process(state) ?: state
world.setBlockState(position.add(offset), trueState)
}

return PlacedBlueprint(this, position)
Expand All @@ -61,14 +62,15 @@ data class Blueprint(
* 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<CompletableFuture<PlacedBlueprint>, ProgressProvider> {
fun placeWithProgress(world: ServerWorld, position: BlockPos, processor: BlockStateProcessor? = null): Pair<CompletableFuture<PlacedBlueprint>, ProgressProvider> {
val progress = AtomicReference(0.0f)

val future: CompletableFuture<PlacedBlueprint> = CompletableFuture.supplyAsync {
synchronized(world) {
var i = 0
forEach { offset, state ->
world.setBlockState(position.add(offset), state)
val trueState = processor?.process(state) ?: state
world.setBlockState(position.add(offset), trueState)
progress.set(++i / totalBlocks.toFloat())
}
}
Expand Down

0 comments on commit c8a238d

Please sign in to comment.