diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/Block.kt b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/Block.kt
index 35df25c9a..756179e66 100644
--- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/Block.kt
+++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/Block.kt
@@ -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)
}
diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt
index 2566b4dd1..46970359e 100644
--- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt
+++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt
@@ -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 },
diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/TorchBlock.kt b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/TorchBlock.kt
new file mode 100644
index 000000000..7b604eedb
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/TorchBlock.kt
@@ -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 .
+ *
+ * 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)
+ }
+
+}
diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/registry/Registry.kt b/src/main/java/de/bixilon/minosoft/data/mappings/registry/Registry.kt
index 8092b5cf4..eaf3eecc6 100644
--- a/src/main/java/de/bixilon/minosoft/data/mappings/registry/Registry.kt
+++ b/src/main/java/de/bixilon/minosoft/data/mappings/registry/Registry.kt
@@ -44,6 +44,18 @@ open class Registry(
}
}
+ 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(
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")
}
diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.kt b/src/main/java/de/bixilon/minosoft/data/world/World.kt
index 9c7f3446d..512ff4762 100644
--- a/src/main/java/de/bixilon/minosoft/data/world/World.kt
+++ b/src/main/java/de/bixilon/minosoft/data/world/World.kt
@@ -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 {
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt
index da59377bb..27e86a950 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt
@@ -93,7 +93,7 @@ abstract class Particle(
spacing = Vec3(0.2)
}
- fun move(velocity: Vec3d) {
+ open fun move(velocity: Vec3d) {
if (alreadyCollided) {
return
}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/FlameParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/FlameParticle.kt
index ef08a0320..552d93595 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/FlameParticle.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/FlameParticle.kt
@@ -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 {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:flame".asResourceLocation()
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SlowingParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SlowingParticle.kt
index 5c147fe75..e1109f649 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SlowingParticle.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SlowingParticle.kt
@@ -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
}
}