diff --git a/src/main/kotlin/net/shadowfacts/phycon/item/FaceDeviceBlockItem.kt b/src/main/kotlin/net/shadowfacts/phycon/item/FaceDeviceBlockItem.kt index f8f010d..028ba50 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/item/FaceDeviceBlockItem.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/item/FaceDeviceBlockItem.kt @@ -2,11 +2,14 @@ package net.shadowfacts.phycon.item import net.minecraft.block.BlockState import net.minecraft.item.ItemPlacementContext +import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Direction import net.shadowfacts.phycon.block.FaceDeviceBlock import net.shadowfacts.phycon.block.cable.CableBlock import net.shadowfacts.phycon.init.PhyBlocks import net.shadowfacts.phycon.util.CableConnection +import kotlin.math.floor +import kotlin.math.roundToInt /** * @author shadowfacts @@ -18,8 +21,14 @@ class FaceDeviceBlockItem(block: FaceDeviceBlock<*>, settings: Settings = Settin val hitBlock = hitState.block if (hitBlock is CableBlock) { val hitBlockEdge = context.hitPos.getComponentAlongAxis(context.side.axis) % 1 == 0.0 + val hitBlockBeingPlacedIn = floor(context.hitPos.getComponentAlongAxis(context.side.axis)).toInt() == context.blockPos.getComponentAlongAxis(context.side.axis) - val placementSide = if (hitBlockEdge) context.side.opposite else context.side + val placementSide: Direction = + if (hitBlockEdge xor hitBlockBeingPlacedIn) { + context.side + } else { + context.side.opposite + } if (hitState[CableBlock.CONNECTIONS[placementSide]] != CableConnection.ON) { var connection = FaceDeviceBlock.FaceCableConnection.NONE