diff --git a/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlock.kt b/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlock.kt index 062b51ce3..d6f5bfa4f 100644 --- a/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlock.kt +++ b/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlock.kt @@ -6,6 +6,10 @@ import com.simibubi.create.foundation.block.IBE import com.simibubi.create.foundation.utility.Iterate import net.minecraft.core.BlockPos import net.minecraft.core.Direction +import net.minecraft.world.InteractionHand +import net.minecraft.world.InteractionResult +import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.ItemStack import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block @@ -13,6 +17,7 @@ import net.minecraft.world.level.block.DirectionalBlock import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.phys.BlockHitResult import org.valkyrienskies.clockwork.ClockworkBlockEntities import org.valkyrienskies.clockwork.content.logistics.gas.INodeBlock @@ -85,4 +90,19 @@ class ExtendonBlock(properties: Properties) : DirectionalBlock(properties), IBE< override fun getBlockEntityType(): BlockEntityType { return ClockworkBlockEntities.EXTENDON.get() } + + override fun use( + state: BlockState, + level: Level, + pos: BlockPos, + player: Player, + hand: InteractionHand, + hit: BlockHitResult + ): InteractionResult { + + val be = level.getBlockEntity(pos) as? ExtendonBlockEntity? ?: return super.use(state, level, pos, player, hand, hit) + if (player.getItemInHand(hand) == ItemStack.EMPTY) be.disconnect() + + return super.use(state, level, pos, player, hand, hit) + } } \ No newline at end of file diff --git a/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlockEntity.kt b/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlockEntity.kt index d1edae276..d55eb190b 100644 --- a/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlockEntity.kt +++ b/common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlockEntity.kt @@ -52,6 +52,7 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block override fun tick() { super.tick() + if (level!!.isClientSide) return if (connectedBe == null || connectedJoint == null || distanceJoint == null || distanceJointId == null || !main) return @@ -98,14 +99,14 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block if (connectedJoint == null) return if (connectedBe!!.edge == null) edge = null - else removeEdge() + else if (edge != null) removeEdge() if (connectedBe!!.distanceJoint == null) { distanceJoint = null distanceJointId = null sphericalJoint = null sphericalJointId = null - } else removeJoint() + } else if (distanceJointId != null) removeJoint() connectedBe = null main = false @@ -201,7 +202,7 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block connectedBe = level?.getBlockEntity(BlockPos(compound.getInt("ConnectedPosX"),compound.getInt("ConnectedPosY"),compound.getInt("ConnectedPosZ"))) as? ExtendonBlockEntity connectedJoint = connectedBe main = compound.getBoolean("IsMain") - } + } else disconnect() super.read(compound, clientPacket) }