diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/SignBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/SignBlockEntity.kt index fe7d86a76..f8bf47342 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/SignBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/SignBlockEntity.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2021 Moritz Zwerger + * Copyright (C) 2020-2022 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. * @@ -15,9 +15,13 @@ package de.bixilon.minosoft.data.entities.block import de.bixilon.kutil.cast.CastUtil.nullCast import de.bixilon.minosoft.data.registries.ResourceLocation +import de.bixilon.minosoft.data.registries.blocks.BlockState import de.bixilon.minosoft.data.text.ChatComponent +import de.bixilon.minosoft.gui.rendering.RenderWindow +import de.bixilon.minosoft.gui.rendering.world.entities.renderer.SignBlockEntityRenderer import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition +import glm_.vec3.Vec3i class SignBlockEntity(connection: PlayConnection) : BlockEntity(connection) { var lines: Array = Array(ProtocolDefinition.SIGN_LINES) { ChatComponent.of("") } @@ -31,6 +35,10 @@ class SignBlockEntity(connection: PlayConnection) : BlockEntity(connection) { } } + override fun createRenderer(renderWindow: RenderWindow, blockState: BlockState, blockPosition: Vec3i, light: Int): SignBlockEntityRenderer { + return SignBlockEntityRenderer(this) + } + companion object : BlockEntityFactory { override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:sign") diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/SingleBlockRenderable.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/SingleBlockRenderable.kt new file mode 100644 index 000000000..7720a194d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/SingleBlockRenderable.kt @@ -0,0 +1,24 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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.gui.rendering.models + +import de.bixilon.minosoft.data.registries.blocks.BlockState +import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh +import glm_.vec3.Vec3i +import java.util.* + +interface SingleBlockRenderable { + + fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockModel.kt index e883bb783..11651de86 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockModel.kt @@ -15,18 +15,15 @@ package de.bixilon.minosoft.gui.rendering.models.baked.block import de.bixilon.kotlinglm.vec3.Vec3i import de.bixilon.minosoft.data.direction.Directions -import de.bixilon.minosoft.data.registries.blocks.BlockState +import de.bixilon.minosoft.gui.rendering.models.SingleBlockRenderable import de.bixilon.minosoft.gui.rendering.models.baked.BakedModel import de.bixilon.minosoft.gui.rendering.models.properties.AbstractFaceProperties import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture -import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh import java.util.* -interface BakedBlockModel : BakedModel { +interface BakedBlockModel : BakedModel, SingleBlockRenderable { fun getTouchingFaceProperties(random: Random, direction: Directions): Array - fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean - fun getParticleTexture(random: Random, blockPosition: Vec3i): AbstractTexture? } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/MeshedBlockEntityRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/MeshedBlockEntityRenderer.kt new file mode 100644 index 000000000..811b44dc0 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/MeshedBlockEntityRenderer.kt @@ -0,0 +1,32 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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.gui.rendering.world.entities + +import de.bixilon.minosoft.data.entities.block.BlockEntity +import de.bixilon.minosoft.data.registries.blocks.BlockState +import de.bixilon.minosoft.gui.rendering.RenderWindow +import de.bixilon.minosoft.gui.rendering.models.SingleBlockRenderable + +interface MeshedBlockEntityRenderer : BlockEntityRenderer, SingleBlockRenderable { + override val blockState: BlockState + get() = TODO("Not yet implemented") + override var light: Int + get() = 0 + set(value) {} + + override fun draw(renderWindow: RenderWindow) = Unit + override fun load() = Unit + override fun unload() = Unit + +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/renderer/SignBlockEntityRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/renderer/SignBlockEntityRenderer.kt new file mode 100644 index 000000000..f1148bd39 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/renderer/SignBlockEntityRenderer.kt @@ -0,0 +1,31 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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.gui.rendering.world.entities.renderer + +import de.bixilon.minosoft.data.entities.block.SignBlockEntity +import de.bixilon.minosoft.data.registries.blocks.BlockState +import de.bixilon.minosoft.gui.rendering.world.entities.MeshedBlockEntityRenderer +import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh +import glm_.vec3.Vec3i +import java.util.* + +class SignBlockEntityRenderer( + val sign: SignBlockEntity, +) : MeshedBlockEntityRenderer { + + override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean { + println("Rendering sign at $position") + return true + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/renderer/storage/DoubleChestRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/renderer/storage/DoubleChestRenderer.kt index fc5283c1d..2e2da91a8 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/renderer/storage/DoubleChestRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/entities/renderer/storage/DoubleChestRenderer.kt @@ -43,7 +43,6 @@ class DoubleChestRenderer( light, ) { - companion object { val DOUBLE_MODEL = "minecraft:block/entities/double_chest".toResourceLocation().bbModel() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/preparer/cull/SolidCullSectionPreparer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/preparer/cull/SolidCullSectionPreparer.kt index 5771dd33d..1b77df6b7 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/world/preparer/cull/SolidCullSectionPreparer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/preparer/cull/SolidCullSectionPreparer.kt @@ -30,9 +30,10 @@ import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock import de.bixilon.minosoft.data.world.Chunk import de.bixilon.minosoft.data.world.ChunkSection import de.bixilon.minosoft.gui.rendering.RenderWindow -import de.bixilon.minosoft.gui.rendering.models.baked.block.BakedBlockModel +import de.bixilon.minosoft.gui.rendering.models.SingleBlockRenderable import de.bixilon.minosoft.gui.rendering.util.VecUtil import de.bixilon.minosoft.gui.rendering.world.entities.BlockEntityRenderer +import de.bixilon.minosoft.gui.rendering.world.entities.MeshedBlockEntityRenderer import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh import de.bixilon.minosoft.gui.rendering.world.preparer.SolidSectionPreparer import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition @@ -66,8 +67,8 @@ class SolidCullSectionPreparer( val blockEntities: MutableSet> = mutableSetOf() section.acquire() neighbours.acquire() - var blockEntity: BlockEntity? = null - var model: BakedBlockModel + var blockEntity: BlockEntity? + var model: SingleBlockRenderable var blockState: BlockState var position: Vec3i var rendered: Boolean @@ -95,7 +96,11 @@ class SolidCullSectionPreparer( blockEntities += blockEntityModel mesh.addBlock(x, y, z) } - model = blockState.blockModel ?: continue + model = if (blockEntityModel is MeshedBlockEntityRenderer) { + blockEntityModel + } else { + blockState.blockModel ?: continue + } if (y == 0) { diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/connection/status/StatusConnection.kt b/src/main/java/de/bixilon/minosoft/protocol/network/connection/status/StatusConnection.kt index ee44a4a63..03fe356b4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/connection/status/StatusConnection.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/connection/status/StatusConnection.kt @@ -137,6 +137,9 @@ class StatusConnection( // timeout task // ToDo: Cancel on success TimeWorker.runIn(30000) { + if (state == StatusConnectionStates.ERROR) { + return@runIn + } if (state != StatusConnectionStates.PING_DONE) { network.disconnect() error = TimeoutException()