Fix not being able to place face devices by right-clicking non-full blocks
This commit is contained in:
parent
b2e794e5a4
commit
b416f98ef6
|
@ -2,11 +2,14 @@ package net.shadowfacts.phycon.item
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.item.ItemPlacementContext
|
import net.minecraft.item.ItemPlacementContext
|
||||||
|
import net.minecraft.util.math.BlockPos
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||||
import net.shadowfacts.phycon.block.cable.CableBlock
|
import net.shadowfacts.phycon.block.cable.CableBlock
|
||||||
import net.shadowfacts.phycon.init.PhyBlocks
|
import net.shadowfacts.phycon.init.PhyBlocks
|
||||||
import net.shadowfacts.phycon.util.CableConnection
|
import net.shadowfacts.phycon.util.CableConnection
|
||||||
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
|
@ -18,8 +21,14 @@ class FaceDeviceBlockItem(block: FaceDeviceBlock<*>, settings: Settings = Settin
|
||||||
val hitBlock = hitState.block
|
val hitBlock = hitState.block
|
||||||
if (hitBlock is CableBlock) {
|
if (hitBlock is CableBlock) {
|
||||||
val hitBlockEdge = context.hitPos.getComponentAlongAxis(context.side.axis) % 1 == 0.0
|
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) {
|
if (hitState[CableBlock.CONNECTIONS[placementSide]] != CableConnection.ON) {
|
||||||
var connection = FaceDeviceBlock.FaceCableConnection.NONE
|
var connection = FaceDeviceBlock.FaceCableConnection.NONE
|
||||||
|
|
Loading…
Reference in New Issue