Fix not being able to place face devices by right-clicking non-full blocks

This commit is contained in:
Shadowfacts 2021-12-23 14:39:56 -05:00
parent b2e794e5a4
commit b416f98ef6
1 changed files with 10 additions and 1 deletions

View File

@ -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