Skip to content

Commit 3f40427

Browse files
authored
Merge pull request #106 from ValkyrienSkies/1.18.x/universal-joint
1.18.x/universal joint
2 parents 6292156 + d07ad76 commit 3f40427

File tree

28 files changed

+1490
-3
lines changed

28 files changed

+1490
-3
lines changed

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkBlockEntities.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.valkyrienskies.clockwork.content.kinetics.resistor.RedstoneResistorBl
4040
import org.valkyrienskies.clockwork.content.kinetics.resistor.RedstoneResistorRenderer
4141
import org.valkyrienskies.clockwork.content.kinetics.sequenced_seat.SequencedSeatBlockEntity
4242
import org.valkyrienskies.clockwork.content.kinetics.sequenced_seat.SequencedSeatRenderer
43+
import org.valkyrienskies.clockwork.content.kinetics.universal_shaft.UniversalShaftBlockEntity
4344
import org.valkyrienskies.clockwork.content.logistics.gas.backtank.GasBacktankBlockEntity
4445
import org.valkyrienskies.clockwork.content.logistics.gas.duct.DuctBlockEntity
4546
import org.valkyrienskies.clockwork.content.logistics.gas.duct.DuctRenderer
@@ -62,6 +63,8 @@ import org.valkyrienskies.clockwork.content.logistics.solid.delivery.cannon.Deli
6263
import org.valkyrienskies.clockwork.content.logistics.solid.delivery.chute.DeliveryChuteBlockEntity
6364
import org.valkyrienskies.clockwork.content.logistics.solid.delivery.frequency_slot.FrequencySlotRenderer
6465
import org.valkyrienskies.clockwork.content.logistics.solid.delivery.cannon.DeliveryCannonRenderer
66+
import org.valkyrienskies.clockwork.content.physicalities.extendon.ExtendonBlockEntity
67+
import org.valkyrienskies.clockwork.content.physicalities.extendon.ExtendonRenderer
6568
import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.ReactionWheelBlockEntity
6669
import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.ReactionWheelInstance
6770
import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.ReactionWheelRenderer
@@ -655,6 +658,39 @@ object ClockworkBlockEntities {
655658
.validBlocks(ClockworkBlocks.GAS_BACKTANK)
656659
.register()
657660

661+
@JvmField
662+
val UNIVERSAL_SHAFT: BlockEntityEntry<UniversalShaftBlockEntity> = ClockworkMod.REGISTRATE
663+
.blockEntity<UniversalShaftBlockEntity>(
664+
"universal_shaft"
665+
) { typeIn: BlockEntityType<UniversalShaftBlockEntity?>?, pos: BlockPos?, state: BlockState? ->
666+
UniversalShaftBlockEntity(
667+
typeIn,
668+
pos!!, state!!
669+
)
670+
}
671+
.validBlocks(ClockworkBlocks.UNIVERSAL_SHAFT)
672+
.register()
673+
674+
@JvmField
675+
val EXTENDON: BlockEntityEntry<ExtendonBlockEntity> = ClockworkMod.REGISTRATE
676+
.blockEntity<ExtendonBlockEntity>(
677+
"extendon"
678+
) { typeIn: BlockEntityType<ExtendonBlockEntity?>?, pos: BlockPos?, state: BlockState? ->
679+
ExtendonBlockEntity(
680+
typeIn,
681+
pos!!, state!!
682+
)
683+
}
684+
.renderer {
685+
NonNullFunction<BlockEntityRendererProvider.Context?, BlockEntityRenderer<in ExtendonBlockEntity?>> { context: BlockEntityRendererProvider.Context? ->
686+
ExtendonRenderer(
687+
context!!
688+
)
689+
}
690+
}
691+
.validBlocks(ClockworkBlocks.EXTENDON)
692+
.register()
693+
658694
@JvmStatic
659695
fun register() {
660696
}

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkBlocks.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import org.valkyrienskies.clockwork.content.curiosities.sensor.rotation.Gyroscop
4848
import org.valkyrienskies.clockwork.content.curiosities.sensor.rotation.LodefocusBlock
4949
import org.valkyrienskies.clockwork.content.kinetics.resistor.RedstoneResistorBlock
5050
import org.valkyrienskies.clockwork.content.kinetics.sequenced_seat.SequencedSeatBlock
51+
import org.valkyrienskies.clockwork.content.kinetics.universal_shaft.UniversalShaftBlock
5152
import org.valkyrienskies.clockwork.content.logistics.gas.backtank.GasBacktankBlock
5253
import org.valkyrienskies.clockwork.content.logistics.gas.generation.coal_burner.CoalBurnerBlock
5354
import org.valkyrienskies.clockwork.content.logistics.gas.duct.DuctBlock
@@ -61,6 +62,7 @@ import org.valkyrienskies.clockwork.content.logistics.solid.delivery.chute.Deliv
6162
import org.valkyrienskies.clockwork.content.physicalities.ballast.BallastBlock
6263
import org.valkyrienskies.clockwork.content.logistics.gas.pockets.nozzle.GasNozzleBlock
6364
import org.valkyrienskies.clockwork.content.logistics.gas.valve.ValveDuctBlock
65+
import org.valkyrienskies.clockwork.content.physicalities.extendon.ExtendonBlock
6466
import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.ReactionWheelBlock
6567
import org.valkyrienskies.clockwork.content.physicalities.wing.DyedWingBlockItem
6668
import org.valkyrienskies.clockwork.content.physicalities.wing.FlapBlock
@@ -864,6 +866,37 @@ object ClockworkBlocks {
864866
.build()
865867
.register()
866868

869+
@JvmField
870+
val UNIVERSAL_SHAFT: BlockEntry<UniversalShaftBlock> =
871+
REGISTRATE.block<UniversalShaftBlock>("universal_shaft") { properties: BlockBehaviour.Properties? ->
872+
UniversalShaftBlock(properties!!)
873+
}
874+
.initialProperties { SharedProperties.wooden() }
875+
.transform(TagGen.axeOrPickaxe())
876+
.properties { it.noOcclusion() }
877+
.addLayer { Supplier { RenderType.cutout() } }
878+
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
879+
.item()
880+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
881+
.build()
882+
.register()
883+
884+
@JvmField
885+
val EXTENDON: BlockEntry<ExtendonBlock> =
886+
REGISTRATE.block<ExtendonBlock>("extendon") { properties: BlockBehaviour.Properties? ->
887+
ExtendonBlock(properties!!)
888+
}
889+
.initialProperties { SharedProperties.netheriteMetal() }
890+
.transform(axeOrPickaxe())
891+
.properties { it.noOcclusion() }
892+
.addLayer { Supplier { RenderType.cutout() } }
893+
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
894+
.item()
895+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
896+
.build()
897+
.register()
898+
899+
867900
@JvmField
868901
val GAS_BACKTANK: BlockEntry<GasBacktankBlock> =
869902
REGISTRATE.block<GasBacktankBlock>("gas_backtank") { properties: BlockBehaviour.Properties? ->
@@ -879,6 +912,7 @@ object ClockworkBlocks {
879912

880913

881914

915+
882916
@JvmStatic
883917
fun register() {
884918

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkItems.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import org.valkyrienskies.clockwork.content.curiosities.tools.gravitron.Creative
1919
import org.valkyrienskies.clockwork.content.curiosities.tools.gravitron.GravitronItem
2020
import org.valkyrienskies.clockwork.content.curiosities.tools.gravitron.GravitronItemRenderer
2121
import org.valkyrienskies.clockwork.content.curiosities.tools.screwdriver.ScrewdriverItem
22+
import org.valkyrienskies.clockwork.content.kinetics.universal_shaft.UniversalShaftItem
2223
import org.valkyrienskies.clockwork.content.logistics.gas.backtank.GasBackTankItem
24+
import org.valkyrienskies.clockwork.content.physicalities.extendon.ExtendonHoseItem
2325
import org.valkyrienskies.clockwork.platform.CWItem
2426
import org.valkyrienskies.clockwork.util.builder.ClockworkRegistrate
2527
import java.util.function.Supplier
@@ -159,6 +161,22 @@ object ClockworkItems {
159161
.tag(AllItemTags.PRESSURIZED_AIR_SOURCES.tag)
160162
.register()
161163

164+
@JvmField
165+
val UNIVERSAL_SHAFT_ITEM: ItemEntry<UniversalShaftItem> =
166+
REGISTRATE.item<UniversalShaftItem>("universal_shaft_item") { properties: Item.Properties? ->
167+
UniversalShaftItem(properties!!)
168+
}
169+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
170+
.register()
171+
172+
@JvmField
173+
val EXTENDON_HOSE: ItemEntry<ExtendonHoseItem> =
174+
REGISTRATE.item<ExtendonHoseItem>("extendon_hose") { properties: Item.Properties? ->
175+
ExtendonHoseItem(properties!!)
176+
}
177+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
178+
.register()
179+
162180
@JvmStatic
163181
fun register() {
164182

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkPackets.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.valkyrienskies.clockwork.platform.api.network.C2SCWPacket
2929
import org.valkyrienskies.clockwork.platform.api.network.CWPacket
3030
import org.valkyrienskies.clockwork.platform.api.network.S2CCWPacket
3131
import org.valkyrienskies.clockwork.util.blocktype.SyncableStoragePacket
32+
import org.valkyrienskies.clockwork.util.universal_joint.UniversalJointItemPacket
3233
import java.util.function.Function
3334

3435
@Suppress("UNCHECKED_CAST")
@@ -64,8 +65,9 @@ enum class ClockworkPackets(
6465

6566
UPDATE_DUCT_EDGE(DuctEdgeSyncPacket::class.java, ::DuctEdgeSyncPacket),
6667
AIR_COMPRESSOR_PACKET(AirCompressorPacket::class.java, ::AirCompressorPacket),
67-
GAS_NOZZLE_PACKET(GasNozzlePacket::class.java, ::GasNozzlePacket)
68+
GAS_NOZZLE_PACKET(GasNozzlePacket::class.java, ::GasNozzlePacket),
6869

70+
UNIVERSAL_JOINT_ITEM_PACKET(UniversalJointItemPacket::class.java, ::UniversalJointItemPacket)
6971

7072
;
7173

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkPartials.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ object ClockworkPartials {
126126
val CANNON_BARREL = PartialModel(ClockworkMod.asResource("block/delivery_cannon/cannon_barrel"))
127127
val CANNON_BASE = PartialModel(ClockworkMod.asResource("block/delivery_cannon/cannon_base"))
128128
val CANNON_MOUNT = PartialModel(ClockworkMod.asResource("block/delivery_cannon/mount"))
129+
// region Extendon
130+
val EXTENDON_AXIS0 = PartialModel(ClockworkMod.asResource("block/extendon/axis0"))
131+
val EXTENDON_AXIS1 = PartialModel(ClockworkMod.asResource("block/extendon/axis1"))
132+
val EXTENDON_HOSE = PartialModel(ClockworkMod.asResource("block/extendon/hose"))
133+
129134
// endregion
130135

131136
val ALTIMETER_REDSTONE = PartialModel(ClockworkMod.asResource("block/alt_meter/redstone"))

common/src/main/kotlin/org/valkyrienskies/clockwork/content/contraptions/phys/bearing/PhysBearingBlockEntity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ class PhysBearingBlockEntity(type: BlockEntityType<*>?, pos: BlockPos?, state: B
527527
fun tryRefresh() {
528528
if (!isRunning || !shouldRefresh || joint == null) {return}
529529
val level = level as ServerLevel
530+
if (joint!!.joint !is VSRevoluteJoint) return
530531

531532
val (shipId00, pose0, _, pose1, maxForceTorque) = joint!!.joint as VSRevoluteJoint
532533

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.valkyrienskies.clockwork.content.kinetics.universal_shaft
2+
3+
import com.simibubi.create.content.kinetics.base.DirectionalKineticBlock
4+
import com.simibubi.create.content.kinetics.base.KineticBlock
5+
import com.simibubi.create.content.kinetics.simpleRelays.ShaftBlock
6+
import com.simibubi.create.foundation.block.IBE
7+
import net.minecraft.core.BlockPos
8+
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
13+
import net.minecraft.world.level.BlockGetter
14+
import net.minecraft.world.level.Level
15+
import net.minecraft.world.level.LevelReader
16+
import net.minecraft.world.level.block.entity.BlockEntityType
17+
import net.minecraft.world.level.block.state.BlockState
18+
import net.minecraft.world.level.block.state.properties.BlockStateProperties
19+
import net.minecraft.world.phys.BlockHitResult
20+
import org.valkyrienskies.clockwork.ClockworkBlockEntities
21+
import java.util.function.Function
22+
23+
class UniversalShaftBlock(properties: Properties?) : DirectionalKineticBlock(properties), IBE<UniversalShaftBlockEntity> {
24+
override fun getRotationAxis(state: BlockState): Direction.Axis {
25+
return state.getValue(BlockStateProperties.FACING).axis
26+
}
27+
28+
override fun getBlockEntityClass(): Class<UniversalShaftBlockEntity> {
29+
return UniversalShaftBlockEntity::class.java
30+
}
31+
32+
override fun getBlockEntityType(): BlockEntityType<out UniversalShaftBlockEntity> {
33+
return ClockworkBlockEntities.UNIVERSAL_SHAFT.get()
34+
}
35+
36+
override fun hasShaftTowards(world: LevelReader, pos: BlockPos, state: BlockState, face: Direction): Boolean {
37+
return face == state.getValue(BlockStateProperties.FACING)
38+
}
39+
40+
override fun use(
41+
state: BlockState,
42+
level: Level,
43+
pos: BlockPos,
44+
player: Player,
45+
hand: InteractionHand,
46+
hit: BlockHitResult
47+
): InteractionResult {
48+
val be = level.getBlockEntity(pos) as? UniversalShaftBlockEntity ?: return InteractionResult.PASS
49+
if (player.isShiftKeyDown && player.getItemInHand(InteractionHand.MAIN_HAND) == ItemStack.EMPTY) {
50+
be.disconnect()
51+
return InteractionResult.SUCCESS
52+
}
53+
54+
return InteractionResult.PASS
55+
}
56+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package org.valkyrienskies.clockwork.content.kinetics.universal_shaft
2+
3+
import com.simibubi.create.content.kinetics.base.IRotate
4+
import com.simibubi.create.content.kinetics.base.KineticBlockEntity
5+
import net.minecraft.core.BlockPos
6+
import net.minecraft.nbt.CompoundTag
7+
import net.minecraft.world.level.block.entity.BlockEntity
8+
import net.minecraft.world.level.block.entity.BlockEntityType
9+
import net.minecraft.world.level.block.state.BlockState
10+
import org.valkyrienskies.clockwork.util.universal_joint.IUniversalJoint
11+
12+
class UniversalShaftBlockEntity(typeIn: BlockEntityType<*>?, pos: BlockPos?, state: BlockState?) : KineticBlockEntity(typeIn, pos, state), IUniversalJoint {
13+
override var connectedJoint: IUniversalJoint? = null
14+
override var pos = blockPos
15+
var connectedPos: BlockPos? = null
16+
17+
18+
override fun onSpeedChanged(previousSpeed: Float) {
19+
super.onSpeedChanged(previousSpeed)
20+
}
21+
22+
// Custom Propagation
23+
override fun propagateRotationTo(
24+
target: KineticBlockEntity, stateFrom: BlockState, stateTo: BlockState, diff: BlockPos,
25+
connectedViaAxes: Boolean, connectedViaCogs: Boolean
26+
): Float {
27+
println("${target.blockPos} $connectedPos")
28+
if (connectedJoint == null || target.blockPos != connectedPos) return 0f
29+
return 1f
30+
}
31+
32+
override fun addPropagationLocations(
33+
block: IRotate,
34+
state: BlockState,
35+
neighbours: MutableList<BlockPos>
36+
): List<BlockPos> {
37+
if (connectedJoint != null) neighbours.add(connectedPos!!)
38+
return neighbours
39+
}
40+
41+
override fun isCustomConnection(other: KineticBlockEntity?, state: BlockState?, otherState: BlockState?): Boolean {
42+
return true
43+
}
44+
45+
override fun disconnect() {
46+
super.disconnect()
47+
connectedPos = null
48+
detachKinetics()
49+
sendData()
50+
}
51+
52+
override fun connectTo(other: IUniversalJoint) {
53+
54+
connectedPos = other.pos
55+
56+
super.connectTo(other)
57+
58+
sendData()
59+
attachKinetics()
60+
}
61+
62+
override fun tick() {
63+
super.tick()
64+
65+
if (connectedJoint == null && connectedPos != null) {
66+
val be = level!!.getBlockEntity(connectedPos!!)
67+
if (be != null && be !is UniversalShaftBlockEntity) connectedPos = null
68+
else if(be != null) connectedJoint = be as UniversalShaftBlockEntity
69+
}
70+
71+
}
72+
73+
override fun isThisJoint(be: BlockEntity): Boolean {
74+
return be is UniversalShaftBlockEntity
75+
}
76+
77+
override fun write(compound: CompoundTag, clientPacket: Boolean) {
78+
if (connectedJoint != null) {
79+
compound.putInt("otherPosX",connectedPos!!.x)
80+
compound.putInt("otherPosY",connectedPos!!.y)
81+
compound.putInt("otherPosZ",connectedPos!!.z)
82+
}
83+
84+
super.write(compound, clientPacket)
85+
}
86+
87+
override fun read(compound: CompoundTag, clientPacket: Boolean) {
88+
if (compound.contains("otherPosX")) {
89+
connectedPos = BlockPos(compound.getInt("otherPosX"),compound.getInt("otherPosY"),compound.getInt("otherPosZ"))
90+
91+
} else {
92+
connectedPos = null
93+
}
94+
95+
super.read(compound, clientPacket)
96+
}
97+
98+
override fun remove() {
99+
disconnect()
100+
super.remove()
101+
}
102+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.valkyrienskies.clockwork.content.kinetics.universal_shaft
2+
3+
import net.minecraft.world.level.block.entity.BlockEntity
4+
import org.valkyrienskies.clockwork.util.universal_joint.UniversalJointItem
5+
6+
class UniversalShaftItem(properties: Properties) : UniversalJointItem<UniversalShaftBlockEntity>(properties) {
7+
8+
override fun isJoint(be: BlockEntity): Boolean {
9+
return be is UniversalShaftBlockEntity
10+
}
11+
}

common/src/main/kotlin/org/valkyrienskies/clockwork/content/logistics/gas/duct/DuctBlock.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.valkyrienskies.clockwork.content.logistics.gas.duct
33
import com.google.common.collect.ImmutableMap
44
import com.simibubi.create.AllSoundEvents
55
import com.simibubi.create.content.equipment.wrench.IWrenchable
6+
import com.simibubi.create.content.kinetics.simpleRelays.ShaftBlock
67
import com.simibubi.create.foundation.block.IBE
78
import net.minecraft.core.BlockPos
89
import net.minecraft.core.Direction
@@ -345,7 +346,7 @@ class DuctBlock(properties: Properties) : Block(properties), INodeBlock, IDuct,
345346

346347
fun getConnectionType(state: BlockState, currentPos: BlockPos, neighborState: BlockState, neighborPos: BlockPos, direction: Direction, level: BlockGetter): DuctConnectionType {
347348

348-
349+
349350
val type: DuctConnectionType = state.getValue(DIR_TO_CONNECTION[direction]!!)
350351
var forced = type == DuctConnectionType.FORCED
351352
var otherConnected = false

0 commit comments

Comments
 (0)