Skip to content

Commit

Permalink
fix(anchors): swapped yaw/pitch & anchors not spawning in editor worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jan 13, 2025
1 parent f48c486 commit a59c1d4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 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=8
loader_version=0.16.10

# Mod Properties
mod_version=1.14.4
mod_version=1.14.5
maven_group=net.mcbrawls
mod_id=blueprint

Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/net/mcbrawls/blueprint/entity/AnchorEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import net.minecraft.world.World
import xyz.nucleoid.packettweaker.PacketContext

class AnchorEntity(type: EntityType<*>, world: World) : InteractionEntity(type, world), PolymerEntity {
var id: String? = null
var anchorId: String? = null
var data: String? = null

init {
Expand Down Expand Up @@ -66,8 +66,8 @@ class AnchorEntity(type: EntityType<*>, world: World) : InteractionEntity(type,

fun openAnchorIdEditor(player: ServerPlayerEntity) {
openInputGui(player, Text.literal("Set Anchor ID").formatted(Formatting.BOLD), getOrCreateId(), "anchor ID") { input, dataName ->
id = input.trim()
player.sendMessage(Text.literal("Set $dataName: \"$id\"").formatted(Formatting.GREEN))
anchorId = input.trim()
player.sendMessage(Text.literal("Set $dataName: \"$anchorId\"").formatted(Formatting.GREEN))
}
}

Expand All @@ -82,38 +82,38 @@ class AnchorEntity(type: EntityType<*>, world: World) : InteractionEntity(type,
discard()

if (attacker is ServerPlayerEntity) {
attacker.sendMessage(Text.literal("Removed anchor: id \"$id\", data \"$data\"").formatted(Formatting.RED))
attacker.sendMessage(Text.literal("Removed anchor: id \"$anchorId\", data \"$data\"").formatted(Formatting.RED))
}

return false
}

fun createAnchor(root: BlockPos): Anchor {
return Anchor(pos.subtract(Vec3d.of(root)), Vec2f(pitch, yaw), data)
return Anchor(pos.subtract(Vec3d.of(root)), Vec2f(yaw, pitch), data)
}

/**
* Gets the stored identifier or creates one from the entity's world key and position.
* @return an anchor id
*/
fun getOrCreateId(): String {
id?.also { return it }
anchorId?.also { return it }

return Blueprint.Companion.createUniqueId(world ?: throw IllegalStateException("World not set"), pos)
}

override fun writeCustomDataToNbt(nbt: NbtCompound) {
super.writeCustomDataToNbt(nbt)

id?.also { nbt.putString(ANCHOR_ID_KEY, it) }
anchorId?.also { nbt.putString(ANCHOR_ID_KEY, it) }
data?.also { nbt.putString(DATA_KEY, it) }
}

override fun readCustomDataFromNbt(nbt: NbtCompound) {
super.readCustomDataFromNbt(nbt)

if (nbt.contains(ANCHOR_ID_KEY, NbtElement.STRING_TYPE.toInt())) {
id = nbt.getString(ANCHOR_ID_KEY)
anchorId = nbt.getString(ANCHOR_ID_KEY)
}

if (nbt.contains(DATA_KEY, NbtElement.STRING_TYPE.toInt())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ object BlueprintEntityTypes {
.dimensions(0.3f, 0.3f)
.maxTrackingRange(2)
.trackingTickInterval(10)
.disableSaving()
.disableSummon()
)

Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/net/mcbrawls/blueprint/item/AnchorItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class AnchorItem(settings: Settings) : Item(settings), PolymerItem {
return ActionResult.PASS
}

BlueprintEntityTypes.ANCHOR.create(world, SpawnReason.COMMAND)?.also { anchorEntity ->
anchorEntity.setPosition(context.hitPos)
anchorEntity.rotate(context.playerYaw, 0.0f)
world.spawnEntity(anchorEntity)
anchorEntity.openAnchorIdEditor(player)
BlueprintEntityTypes.ANCHOR.create(world, SpawnReason.SPAWN_ITEM_USE)?.also { entity ->
entity.setPosition(context.hitPos)
entity.rotate(context.playerYaw, 0.0f)
world.spawnEntity(entity)
entity.openAnchorIdEditor(player)

return ActionResult.SUCCESS
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/net/mcbrawls/blueprint/structure/Blueprint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ data class Blueprint(

fun placeAnchors(world: ServerWorld, pos: BlockPos) {
anchors.forEach { (id, anchor) ->
BlueprintEntityTypes.ANCHOR.create(world, SpawnReason.COMMAND)?.also { anchorEntity ->
anchorEntity.id = id
anchorEntity.data = anchor.data
anchorEntity.setPosition(anchor.position.add(Vec3d.of(pos)))
anchorEntity.rotate(anchor.rotation.x, anchor.rotation.y)
world.spawnEntity(anchorEntity)
BlueprintEntityTypes.ANCHOR.create(world, SpawnReason.CHUNK_GENERATION)?.also { entity ->
entity.anchorId = id
entity.data = anchor.data
entity.setPosition(anchor.position.add(Vec3d.of(pos)))
entity.rotate(anchor.rotation.x, anchor.rotation.y)
world.spawnEntity(entity)
}
}
}
Expand Down

0 comments on commit a59c1d4

Please sign in to comment.