remove WorldParticleRenderer

This commit is contained in:
Moritz Zwerger 2023-12-18 17:43:54 +01:00
parent ac3a8279a5
commit 47ee3d58df
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
18 changed files with 60 additions and 88 deletions

View File

@ -64,6 +64,7 @@ class CampfireBlockEntity(connection: PlayConnection) : BlockEntity(connection)
override fun tick(connection: PlayConnection, state: BlockState, position: Vec3i, random: Random) {
val particle = connection.world.particle ?: return
if (state.block !is CampfireBlock || !state.isLit()) {
return
}
@ -90,7 +91,7 @@ class CampfireBlockEntity(connection: PlayConnection) : BlockEntity(connection)
)
for (i in 0 until 4) {
connection.world.addParticle(SmokeParticle(connection, position, Vec3d(0.0, 5.0E-4, 0.0)))
particle += SmokeParticle(connection, position, Vec3d(0.0, 5.0E-4, 0.0))
}
}
}

View File

@ -40,12 +40,13 @@ class MobSpawnerBlockEntity(connection: PlayConnection) : BlockEntity(connection
}
private fun spawnParticles(blockPosition: Vec3i, random: Random) {
val particle = connection.world.particle ?: return
if (!isPlayerInRange(blockPosition)) {
return
}
val particlePosition = blockPosition.toVec3d + { random.nextDouble() }
smokeParticleType?.let { connection.world += SmokeParticle(connection, Vec3d(particlePosition), Vec3d.EMPTY, it.default()) }
flameParticleType?.let { connection.world += FlameParticle(connection, Vec3d(particlePosition), Vec3d.EMPTY, it.default()) }
smokeParticleType?.let { particle += SmokeParticle(connection, Vec3d(particlePosition), Vec3d.EMPTY, it.default()) }
flameParticleType?.let { particle += FlameParticle(connection, Vec3d(particlePosition), Vec3d.EMPTY, it.default()) }
}
override fun setBlockActionData(type: Int, data: Int) {

View File

@ -61,11 +61,12 @@ class NoteBlockBlockEntity(connection: PlayConnection) : BlockEntity(connection)
if (!showParticleNextTick) {
return
}
val particle = connection.world.particle ?: return
showParticleNextTick = false
noteParticleType?.let {
connection.world += NoteParticle(connection, position.toVec3d + Vec3d(0.5, 1.2, 0.5), state.getNote() / 24.0f, it.default())
particle += NoteParticle(connection, position.toVec3d + Vec3d(0.5, 1.2, 0.5), state.getNote() / 24.0f, it.default())
}
}

View File

@ -38,7 +38,7 @@ class PrimedTNT(connection: PlayConnection, entityType: EntityType, data: Entity
super.tick()
val position = physics.position
connection.world += SmokeParticle(connection, position + SMOKE_OFFSET, Vec3d.EMPTY)
connection.world.particle?.let { it += SmokeParticle(connection, position + SMOKE_OFFSET, Vec3d.EMPTY) }
}
override fun createPhysics() = PrimedTNTPhysics(this)

View File

