blocks: TorchBlock, fix bracket mistake in FlameParticle

This commit is contained in:
Bixilon 2021-06-07 18:08:24 +02:00 committed by Lukas
parent 277d23fff4
commit 80c55e39f8
8 changed files with 75 additions and 18 deletions

View File

@ -117,6 +117,7 @@ open class Block(
"RepeaterBlock" -> RepeaterBlock(resourceLocation, mappings, data)
"ComparatorBlock" -> ComparatorBlock(resourceLocation, mappings, data)
"CampfireBlock" -> CampfireBlock(resourceLocation, mappings, data)
"TorchBlock" -> TorchBlock(resourceLocation, mappings, data)
else -> Block(resourceLocation, mappings, data)
}

View File

@ -52,23 +52,21 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
}
fun spawnSmokeParticles(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, extinguished: Boolean) {
let {
val position = Vec3d(blockPosition).horizontalPlus(
{ 0.5 + 3.0.noise },
Random.nextDouble() + Random.nextDouble() + 0.5 // ToDo: This +0.5f is a temporary fix for not making the particle stuck in ourself
)
val position = Vec3d(blockPosition).horizontalPlus(
{ 0.5 + 3.0.noise },
Random.nextDouble() + Random.nextDouble() + 0.5 // ToDo: This +0.5f is a temporary fix for not making the particle stuck in ourself
)
val isSignal = blockState.properties[BlockProperties.CAMPFIRE_SIGNAL_FIRE] == true
val isSignal = blockState.properties[BlockProperties.CAMPFIRE_SIGNAL_FIRE] == true
val particleType = if (isSignal) {
signalSmokeParticle
} else {
cosySmokeParticle
}
connection.world += CampfireSmokeParticle(connection, position, Vec3d(0.0f, 0.07f, 0.0f), particleType.default(), isSignal)
val particleType = if (isSignal) {
signalSmokeParticle
} else {
cosySmokeParticle
}
connection.world += CampfireSmokeParticle(connection, position, Vec3d(0.0f, 0.07f, 0.0f), particleType.default(), isSignal)
if (extinguished) {
val position = Vec3d(blockPosition).horizontalPlus(
{ 0.5 + 4.0.noise },

View File

@ -0,0 +1,43 @@
/*
* 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.data.mappings.blocks.types
import com.google.gson.JsonObject
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.blocks.BlockState
import de.bixilon.minosoft.data.mappings.versions.Registries
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.fire.SmokeParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.slowing.FlameParticle
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import glm_.vec3.Vec3d
import glm_.vec3.Vec3i
import kotlin.random.Random
open class TorchBlock(resourceLocation: ResourceLocation, registries: Registries, data: JsonObject) : Block(resourceLocation, registries, data) {
private val smokeParticle = registries.particleTypeRegistry[SmokeParticle]
private val flameParticle = registries.particleTypeRegistry[data["flame_particle"] ?: FlameParticle]
private fun spawnSmokeParticles(connection: PlayConnection, blockPosition: Vec3i) {
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) }
}
override fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {
spawnSmokeParticles(connection, blockPosition)
}
}

View File

@ -44,6 +44,18 @@ open class Registry<T : RegistryItem>(
}
}
open operator fun get(any: Any?): T? {
return when (any) {
null -> null
is Number -> get(any.toInt())
is JsonElement -> get(any)
is ResourceLocation -> get(any)
is String -> get(any)
is ResourceLocationAble -> get(any.resourceLocation)
else -> TODO()
}
}
open operator fun get(resourceLocation: ResourceLocation): T? {
return resourceLocationMap[resourceLocation] ?: parentRegistry?.get(resourceLocation)
}
@ -56,7 +68,6 @@ open class Registry<T : RegistryItem>(
return get(resourceLocation.resourceLocation)
}
open operator fun get(id: Int): T {
return idValueMap[id] ?: parentRegistry?.get(id) ?: throw NullPointerException("Can not find item with id $id")
}

View File

@ -230,8 +230,8 @@ class World(
particleRenderer?.add(particle)
}
operator fun plusAssign(particle: Particle) {
addParticle(particle)
operator fun plusAssign(particle: Particle?) {
addParticle(particle ?: return)
}
fun isSpaceEmpty(aabb: AABB): Boolean {

View File

@ -93,7 +93,7 @@ abstract class Particle(
spacing = Vec3(0.2)
}
fun move(velocity: Vec3d) {
open fun move(velocity: Vec3d) {
if (alreadyCollided) {
return
}

View File

@ -29,6 +29,10 @@ open class FlameParticle(connection: PlayConnection, position: Vec3d, velocity:
super.scale = value
}
override fun move(velocity: Vec3d) {
position += velocity
}
companion object : ParticleFactory<FlameParticle> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:flame".asResourceLocation()

View File

@ -25,7 +25,7 @@ abstract class SlowingParticle(connection: PlayConnection, position: Vec3d, velo
init {
friction = 0.96f
this.velocity assign (this.velocity * 0.009999999776482582 + velocity)
this.position += { random.nextDouble() - random.nextDouble() * 0.05 }
this.position += { (random.nextDouble() - random.nextDouble()) * 0.05 }
maxAge = (8.0 / (random.nextDouble() * 0.8 + 0.2)).toInt() + 4
}
}