Skip to content

Commit 0d8ffbd

Browse files
authored
Merge pull request #246 from Agarmal/1.20.1/nozzle_display_source
Implement DisplaySource system + Gas Nozzle display output
2 parents 5339298 + 6af17f8 commit 0d8ffbd

File tree

11 files changed

+400
-0
lines changed

11 files changed

+400
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.valkyrienskies.clockwork
22

3+
import com.simibubi.create.api.behaviour.display.DisplaySource.displaySource
4+
35
import com.simibubi.create.AllBlocks
46
import com.simibubi.create.AllSpriteShifts
57
import com.simibubi.create.AllTags
@@ -128,6 +130,7 @@ object ClockworkBlocks {
128130
}
129131
.transform(axeOrPickaxe())
130132
//.transform(BuilderTransformersClockwork.bearing("propeller", "gearbox"))
133+
.transform(displaySource(ClockworkDisplaySources.COPTER_BEARING))
131134
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
132135
.addLayer { Supplier { RenderType.cutoutMipped() } }
133136
.properties { it.noOcclusion() }
@@ -173,6 +176,7 @@ object ClockworkBlocks {
173176
}
174177
.initialProperties { SharedProperties.stone() }
175178
.transform(axeOrPickaxe())
179+
.transform(displaySource(ClockworkDisplaySources.PHYS_BEARING))
176180
.properties {
177181
it.lightLevel { state: BlockState? -> PhysBearingBlock.getLight(state) }
178182
}
@@ -194,6 +198,7 @@ object ClockworkBlocks {
194198
}
195199
.transform(axeOrPickaxe())
196200
.transform(ClockworkStress.setImpact(4.0))
201+
.transform(displaySource(ClockworkDisplaySources.FLAP_BEARING))
197202
.addLayer { Supplier { RenderType.cutout() } }
198203
.properties { it.noOcclusion() }
199204
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
@@ -210,6 +215,7 @@ object ClockworkBlocks {
210215
.transform(axeOrPickaxe())
211216
//.transform(flapbearing())
212217
.transform(ClockworkStress.setImpact(4.0))
218+
.transform(displaySource(ClockworkDisplaySources.FLAP_BEARING))
213219
.addLayer { Supplier { RenderType.cutout() } }
214220
.properties { it.noOcclusion() }
215221
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
@@ -225,6 +231,7 @@ object ClockworkBlocks {
225231
}
226232
.initialProperties { SharedProperties.stone() }
227233
.transform(axeOrPickaxe())
234+
.transform(displaySource(ClockworkDisplaySources.ALT_METER))
228235
.properties { it.noOcclusion() }
229236
.addLayer { Supplier { RenderType.cutout() } }
230237
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
@@ -438,6 +445,7 @@ object ClockworkBlocks {
438445
.item()
439446
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
440447
.transform(customItemModel())
448+
.transform(displaySource(ClockworkDisplaySources.KNODE))
441449
.register()
442450

443451
@JvmField
@@ -450,6 +458,7 @@ object ClockworkBlocks {
450458
}
451459
.initialProperties { SharedProperties.netheriteMetal() }
452460
.addLayer { Supplier { RenderType.cutout() } }
461+
.transform(displaySource(ClockworkDisplaySources.KNODE))
453462
.properties { it.noOcclusion() }
454463
.item()
455464
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
@@ -470,6 +479,7 @@ object ClockworkBlocks {
470479
.initialProperties { SharedProperties.netheriteMetal() }
471480
.addLayer { Supplier { RenderType.cutout() } }
472481
.properties { it.noOcclusion() }
482+
.transform(displaySource(ClockworkDisplaySources.KNODE))
473483
//.onRegister(connectedTextures { DuctTankCTBehaviour(ClockworkSpriteShifts.DUCT_TANK, ClockworkSpriteShifts.DUCT_TANK_TOP, AllSpriteShifts.FLUID_TANK_INNER) })
474484
.onRegister(ClockworkRegistrate.blockModel { NonNullFunction<BakedModel, BakedModel> { originalModel: BakedModel -> DuctTankModel(originalModel) } })
475485
.item()
@@ -488,6 +498,7 @@ object ClockworkBlocks {
488498
.initialProperties { SharedProperties.netheriteMetal() }
489499
.addLayer { Supplier { RenderType.cutout() } }
490500
.transform(ClockworkStress.setImpact(4.0))
501+
.transform(displaySource(ClockworkDisplaySources.KNODE))
491502
.properties { it.noOcclusion() }
492503
.item()
493504
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
@@ -559,6 +570,7 @@ object ClockworkBlocks {
559570
.addLayer { Supplier { RenderType.cutout() } }
560571
.properties { it.noOcclusion() }
561572
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
573+
.transform(displaySource(ClockworkDisplaySources.GAS_NOZZLE))
562574
.item()
563575
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
564576
.model(AssetLookup.customBlockItemModel("gas_nozzle"))
@@ -576,6 +588,7 @@ object ClockworkBlocks {
576588
.addLayer { Supplier { RenderType.cutout() } }
577589
.properties { it.noOcclusion() }
578590
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
591+
.transform(displaySource(ClockworkDisplaySources.KNODE))
579592
.item()
580593
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
581594
.build()
@@ -592,6 +605,7 @@ object ClockworkBlocks {
592605
.addLayer { Supplier { RenderType.cutout() } }
593606
.properties { it.noOcclusion() }
594607
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
608+
.transform(displaySource(ClockworkDisplaySources.KNODE))
595609
.item()
596610
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
597611
.build()
@@ -608,6 +622,7 @@ object ClockworkBlocks {
608622
.addLayer { Supplier { RenderType.cutout() } }
609623
.properties { it.noOcclusion() }
610624
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
625+
.transform(displaySource(ClockworkDisplaySources.KNODE))
611626
.item()
612627
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
613628
.build()
@@ -623,6 +638,7 @@ object ClockworkBlocks {
623638
.properties { it.noOcclusion() }
624639
.addLayer { Supplier { RenderType.cutout() } }
625640
.properties { it.noOcclusion() }
641+
.transform(displaySource(ClockworkDisplaySources.KNODE))
626642
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
627643
.item()
628644
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
@@ -639,6 +655,7 @@ object ClockworkBlocks {
639655
.properties { it.noOcclusion() }
640656
.addLayer { Supplier { RenderType.cutout() } }
641657
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
658+
.transform(displaySource(ClockworkDisplaySources.KNODE))
642659
.item()
643660
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
644661
.build()
@@ -654,6 +671,7 @@ object ClockworkBlocks {
654671
.properties { it.noOcclusion() }
655672
.addLayer { Supplier { RenderType.cutout() } }
656673
.properties { it.noOcclusion() }
674+
.transform(displaySource(ClockworkDisplaySources.KNODE))
657675
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
658676
.item()
659677
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
@@ -668,6 +686,7 @@ object ClockworkBlocks {
668686
.initialProperties { SharedProperties.netheriteMetal() }
669687
.transform(axeOrPickaxe())
670688
.properties { it.noOcclusion() }
689+
.transform(displaySource(ClockworkDisplaySources.KNODE))
671690
.addLayer { Supplier { RenderType.cutout() } }
672691
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
673692
.item()
@@ -684,6 +703,7 @@ object ClockworkBlocks {
684703
.transform(axeOrPickaxe())
685704
.properties { it.noOcclusion() }
686705
.addLayer { Supplier { RenderType.cutout() } }
706+
.transform(displaySource(ClockworkDisplaySources.KNODE))
687707
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
688708
.item()
689709
//.tab(ClockworkMod.BASE_CREATIVE_TABINFO)
@@ -699,6 +719,7 @@ object ClockworkBlocks {
699719
.initialProperties { SharedProperties.softMetal() }
700720
.transform(axeOrPickaxe())
701721
.properties { it.noOcclusion() }
722+
.transform(displaySource(ClockworkDisplaySources.KNODE))
702723
.addLayer { Supplier { RenderType.cutout() } }
703724
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
704725
.register()
@@ -714,6 +735,7 @@ object ClockworkBlocks {
714735
.initialProperties { SharedProperties.netheriteMetal() }
715736
.addLayer { Supplier { RenderType.cutout() } }
716737
.properties { it.noOcclusion() }
738+
.transform(displaySource(ClockworkDisplaySources.KNODE))
717739
.item()
718740
.tab(ClockworkMod.GAS_CREATIVE_TABINFO)
719741
.build()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.valkyrienskies.clockwork
2+
3+
import com.tterrag.registrate.util.entry.RegistryEntry
4+
import org.valkyrienskies.clockwork.ClockworkMod.REGISTRATE
5+
import org.valkyrienskies.clockwork.content.contraptions.flap.FlapBearingDisplaySource
6+
import org.valkyrienskies.clockwork.content.contraptions.phys.bearing.PhysBearingDisplaySource
7+
import org.valkyrienskies.clockwork.content.contraptions.propeller.copter.CopterBearingDisplaySource
8+
import org.valkyrienskies.clockwork.content.curiosities.altmeter.AltMeterDisplaySource
9+
import org.valkyrienskies.clockwork.content.logistics.gas.duct.KNodeDisplaySource
10+
import org.valkyrienskies.clockwork.content.logistics.gas.pockets.nozzle.GasNozzleDisplaySource
11+
12+
object ClockworkDisplaySources {
13+
@JvmField
14+
val GAS_NOZZLE: RegistryEntry<GasNozzleDisplaySource> =
15+
REGISTRATE.displaySource("gas_nozzle", ::GasNozzleDisplaySource).register()
16+
17+
@JvmField
18+
val FLAP_BEARING: RegistryEntry<FlapBearingDisplaySource> =
19+
REGISTRATE.displaySource("flap_bearing", ::FlapBearingDisplaySource).register()
20+
21+
@JvmField
22+
val COPTER_BEARING: RegistryEntry<CopterBearingDisplaySource> =
23+
REGISTRATE.displaySource("copter_bearing", ::CopterBearingDisplaySource).register()
24+
25+
@JvmField
26+
val ALT_METER: RegistryEntry<AltMeterDisplaySource> =
27+
REGISTRATE.displaySource("alt_meter", ::AltMeterDisplaySource).register()
28+
29+
@JvmField
30+
val PHYS_BEARING: RegistryEntry<PhysBearingDisplaySource> =
31+
REGISTRATE.displaySource("phys_bearing", ::PhysBearingDisplaySource).register()
32+
33+
@JvmField
34+
val KNODE: RegistryEntry<KNodeDisplaySource> =
35+
REGISTRATE.displaySource("duct", ::KNodeDisplaySource).register()
36+
37+
@JvmStatic
38+
fun register() {
39+
40+
}
41+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.valkyrienskies.clockwork.content.contraptions.flap
2+
3+
import com.simibubi.create.content.redstone.displayLink.DisplayLinkContext
4+
import com.simibubi.create.content.redstone.displayLink.source.NumericSingleLineDisplaySource
5+
import com.simibubi.create.content.redstone.displayLink.target.DisplayTargetStats
6+
import net.minecraft.network.chat.Component
7+
import net.minecraft.network.chat.MutableComponent
8+
import org.valkyrienskies.clockwork.ClockworkLang
9+
10+
class FlapBearingDisplaySource: NumericSingleLineDisplaySource() {
11+
override fun provideLine(context: DisplayLinkContext?, stats: DisplayTargetStats?): MutableComponent? {
12+
val bearing = context?.sourceBlockEntity as? FlapBearingBlockEntity ?: return ZERO.copy()
13+
14+
return ClockworkLang.text(bearing.getInterpolatedAngle(0.0f).toString()).component()
15+
}
16+
17+
override fun getName(): Component? {
18+
return Component.literal(Component.translatable("block.vs_clockwork.andesite_flap_bearing").string + " " + Component.translatable("sequenced_seat.value.angle").string) // Avoids having to add new translation keys
19+
}
20+
21+
override fun allowsLabeling(context: DisplayLinkContext?) = true
22+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.valkyrienskies.clockwork.content.contraptions.phys.bearing
2+
3+
import com.simibubi.create.content.redstone.displayLink.DisplayLinkContext
4+
import com.simibubi.create.content.redstone.displayLink.source.NumericSingleLineDisplaySource
5+
import com.simibubi.create.content.redstone.displayLink.source.NumericSingleLineDisplaySource.ZERO
6+
import com.simibubi.create.content.redstone.displayLink.target.DisplayTargetStats
7+
import com.simibubi.create.foundation.gui.ModularGuiLineBuilder
8+
import net.minecraft.network.chat.Component
9+
import net.minecraft.network.chat.MutableComponent
10+
import org.joml.Math.toDegrees
11+
import org.valkyrienskies.clockwork.ClockworkLang
12+
import org.valkyrienskies.clockwork.content.curiosities.altmeter.AltMeterBlockEntity
13+
import org.valkyrienskies.clockwork.platform.api.ContraptionController
14+
import org.valkyrienskies.mod.api.toJOML
15+
import org.valkyrienskies.mod.common.getLoadedShipManagingPos
16+
import kotlin.math.round
17+
import kotlin.math.roundToInt
18+
19+
class PhysBearingDisplaySource: NumericSingleLineDisplaySource() {
20+
override fun provideLine(context: DisplayLinkContext?, stats: DisplayTargetStats?): MutableComponent? {
21+
val bearing = context?.sourceBlockEntity as? PhysBearingBlockEntity ?: return ZERO.copy()
22+
23+
val angle = round(toDegrees(bearing.getActualAngle() ?: 0.0) * 10) / 10.0
24+
val mode = bearing.movementMode!!.get()
25+
26+
return when (context.sourceConfig().getInt("TargetData")) {
27+
0 -> ClockworkLang.text(angle.toString())
28+
.component()
29+
1 -> ClockworkLang.text(mode.name)
30+
.component()
31+
else -> ZERO.copy() // Only reachable if the tag is corrupted
32+
}
33+
}
34+
35+
override fun getName(): Component? {
36+
return Component.translatable("block.vs_clockwork.phys_bearing") // Avoids having to add new translation keys
37+
}
38+
39+
override fun initConfigurationWidgets(
40+
context: DisplayLinkContext?,
41+
builder: ModularGuiLineBuilder?,
42+
isFirstLine: Boolean
43+
) {
44+
super.initConfigurationWidgets(context, builder, isFirstLine)
45+
if (isFirstLine) return
46+
47+
builder?.addSelectionScrollInput(0, 137, { selectionScrollInput, _ ->
48+
selectionScrollInput
49+
.forOptions(ClockworkLang.translatedOptions("display_source.phys_bearing", "current", "mode"))
50+
}, "TargetData")
51+
}
52+
53+
override fun allowsLabeling(context: DisplayLinkContext?) = true
54+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.valkyrienskies.clockwork.content.contraptions.propeller.copter
2+
3+
import com.simibubi.create.content.redstone.displayLink.DisplayLinkContext
4+
import com.simibubi.create.content.redstone.displayLink.source.NumericSingleLineDisplaySource
5+
import com.simibubi.create.content.redstone.displayLink.target.DisplayTargetStats
6+
import com.simibubi.create.foundation.gui.ModularGuiLineBuilder
7+
import net.minecraft.network.chat.Component
8+
import net.minecraft.network.chat.MutableComponent
9+
import net.minecraft.world.phys.Vec3
10+
import org.valkyrienskies.clockwork.ClockworkLang
11+
import org.valkyrienskies.mod.api.toMinecraft
12+
import kotlin.math.round
13+
14+
class CopterBearingDisplaySource: NumericSingleLineDisplaySource() {
15+
override fun provideLine(context: DisplayLinkContext?, stats: DisplayTargetStats?): MutableComponent? {
16+
val copter = context?.sourceBlockEntity as? CopterBearingBlockEntity ?: return ZERO.copy()
17+
18+
val currentVec = copter.tiltVector
19+
val targetVec = copter.targetTiltVector
20+
val offsetVec = copter.desiredLocalOffset
21+
22+
return when (context.sourceConfig().getInt("TargetData")) {
23+
0 -> ClockworkLang.text(currentVec.niceString())
24+
.component()
25+
1 -> ClockworkLang.text(targetVec.niceString())
26+
.component()
27+
2 -> ClockworkLang.text(offsetVec.toMinecraft().niceString())
28+
.component()
29+
else -> ZERO.copy() // Only reachable if the tag is corrupted
30+
}
31+
}
32+
33+
override fun getName(): Component? {
34+
return Component.translatable("block.vs_clockwork.copter_bearing") // Avoids having to add new translation keys
35+
}
36+
37+
override fun initConfigurationWidgets(
38+
context: DisplayLinkContext?,
39+
builder: ModularGuiLineBuilder?,
40+
isFirstLine: Boolean
41+
) {
42+
super.initConfigurationWidgets(context, builder, isFirstLine)
43+
if (isFirstLine) return
44+
45+
builder?.addSelectionScrollInput(0, 137, { selectionScrollInput, _ ->
46+
selectionScrollInput
47+
.forOptions(ClockworkLang.translatedOptions("display_source.copter_bearing", "current", "target", "offset"))
48+
}, "TargetData")
49+
}
50+
51+
override fun allowsLabeling(context: DisplayLinkContext?) = true
52+
}
53+
54+
private fun Vec3.niceString(): String {
55+
val roundedX = round(this.x*10)/10.0
56+
val roundedY = round(this.y*10)/10.0
57+
val roundedZ = round(this.z*10)/10.0
58+
return "$roundedX $roundedY $roundedZ"
59+
}

0 commit comments

Comments
 (0)