Skip to content

Commit

Permalink
Fix block placing direction against Nova blocks with replaceable hitbox
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Sep 2, 2024
1 parent d5ff90d commit 7319d45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions nova/src/main/kotlin/xyz/xenondevs/nova/util/BlockUtils.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.xenondevs.nova.util

import net.kyori.adventure.text.Component
import net.minecraft.core.Direction
import net.minecraft.core.Holder
import net.minecraft.core.component.DataComponents
import net.minecraft.core.particles.ParticleTypes
Expand Down Expand Up @@ -29,6 +28,7 @@ import net.minecraft.world.phys.shapes.CollisionContext
import org.bukkit.GameMode
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.block.BlockFace
import org.bukkit.block.Campfire
import org.bukkit.block.Chest
import org.bukkit.block.Container
Expand Down Expand Up @@ -285,7 +285,14 @@ object BlockUtils {
ctx[DefaultContextParamTypes.SOURCE_LOCATION] ?: pos.location,
UUID.randomUUID(), ""
)
return placeVanillaBlock(pos, fakePlayer, itemStack, placeEffects)

return placeVanillaBlock(
pos,
ctx[DefaultContextParamTypes.CLICKED_BLOCK_FACE] ?: BlockFace.UP,
fakePlayer,
itemStack,
placeEffects
)
}
}

Expand Down Expand Up @@ -314,7 +321,7 @@ object BlockUtils {
* @param placeEffects If the place effects should be played
* @return If the item could be placed
*/
internal fun placeVanillaBlock(pos: BlockPos, player: ServerPlayer, itemStack: ItemStack, placeEffects: Boolean): Boolean {
internal fun placeVanillaBlock(pos: BlockPos, clickedFace: BlockFace, player: ServerPlayer, itemStack: ItemStack, placeEffects: Boolean): Boolean {
val nmsStack = itemStack.unwrap().copy()
val blockItem = nmsStack.item as BlockItem
val result = blockItem.place(BlockPlaceContext(UseOnContext(
Expand All @@ -324,7 +331,7 @@ object BlockUtils {
nmsStack,
BlockHitResult(
Vec3(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble()),
Direction.UP,
clickedFace.nmsDirection,
pos.nmsPos,
false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ internal object BlockPlacing : Listener {
ProtectionManager.canPlace(player, handItem, pos)
&& canPlace(player, handItem, pos, placedOn)
) {
val placed = BlockUtils.placeVanillaBlock(pos, player.serverPlayer, handItem, true)
val placed = BlockUtils.placeVanillaBlock(pos, event.blockFace, player.serverPlayer, handItem, true)
if (placed && player.gameMode != GameMode.CREATIVE) {
player.inventory.setItem(event.hand!!, handItem.apply { amount -= 1 })
}
Expand Down

0 comments on commit 7319d45

Please sign in to comment.