Skip to content

Commit 4dbb063

Browse files
committed
Fix disconnection issues
1 parent 8752f1c commit 4dbb063

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlock.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import com.simibubi.create.foundation.block.IBE
66
import com.simibubi.create.foundation.utility.Iterate
77
import net.minecraft.core.BlockPos
88
import net.minecraft.core.Direction
9+
import net.minecraft.world.InteractionHand
10+
import net.minecraft.world.InteractionResult
11+
import net.minecraft.world.entity.player.Player
12+
import net.minecraft.world.item.ItemStack
913
import net.minecraft.world.item.context.BlockPlaceContext
1014
import net.minecraft.world.level.Level
1115
import net.minecraft.world.level.block.Block
1216
import net.minecraft.world.level.block.DirectionalBlock
1317
import net.minecraft.world.level.block.entity.BlockEntityType
1418
import net.minecraft.world.level.block.state.BlockState
1519
import net.minecraft.world.level.block.state.StateDefinition
20+
import net.minecraft.world.phys.BlockHitResult
1621
import org.valkyrienskies.clockwork.ClockworkBlockEntities
1722
import org.valkyrienskies.clockwork.content.logistics.gas.INodeBlock
1823

@@ -85,4 +90,19 @@ class ExtendonBlock(properties: Properties) : DirectionalBlock(properties), IBE<
8590
override fun getBlockEntityType(): BlockEntityType<out ExtendonBlockEntity> {
8691
return ClockworkBlockEntities.EXTENDON.get()
8792
}
93+
94+
override fun use(
95+
state: BlockState,
96+
level: Level,
97+
pos: BlockPos,
98+
player: Player,
99+
hand: InteractionHand,
100+
hit: BlockHitResult
101+
): InteractionResult {
102+
103+
val be = level.getBlockEntity(pos) as? ExtendonBlockEntity? ?: return super.use(state, level, pos, player, hand, hit)
104+
if (player.getItemInHand(hand) == ItemStack.EMPTY) be.disconnect()
105+
106+
return super.use(state, level, pos, player, hand, hit)
107+
}
88108
}

common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlockEntity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block
5252
override fun tick() {
5353
super.tick()
5454

55+
5556
if (level!!.isClientSide) return
5657

5758
if (connectedBe == null || connectedJoint == null || distanceJoint == null || distanceJointId == null || !main) return
@@ -98,14 +99,14 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block
9899
if (connectedJoint == null) return
99100

100101
if (connectedBe!!.edge == null) edge = null
101-
else removeEdge()
102+
else if (edge != null) removeEdge()
102103

103104
if (connectedBe!!.distanceJoint == null) {
104105
distanceJoint = null
105106
distanceJointId = null
106107
sphericalJoint = null
107108
sphericalJointId = null
108-
} else removeJoint()
109+
} else if (distanceJointId != null) removeJoint()
109110

110111
connectedBe = null
111112
main = false
@@ -201,7 +202,7 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block
201202
connectedBe = level?.getBlockEntity(BlockPos(compound.getInt("ConnectedPosX"),compound.getInt("ConnectedPosY"),compound.getInt("ConnectedPosZ"))) as? ExtendonBlockEntity
202203
connectedJoint = connectedBe
203204
main = compound.getBoolean("IsMain")
204-
}
205+
} else disconnect()
205206

206207
super.read(compound, clientPacket)
207208
}

0 commit comments

Comments
 (0)