diff --git a/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt b/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt index dfecfad..e94a46a 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt @@ -1,6 +1,5 @@ package com.mineinabyss.blocky.components.core -import com.mineinabyss.blocky.helpers.GenericHelpers.toBlockCenterLocation import com.mineinabyss.blocky.serializers.BrightnessSerializer import com.mineinabyss.idofront.serialization.* import kotlinx.serialization.SerialName @@ -33,16 +32,16 @@ data class BlockyFurniture( val offset: @Serializable(VectorSerializer::class) Vector = Vector(), val width: Float, val height: Float, - val outline: SerializableItemStack = ItemStack(Material.GLASS).toSerializable()) { + val outline: SerializableItemStack = ItemStack(Material.GLASS).toSerializable() + ) { fun toBoundingBox(location: Location) = BoundingBox.of(location, width.times(0.7), height.times(0.7), width.times(0.7)) fun location(furniture: ItemDisplay): Location { - return furniture.location.toBlockCenterLocation().add(offset(furniture.yaw)) + return furniture.location.add(offset(furniture.yaw)) } fun offset(furnitureYaw: Float): Vector { val angleRad = Math.toRadians(furnitureYaw.toDouble()) - // Get the coordinates relative to the local y-axis val x = cos(angleRad) * offset.x + sin(angleRad) * offset.z val y = offset.y diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt index c1f1a54..0b043b8 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt @@ -11,6 +11,7 @@ import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.geary.prefabs.PrefabKey import com.mineinabyss.geary.serialization.setPersisting import com.mineinabyss.idofront.items.asColorable +import com.mineinabyss.idofront.operators.plus import com.mineinabyss.idofront.spawning.spawn import io.papermc.paper.math.Position import kotlinx.coroutines.async @@ -51,8 +52,7 @@ object FurnitureHelpers { rotation: Float, center: Location, hitbox: Set - ): List = - hitbox.map { i -> center.clone().add(i.offset(rotation)) } + ): List = hitbox.map { i -> center.clone().plus(i.offset(rotation)) } fun rotation(yaw: Float, nullFurniture: BlockyFurniture?): Rotation { val furniture = nullFurniture ?: BlockyFurniture() diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurniturePacketHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurniturePacketHelpers.kt index 1da31e2..bec0ee7 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurniturePacketHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurniturePacketHelpers.kt @@ -162,7 +162,7 @@ object FurniturePacketHelpers { add(FurnitureSubEntityPacket(entityId, addEntityPacket, metadataPacket)) } } - }.forEach { (player as CraftPlayer).handle.connection.send(ClientboundBundlePacket(listOf(it.addEntity, it.metadata))) } + }.forEach { (player as CraftPlayer).handle.connection.send(it.bundlePacket()) } } fun removeHitboxOutlinePacket(furniture: ItemDisplay) { diff --git a/src/main/kotlin/com/mineinabyss/blocky/listeners/BlockyFurnitureListener.kt b/src/main/kotlin/com/mineinabyss/blocky/listeners/BlockyFurnitureListener.kt index cd80121..abc7f54 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/listeners/BlockyFurnitureListener.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/listeners/BlockyFurnitureListener.kt @@ -83,7 +83,7 @@ class BlockyFurnitureListener : Listener { when { action != Action.RIGHT_CLICK_BLOCK || player.gameMode == GameMode.ADVENTURE -> return - !FurnitureHelpers.hasEnoughSpace(furniture, targetBlock.location, yaw) -> return + !FurnitureHelpers.hasEnoughSpace(furniture, targetBlock.location.toCenterLocation(), yaw) -> return !ProtectionLib.canBuild(player, targetBlock.location) -> return gearyEntity.get()?.isPlacableOn(targetBlock, blockFace) == false -> return targetBlock.getRelative(BlockFace.DOWN).isVanillaNoteBlock -> return