feat: PSH for more projections

This commit is contained in:
xtex 2023-07-25 10:58:05 +08:00
parent 968c885dba
commit 5a41bf0665
Signed by: xtex
GPG Key ID: B918086ED8045B91
5 changed files with 52 additions and 6 deletions

View File

@ -8,6 +8,8 @@ import quaedam.projection.EntityProjectionBlock
import quaedam.projection.ProjectionEffect import quaedam.projection.ProjectionEffect
import quaedam.projection.ProjectionEffectType import quaedam.projection.ProjectionEffectType
import quaedam.projection.SimpleProjectionEntity import quaedam.projection.SimpleProjectionEntity
import quaedam.shell.ProjectionEffectShell
import quaedam.shell.buildProjectionEffectShell
import kotlin.math.min import kotlin.math.min
object NoiseProjection { object NoiseProjection {
@ -40,7 +42,7 @@ object NoiseProjectionBlock : EntityProjectionBlock<NoiseProjectionEffect>(creat
} }
data class NoiseProjectionEffect(var amount: Int = 5) : ProjectionEffect() { data class NoiseProjectionEffect(var amount: Int = 5) : ProjectionEffect(), ProjectionEffectShell.Provider {
companion object { companion object {
const val TAG_AMOUNT = "Amount" 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)
}
} }

View File

@ -8,6 +8,8 @@ import quaedam.projection.EntityProjectionBlock
import quaedam.projection.ProjectionEffect import quaedam.projection.ProjectionEffect
import quaedam.projection.ProjectionEffectType import quaedam.projection.ProjectionEffectType
import quaedam.projection.SimpleProjectionEntity import quaedam.projection.SimpleProjectionEntity
import quaedam.shell.ProjectionEffectShell
import quaedam.shell.buildProjectionEffectShell
object SoundProjection { object SoundProjection {
@ -39,7 +41,7 @@ object SoundProjectionBlock : EntityProjectionBlock<SoundProjectionEffect>(creat
} }
object SoundProjectionEffect : ProjectionEffect() { object SoundProjectionEffect : ProjectionEffect(), ProjectionEffectShell.Provider {
override val type override val type
get() = SoundProjection.effect.get()!! get() = SoundProjection.effect.get()!!
@ -50,4 +52,7 @@ object SoundProjectionEffect : ProjectionEffect() {
override fun fromNbt(tag: CompoundTag, trusted: Boolean) { override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
} }
override fun createShell() = buildProjectionEffectShell(this) {
}
} }

View File

@ -7,11 +7,13 @@ import net.minecraft.world.entity.MobSpawnType
import net.minecraft.world.level.levelgen.Heightmap import net.minecraft.world.level.levelgen.Heightmap
import quaedam.projection.ProjectionEffect import quaedam.projection.ProjectionEffect
import quaedam.projector.ProjectorBlockEntity import quaedam.projector.ProjectorBlockEntity
import quaedam.shell.ProjectionEffectShell
import quaedam.shell.buildProjectionEffectShell
import kotlin.math.min import kotlin.math.min
data class SwarmProjectionEffect( data class SwarmProjectionEffect(
var maxCount: Int = 180, var maxCount: Int = 180,
) : ProjectionEffect() { ) : ProjectionEffect(), ProjectionEffectShell.Provider {
companion object { companion object {
const val TAG_MAX_COUNT = "MaxCount" 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)
}
} }

View File

@ -29,11 +29,13 @@ class ProjectionEffectShell(val effect: ProjectionEffect) {
fun text(key: String, value: Component) = row(key) { StringWidget(value, it.font) } fun text(key: String, value: Component) = row(key) { StringWidget(value, it.font) }
fun doubleSlider(key: String, property: KMutableProperty0<Double>, range: ClosedRange<Double>, step: Double) = fun doubleSlider(key: String, property: KMutableProperty0<Double>, range: ClosedRange<Double>, step: Double) {
val len = range.endInclusive - range.start
val step = step / len
row(key) { row(key) {
object : AbstractSliderButton( object : AbstractSliderButton(
0, 0, width, height, 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() { override fun updateMessage() {
message = Component.literal(value.toString()) message = Component.literal(value.toString())
@ -41,7 +43,28 @@ class ProjectionEffectShell(val effect: ProjectionEffect) {
override fun applyValue() { override fun applyValue() {
value = floor(value / step) * step value = floor(value / step) * step
property.set(value) property.set(range.start + floor(value * len))
}
}
}
}
fun intSlider(key: String, property: KMutableProperty0<Int>, 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())
}
} }
} }
} }

View File

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quaedam:item/projection_shell"
}
}