Skip to content

Commit

Permalink
feat(anchors): placeBlock/placeEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jan 13, 2025
1 parent 4357373 commit 3f9638d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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=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

Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/net/mcbrawls/blueprint/anchor/Anchor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <T : Entity> placeEntity(world: ServerWorld, type: EntityType<T>, 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<Anchor> = RecordCodecBuilder.create { instance ->
instance.group(
Expand Down

0 comments on commit 3f9638d

Please sign in to comment.