diff --git a/gradle.properties b/gradle.properties index d752784..5990f45 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_build=8 loader_version=0.16.10 # Mod Properties -mod_version=1.14.6 +mod_version=1.14.7 maven_group=net.mcbrawls mod_id=blueprint diff --git a/src/main/kotlin/net/mcbrawls/blueprint/anchor/Anchor.kt b/src/main/kotlin/net/mcbrawls/blueprint/anchor/Anchor.kt index 4173c73..966eb6d 100644 --- a/src/main/kotlin/net/mcbrawls/blueprint/anchor/Anchor.kt +++ b/src/main/kotlin/net/mcbrawls/blueprint/anchor/Anchor.kt @@ -4,6 +4,12 @@ import com.mojang.serialization.Codec import com.mojang.serialization.codecs.RecordCodecBuilder import dev.andante.codex.ExtraCodecs import dev.andante.codex.nullableFieldOf +import net.minecraft.block.BlockState +import net.minecraft.entity.Entity +import net.minecraft.entity.EntityType +import net.minecraft.entity.SpawnReason +import net.minecraft.server.world.ServerWorld +import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec2f import net.minecraft.util.math.Vec3d @@ -15,6 +21,20 @@ data class Anchor( val rotation: Vec2f, val data: String? = null, ) { + fun placeBlock(world: ServerWorld, state: BlockState) { + val pos = BlockPos.ofFloored(position) + world.setBlockState(pos, state) + } + + fun placeEntity(world: ServerWorld, type: EntityType, builder: (entity: T, data: String?) -> Unit = { _, _ -> }) { + type.create(world, SpawnReason.CHUNK_GENERATION)?.also { entity -> + entity.setPosition(position) + entity.rotate(rotation.x, rotation.y) + builder.invoke(entity, data) + world.spawnEntity(entity) + } + } + companion object { val CODEC: Codec = RecordCodecBuilder.create { instance -> instance.group(