Skip to content

Commit

Permalink
fix: interaction-hitbox always aligning to block-locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Oct 14, 2024
1 parent 9fb338a commit 5d1bddf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,8 +52,7 @@ object FurnitureHelpers {
rotation: Float,
center: Location,
hitbox: Set<BlockyFurniture.InteractionHitbox>
): List<Location> =
hitbox.map { i -> center.clone().add(i.offset(rotation)) }
): List<Location> = hitbox.map { i -> center.clone().plus(i.offset(rotation)) }

fun rotation(yaw: Float, nullFurniture: BlockyFurniture?): Rotation {
val furniture = nullFurniture ?: BlockyFurniture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockyPlacableOn>()?.isPlacableOn(targetBlock, blockFace) == false -> return
targetBlock.getRelative(BlockFace.DOWN).isVanillaNoteBlock -> return
Expand Down

0 comments on commit 5d1bddf

Please sign in to comment.