From 6b608738b97c077b03cd54d27fd25826fef9478f Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sat, 12 Jun 2021 15:13:01 +0200 Subject: [PATCH] particles: RedstoneTorchBlock --- .../data/mappings/blocks/types/Block.kt | 1 + .../blocks/types/RedstoneTorchBlock.kt | 39 +++++++++++++++++++ .../data/mappings/blocks/types/TorchBlock.kt | 4 +- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/RedstoneTorchBlock.kt 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 2a23bff06..2dd6b4f82 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 @@ -124,6 +124,7 @@ open class Block( "BrewingStandBlock" to { resourceLocation, registries, data -> BrewingStandBlock(resourceLocation, registries, data) }, "EnderChestBlock" to { resourceLocation, registries, data -> EnderChestBlock(resourceLocation, registries, data) }, "NetherPortalBlock" to { resourceLocation, registries, data -> NetherPortalBlock(resourceLocation, registries, data) }, + "RedstoneTorchBlock" to { resourceLocation, registries, data -> RedstoneTorchBlock(resourceLocation, registries, data) }, ) override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: JsonObject): Block { diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/RedstoneTorchBlock.kt b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/RedstoneTorchBlock.kt new file mode 100644 index 000000000..1517801c1 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/RedstoneTorchBlock.kt @@ -0,0 +1,39 @@ +/* + * 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.blocks.properties.BlockProperties +import de.bixilon.minosoft.data.mappings.versions.Registries +import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY +import de.bixilon.minosoft.gui.rendering.util.VecUtil.of +import de.bixilon.minosoft.protocol.network.connection.PlayConnection +import glm_.vec3.Vec3d +import glm_.vec3.Vec3i +import kotlin.random.Random + +open class RedstoneTorchBlock(resourceLocation: ResourceLocation, registries: Registries, data: JsonObject) : TorchBlock(resourceLocation, registries, data) { + + + override fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) { + if (blockState.properties[BlockProperties.LIT] != true) { + return + } + + flameParticle?.let { connection.world += it.factory?.build(connection, Vec3d(blockPosition) + Vec3d(0.5, 0.7, 0.5) + (Vec3d.of { random.nextDouble() - 0.5 } * 0.2), Vec3d.EMPTY) } + } + +} 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 index 7b604eedb..4f401d0ee 100644 --- 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 @@ -26,8 +26,8 @@ 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] + protected val smokeParticle = registries.particleTypeRegistry[SmokeParticle] + protected val flameParticle = registries.particleTypeRegistry[data["flame_particle"] ?: FlameParticle] private fun spawnSmokeParticles(connection: PlayConnection, blockPosition: Vec3i) {