Skip to content

Commit 7dbe0ff

Browse files
authored
Merge pull request #105 from ValkyrienSkies/1.18.x/observation
1.18.x/observation
2 parents 4c12de0 + 762f3a8 commit 7dbe0ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2843
-6
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ import org.valkyrienskies.clockwork.content.contraptions.phys.slicker.SlickerBlo
3030
import org.valkyrienskies.clockwork.content.contraptions.propeller.PropellerBearingBlockEntity
3131
import org.valkyrienskies.clockwork.content.contraptions.propeller.blades.BladeControllerBlockEntity
3232
import org.valkyrienskies.clockwork.content.contraptions.propeller.blades.BladeControllerRenderer
33+
import org.valkyrienskies.clockwork.content.curiosities.altmeter.AltMeterRenderer
3334
import org.valkyrienskies.clockwork.content.curiosities.clock.ClockBlockEntity
3435
import org.valkyrienskies.clockwork.content.curiosities.clock.ClockRenderer
36+
import org.valkyrienskies.clockwork.content.curiosities.sensor.rotation.LodefocusBlockEntity
37+
import org.valkyrienskies.clockwork.content.curiosities.sensor.rotation.LodefocusRenderer
3538
import org.valkyrienskies.clockwork.content.generic.ColorBlockEntity
3639
import org.valkyrienskies.clockwork.content.kinetics.resistor.RedstoneResistorBlockEntity
3740
import org.valkyrienskies.clockwork.content.kinetics.resistor.RedstoneResistorRenderer
@@ -62,9 +65,32 @@ import org.valkyrienskies.clockwork.content.logistics.solid.delivery.cannon.Deli
6265
import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.ReactionWheelBlockEntity
6366
import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.ReactionWheelInstance
6467
import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.ReactionWheelRenderer
68+
import org.valkyrienskies.clockwork.content.propulsion.sugar_rocket.SugarRocketBlockEntity
69+
import org.valkyrienskies.clockwork.content.propulsion.sugar_rocket.SugarRocketRenderer
6570

