feat: add music projection stub

This commit is contained in:
xtex 2023-07-29 19:52:23 +08:00
parent 023017a829
commit e917807adc
Signed by: xtex
GPG Key ID: B918086ED8045B91
8 changed files with 144 additions and 4 deletions

View File

@ -18,6 +18,7 @@ import quaedam.projection.SimpleProjectionUpdate
import quaedam.projection.misc.NoiseProjection import quaedam.projection.misc.NoiseProjection
import quaedam.projection.misc.SkylightProjection import quaedam.projection.misc.SkylightProjection
import quaedam.projection.misc.SoundProjection import quaedam.projection.misc.SoundProjection
import quaedam.projection.music.MusicProjection
import quaedam.projection.swarm.SwarmProjection import quaedam.projection.swarm.SwarmProjection
import quaedam.projector.Projector import quaedam.projector.Projector
import quaedam.shell.ProjectionShell import quaedam.shell.ProjectionShell
@ -53,6 +54,7 @@ object Quaedam {
SwarmProjection SwarmProjection
SoundProjection SoundProjection
NoiseProjection NoiseProjection
MusicProjection
ProjectionCommand ProjectionCommand
SimpleProjectionUpdate SimpleProjectionUpdate
ProjectionShell ProjectionShell

View File

@ -0,0 +1,75 @@
package quaedam.projection.music
import net.minecraft.nbt.CompoundTag
import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.Item
import quaedam.Quaedam
import quaedam.projection.EntityProjectionBlock
import quaedam.projection.ProjectionEffect
import quaedam.projection.ProjectionEffectType
import quaedam.projection.SimpleProjectionEntity
import quaedam.projection.misc.SoundProjection
import quaedam.shell.ProjectionEffectShell
import quaedam.shell.buildProjectionEffectShell
import kotlin.math.min
object MusicProjection {
const val ID = "music_projection"
const val SHORT_ID = "projection"
val block = Quaedam.blocks.register(ID) { MusicProjectionBlock }!!
val item = Quaedam.items.register(ID) {
BlockItem(
MusicProjectionBlock, Item.Properties()
.`arch$tab`(Quaedam.creativeModeTab)
)
}!!
val effect = Quaedam.projectionEffects.register(SHORT_ID) {
ProjectionEffectType { MusicProjectionEffect() }
}!!
val blockEntity = Quaedam.blockEntities.register(ID) {
SimpleProjectionEntity.createBlockEntityType(block) { MusicProjectionEffect() }
}!!
}
object MusicProjectionBlock : EntityProjectionBlock<MusicProjectionEffect>(createProperties().lightLevel { 3 }) {
override val blockEntity = MusicProjection.blockEntity
}
data class MusicProjectionEffect(var volumeFactor: Float = 1.0f, var multiTracks: Boolean = true) : ProjectionEffect(),
ProjectionEffectShell.Provider {
companion object {
const val TAG_VOLUME_FACTOR = "VolumeFactor"
const val TAG_MULTI_TRACKS = "MultiTracks"
}
override val type
get() = MusicProjection.effect.get()!!
override fun toNbt(tag: CompoundTag) {
tag.putFloat(TAG_VOLUME_FACTOR, volumeFactor)
tag.putBoolean(TAG_MULTI_TRACKS, multiTracks)
}
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
volumeFactor = tag.getFloat(TAG_VOLUME_FACTOR)
multiTracks = tag.getBoolean(TAG_MULTI_TRACKS)
if (!trusted) {
volumeFactor = min(volumeFactor, 5.0f)
}
}
override fun createShell() = buildProjectionEffectShell(this) {
floatSlider("quaedam.shell.music.volume_factor", ::volumeFactor, 0.0f..1.0f, 0.1f)
boolean("quaedam.shell.music.multi_tracks", ::multiTracks)
}
}

View File

