Skip to content

Commit

Permalink
fix furniture-position before spawning, drop setRotation, fix scaling…
Browse files Browse the repository at this point in the history
… & brightness issues
  • Loading branch information
Boy0000 committed Oct 20, 2023
1 parent b1171c8 commit 10e381a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data class BlockyFurniture(
@SerialName("blocky:furniture_properties")
data class FurnitureProperties(
val displayTransform: ItemDisplayTransform = ItemDisplayTransform.NONE,
val scale: @Serializable(Vector3fSerializer::class) Vector3f? = null,
val scale: @Serializable(Vector3fSerializer::class) Vector3f = Vector3f(1f, 1f, 1f),
val displayWidth: Float = 0f,
val displayHeight: Float = 0f,
val viewRange: Float? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object BlockStateCorrection {

private fun getBlockHitResult(player: Player, block: Block, blockFace: BlockFace): BlockHitResult? {
val vec3 = player.eyeLocation.let { Vec3(it.x, it.y, it.z) }
val direction = Direction.values().find { it.name == blockFace.name } ?: return null
val direction = Direction.entries.find { it.name == blockFace.name } ?: return null
return BlockHitResult(vec3, direction.opposite, block.toBlockPos().relative(direction), false)
}
}
30 changes: 11 additions & 19 deletions src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object FurnitureHelpers {
center: Location,
hitbox: List<BlockyFurniture.CollisionHitbox>
): Map<BlockyFurniture.CollisionHitboxType, List<Location>> =
BlockyFurniture.CollisionHitboxType.values().associateWith {
BlockyFurniture.CollisionHitboxType.entries.associateWith {
hitbox.filter { c -> c.type == it }.map { c -> c.location.groundRotate(rotation).add(center) }
}

Expand All @@ -56,10 +56,10 @@ object FurnitureHelpers {
val id = (((Location.normalizeYaw(yaw) + 180) * 8 / 360 + 0.5).toInt() % 8).apply {
if (furniture.hasStrictRotation && this % 2 != 0) this - rotationDegree
}
return Rotation.values()[id]
return Rotation.entries[id].rotateClockwise().rotateClockwise()
}

fun getYaw(rotation: Rotation) = listOf(*Rotation.values()).indexOf(rotation) * 360f / 8f
fun getYaw(rotation: Rotation) = Rotation.entries.indexOf(rotation) * 360f / 8f

fun hasEnoughSpace(blockyFurniture: BlockyFurniture, loc: Location, yaw: Float): Boolean {
return if (blockyFurniture.collisionHitbox.isEmpty()) true
Expand All @@ -85,7 +85,13 @@ object FurnitureHelpers {
?: (this as? MapMeta)?.setColor((itemStack.itemMeta as? MapMeta)?.color) ?: return@editItemMeta
}

val newFurniture = loc.toBlockCenterLocation().spawn<ItemDisplay> {
val spawnLoc = loc.clone().toBlockCenterLocation().apply {
if (furniture.properties.displayTransform == NONE) this.y += 0.5 * furniture.properties.scale.y
this.yaw = getYaw(getRotation(yaw, furniture))
this.pitch = if (furniture.properties.displayTransform == FIXED) 90f else 0f
}

val newFurniture = spawnLoc.spawn<ItemDisplay> {
isPersistent = true

furniture.properties.let { properties ->
Expand All @@ -97,21 +103,7 @@ object FurnitureHelpers {
properties.viewRange?.let { viewRange = it }
properties.shadowRadius?.let { shadowRadius = it }
properties.shadowStrength?.let { shadowStrength = it }

val isFixed = itemDisplayTransform == FIXED
transformation = transformation.apply {
scale.set(properties.scale ?: if (isFixed) Vector3f(0.5f, 0.5f, 0.5f) else Vector3f(1f, 1f, 1f))
}

val (newYaw, newPitch) = when {
isFixed -> getYaw(getRotation(yaw, furniture)) - 180 to -90f
else -> yaw to 0f
}

// NONE spawns into the ground, so we teleport it up
// Rotation therefore doesn't always apply due to teleportAsync, so apply yaw/pitch to loc
if (itemDisplayTransform == NONE) teleportAsync(loc.toCenterLocation().apply { this.yaw = newYaw; this.pitch = newPitch })
else setRotation(newYaw, newPitch)
transformation = transformation.apply { scale.set(properties.scale) }
}
this.itemStack = furnitureItem
} ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BlockyWireListener : Listener {
block.state.update(true, false)
}

BlockFace.values().filter { it.isCardinal }.forEach { f ->
BlockFace.entries.filter { it.isCardinal }.forEach { f ->
val changed = block.getRelative(f)
if (changed.type != Material.TRIPWIRE) return@forEach

Expand Down

0 comments on commit 10e381a

Please sign in to comment.