6671
object ClockworkBlockEntities {
6772

73+
@JvmField
74+
val SUGAR_ROCKET: BlockEntityEntry<SugarRocketBlockEntity> = ClockworkMod.REGISTRATE
75+
.blockEntity<SugarRocketBlockEntity>(
76+
"sugar_rocket"
77+
) { type: BlockEntityType<SugarRocketBlockEntity?>?, pos: BlockPos?, state: BlockState? ->
78+
SugarRocketBlockEntity(
79+
type!!,
80+
pos!!,
81+
state!!
82+
)
83+
}
84+
.validBlocks(ClockworkBlocks.SUGAR_ROCKET)
85+
.renderer {
86+
NonNullFunction<BlockEntityRendererProvider.Context?, BlockEntityRenderer<in SugarRocketBlockEntity?>> { context: BlockEntityRendererProvider.Context? ->
87+
SugarRocketRenderer(
88+
context!!
89+
)
90+
}
91+
}
92+
.register()
93+
6894
@JvmField
6995
val PROPELLER_BEARING: BlockEntityEntry<PropellerBearingBlockEntity> = ClockworkMod.REGISTRATE
7096
.blockEntity<PropellerBearingBlockEntity>(
@@ -187,6 +213,31 @@ object ClockworkBlockEntities {
187213
)
188214
}
189215
.validBlocks(ClockworkBlocks.ALT_METER)
216+
.renderer {
217+
NonNullFunction<BlockEntityRendererProvider.Context?, BlockEntityRenderer<in AltMeterBlockEntity?>> { context: BlockEntityRendererProvider.Context? ->
218+
AltMeterRenderer(
219+
context
220+
)
221+
}
222+
}
223+
.register()
224+
225+
@JvmField
226+
val LODEFOCUS = ClockworkMod.REGISTRATE.blockEntity<LodefocusBlockEntity>("lodefocus") { type: BlockEntityType<*>, pos: BlockPos, state: BlockState ->
227+
LodefocusBlockEntity(
228+
type,
229+
pos,
230+
state
231+
)
232+
}
233+
.validBlocks(ClockworkBlocks.LODEFOCUS)
234+
.renderer {
235+
NonNullFunction<BlockEntityRendererProvider.Context?, BlockEntityRenderer<in LodefocusBlockEntity?>> { context: BlockEntityRendererProvider.Context? ->
236+
LodefocusRenderer(
237+
context
238+
)
239+
}
240+
}
190241
.register()
191242

192243
@JvmField

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import net.minecraft.world.item.Item
2121
import net.minecraft.world.level.block.Block
2222
import net.minecraft.world.level.block.Blocks
2323
import net.minecraft.world.level.block.state.BlockBehaviour
24+
import net.minecraft.world.level.block.state.BlockBehaviour.Properties
2425
import net.minecraft.world.level.block.state.BlockState
2526
import org.valkyrienskies.clockwork.ClockworkMod.REGISTRATE
2627
import org.valkyrienskies.clockwork.client.render.WingBlockItemRenderer
@@ -41,6 +42,10 @@ import org.valkyrienskies.clockwork.content.curiosities.GenericWanderliteSlab
4142
import org.valkyrienskies.clockwork.content.curiosities.GenericWanderliteStairs
4243
import org.valkyrienskies.clockwork.content.curiosities.asteroid.AsteroidBlock
4344
import org.valkyrienskies.clockwork.content.curiosities.clock.ClockBlock
45+
import org.valkyrienskies.clockwork.content.curiosities.sensor.distance.DistanceSensorBlock
46+
import org.valkyrienskies.clockwork.content.curiosities.sensor.impact.ImpactSensorBlock
47+
import org.valkyrienskies.clockwork.content.curiosities.sensor.rotation.GyroscopicSensorBlock
48+
import org.valkyrienskies.clockwork.content.curiosities.sensor.rotation.LodefocusBlock
4449
import org.valkyrienskies.clockwork.content.kinetics.resistor.RedstoneResistorBlock
4550
import org.valkyrienskies.clockwork.content.kinetics.sequenced_seat.SequencedSeatBlock
4651
import org.valkyrienskies.clockwork.content.logistics.gas.backtank.GasBacktankBlock
@@ -60,13 +65,29 @@ import org.valkyrienskies.clockwork.content.physicalities.reactionwheel.Reaction
6065
import org.valkyrienskies.clockwork.content.physicalities.wing.DyedWingBlockItem
6166
import org.valkyrienskies.clockwork.content.physicalities.wing.FlapBlock
6267
import org.valkyrienskies.clockwork.content.physicalities.wing.WingBlock
68+
import org.valkyrienskies.clockwork.content.propulsion.sugar_rocket.SugarRocketBlock
6369
import org.valkyrienskies.clockwork.util.builder.BuilderTransformersClockwork.flapbearing
6470
import org.valkyrienskies.clockwork.util.builder.ClockworkRegistrate
6571
import java.util.function.Supplier
6672

6773

6874
object ClockworkBlocks {
6975

76+
@JvmField
77+
val SUGAR_ROCKET: BlockEntry<SugarRocketBlock> =
78+
REGISTRATE.block<SugarRocketBlock>("sugar_rocket") { properties: BlockBehaviour.Properties? ->
79+
SugarRocketBlock(properties!!)
80+
}
81+
.initialProperties(SharedProperties.BELT_MATERIAL)
82+
.transform(TagGen.axeOrPickaxe())
83+
.properties { it.instabreak().explosionResistance(0f) }
84+
.addLayer { Supplier { RenderType.cutout() } }
85+
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
86+
.item()
87+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
88+
.build()
89+
.register()
90+
7091
@JvmField
7192
val BRASS_PROPELLER_BEARING: BlockEntry<PropellerBearingBlock> =
7293
REGISTRATE.block<PropellerBearingBlock>("brass_propeller_bearing") { properties: BlockBehaviour.Properties? ->
@@ -175,6 +196,65 @@ object ClockworkBlocks {
175196
.build()
176197
.register()
177198

199+
@JvmField
200+
val DISTANCE_SENSOR: BlockEntry<DistanceSensorBlock> =
201+
REGISTRATE.block<DistanceSensorBlock>("distance_sensor") { properties: BlockBehaviour.Properties? ->
202+
DistanceSensorBlock(properties!!)
203+
}
204+
.initialProperties { SharedProperties.stone() }
205+
.transform(TagGen.axeOrPickaxe())
206+
.properties { it.noOcclusion() }
207+
.addLayer { Supplier { RenderType.cutout() } }
208+
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
209+
.item()
210+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
211+
.build()
212+
.register()
213+
214+
@JvmField
215+
val GYROSCOPIC_SENSOR: BlockEntry<GyroscopicSensorBlock> = REGISTRATE.block<GyroscopicSensorBlock>("gyroscopic_sensor") { properties: BlockBehaviour.Properties? ->
216+
GyroscopicSensorBlock(properties!!)
217+
}
218+
.initialProperties { SharedProperties.stone() }
219+
.transform(TagGen.axeOrPickaxe())
220+
.properties { it.noOcclusion() }
221+
.addLayer { Supplier { RenderType.cutout() } }
222+
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
223+
.item()
224+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
225+
.build()
226+
.register()
227+
228+
@JvmField
229+
val LODEFOCUS: BlockEntry<LodefocusBlock> = REGISTRATE.block<LodefocusBlock>("lodefocus") { properties: BlockBehaviour.Properties? ->
230+
LodefocusBlock(properties!!)
231+
}
232+
.initialProperties { Blocks.GLASS }
233+
.transform(TagGen.axeOrPickaxe())
234+
.properties { it.noOcclusion() ; it.lightLevel{ _ -> 1 } ; it.isViewBlocking{ _, _, _ -> false } }
235+
.addLayer { Supplier { RenderType.cutout() } }
236+
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
237+
.tag(ClockworkTags.AllBlockTags.SENSOR_LENS.tag)
238+
.item()
239+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
240+
.build()
241+
.register()
242+
243+
@JvmField
244+
val IMPACT_SENSOR: BlockEntry<ImpactSensorBlock> =
245+
REGISTRATE.block<ImpactSensorBlock>("impact_sensor") { properties: BlockBehaviour.Properties? ->
246+
ImpactSensorBlock(properties!!)
247+
}
248+
.initialProperties { SharedProperties.stone() }
249+
.transform(TagGen.axeOrPickaxe())
250+
.properties { it.noOcclusion() }
251+
.addLayer { Supplier { RenderType.cutout() } }
252+
.tag(AllTags.AllBlockTags.SAFE_NBT.tag)
253+
.item()
254+
.tab { ClockworkMod.BASE_CREATIVE_TAB }
255+
.build()
256+
.register()
257+
178258
@JvmField
179259
val GYRO: BlockEntry<GyroBlock> = REGISTRATE.block<GyroBlock>("gyro") { properties: BlockBehaviour.Properties? ->
180260
GyroBlock(properties!!)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import com.simibubi.create.foundation.data.CreateRegistrate
55
import dev.architectury.event.events.common.InteractionEvent
66
import dev.architectury.event.events.common.LifecycleEvent
77
import dev.architectury.event.events.common.TickEvent
8+
import dev.architectury.registry.client.rendering.ColorHandlerRegistry
9+
import net.minecraft.client.color.block.BlockColor
10+
import net.minecraft.client.color.block.BlockTintCache
811
import net.minecraft.resources.ResourceLocation
912
import net.minecraft.world.item.CreativeModeTab
1013
import org.slf4j.LoggerFactory
@@ -56,6 +59,7 @@ object ClockworkMod {
5659
vsApi.registerAttachment(EncasedFanController::class.java)
5760
vsApi.registerAttachment(GyroShipControl::class.java)
5861
vsApi.registerAttachment(GravitronController::class.java)
62+
vsApi.registerAttachment(SugarRocketController::class.java)
5963

6064

6165
VSEvents.ShipLoadEvent.on { event ->
@@ -91,7 +95,6 @@ object ClockworkMod {
9195
DualLinkHandler.handler(player, hand, pos, face)
9296
})
9397

94-
9598
}
9699

97100
fun getKelvin(): DuctNetworkServer {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ object ClockworkTags {
3737
optional: Boolean = namespace.optionalDefault,
3838
alwaysDatagen: Boolean = namespace.alwaysDatagenDefault
3939
) {
40-
BALLOON_BLOCK;
40+
BALLOON_BLOCK,
41+
SENSOR_LENS;
4142

4243
val tag: TagKey<Block>
4344
val alwaysDatagen: Boolean

common/src/main/kotlin/org/valkyrienskies/clockwork/content/curiosities/altmeter/AltMeterBlock.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class AltMeterBlock(properties: Properties) : Block(properties), IBE<AltMeterBlo
8181

8282
override fun getSignal(state: BlockState, level: BlockGetter, pos: BlockPos, direction: Direction): Int {
8383
return if (state.getValue(POWERED)) {
84-
15
84+
(level.getBlockEntity(pos) as? AltMeterBlockEntity)?.getSignalPower()
85+
?: return 15
8586
} else 0
8687
}
8788

common/src/main/kotlin/org/valkyrienskies/clockwork/content/curiosities/altmeter/AltMeterBlockEntity.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ import net.minecraft.world.level.block.state.BlockState
99
import org.joml.Vector3d
1010
import org.valkyrienskies.clockwork.util.ClockworkConstants
1111
import org.valkyrienskies.mod.common.getShipManagingPos
12+
import kotlin.math.absoluteValue
13+
import kotlin.math.min
1214

1315
class AltMeterBlockEntity(typeIn: BlockEntityType<*>?, pos: BlockPos, state: BlockState) :
1416
SmartBlockEntity(typeIn, pos, state) {
1517
internal var triggerHeight: Double = 0.0
18+
internal var signalStrength = 0
1619
override fun addBehaviours(behaviours: MutableList<BlockEntityBehaviour>) {}
1720

21+
fun getSignalPower(): Int {
22+
return signalStrength
23+
}
24+
1825
override fun tick() {
1926
super.tick()
2027
if (level!!.isClientSide) return
@@ -25,7 +32,9 @@ class AltMeterBlockEntity(typeIn: BlockEntityType<*>?, pos: BlockPos, state: Blo
2532
val posInWorld = Vector3d(blockPos.x + 0.5, blockPos.y + 0.5, blockPos.z + 0.5)
2633
val shipOn = level.getShipManagingPos(blockPos)
2734
shipOn?.transform?.shipToWorld?.transformPosition(posInWorld)
28-
val shouldBePowered = posInWorld.y() >= triggerHeightCopy
35+
val distance = posInWorld.y - triggerHeightCopy
36+
val shouldBePowered = distance.absoluteValue > 0.9
37+
signalStrength = if (shouldBePowered) min(distance.absoluteValue.toInt(), 15) else 0
2938

3039
val isCurrentlyPowered = blockState.getValue(AltMeterBlock.POWERED)
3140

@@ -43,10 +52,12 @@ class AltMeterBlockEntity(typeIn: BlockEntityType<*>?, pos: BlockPos, state: Blo
4352
super.write(compound, clientPacket)
4453
val triggerHeightCopy = triggerHeight
4554
compound.putDouble(ClockworkConstants.Nbt.TRIGGER_HEIGHT, triggerHeightCopy)
55+
compound.putInt("Signal Strength", signalStrength)
4656
}
4757

4858
public override fun read(compound: CompoundTag, clientPacket: Boolean) {
4959
super.read(compound, clientPacket)
5060
triggerHeight = compound.getDouble(ClockworkConstants.Nbt.TRIGGER_HEIGHT)
61+
signalStrength = compound.getInt("Signal Strength")
5162
}
5263
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.valkyrienskies.clockwork.content.curiosities.altmeter
2+
3+
import com.mojang.blaze3d.vertex.PoseStack
4+
import com.simibubi.create.foundation.blockEntity.renderer.SmartBlockEntityRenderer
5+
import com.simibubi.create.foundation.render.CachedBufferer
6+
import com.simibubi.create.foundation.utility.Color
7+
import net.minecraft.client.renderer.MultiBufferSource
8+
import net.minecraft.client.renderer.RenderType
9+
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
10+
import org.valkyrienskies.clockwork.ClockworkPartials
11+
12+
class AltMeterRenderer(context: BlockEntityRendererProvider.Context?) : SmartBlockEntityRenderer<AltMeterBlockEntity>(
13+
context
14+
) {
15+
override fun renderSafe(
16+
blockEntity: AltMeterBlockEntity,
17+
partialTicks: Float,
18+
ms: PoseStack,
19+
buffer: MultiBufferSource,
20+
light: Int,
21+
overlay: Int
22+
) {
23+
super.renderSafe(blockEntity, partialTicks, ms, buffer, light, overlay)
24+
val indicator = CachedBufferer.partial(ClockworkPartials.ALTIMETER_REDSTONE, blockEntity.blockState)
25+
val color = Color.mixColors(0x2C0300, 0xCD0000, blockEntity.signalStrength / 15f)
26+
27+
indicator.light(light).overlay(overlay)
28+
.color(color)
29+
.renderInto(ms, buffer.getBuffer(RenderType.solid()))
30+
}
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.valkyrienskies.clockwork.content.curiosities.sensor
2+
3+
import com.simibubi.create.content.equipment.wrench.IWrenchable
4+
import net.minecraft.core.BlockPos
5+
import net.minecraft.server.level.ServerLevel
6+
import net.minecraft.world.level.block.state.BlockState
7+
import net.minecraft.world.level.block.state.properties.BlockStateProperties
8+
import net.minecraft.world.level.block.state.properties.IntegerProperty
9+
import java.util.*
10+
11+
interface ISensorBlock : IWrenchable {
12+
companion object {
13+
val POWER: IntegerProperty = BlockStateProperties.POWER
14+
}
15+
16+
fun updatePower(state: BlockState, level: ServerLevel, pos: BlockPos, random: Random): Int
17+
}

0 commit comments

Comments
 (0)