mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 00:47:26 -04:00
particles: note
This commit is contained in:
parent
644bdef61f
commit
432253cc18
@ -15,15 +15,24 @@ package de.bixilon.minosoft.data.entities.block
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.mappings.MultiResourceLocationAble
|
import de.bixilon.minosoft.data.mappings.MultiResourceLocationAble
|
||||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||||
|
import de.bixilon.minosoft.data.mappings.blocks.properties.BlockProperties
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.properties.Instruments
|
import de.bixilon.minosoft.data.mappings.blocks.properties.Instruments
|
||||||
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.NoteParticle
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3d
|
||||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||||
|
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||||
|
import glm_.vec3.Vec3d
|
||||||
|
import glm_.vec3.Vec3i
|
||||||
|
|
||||||
class NoteBlockBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
|
class NoteBlockBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
|
||||||
|
private val noteParticleType = connection.registries.particleTypeRegistry[NoteParticle]
|
||||||
var instrument: Instruments? = null
|
var instrument: Instruments? = null
|
||||||
private set
|
private set
|
||||||
var pitch: Int? = null
|
var pitch: Int? = null
|
||||||
private set
|
private set
|
||||||
|
private var showParticleNextTick = false
|
||||||
|
|
||||||
override fun setBlockActionData(data1: Byte, data2: Byte) {
|
override fun setBlockActionData(data1: Byte, data2: Byte) {
|
||||||
instrument = when (data1.toInt()) {
|
instrument = when (data1.toInt()) {
|
||||||
@ -36,6 +45,22 @@ class NoteBlockBlockEntity(connection: PlayConnection) : BlockEntity(connection)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pitch = data2.toInt()
|
pitch = data2.toInt()
|
||||||
|
|
||||||
|
showParticleNextTick = true
|
||||||
|
// ToDo: Play sound?
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun realTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i) {
|
||||||
|
super.realTick(connection, blockState, blockPosition)
|
||||||
|
if (!showParticleNextTick) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showParticleNextTick = false
|
||||||
|
|
||||||
|
|
||||||
|
noteParticleType?.let {
|
||||||
|
connection.world += NoteParticle(connection, blockPosition.toVec3d + Vec3d(0.5, 1.2, 0.5), (blockState.properties[BlockProperties.NOTE]?.nullCast<Number>()?.toInt() ?: 0) / 24.0f, it.default())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : BlockEntityFactory<NoteBlockBlockEntity>, MultiResourceLocationAble {
|
companion object : BlockEntityFactory<NoteBlockBlockEntity>, MultiResourceLocationAble {
|
||||||
|
@ -18,6 +18,7 @@ import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
|||||||
import de.bixilon.minosoft.gui.rendering.particle.types.norender.ExplosionEmitterParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.norender.ExplosionEmitterParticle
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.advanced.block.BlockDustParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.advanced.block.BlockDustParticle
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.ExplosionParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.ExplosionParticle
|
||||||
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.NoteParticle
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.campfire.CampfireSmokeParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.campfire.CampfireSmokeParticle
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.cloud.CloudParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.cloud.CloudParticle
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.cloud.SneezeParticle
|
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.cloud.SneezeParticle
|
||||||
@ -70,4 +71,5 @@ object DefaultParticleFactory : DefaultFactory<ParticleFactory<out Particle>>(
|
|||||||
CritParticle,
|
CritParticle,
|
||||||
CrimsonSporeParticle,
|
CrimsonSporeParticle,
|
||||||
WarpedSporeParticle,
|
WarpedSporeParticle,
|
||||||
|
NoteParticle,
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||||
|
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||||
|
import glm_.glm
|
||||||
|
import glm_.vec3.Vec3d
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.sin
|
||||||
|
|
||||||
|
class NoteParticle(connection: PlayConnection, position: Vec3d, colorModifier: Float, data: ParticleData? = null) : SimpleTextureParticle(connection, position, Vec3d.EMPTY, data) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.friction = 0.66f
|
||||||
|
this.velocity *= 0.009999999776482582
|
||||||
|
accelerateIfYBlocked = true
|
||||||
|
this.velocity.y += 0.2
|
||||||
|
|
||||||
|
fun getColor(offset: Float): Float {
|
||||||
|
return max(0.0f, sin((colorModifier + offset) * 2 * glm.PIf) * 0.65f + 0.35f)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.color = RGBColor(
|
||||||
|
red = getColor(0.0f),
|
||||||
|
green = getColor(ONE_THIRD),
|
||||||
|
blue = getColor(TWO_THIRD),
|
||||||
|
)
|
||||||
|
|
||||||
|
this.scale *= 1.5f
|
||||||
|
this.maxAge = 6
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
companion object : ParticleFactory<NoteParticle> {
|
||||||
|
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:note".asResourceLocation()
|
||||||
|
private const val ONE_THIRD = 1.0f / 3
|
||||||
|
private const val TWO_THIRD = ONE_THIRD * 2
|
||||||
|
|
||||||
|
override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): NoteParticle {
|
||||||
|
return NoteParticle(connection, position, velocity.x.toFloat(), data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user