mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
world: play sounds and add particles, remove some parameters from particle constructor
This commit is contained in:
parent
f094400c99
commit
05e9063b42
@ -19,7 +19,6 @@ import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.mappings.blocks.properties.BlockProperties
|
||||
import de.bixilon.minosoft.data.mappings.blocks.types.CampfireBlock
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
|
||||
@ -46,7 +45,6 @@ class CampfireBlockEntity(connection: PlayConnection) : BlockEntity(connection)
|
||||
|
||||
|
||||
override fun realTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i) {
|
||||
val particleRenderer = connection.rendering?.renderWindow?.get(ParticleRenderer) ?: return
|
||||
if (blockState.properties[BlockProperties.LIT] != true) {
|
||||
return
|
||||
}
|
||||
@ -56,7 +54,7 @@ class CampfireBlockEntity(connection: PlayConnection) : BlockEntity(connection)
|
||||
|
||||
if (Random.nextFloat() < 0.11f) {
|
||||
for (i in 0 until Random.nextInt(2) + 2) {
|
||||
blockState.block.spawnSmokeParticles(connection, particleRenderer, blockState, blockPosition, false)
|
||||
blockState.block.spawnSmokeParticles(connection, blockState, blockPosition, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.TintColorCalculator
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.input.camera.RaycastHit
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import glm_.vec3.Vec3i
|
||||
import kotlin.random.Random
|
||||
@ -98,7 +97,7 @@ open class Block(
|
||||
return this.defaultState.withProperties(properties)
|
||||
}
|
||||
|
||||
open fun randomTick(connection: PlayConnection, particleRenderer: ParticleRenderer?, blockState: BlockState, blockPosition: Vec3i, random: Random) {}
|
||||
open fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {}
|
||||
|
||||
companion object : ResourceLocationDeserializer<Block> {
|
||||
override fun deserialize(mappings: Registries?, resourceLocation: ResourceLocation, data: JsonObject): Block {
|
||||
|
@ -23,7 +23,6 @@ import de.bixilon.minosoft.data.mappings.items.tools.ShovelItem
|
||||
import de.bixilon.minosoft.data.mappings.versions.Registries
|
||||
import de.bixilon.minosoft.data.player.Hands
|
||||
import de.bixilon.minosoft.gui.rendering.input.camera.RaycastHit
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.CampfireSmokeParticle
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.fire.SmokeParticle
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.lava.LavaParticle
|
||||
@ -46,13 +45,12 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
|
||||
private val smokeParticle = registries.particleTypeRegistry[SmokeParticle]!!
|
||||
|
||||
private fun extinguish(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i) {
|
||||
val particleRenderer = connection.rendering?.renderWindow?.get(ParticleRenderer) ?: return
|
||||
for (i in 0 until 20) {
|
||||
spawnSmokeParticles(connection, particleRenderer, blockState, blockPosition, true)
|
||||
spawnSmokeParticles(connection, blockState, blockPosition, true)
|
||||
}
|
||||
}
|
||||
|
||||
fun spawnSmokeParticles(connection: PlayConnection, particleRenderer: ParticleRenderer, blockState: BlockState, blockPosition: Vec3i, extinguished: Boolean) {
|
||||
fun spawnSmokeParticles(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, extinguished: Boolean) {
|
||||
let {
|
||||
val position = Vec3(blockPosition).verticalPlus(
|
||||
{ 0.5f + 3.0f.noise },
|
||||
@ -67,7 +65,7 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
|
||||
cosySmokeParticle
|
||||
}
|
||||
|
||||
particleRenderer.add(CampfireSmokeParticle(connection, particleRenderer, position, Vec3(0.0f, 0.07f, 0.0f), particleType.simple(), isSignal))
|
||||
connection.world += CampfireSmokeParticle(connection, position, Vec3(0.0f, 0.07f, 0.0f), particleType.default(), isSignal)
|
||||
}
|
||||
|
||||
if (extinguished) {
|
||||
@ -75,23 +73,22 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
|
||||
{ 0.5f + 4.0f.noise },
|
||||
0.5f
|
||||
)
|
||||
particleRenderer.add(SmokeParticle(connection, particleRenderer, position, Vec3(0.0f, 0.005f, 0.0f), smokeParticle.simple()))
|
||||
connection.world += SmokeParticle(connection, position, Vec3(0.0f, 0.005f, 0.0f), smokeParticle.default())
|
||||
}
|
||||
}
|
||||
|
||||
override fun randomTick(connection: PlayConnection, particleRenderer: ParticleRenderer?, blockState: BlockState, blockPosition: Vec3i, random: Random) {
|
||||
particleRenderer ?: return
|
||||
override fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {
|
||||
if (blockState.properties[BlockProperties.LIT] != true) {
|
||||
return
|
||||
}
|
||||
if (random.chance(10)) {
|
||||
connection.rendering?.audioPlayer?.playSoundEvent(campfireCrackleSoundEvent, blockPosition + Vec3(0.5f), 0.5f + random.nextFloat(), 0.6f + random.nextFloat() * 0.7f)
|
||||
connection.world.playSoundEvent(campfireCrackleSoundEvent, blockPosition + Vec3(0.5f), 0.5f + random.nextFloat(), 0.6f + random.nextFloat() * 0.7f)
|
||||
}
|
||||
|
||||
if (lavaParticles && random.chance(20)) {
|
||||
val position = Vec3(blockPosition) + Vec3(0.5f)
|
||||
for (i in 0 until random.nextInt(1) + 1) {
|
||||
particleRenderer.add(LavaParticle(connection, particleRenderer, position, lavaParticle.simple()))
|
||||
connection.world += LavaParticle(connection, position, lavaParticle.default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ open class BlockItem(
|
||||
}
|
||||
|
||||
placeBlockState.placeSoundEvent?.let {
|
||||
connection.rendering?.audioPlayer?.playSoundEvent(it, placePosition, placeBlockState.soundEventVolume, placeBlockState.soundEventPitch)
|
||||
connection.world.playSoundEvent(it, placePosition, placeBlockState.soundEventVolume, placeBlockState.soundEventPitch)
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ data class ParticleType(
|
||||
return resourceLocation.full
|
||||
}
|
||||
|
||||
fun simple(): ParticleData {
|
||||
fun default(): ParticleData {
|
||||
return ParticleData(this)
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,17 @@ package de.bixilon.minosoft.data.world
|
||||
import de.bixilon.minosoft.data.Difficulties
|
||||
import de.bixilon.minosoft.data.entities.block.BlockEntity
|
||||
import de.bixilon.minosoft.data.mappings.Dimension
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.biomes.Biome
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.mappings.sounds.SoundEvent
|
||||
import de.bixilon.minosoft.data.mappings.tweaker.VersionTweaker
|
||||
import de.bixilon.minosoft.data.world.biome.accessor.BiomeAccessor
|
||||
import de.bixilon.minosoft.data.world.biome.accessor.NullBiomeAccessor
|
||||
import de.bixilon.minosoft.data.world.light.WorldLightAccessor
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
||||
import de.bixilon.minosoft.gui.rendering.sound.AudioPlayer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.blockPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkPosition
|
||||
@ -36,6 +40,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
|
||||
import de.bixilon.minosoft.util.KUtil.toSynchronizedMap
|
||||
import glm_.vec2.Vec2i
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3i
|
||||
import kotlin.random.Random
|
||||
|
||||
@ -58,6 +63,9 @@ class World(
|
||||
var age = 0L
|
||||
private val random = Random
|
||||
|
||||
var audioPlayer: AudioPlayer? = null
|
||||
var particleRenderer: ParticleRenderer? = null
|
||||
|
||||
operator fun get(blockPosition: Vec3i): BlockState? {
|
||||
return chunks[blockPosition.chunkPosition]?.get(blockPosition.inChunkPosition)
|
||||
}
|
||||
@ -169,19 +177,18 @@ class World(
|
||||
}
|
||||
|
||||
fun randomTick() {
|
||||
val particleRenderer = connection.rendering?.renderWindow?.get(ParticleRenderer)
|
||||
for (i in 0 until 667) {
|
||||
randomTick(16, particleRenderer)
|
||||
randomTick(32, particleRenderer)
|
||||
randomTick(16)
|
||||
randomTick(32)
|
||||
}
|
||||
}
|
||||
|
||||
private fun randomTick(radius: Int, particleRenderer: ParticleRenderer?) {
|
||||
private fun randomTick(radius: Int) {
|
||||
val blockPosition = connection.player.entity.position.blockPosition + { random.nextInt(radius) } - { random.nextInt(radius) }
|
||||
|
||||
val blockState = this[blockPosition] ?: return
|
||||
|
||||
blockState.block.randomTick(connection, particleRenderer, blockState, blockPosition, random)
|
||||
blockState.block.randomTick(connection, blockState, blockPosition, random)
|
||||
}
|
||||
|
||||
fun getBlocks(start: Vec3i, end: Vec3i): Map<Vec3i, BlockState> {
|
||||
@ -200,4 +207,29 @@ class World(
|
||||
|
||||
return blocks.toMap()
|
||||
}
|
||||
|
||||
|
||||
fun playSoundEvent(resourceLocation: ResourceLocation, position: Vec3i? = null, volume: Float = 1.0f, pitch: Float = 1.0f) {
|
||||
audioPlayer?.playSoundEvent(resourceLocation, position, volume, pitch)
|
||||
}
|
||||
|
||||
fun playSoundEvent(resourceLocation: ResourceLocation, position: Vec3? = null, volume: Float = 1.0f, pitch: Float = 1.0f) {
|
||||
audioPlayer?.playSoundEvent(resourceLocation, position, volume, pitch)
|
||||
}
|
||||
|
||||
fun playSoundEvent(soundEvent: SoundEvent, position: Vec3i? = null, volume: Float = 1.0f, pitch: Float = 1.0f) {
|
||||
audioPlayer?.playSoundEvent(soundEvent, position, volume, pitch)
|
||||
}
|
||||
|
||||
fun playSoundEvent(soundEvent: SoundEvent, position: Vec3? = null, volume: Float = 1.0f, pitch: Float = 1.0f) {
|
||||
audioPlayer?.playSoundEvent(soundEvent, position, volume, pitch)
|
||||
}
|
||||
|
||||
fun addParticle(particle: Particle) {
|
||||
particleRenderer?.add(particle)
|
||||
}
|
||||
|
||||
operator fun plusAssign(particle: Particle) {
|
||||
addParticle(particle)
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ class LeftClickHandler(
|
||||
connection.world.setBlockState(raycastHit.blockPosition, null)
|
||||
|
||||
raycastHit.blockState.breakSoundEvent?.let {
|
||||
renderWindow.rendering.audioPlayer.playSoundEvent(it, raycastHit.blockPosition, volume = raycastHit.blockState.soundEventVolume, pitch = raycastHit.blockState.soundEventPitch)
|
||||
connection.world.playSoundEvent(it, raycastHit.blockPosition, volume = raycastHit.blockState.soundEventVolume, pitch = raycastHit.blockState.soundEventPitch)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,18 +34,18 @@ object DefaultParticleBehavior {
|
||||
val invokers = listOf(
|
||||
CallbackEventInvoker.of<ExplosionEvent> {
|
||||
if (it.power >= 2.0f) {
|
||||
particleRenderer.add(ExplosionEmitterParticle(connection, particleRenderer, it.position, explosionEmitterParticleType.simple()))
|
||||
particleRenderer += ExplosionEmitterParticle(connection, it.position, explosionEmitterParticleType.default())
|
||||
} else {
|
||||
particleRenderer.add(ExplosionParticle(connection, particleRenderer, it.position, explosionParticleType.simple()))
|
||||
particleRenderer += ExplosionParticle(connection, it.position, explosionParticleType.default())
|
||||
}
|
||||
},
|
||||
CallbackEventInvoker.of<ParticleSpawnEvent> {
|
||||
fun spawn(position: Vec3, velocity: Vec3) {
|
||||
val particle = it.data.type.factory?.build(connection, particleRenderer, position, velocity, it.data) ?: let { _ ->
|
||||
val particle = it.data.type.factory?.build(connection, position, velocity, it.data) ?: let { _ ->
|
||||
Log.log(LogMessageType.RENDERING_GENERAL, LogLevels.WARN) { "Can not spawn particle: ${it.data.type}" }
|
||||
return
|
||||
}
|
||||
particleRenderer.add(particle)
|
||||
particleRenderer += particle
|
||||
}
|
||||
// ToDo: long distance = always spawn?
|
||||
if (it.count == 0) {
|
||||
|
@ -21,6 +21,6 @@ import glm_.vec3.Vec3
|
||||
|
||||
interface ParticleFactory<T : Particle> : CompanionResourceLocation {
|
||||
|
||||
fun build(connection: PlayConnection, particleRenderer: ParticleRenderer = connection.rendering!!.renderWindow[ParticleRenderer]!!, position: Vec3, velocity: Vec3, data: ParticleData = ParticleData(connection.registries.particleTypeRegistry[RESOURCE_LOCATION]!!)): T
|
||||
fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData = connection.registries.particleTypeRegistry[RESOURCE_LOCATION]!!.default()): T
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,8 @@ class ParticleRenderer(
|
||||
particleShader.load()
|
||||
renderWindow.textures.use(particleShader)
|
||||
renderWindow.textures.animator.use(particleShader)
|
||||
|
||||
connection.world.particleRenderer = this
|
||||
}
|
||||
|
||||
|
||||
@ -76,6 +78,10 @@ class ParticleRenderer(
|
||||
particles += particle
|
||||
}
|
||||
|
||||
operator fun plusAssign(particle: Particle) {
|
||||
add(particle)
|
||||
}
|
||||
|
||||
|
||||
override fun draw() {
|
||||
particleShader.use()
|
||||
|
@ -16,8 +16,8 @@ package de.bixilon.minosoft.gui.rendering.particle.types
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.data.physics.Speedable
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.AABB
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.assign
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.millis
|
||||
@ -29,14 +29,18 @@ import glm_.vec3.Vec3
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.random.Random
|
||||
import kotlin.reflect.full.companionObjectInstance
|
||||
|
||||
abstract class Particle(
|
||||
protected val connection: PlayConnection,
|
||||
protected val particleRenderer: ParticleRenderer,
|
||||
final override val position: Vec3,
|
||||
final override val velocity: Vec3 = Vec3.EMPTY,
|
||||
protected val data: ParticleData,
|
||||
data: ParticleData? = null,
|
||||
) : Speedable {
|
||||
protected val data: ParticleData = data ?: let {
|
||||
val resourceLocation = this::class.companionObjectInstance as ParticleFactory<*>
|
||||
connection.registries.particleTypeRegistry[resourceLocation]!!.default()
|
||||
}
|
||||
protected val random = Random
|
||||
var lastTickTime = -1L
|
||||
|
||||
|
@ -16,7 +16,6 @@ package de.bixilon.minosoft.gui.rendering.particle.types.norender
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.ExplosionParticle
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
@ -24,8 +23,8 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
class ExplosionEmitterParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, data: ParticleData) : NoRenderParticle(connection, particleRenderer, position, Vec3.EMPTY, data) {
|
||||
private val explosionParticleType = connection.registries.particleTypeRegistry[ExplosionParticle]!!
|
||||
class ExplosionEmitterParticle(connection: PlayConnection, position: Vec3, data: ParticleData? = null) : NoRenderParticle(connection, position, Vec3.EMPTY, data) {
|
||||
private val explosionParticleType = connection.registries.particleTypeRegistry[ExplosionParticle]
|
||||
|
||||
init {
|
||||
maxAge = MAX_AGE
|
||||
@ -34,10 +33,14 @@ class ExplosionEmitterParticle(connection: PlayConnection, particleRenderer: Par
|
||||
|
||||
override fun realTick() {
|
||||
super.realTick()
|
||||
explosionParticleType ?: let {
|
||||
dead = true
|
||||
return
|
||||
}
|
||||
for (i in 0 until 6) {
|
||||
val position = position + { (random.nextFloat() - random.nextFloat()) * 4.0f }
|
||||
|
||||
particleRenderer.add(ExplosionParticle(connection, particleRenderer, position, explosionParticleType.simple(), floatAge / MAX_AGE))
|
||||
connection.world += ExplosionParticle(connection, position, explosionParticleType.default(), floatAge / MAX_AGE)
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,8 +48,8 @@ class ExplosionEmitterParticle(connection: PlayConnection, particleRenderer: Par
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:explosion_emitter".asResourceLocation()
|
||||
private const val MAX_AGE = 9
|
||||
|
||||
override fun build(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData): ExplosionEmitterParticle {
|
||||
return ExplosionEmitterParticle(connection, particleRenderer, position, data)
|
||||
override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): ExplosionEmitterParticle {
|
||||
return ExplosionEmitterParticle(connection, position, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,11 @@ package de.bixilon.minosoft.gui.rendering.particle.types.norender
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
abstract class NoRenderParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData) : Particle(connection, particleRenderer, position, velocity, data) {
|
||||
abstract class NoRenderParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData?) : Particle(connection, position, velocity, data) {
|
||||
|
||||
override fun addVertex(particleMesh: ParticleMesh) {}
|
||||
}
|
||||
|
@ -16,12 +16,11 @@ package de.bixilon.minosoft.gui.rendering.particle.types.render
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.data.text.ChatColors
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
abstract class RenderParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData) : Particle(connection, particleRenderer, position, velocity, data) {
|
||||
abstract class RenderParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null) : Particle(connection, position, velocity, data) {
|
||||
protected open var scale: Float = 0.1f * (random.nextFloat() * 0.5f + 0.5f) * 2.0f
|
||||
protected var color: RGBColor = ChatColors.WHITE
|
||||
}
|
||||
|
@ -15,17 +15,18 @@ package de.bixilon.minosoft.gui.rendering.particle.types.render.texture
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.RenderParticle
|
||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
abstract class TextureParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, velocity: Vec3, position: Vec3, data: ParticleData) : RenderParticle(connection, particleRenderer, velocity, position, data) {
|
||||
abstract val texture: Texture
|
||||
abstract class TextureParticle(connection: PlayConnection, velocity: Vec3, position: Vec3, data: ParticleData? = null) : RenderParticle(connection, velocity, position, data) {
|
||||
abstract val texture: Texture?
|
||||
|
||||
|
||||
override fun addVertex(particleMesh: ParticleMesh) {
|
||||
particleMesh.addVertex(position, scale, texture, color)
|
||||
texture?.let {
|
||||
particleMesh.addVertex(position, scale, it, color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.data.text.RGBColor.Companion.asGray
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.MMath
|
||||
@ -23,7 +22,6 @@ import glm_.vec3.Vec3
|
||||
|
||||
abstract class AscendingParticle(
|
||||
connection: PlayConnection,
|
||||
particleRenderer: ParticleRenderer,
|
||||
position: Vec3,
|
||||
velocity: Vec3,
|
||||
velocityMultiplier: Vec3,
|
||||
@ -32,8 +30,8 @@ abstract class AscendingParticle(
|
||||
baseAge: Int,
|
||||
gravityStrength: Float,
|
||||
physics: Boolean,
|
||||
data: ParticleData,
|
||||
) : SimpleTextureParticle(connection, particleRenderer, position, Vec3.EMPTY, data) {
|
||||
data: ParticleData? = null,
|
||||
) : SimpleTextureParticle(connection, position, Vec3.EMPTY, data) {
|
||||
|
||||
override var scale: Float
|
||||
get() = super.scale * MMath.clamp(floatAge / maxAge * 32.0f, 0.0f, 1.0f)
|
||||
|
@ -16,7 +16,6 @@ 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.gui.rendering.particle.ParticleFactory
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.assign
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.millis
|
||||
@ -24,7 +23,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
class CampfireSmokeParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData, signal: Boolean) : SimpleTextureParticle(connection, particleRenderer, position, Vec3.EMPTY, data) {
|
||||
class CampfireSmokeParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null, signal: Boolean) : SimpleTextureParticle(connection, position, Vec3.EMPTY, data) {
|
||||
|
||||
init {
|
||||
scale *= 3.0f
|
||||
@ -70,8 +69,8 @@ class CampfireSmokeParticle(connection: PlayConnection, particleRenderer: Partic
|
||||
object CosyFactory : ParticleFactory<CampfireSmokeParticle> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:campfire_cosy_smoke".asResourceLocation()
|
||||
|
||||
override fun build(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData): CampfireSmokeParticle {
|
||||
return CampfireSmokeParticle(connection, particleRenderer, position, velocity, data, false)
|
||||
override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): CampfireSmokeParticle {
|
||||
return CampfireSmokeParticle(connection, position, velocity, data, false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,8 +78,8 @@ class CampfireSmokeParticle(connection: PlayConnection, particleRenderer: Partic
|
||||
object SignalFactory : ParticleFactory<CampfireSmokeParticle> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:campfire_signal_smoke".asResourceLocation()
|
||||
|
||||
override fun build(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData): CampfireSmokeParticle {
|
||||
return CampfireSmokeParticle(connection, particleRenderer, position, velocity, data, true)
|
||||
override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): CampfireSmokeParticle {
|
||||
return CampfireSmokeParticle(connection, position, velocity, data, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,12 @@ import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.data.text.RGBColor.Companion.asGray
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
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_.vec3.Vec3
|
||||
|
||||
class ExplosionParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, data: ParticleData, power: Float = 1.0f) : SimpleTextureParticle(connection, particleRenderer, position, Vec3.EMPTY, data) {
|
||||
class ExplosionParticle(connection: PlayConnection, position: Vec3, data: ParticleData? = null, power: Float = 1.0f) : SimpleTextureParticle(connection, position, Vec3.EMPTY, data) {
|
||||
|
||||
init {
|
||||
movement = false
|
||||
@ -36,8 +35,8 @@ class ExplosionParticle(connection: PlayConnection, particleRenderer: ParticleRe
|
||||
companion object : ParticleFactory<ExplosionParticle> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:explosion".asResourceLocation()
|
||||
|
||||
override fun build(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData): ExplosionParticle {
|
||||
return ExplosionParticle(connection, particleRenderer, position, data, velocity.x)
|
||||
override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): ExplosionParticle {
|
||||
return ExplosionParticle(connection, position, data, velocity.x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,12 @@
|
||||
package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.TextureParticle
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
abstract class SimpleTextureParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData) : TextureParticle(connection, particleRenderer, position, velocity, data) {
|
||||
override var texture = particleRenderer.renderWindow.textures.allTextures[data.type.textures.first()]!!
|
||||
abstract class SimpleTextureParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null) : TextureParticle(connection, position, velocity, data) {
|
||||
override var texture = connection.rendering?.renderWindow?.textures?.allTextures?.get(this.data.type.textures.first())
|
||||
var spriteDisabled = false
|
||||
|
||||
|
||||
@ -31,14 +30,14 @@ abstract class SimpleTextureParticle(connection: PlayConnection, particleRendere
|
||||
}
|
||||
// calculate next texture
|
||||
val nextTextureResourceLocation = data.type.textures[age / (maxAge / totalTextures + 1)]
|
||||
if (texture.resourceLocation == nextTextureResourceLocation) {
|
||||
if (texture?.resourceLocation == nextTextureResourceLocation) {
|
||||
return
|
||||
}
|
||||
texture = particleRenderer.renderWindow.textures.allTextures[nextTextureResourceLocation]!!
|
||||
texture = connection.rendering?.renderWindow?.textures?.allTextures?.get(nextTextureResourceLocation)
|
||||
}
|
||||
|
||||
fun setRandomSprite() {
|
||||
texture = particleRenderer.renderWindow.textures.allTextures[data.type.textures.random(random)]!!
|
||||
texture = connection.rendering?.renderWindow?.textures?.allTextures?.get(data.type.textures.random(random))
|
||||
}
|
||||
|
||||
override fun tick(deltaTime: Int) {
|
||||
|
@ -16,20 +16,19 @@ package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.f
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.AscendingParticle
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
class SmokeParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData, scaleMultiplier: Float = 1.0f) : AscendingParticle(connection, particleRenderer, position, velocity, Vec3(0.1f), scaleMultiplier, 0.3f, 8, -0.1f, true, data) {
|
||||
class SmokeParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null, scaleMultiplier: Float = 1.0f) : AscendingParticle(connection, position, velocity, Vec3(0.1f), scaleMultiplier, 0.3f, 8, -0.1f, true, data) {
|
||||
|
||||
|
||||
companion object : ParticleFactory<SmokeParticle> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:smoke".asResourceLocation()
|
||||
|
||||
override fun build(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData): SmokeParticle {
|
||||
return SmokeParticle(connection, particleRenderer, position, velocity, data)
|
||||
override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): SmokeParticle {
|
||||
return SmokeParticle(connection, position, velocity, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.l
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.SimpleTextureParticle
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.fire.SmokeParticle
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
@ -25,8 +24,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
class LavaParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, data: ParticleData) : SimpleTextureParticle(connection, particleRenderer, position, Vec3.EMPTY, data) {
|
||||
private val smokeParticleType = connection.registries.particleTypeRegistry[SmokeParticle]!!
|
||||
class LavaParticle(connection: PlayConnection, position: Vec3, data: ParticleData? = null) : SimpleTextureParticle(connection, position, Vec3.EMPTY, data) {
|
||||
|
||||
override var scale: Float
|
||||
get() = super.scale * (1.0f - (floatAge / maxAge).sqr)
|
||||
@ -48,15 +46,15 @@ class LavaParticle(connection: PlayConnection, particleRenderer: ParticleRendere
|
||||
super.realTick()
|
||||
|
||||
if (random.nextFloat() > (floatAge / maxAge)) {
|
||||
particleRenderer.add(SmokeParticle(connection, particleRenderer, Vec3(position), Vec3(velocity), smokeParticleType.simple()))
|
||||
connection.world += SmokeParticle(connection, Vec3(position), Vec3(velocity))
|
||||
}
|
||||
}
|
||||
|
||||
companion object : ParticleFactory<LavaParticle> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:lava".asResourceLocation()
|
||||
|
||||
override fun build(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData): LavaParticle {
|
||||
return LavaParticle(connection, particleRenderer, position, data)
|
||||
override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): LavaParticle {
|
||||
return LavaParticle(connection, position, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,12 +112,13 @@ class AudioPlayer(
|
||||
}
|
||||
})
|
||||
|
||||
DefaultAudioBehavior.register(connection, this)
|
||||
DefaultAudioBehavior.register(connection)
|
||||
|
||||
Log.log(LogMessageType.AUDIO_LOADING, LogLevels.INFO) { "OpenAL loaded!" }
|
||||
|
||||
|
||||
initialized = true
|
||||
connection.world.audioPlayer = this
|
||||
latch.dec()
|
||||
}
|
||||
|
||||
@ -133,7 +134,6 @@ class AudioPlayer(
|
||||
playSoundEvent(soundEvent, position?.center, volume, pitch)
|
||||
}
|
||||
|
||||
|
||||
fun playSoundEvent(soundEvent: SoundEvent, position: Vec3? = null, volume: Float = 1.0f, pitch: Float = 1.0f) {
|
||||
if (!initialized) {
|
||||
return
|
||||
|
@ -24,10 +24,11 @@ import kotlin.random.Random
|
||||
object DefaultAudioBehavior {
|
||||
val ENTITY_GENERIC_EXPLODE = "minecraft:entity.generic.explode".asResourceLocation()
|
||||
|
||||
fun register(connection: PlayConnection, audioPlayer: AudioPlayer) {
|
||||
fun register(connection: PlayConnection) {
|
||||
val world = connection.world
|
||||
val invokers = listOf(
|
||||
CallbackEventInvoker.of<PlaySoundEvent> { audioPlayer.playSoundEvent(it.soundEvent, it.position.toVec3, it.volume, it.pitch) },
|
||||
CallbackEventInvoker.of<ExplosionEvent> { audioPlayer.playSoundEvent(ENTITY_GENERIC_EXPLODE, it.position, 4.0f, (1.0f + (Random.nextFloat() - Random.nextFloat()) * 0.2f) * 0.7f) },
|
||||
CallbackEventInvoker.of<PlaySoundEvent> { world.playSoundEvent(it.soundEvent, it.position.toVec3, it.volume, it.pitch) },
|
||||
CallbackEventInvoker.of<ExplosionEvent> { world.playSoundEvent(ENTITY_GENERIC_EXPLODE, it.position, 4.0f, (1.0f + (Random.nextFloat() - Random.nextFloat()) * 0.2f) * 0.7f) },
|
||||
)
|
||||
|
||||
connection.registerEvents(*invokers.toTypedArray())
|
||||
|
Loading…
x
Reference in New Issue
Block a user