@ -28,9 +28,9 @@ 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>, rawStep: Double) {
val len = range.endInclusive - range.start val len = range.endInclusive - range.start
val step = step / len val step = rawStep / len
row(key) { row(key) {
object : AbstractSliderButton( object : AbstractSliderButton(
0, 0, width, height, 0, 0, width, height,
@ -53,6 +53,35 @@ class ProjectionEffectShell(val effect: ProjectionEffect) {
} }
} }
fun floatSlider(key: String, property: KMutableProperty0<Float>, range: ClosedRange<Float>, rawStep: Float) {
val len = range.endInclusive - range.start
val step = rawStep / len
row(key) {
object : AbstractSliderButton(
0,
0,
width,
height,
Component.literal(String.format("%.2f", property.get())),
(property.get() - range.start) / len.toDouble()
) {
override fun updateMessage() {
message = Component.literal(String.format("%.2f", property.get()))
}
override fun applyValue() {
val diff = value % step
if (diff < step * 0.5) {
value -= diff
} else {
value += (step - diff)
}
property.set(range.start + (value.toFloat() * len))
}
}
}
}
fun intSlider(key: String, property: KMutableProperty0<Int>, range: IntProgression) { fun intSlider(key: String, property: KMutableProperty0<Int>, range: IntProgression) {
val len = range.last - range.first val len = range.last - range.first
val step = range.step.toDouble() / len val step = range.step.toDouble() / len
@ -86,6 +115,14 @@ class ProjectionEffectShell(val effect: ProjectionEffect) {
.create(0, 0, width, height, Component.translatable(key)) .create(0, 0, width, height, Component.translatable(key))
} }
fun boolean(key: String, property: KMutableProperty0<Boolean>) =
row(key) {
CycleButton.builder<Boolean> { Component.translatable("$key.$it") }
.displayOnlyValue()
.withValues(listOf(true, false))
.create(0, 0, width, height, Component.translatable(key))
}
} }
inline fun buildProjectionEffectShell(effect: ProjectionEffect, builder: ProjectionEffectShell.() -> Unit) = inline fun buildProjectionEffectShell(effect: ProjectionEffect, builder: ProjectionEffectShell.() -> Unit) =

View File

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quaedam:block/music_projection"
}
}
}

View File

@ -5,6 +5,7 @@
"block.quaedam.swarm_projection": "Swarm Projection", "block.quaedam.swarm_projection": "Swarm Projection",
"block.quaedam.sound_projection": "Sound Projection", "block.quaedam.sound_projection": "Sound Projection",
"block.quaedam.noise_projection": "Noise Projection", "block.quaedam.noise_projection": "Noise Projection",
"block.quaedam.music_projection": "Music Projection",
"block.quaedam.causality_anchor": "Causality Anchor", "block.quaedam.causality_anchor": "Causality Anchor",
"block.quaedam.reality_stabler": "Reality Stabler", "block.quaedam.reality_stabler": "Reality Stabler",
"entity.quaedam.projected_person": "Virtual Person", "entity.quaedam.projected_person": "Virtual Person",
@ -19,5 +20,9 @@
"quaedam.shell.noise.rate": "Rate", "quaedam.shell.noise.rate": "Rate",
"quaedam.shell.noise.amount": "Amount", "quaedam.shell.noise.amount": "Amount",
"quaedam.shell.swarm.max_count": "Max Count", "quaedam.shell.swarm.max_count": "Max Count",
"quaedam.shell.sound.rate": "Rate" "quaedam.shell.sound.rate": "Rate",
"quaedam.shell.music.volume_factor": "Volume Factor",
"quaedam.shell.music.multi_tracks": "Multi Tracks",
"quaedam.shell.music.multi_tracks.true": "Enabled",
"quaedam.shell.music.multi_tracks.false": "Disabled"
} }

View File

@ -5,6 +5,7 @@
"block.quaedam.swarm_projection": "人群投影", "block.quaedam.swarm_projection": "人群投影",
"block.quaedam.sound_projection": "声音投影", "block.quaedam.sound_projection": "声音投影",
"block.quaedam.noise_projection": "噪音投影", "block.quaedam.noise_projection": "噪音投影",
"block.quaedam.music_projection": "音乐投影",
"block.quaedam.causality_anchor": "因果锚", "block.quaedam.causality_anchor": "因果锚",
"block.quaedam.reality_stabler": "现实稳定器", "block.quaedam.reality_stabler": "现实稳定器",
"entity.quaedam.projected_person": "虚拟个体", "entity.quaedam.projected_person": "虚拟个体",
@ -19,5 +20,9 @@
"quaedam.shell.noise.rate": "速率", "quaedam.shell.noise.rate": "速率",
"quaedam.shell.noise.amount": "数量", "quaedam.shell.noise.amount": "数量",
"quaedam.shell.swarm.max_count": "最大数量", "quaedam.shell.swarm.max_count": "最大数量",
"quaedam.shell.sound.rate": "速率" "quaedam.shell.sound.rate": "速率",
"quaedam.shell.music.volume_factor": "响度因子",
"quaedam.shell.music.multi_tracks": "多轨音乐",
"quaedam.shell.music.multi_tracks.true": "开启",
"quaedam.shell.music.multi_tracks.false": "关闭"
} }

View File

@ -0,0 +1,6 @@
{
"parent": "quaedam:block/projection",
"textures": {
"ext": "quaedam:block/music_projection"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "quaedam:block/music_projection"
}