diff --git a/common/src/main/kotlin/quaedam/projection/misc/NoiseProjection.kt b/common/src/main/kotlin/quaedam/projection/misc/NoiseProjection.kt index 8df4f35..b367857 100644 --- a/common/src/main/kotlin/quaedam/projection/misc/NoiseProjection.kt +++ b/common/src/main/kotlin/quaedam/projection/misc/NoiseProjection.kt @@ -8,6 +8,8 @@ import quaedam.projection.EntityProjectionBlock import quaedam.projection.ProjectionEffect import quaedam.projection.ProjectionEffectType import quaedam.projection.SimpleProjectionEntity +import quaedam.shell.ProjectionEffectShell +import quaedam.shell.buildProjectionEffectShell import kotlin.math.min object NoiseProjection { @@ -40,7 +42,7 @@ object NoiseProjectionBlock : EntityProjectionBlock(creat } -data class NoiseProjectionEffect(var amount: Int = 5) : ProjectionEffect() { +data class NoiseProjectionEffect(var amount: Int = 5) : ProjectionEffect(), ProjectionEffectShell.Provider { companion object { const val TAG_AMOUNT = "Amount" @@ -60,4 +62,8 @@ data class NoiseProjectionEffect(var amount: Int = 5) : ProjectionEffect() { } } + override fun createShell() = buildProjectionEffectShell(this) { + intSlider("quaedam.shell.noise.amount", ::amount, 0..8) + } + } diff --git a/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt b/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt index cf03fdf..c7ea648 100644 --- a/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt +++ b/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt @@ -8,6 +8,8 @@ import quaedam.projection.EntityProjectionBlock import quaedam.projection.ProjectionEffect import quaedam.projection.ProjectionEffectType import quaedam.projection.SimpleProjectionEntity +import quaedam.shell.ProjectionEffectShell +import quaedam.shell.buildProjectionEffectShell object SoundProjection { @@ -39,7 +41,7 @@ object SoundProjectionBlock : EntityProjectionBlock(creat } -object SoundProjectionEffect : ProjectionEffect() { +object SoundProjectionEffect : ProjectionEffect(), ProjectionEffectShell.Provider { override val type get() = SoundProjection.effect.get()!! @@ -50,4 +52,7 @@ object SoundProjectionEffect : ProjectionEffect() { override fun fromNbt(tag: CompoundTag, trusted: Boolean) { } + override fun createShell() = buildProjectionEffectShell(this) { + } + } diff --git a/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt b/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt index 1f9ad21..214cab5 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt @@ -7,11 +7,13 @@ import net.minecraft.world.entity.MobSpawnType import net.minecraft.world.level.levelgen.Heightmap import quaedam.projection.ProjectionEffect import quaedam.projector.ProjectorBlockEntity +import quaedam.shell.ProjectionEffectShell +import quaedam.shell.buildProjectionEffectShell import kotlin.math.min data class SwarmProjectionEffect( var maxCount: Int = 180, -) : ProjectionEffect() { +) : ProjectionEffect(), ProjectionEffectShell.Provider { companion object { const val TAG_MAX_COUNT = "MaxCount" @@ -50,4 +52,8 @@ data class SwarmProjectionEffect( } } + override fun createShell() = buildProjectionEffectShell(this) { + intSlider("quaedam.shell.swarm.max_count", ::maxCount, 0..180 step 5) + } + } diff --git a/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt b/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt index 57d25aa..987a809 100644 --- a/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt +++ b/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt @@ -29,11 +29,13 @@ class ProjectionEffectShell(val effect: ProjectionEffect) { fun text(key: String, value: Component) = row(key) { StringWidget(value, it.font) } - fun doubleSlider(key: String, property: KMutableProperty0, range: ClosedRange, step: Double) = + fun doubleSlider(key: String, property: KMutableProperty0, range: ClosedRange, step: Double) { + val len = range.endInclusive - range.start + val step = step / len row(key) { object : AbstractSliderButton( 0, 0, width, height, - Component.literal(property.get().toString()), property.get() + Component.literal(property.get().toString()), (property.get() - range.start).toDouble() / len ) { override fun updateMessage() { message = Component.literal(value.toString()) @@ -41,10 +43,31 @@ class ProjectionEffectShell(val effect: ProjectionEffect) { override fun applyValue() { value = floor(value / step) * step - property.set(value) + property.set(range.start + floor(value * len)) } } } + } + + fun intSlider(key: String, property: KMutableProperty0, range: IntProgression) { + val len = range.last - range.first + val step = range.step / len + row(key) { + object : AbstractSliderButton( + 0, 0, width, height, + Component.literal(property.get().toString()), (property.get() - range.first).toDouble() / len + ) { + override fun updateMessage() { + message = Component.literal(value.toString()) + } + + override fun applyValue() { + value = floor(value / step) * step + property.set((range.first + floor(value * len)).toInt()) + } + } + } + } fun intCycle(key: String, property: KMutableProperty0, range: IntProgression) = row(key) { diff --git a/common/src/main/resources/assets/quaedam/models/item/projection_shell.json b/common/src/main/resources/assets/quaedam/models/item/projection_shell.json new file mode 100644 index 0000000..61df5a2 --- /dev/null +++ b/common/src/main/resources/assets/quaedam/models/item/projection_shell.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "quaedam:item/projection_shell" + } +} \ No newline at end of file