@ -33,11 +33,12 @@ open class RedstoneTorchBlock(resourceLocation: ResourceLocation, registries: Re
private val redstoneDustParticle = registries.particleType[DustParticle]
override fun randomDisplayTick(connection: PlayConnection, state: BlockState, position: BlockPosition, random: Random) {
val particle = connection.world.particle ?: return
if (!state.isLit()) {
return
}
(flameParticle ?: redstoneDustParticle)?.let { connection.world += it.factory?.build(connection, Vec3d(position) + Vec3d(0.5, 0.7, 0.5) + (Vec3d.of { random.nextDouble() - 0.5 } * 0.2), Vec3d.EMPTY, DustParticleData(Colors.TRUE_RED, 1.0f, it)) }
(flameParticle ?: redstoneDustParticle)?.let { particle += it.factory?.build(connection, Vec3d(position) + Vec3d(0.5, 0.7, 0.5) + (Vec3d.of { random.nextDouble() - 0.5 } * 0.2), Vec3d.EMPTY, DustParticleData(Colors.TRUE_RED, 1.0f, it)) }
}
companion object : PixLyzerBlockFactory<RedstoneTorchBlock> {

View File

@ -32,9 +32,10 @@ open class TorchBlock(resourceLocation: ResourceLocation, registries: Registries
private fun spawnSmokeParticles(connection: PlayConnection, blockPosition: Vec3i) {
val particle = connection.world.particle ?: return
val particlePosition = Vec3d(0.5, 0.7, 0.5) + blockPosition
smokeParticle?.let { connection.world += SmokeParticle(connection, Vec3d(particlePosition), Vec3d.EMPTY) }
flameParticle?.let { connection.world += it.factory?.build(connection, Vec3d(particlePosition), Vec3d.EMPTY) }
smokeParticle?.let { particle += SmokeParticle(connection, Vec3d(particlePosition), Vec3d.EMPTY) }
flameParticle?.let { particle += it.factory?.build(connection, Vec3d(particlePosition), Vec3d.EMPTY) }
}
override fun randomDisplayTick(connection: PlayConnection, state: BlockState, position: BlockPosition, random: Random) {

View File

@ -53,6 +53,7 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
}
fun spawnSmokeParticles(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, extinguished: Boolean, random: Random) {
val particle = connection.world.particle ?: return
val position = Vec3d(blockPosition).horizontalPlus(
{ 0.5 + 3.0.noised(random) },
random.nextDouble() + random.nextDouble() + 0.5 // ToDo: This +0.5f is a temporary fix for not making the particle stuck in ourself
@ -60,24 +61,21 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
val isSignal = isSignal(blockState)
val particleType = if (isSignal) {
signalSmokeParticle
} else {
cosySmokeParticle
}
val particleType = if (isSignal) signalSmokeParticle else cosySmokeParticle
connection.world += CampfireSmokeParticle(connection, position, SMOKE_VELOCITY, particleType.default(), isSignal)
particle += CampfireSmokeParticle(connection, position, SMOKE_VELOCITY, particleType.default(), isSignal)
if (extinguished) {
val position = Vec3d(blockPosition).horizontalPlus(
{ 0.5 + 4.0.noised(random) },
0.5
)
connection.world += SmokeParticle(connection, position, EXTINGUISHED_VELOCITY, smokeParticle.default())
particle += SmokeParticle(connection, position, EXTINGUISHED_VELOCITY, smokeParticle.default())
}
}
override fun randomDisplayTick(connection: PlayConnection, state: BlockState, position: BlockPosition, random: Random) {
val particle = connection.world.particle ?: return
if (!state.isLit()) {
return
}
@ -88,7 +86,7 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
if (lavaParticles && random.chance(20)) {
val position = Vec3d(position) + 0.5
for (i in 0 until random.nextInt(1) + 1) {
connection.world += LavaParticle(connection, position, lavaParticle.default())
particle += LavaParticle(connection, position, lavaParticle.default())
}
}
}

View File

@ -32,27 +32,27 @@ open class NetherPortalBlock(resourceLocation: ResourceLocation, registries: Reg
private val portalParticleType = registries.particleType[PortalParticle]
override fun randomDisplayTick(connection: PlayConnection, state: BlockState, position: BlockPosition, random: Random) {
portalParticleType?.let {
for (i in 0 until 4) {
val particlePosition = Vec3d(position) + { random.nextDouble() }
val velocity = Vec3d.of { (random.nextDouble() - 0.5) * 0.5 }
val particle = connection.world.particle ?: return
if (portalParticleType == null) return
for (i in 0 until 4) {
val particlePosition = Vec3d(position) + { random.nextDouble() }
val velocity = Vec3d.of { (random.nextDouble() - 0.5) * 0.5 }
val factor = (random.nextInt(2) * 2 + 1).toDouble()
val factor = (random.nextInt(2) * 2 + 1).toDouble()
if (connection.world[position + Directions.WEST]?.block != this && connection.world[position + Directions.EAST]?.block != this) {
particlePosition.x = position.x + 0.5 + 0.25 * factor
velocity.x = random.nextDouble() * 2.0 * factor
} else {
particlePosition.z = position.z + 0.5 + 0.25 * factor
velocity.z = random.nextDouble() * 2.0 * factor
}
connection.world += PortalParticle(
connection,
particlePosition,
velocity,
it.default(),
)
if (connection.world[position + Directions.WEST]?.block != this && connection.world[position + Directions.EAST]?.block != this) {
particlePosition.x = position.x + 0.5 + 0.25 * factor
velocity.x = random.nextDouble() * 2.0 * factor
} else {
particlePosition.z = position.z + 0.5 + 0.25 * factor
velocity.z = random.nextDouble() * 2.0 * factor
}
particle += PortalParticle(
connection,
particlePosition,
velocity,
portalParticleType.default(),
)
}
}

View File

@ -41,13 +41,14 @@ open class LeverBlock(resourceLocation: ResourceLocation, registries: Registries
private val dustParticleType = registries.particleType[DustParticle]
private fun spawnParticles(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, scale: Float) {
dustParticleType ?: return
val particle = connection.world.particle ?: return
if (dustParticleType == null) return
val direction = blockState.getFacing().inverted
val mountDirection = getRealFacing(blockState)
val position = (Vec3d(blockPosition) + 0.5).plus((direction.vector * 0.1) + (mountDirection.vector * 0.2))
connection.world += DustParticle(connection, position, Vec3d.EMPTY, DustParticleData(Colors.TRUE_RED, scale, dustParticleType))
particle += DustParticle(connection, position, Vec3d.EMPTY, DustParticleData(Colors.TRUE_RED, scale, dustParticleType))
}
override fun randomDisplayTick(connection: PlayConnection, state: BlockState, position: BlockPosition, random: Random) {

View File

@ -78,6 +78,7 @@ open class LavaFluid(identifier: ResourceLocation = Companion.identifier) : Flui
override fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {
super.randomTick(connection, blockState, blockPosition, random)
val particle = connection.world.particle ?: return
val above = connection.world[blockPosition + Directions.UP]
if (above != null) { // ToDo: Or is not a full block
@ -89,7 +90,7 @@ open class LavaFluid(identifier: ResourceLocation = Companion.identifier) : Flui
1.0
)
connection.world += LavaParticle(connection, position, lavaParticleType.default())
particle += LavaParticle(connection, position, lavaParticleType.default())
}
}

View File

@ -79,9 +79,11 @@ class WaterFluid(resourceLocation: ResourceLocation = identifier) : Fluid(resour
override fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {
super.randomTick(connection, blockState, blockPosition, random)
val particle = connection.world.particle ?: return
// ToDo: if not sill and not falling
if (random.chance(10)) {
connection.world += UnderwaterParticle(connection, blockPosition.toVec3d + { random.nextDouble() })
particle += UnderwaterParticle(connection, blockPosition.toVec3d + { random.nextDouble() })
}
}

View File

@ -37,7 +37,6 @@ import de.bixilon.minosoft.data.world.difficulty.WorldDifficulty
import de.bixilon.minosoft.data.world.entities.WorldEntities
import de.bixilon.minosoft.data.world.iterator.WorldIterator
import de.bixilon.minosoft.data.world.particle.AbstractParticleRenderer
import de.bixilon.minosoft.data.world.particle.WorldParticleRenderer
import de.bixilon.minosoft.data.world.positions.BlockPosition
import de.bixilon.minosoft.data.world.positions.ChunkPosition
import de.bixilon.minosoft.data.world.positions.ChunkPositionUtil.chunkPosition
@ -55,9 +54,9 @@ import java.util.*
*/
class World(
val connection: PlayConnection,
) : WorldAudioPlayer, WorldParticleRenderer {
) : WorldAudioPlayer {
val lock = SimpleLock()
override val random = Random()
val random = Random()
val biomes = WorldBiomes(this)
val chunks = ChunkManager(this, 1000, 100)
val entities = WorldEntities()
@ -73,7 +72,7 @@ class World(
override var audio: AbstractAudioPlayer? = null
override var particle: AbstractParticleRenderer? = null
var particle: AbstractParticleRenderer? = null
var occlusion by observed(0)

View File

@ -1,29 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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.data.world.particle
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
@Deprecated("use world.particle")
interface WorldParticleRenderer : AbstractParticleRenderer {
val particle: AbstractParticleRenderer?
override fun addParticle(particle: Particle) {
this.particle?.addParticle(particle)
}
override fun removeAllParticles() {
particle?.removeAllParticles()
}
}

View File

@ -81,8 +81,8 @@ class ParticleRenderer(
get() = particles.size
override fun registerLayers() {
layers.register(OpaqueLayer, shader, this::drawTransparent)
layers.register(TranslucentLayer, shader, this::drawTranslucent)
layers.register(OpaqueLayer, shader, renderer = { mesh.draw() })
layers.register(TranslucentLayer, shader, renderer = { translucentMesh.draw() })
}
private fun loadTextures() {
@ -160,14 +160,6 @@ class ParticleRenderer(
translucentMesh.load()
}
private fun drawTransparent() {
mesh.draw()
}
private fun drawTranslucent() {
translucentMesh.draw()
}
override fun removeAllParticles() {
particles.clear()
queue.clear()

View File

@ -33,14 +33,15 @@ class ExplosionEmitterParticle(connection: PlayConnection, position: Vec3d, data
override fun tick() {
super.tick()
explosionParticleType ?: let {
val particle = connection.world.particle ?: return
if (explosionParticleType == null) {
dead = true
return
}
for (i in 0 until 6) {
val position = position + { (random.nextDouble() - random.nextDouble()) * 4.0 }
connection.world += ExplosionParticle(connection, position, explosionParticleType.default(), floatAge / MAX_AGE)
particle += ExplosionParticle(connection, position, explosionParticleType.default(), floatAge / MAX_AGE)
}
}

View File

@ -42,6 +42,7 @@ class EntityEmitterParticle(
fun emitParticles() {
val particle = connection.world.particle ?: return
val position = entity.physics.position
for (i in 0 until 16) {
val scale = Vec3(random.nextFloat(-1.0f, 1.0f), random.nextFloat(-1.0f, 1.0f), random.nextFloat(-1.0f, 1.0f))
@ -55,8 +56,7 @@ class EntityEmitterParticle(
position.y + (entity.type.height * (0.5f + scale.y / 4.0f)),
position.z + (entity.type.width * (scale.z / 4.0f)),
)
val particle = particleFactory.build(connection, particlePosition, Vec3d(scale.x, scale.y, scale.z), particleData) // ToDo: Velocity.y is getting added with 0.2
connection.world.addParticle(particle ?: continue)
particle += particleFactory.build(connection, particlePosition, Vec3d(scale.x, scale.y, scale.z), particleData) ?: continue// ToDo: Velocity.y is getting added with 0.2
}
}

View File

@ -44,9 +44,10 @@ class LavaParticle(connection: PlayConnection, position: Vec3d, data: ParticleDa
override fun tick() {
super.tick()
val particle = connection.world.particle ?: return
if (random.nextFloat() > (floatAge / maxAge)) {
connection.world += SmokeParticle(connection, Vec3d(position), Vec3d(velocity))
particle += SmokeParticle(connection, Vec3d(position), Vec3d(velocity))
}
}

View File

@ -74,14 +74,15 @@ class AttackHandler(
val critical = (cooldown / COOLDOWN.toFloat()) > 0.9f && player.physics.fallDistance != 0.0f && !player.physics.onGround && !player.physics().isClimbing() && (player.physics.submersion[WaterFluid]) <= 0.0f && player.effects[VisionEffect.Blindness] == null && player.attachment.vehicle == null && entity is LivingEntity
// TODO: use attack speed entity attribute
val particle = interactions.connection.world.particle ?: return
if (critical) {
interactions.connection.world.addParticle(EntityEmitterParticle(interactions.connection, entity, CritParticle))
particle += EntityEmitterParticle(interactions.connection, entity, CritParticle)
}
if (sharpnessLevel > 0) {
// ToDo: Entity animations
interactions.connection.world.addParticle(EntityEmitterParticle(interactions.connection, entity, EnchantedHitParticle))
particle += EntityEmitterParticle(interactions.connection, entity, EnchantedHitParticle)
}
}