wip static block entity models

This commit is contained in:
Bixilon 2022-04-19 00:27:15 +02:00
parent 90892537ad
commit d3bf46c327
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 110 additions and 11 deletions

View File

@ -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<ChatComponent> = 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<SignBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:sign")

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean
}

View File

@ -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<AbstractFaceProperties>
fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean
fun getParticleTexture(random: Random, blockPosition: Vec3i): AbstractTexture?
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<E : BlockEntity> : BlockEntityRenderer<E>, 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
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<SignBlockEntity> {
override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean {
println("Rendering sign at $position")
return true
}
}

View File

@ -43,7 +43,6 @@ class DoubleChestRenderer(
light,
) {
companion object {
val DOUBLE_MODEL = "minecraft:block/entities/double_chest".toResourceLocation().bbModel()

View File

@ -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<BlockEntityRenderer<*>> = 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) {

View File

@ -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()