diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/BeaconBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/BeaconBlockEntity.kt index 99d14f944..57421f95e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/BeaconBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/BeaconBlockEntity.kt @@ -16,11 +16,10 @@ package de.bixilon.minosoft.data.entities.block import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -import de.bixilon.minosoft.util.KUtil class BeaconBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity { - override fun setBlockActionData(data1: Byte, data2: Byte) { + override fun setBlockActionData(data1: Int, data2: Int) { // no data used, just recalculates the beam } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/BellBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/BellBlockEntity.kt index f744c0d0e..eba0261c9 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/BellBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/BellBlockEntity.kt @@ -17,13 +17,12 @@ import de.bixilon.minosoft.data.direction.Directions import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -import de.bixilon.minosoft.util.KUtil class BellBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity { var shakingDirection: Directions = Directions.NORTH private set - override fun setBlockActionData(data1: Byte, data2: Byte) { + override fun setBlockActionData(data1: Int, data2: Int) { shakingDirection = Directions[data2.toInt()] } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/BlockActionEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/BlockActionEntity.kt index 2806067d0..643bba4c1 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/BlockActionEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/BlockActionEntity.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2021 Moritz Zwerger + * Copyright (C) 2020-2023 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. * @@ -14,5 +14,5 @@ package de.bixilon.minosoft.data.entities.block interface BlockActionEntity { - fun setBlockActionData(data1: Byte, data2: Byte) + fun setBlockActionData(data1: Int, data2: Int) } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/MobSpawnerBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/MobSpawnerBlockEntity.kt index 386eb0f97..e1cebff2e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/MobSpawnerBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/MobSpawnerBlockEntity.kt @@ -48,7 +48,7 @@ class MobSpawnerBlockEntity(connection: PlayConnection) : BlockEntity(connection flameParticleType?.let { connection.world += FlameParticle(connection, Vec3d(particlePosition), Vec3d.EMPTY, it.default()) } } - override fun setBlockActionData(data1: Byte, data2: Byte) { + override fun setBlockActionData(data1: Int, data2: Int) { // ToDo } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/NoteBlockBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/NoteBlockBlockEntity.kt index 2f2db496e..6dc004267 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/NoteBlockBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/NoteBlockBlockEntity.kt @@ -41,7 +41,7 @@ class NoteBlockBlockEntity(connection: PlayConnection) : BlockEntity(connection) return properties[BlockProperties.NOTE]?.toInt() ?: 0 } - override fun setBlockActionData(data1: Byte, data2: Byte) { + override fun setBlockActionData(data1: Int, data2: Int) { instrument = when (data1.toInt()) { 0 -> Instruments.HARP 1 -> Instruments.BASS diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/ChestBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/ChestBlockEntity.kt index b3b571ff5..bdb4d6c4e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/ChestBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/ChestBlockEntity.kt @@ -31,23 +31,23 @@ open class ChestBlockEntity(connection: PlayConnection) : StorageBlockEntity(con override fun createRenderer(context: RenderContext, blockState: BlockState, blockPosition: Vec3i, light: Int): BlockEntityRenderer<*>? { val type: ChestTypes = blockState[BlockProperties.CHEST_TYPE] if (type == ChestTypes.SINGLE) { - return SingleChestRenderer(this, context, blockState, blockPosition, context.models.entities.skeletal[getSingleModel()] ?: return null, light) + return SingleChestRenderer(this, context, blockState, blockPosition, context.models.skeletal[getSingleModel()] ?: return null, light) } if (type == ChestTypes.LEFT) { // only left chest will be rendered (the model is the double chest), reduces drawing overhead - return DoubleChestRenderer(this, context, blockState, blockPosition, context.models.entities.skeletal[getDoubleModel()] ?: return null, light) + return DoubleChestRenderer(this, context, blockState, blockPosition, context.models.skeletal[getDoubleModel()] ?: return null, light) } return null } protected open fun getSingleModel(): ResourceLocation { - return SingleChestRenderer.NormalChest.MODEL + return SingleChestRenderer.NormalChest.NAME } protected open fun getDoubleModel(): ResourceLocation { - return DoubleChestRenderer.NormalChest.MODEL + return DoubleChestRenderer.NormalChest.NAME } companion object : BlockEntityFactory { diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/EnderChestBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/EnderChestBlockEntity.kt index e127bcd27..446decf64 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/EnderChestBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/EnderChestBlockEntity.kt @@ -27,7 +27,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection class EnderChestBlockEntity(connection: PlayConnection) : StorageBlockEntity(connection) { override fun createRenderer(context: RenderContext, blockState: BlockState, blockPosition: Vec3i, light: Int): BlockEntityRenderer? { - val model = context.models.entities.skeletal[SingleChestRenderer.EnderChest.MODEL] ?: return null + val model = context.models.skeletal[SingleChestRenderer.EnderChest.NAME] ?: return null return SingleChestRenderer(this, context, blockState, blockPosition, model, light) } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/StorageBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/StorageBlockEntity.kt index ef8d0a35f..27b3a9a13 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/StorageBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/StorageBlockEntity.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 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. * @@ -22,30 +22,39 @@ import de.bixilon.minosoft.gui.rendering.chunk.entities.renderer.storage.Storage import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection abstract class StorageBlockEntity(connection: PlayConnection) : ContainerBlockEntity(connection), BlockActionEntity { - protected var blockEntityRenderer: StorageBlockEntityRenderer<*>? = null + protected var storageRenderer: StorageBlockEntityRenderer<*>? = null override var renderer: BlockEntityRenderer? - get() = blockEntityRenderer + get() = storageRenderer set(value) { - blockEntityRenderer = value?.unsafeCast() + storageRenderer = value?.unsafeCast() } - var playersLookingIntoStorage: Int = 0 + var viewing: Int = 0 private set - val closed: Boolean get() = playersLookingIntoStorage <= 0 + val closed: Boolean get() = viewing <= 0 - override fun setBlockActionData(data1: Byte, data2: Byte) { - val closed = closed - playersLookingIntoStorage = data2.toInt() + override fun setBlockActionData(data1: Int, data2: Int) { + val viewing = data2 and 0xFF // unsigned + if (this.viewing == viewing) return + val previous = this.viewing + this.viewing = viewing - if (this.closed == closed) { - // state has not changed - return - } - if (playersLookingIntoStorage <= 0) { - blockEntityRenderer?.close() - } else { - blockEntityRenderer?.open() + when { + viewing == 0 -> onClose() + previous == 0 -> onOpen() + else -> onViewingChange(viewing) } } + + protected open fun onViewingChange(viewing: Int) = Unit + + protected fun onOpen() { + storageRenderer?.playOpen() + + } + + protected fun onClose() { + storageRenderer?.playClose() + } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/TrappedChestBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/TrappedChestBlockEntity.kt index d2f28fb89..4bd374ec9 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/TrappedChestBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/container/storage/TrappedChestBlockEntity.kt @@ -23,11 +23,11 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection class TrappedChestBlockEntity(connection: PlayConnection) : ChestBlockEntity(connection) { override fun getSingleModel(): ResourceLocation { - return SingleChestRenderer.TrappedChest.MODEL + return SingleChestRenderer.TrappedChest.NAME } override fun getDoubleModel(): ResourceLocation { - return DoubleChestRenderer.TrappedChest.MODEL + return DoubleChestRenderer.TrappedChest.NAME } companion object : BlockEntityFactory { diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/end/EndGatewayBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/end/EndGatewayBlockEntity.kt index cda7b6164..7d88f0074 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/end/EndGatewayBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/end/EndGatewayBlockEntity.kt @@ -19,11 +19,10 @@ import de.bixilon.minosoft.data.entities.block.BlockEntityFactory import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -import de.bixilon.minosoft.util.KUtil class EndGatewayBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity { - override fun setBlockActionData(data1: Byte, data2: Byte) { + override fun setBlockActionData(data1: Int, data2: Int) { // just emits the beacon like beam } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/redstone/piston/PistonBlockEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/block/redstone/piston/PistonBlockEntity.kt index c931da5e9..fb9c90847 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/redstone/piston/PistonBlockEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/redstone/piston/PistonBlockEntity.kt @@ -22,7 +22,6 @@ import de.bixilon.minosoft.data.entities.block.BlockEntityFactory import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -import de.bixilon.minosoft.util.KUtil open class PistonBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity { var state: PistonStates = PistonStates.PULL @@ -30,7 +29,7 @@ open class PistonBlockEntity(connection: PlayConnection) : BlockEntity(connectio var direction: Directions = Directions.NORTH private set - override fun setBlockActionData(data1: Byte, data2: Byte) { + override fun setBlockActionData(data1: Int, data2: Int) { state = PistonStates[data1.toInt()] direction = Directions[data2.toInt()] } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.kt index e249fde21..c9c8595b7 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.kt @@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.entities.entities.player import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec3.Vec3d import de.bixilon.kutil.bit.BitByte.isBitMask -import de.bixilon.kutil.cast.CastUtil.nullCast import de.bixilon.kutil.json.JsonObject import de.bixilon.kutil.observer.set.SetObserver.Companion.observedSet import de.bixilon.kutil.primitive.IntUtil.toInt @@ -37,9 +36,6 @@ import de.bixilon.minosoft.data.registries.item.items.dye.DyeableItem import de.bixilon.minosoft.data.registries.shapes.aabb.AABB import de.bixilon.minosoft.data.text.formatting.color.ChatColors import de.bixilon.minosoft.data.text.formatting.color.RGBColor -import de.bixilon.minosoft.gui.rendering.entity.EntityRenderer -import de.bixilon.minosoft.gui.rendering.entity.models.EntityModel -import de.bixilon.minosoft.gui.rendering.entity.models.minecraft.player.PlayerModel import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY import de.bixilon.minosoft.physics.entities.living.player.PlayerPhysics import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection @@ -55,12 +51,6 @@ abstract class PlayerEntity( val additional: PlayerAdditional, ) : LivingEntity(connection, entityType, data, position, rotation) { - protected var _model: PlayerModel? - get() = super.model.nullCast() - set(value) { - super.model = value - } - override val dimensions: Vec2 get() = pose?.let { getDimensions(it) } ?: Vec2(type.width, type.height) @@ -145,10 +135,6 @@ abstract class PlayerEntity( return ChatColors.RED } - override fun createModel(renderer: EntityRenderer): EntityModel? { - return PlayerModel(renderer, this).apply { this@PlayerEntity.model = this } - } - override fun createPhysics(): PlayerPhysics<*> { return PlayerPhysics(this) } @@ -156,7 +142,6 @@ abstract class PlayerEntity( fun swingHand(hand: Hands) { val arm = hand.getArm(mainArm) - _model?.swingArm(arm) } override fun handleAnimation(animation: EntityAnimations) { diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/LocalPlayerEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/LocalPlayerEntity.kt index f80959af6..97c0dc164 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/LocalPlayerEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/LocalPlayerEntity.kt @@ -27,8 +27,6 @@ import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity import de.bixilon.minosoft.data.entities.entities.player.additional.PlayerAdditional import de.bixilon.minosoft.data.entities.entities.player.compass.CompassPosition import de.bixilon.minosoft.data.registries.effects.attributes.integrated.IntegratedAttributeModifiers -import de.bixilon.minosoft.gui.rendering.entity.EntityRenderer -import de.bixilon.minosoft.gui.rendering.entity.models.minecraft.player.LocalPlayerModel import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY import de.bixilon.minosoft.input.camera.MovementInputActions import de.bixilon.minosoft.input.camera.PlayerMovementInput @@ -109,10 +107,6 @@ class LocalPlayerEntity( override val usingHand: Hands? get() = using?.hand - override fun createModel(renderer: EntityRenderer): LocalPlayerModel { - return LocalPlayerModel(renderer, this).apply { this@LocalPlayerEntity.model = this } - } - override fun createPhysics() = LocalPlayerPhysics(this) override fun physics(): LocalPlayerPhysics = super.physics().unsafeCast() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/DefaultEntityModels.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/DefaultEntityModels.kt index abdddb1c7..6028eab2f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/DefaultEntityModels.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/DefaultEntityModels.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 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. * @@ -13,8 +13,14 @@ package de.bixilon.minosoft.gui.rendering.chunk.entities +import de.bixilon.kutil.latch.AbstractLatch +import de.bixilon.kutil.latch.AbstractLatch.Companion.child import de.bixilon.minosoft.gui.rendering.chunk.entities.renderer.storage.DoubleChestRenderer import de.bixilon.minosoft.gui.rendering.chunk.entities.renderer.storage.SingleChestRenderer +import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader +import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels +import de.bixilon.minosoft.util.logging.LogMessageType object DefaultEntityModels { val MODELS = listOf( @@ -25,4 +31,14 @@ object DefaultEntityModels { DoubleChestRenderer.NormalChest, DoubleChestRenderer.TrappedChest, ) + + + fun load(loader: ModelLoader, latch: AbstractLatch?) { + Log.log(LogMessageType.LOADING, LogLevels.VERBOSE) { "Loading entity models..." } + val innerLatch = latch.child(MODELS.size) + + for (register in MODELS) { + register.register(loader); innerLatch.dec() + } + } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/EntityModels.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/EntityModels.kt deleted file mode 100644 index ede3f9df3..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/EntityModels.kt +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.chunk.entities - -import de.bixilon.kutil.concurrent.pool.DefaultThreadPool -import de.bixilon.kutil.latch.AbstractLatch -import de.bixilon.kutil.latch.AbstractLatch.Companion.child -import de.bixilon.kutil.latch.SimpleLatch -import de.bixilon.minosoft.assets.util.InputStreamUtil.readJson -import de.bixilon.minosoft.data.registries.identified.ResourceLocation -import de.bixilon.minosoft.gui.rendering.RenderContext -import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader -import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel -import de.bixilon.minosoft.gui.rendering.skeletal.model.SkeletalModel -import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture -import de.bixilon.minosoft.util.logging.Log -import de.bixilon.minosoft.util.logging.LogLevels -import de.bixilon.minosoft.util.logging.LogMessageType - -class EntityModels(private val loader: ModelLoader) { - val context: RenderContext = loader.context - private val unbakedModels: MutableMap = mutableMapOf() - val skeletal: MutableMap = mutableMapOf() - - @Synchronized - fun loadUnbakedModel(path: ResourceLocation): SkeletalModel { - return unbakedModels.getOrPut(path) { context.connection.assetsManager[path].readJson() } - } - - @Synchronized - fun loadModel(name: ResourceLocation, path: ResourceLocation, textureOverride: MutableMap = mutableMapOf()): BakedSkeletalModel { - return skeletal.getOrPut(name) { loadUnbakedModel(path).bake(context, textureOverride) } - } - - fun cleanup() { - unbakedModels.clear() - } - - fun bake() { - val latch = SimpleLatch(1) - for (model in skeletal.values) { - latch.inc() - DefaultThreadPool += { model.preload(context); latch.dec() } - } - latch.dec() - latch.await() - - for (model in skeletal.values) { - model.load() - } - } - - - fun load(latch: AbstractLatch?) { - Log.log(LogMessageType.LOADING, LogLevels.VERBOSE) { "Loading entity models..." } - val innerLatch = latch.child(DefaultEntityModels.MODELS.size) - - for (register in DefaultEntityModels.MODELS) { - DefaultThreadPool += { register.register(context, loader); innerLatch.dec() } - } - innerLatch.await() - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/EntityRendererRegister.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/EntityRendererRegister.kt index 065fab07c..c04e3e0d2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/EntityRendererRegister.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/EntityRendererRegister.kt @@ -13,10 +13,9 @@ package de.bixilon.minosoft.gui.rendering.chunk.entities -import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader interface EntityRendererRegister { - fun register(context: RenderContext, modelLoader: ModelLoader) = Unit + fun register(loader: ModelLoader) = Unit } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/DoubleChestRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/DoubleChestRenderer.kt index d5a3936c4..6e7002a72 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/DoubleChestRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/DoubleChestRenderer.kt @@ -18,16 +18,15 @@ import de.bixilon.kutil.time.DateUtil import de.bixilon.minosoft.data.entities.block.container.storage.StorageBlockEntity import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing import de.bixilon.minosoft.data.registries.blocks.state.BlockState +import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.chunk.entities.EntityRendererRegister import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader.Companion.bbModel import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel -import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3 -import de.bixilon.minosoft.util.KUtil.toResourceLocation class DoubleChestRenderer( val entity: StorageBlockEntity, @@ -38,40 +37,41 @@ class DoubleChestRenderer( light: Int, ) : StorageBlockEntityRenderer( blockState, - SkeletalInstance(context, model, (blockPosition - context.camera.offset.offset).toVec3, (blockState.getFacing()).rotatedMatrix), + model.createInstance(context, (blockPosition - context.camera.offset.offset).toVec3, (blockState.getFacing()).rotatedMatrix), light, ) { companion object { - val DOUBLE_MODEL = "minecraft:block/entities/double_chest".toResourceLocation().bbModel() + val DOUBLE_MODEL = minecraft("block/entities/double_chest").bbModel() + private val named = arrayOf(minecraft("left"), minecraft("right")) - fun register(context: RenderContext, modelLoader: ModelLoader, textureName1: ResourceLocation, textureName2: ResourceLocation, model: ResourceLocation) { - val texture1 = context.textures.staticTextures.createTexture(textureName1) - val texture2 = context.textures.staticTextures.createTexture(textureName2) - modelLoader.entities.loadModel(model, DOUBLE_MODEL, mutableMapOf(0 to texture1, 1 to texture2)) + private fun register(loader: ModelLoader, name: ResourceLocation, textures: Array) { + if (textures.size != 2) throw IllegalStateException("Textures must be left and right!") + val static = loader.context.textures.staticTextures + val override = mapOf( + named[0] to static.createTexture(textures[0]), + named[1] to static.createTexture(textures[1]), + ) + loader.skeletal.register(name, DOUBLE_MODEL, override) } } object NormalChest : EntityRendererRegister { - val MODEL = "minecraft:models/block/entities/double_chest".toResourceLocation() - val TEXTURE1 = "minecraft:entity/chest/normal_left".toResourceLocation().texture() - val TEXTURE2 = "minecraft:entity/chest/normal_right".toResourceLocation().texture() - val TEXTURE_CHRISTMAS1 = "minecraft:entity/chest/christmas_left".toResourceLocation().texture() - val TEXTURE_CHRISTMAS2 = "minecraft:entity/chest/christmas_right".toResourceLocation().texture() + val NAME = minecraft("block/entities/double_chest") + private val textures = arrayOf(minecraft("entity/chest/normal_left").texture(), minecraft("entity/chest/normal_right").texture()) + private val christmas = arrayOf(minecraft("entity/chest/christmas_left").texture(), minecraft("entity/chest/christmas_right").texture()) - override fun register(context: RenderContext, modelLoader: ModelLoader) { - val christmas = DateUtil.christmas - register(context, modelLoader, if (christmas) TEXTURE_CHRISTMAS1 else TEXTURE1, if (christmas) TEXTURE_CHRISTMAS2 else TEXTURE2, MODEL) + override fun register(loader: ModelLoader) { + register(loader, NAME, if (DateUtil.christmas) christmas else textures) } } object TrappedChest : EntityRendererRegister { - val MODEL = "minecraft:models/block/entities/double_trapped_chest".toResourceLocation() - val TEXTURE1 = "minecraft:entity/chest/trapped_left".toResourceLocation().texture() - val TEXTURE2 = "minecraft:entity/chest/trapped_right".toResourceLocation().texture() + val NAME = minecraft("block/entities/double_trapped_chest") + private val textures = arrayOf(minecraft("entity/chest/trapped_left").texture(), minecraft("entity/chest/trapped_right").texture()) - override fun register(context: RenderContext, modelLoader: ModelLoader) { - register(context, modelLoader, TEXTURE1, TEXTURE2, MODEL) + override fun register(loader: ModelLoader) { + register(loader, NAME, textures) } } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/SingleChestRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/SingleChestRenderer.kt index 1b227c66d..f82d2a48d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/SingleChestRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/SingleChestRenderer.kt @@ -18,16 +18,15 @@ import de.bixilon.kutil.time.DateUtil import de.bixilon.minosoft.data.entities.block.container.storage.StorageBlockEntity import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing import de.bixilon.minosoft.data.registries.blocks.state.BlockState +import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.chunk.entities.EntityRendererRegister import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader.Companion.bbModel import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel -import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3 -import de.bixilon.minosoft.util.KUtil.toResourceLocation class SingleChestRenderer( val entity: StorageBlockEntity, @@ -38,44 +37,45 @@ class SingleChestRenderer( light: Int, ) : StorageBlockEntityRenderer( blockState, - SkeletalInstance(context, model, (blockPosition - context.camera.offset.offset).toVec3, blockState.getFacing().rotatedMatrix), + model.createInstance(context, (blockPosition - context.camera.offset.offset).toVec3, blockState.getFacing().rotatedMatrix), light, ) { companion object { - val SINGLE_MODEL = "minecraft:block/entities/single_chest".toResourceLocation().bbModel() + val SINGLE_MODEL = minecraft("block/entities/single_chest").bbModel() + private val named = minecraft("chest") - fun register(context: RenderContext, modelLoader: ModelLoader, textureName: ResourceLocation, model: ResourceLocation) { - val texture = context.textures.staticTextures.createTexture(textureName) - modelLoader.entities.loadModel(model, SINGLE_MODEL, mutableMapOf(0 to texture)) + fun register(loader: ModelLoader, name: ResourceLocation, texture: ResourceLocation) { + val texture = loader.context.textures.staticTextures.createTexture(texture) + loader.skeletal.register(name, SINGLE_MODEL, mapOf(named to texture)) } } object NormalChest : EntityRendererRegister { - val MODEL = "minecraft:models/block/entities/single_chest".toResourceLocation() - val TEXTURE = "minecraft:entity/chest/normal".toResourceLocation().texture() - val TEXTURE_CHRISTMAS = "minecraft:entity/chest/christmas".toResourceLocation().texture() + val NAME = minecraft("block/entities/single_chest") + val TEXTURE = minecraft("entity/chest/normal").texture() + val TEXTURE_CHRISTMAS = minecraft("entity/chest/christmas").texture() - override fun register(context: RenderContext, modelLoader: ModelLoader) { - register(context, modelLoader, if (DateUtil.christmas) TEXTURE_CHRISTMAS else TEXTURE, MODEL) + override fun register(loader: ModelLoader) { + register(loader, NAME, if (DateUtil.christmas) TEXTURE_CHRISTMAS else TEXTURE) } } object TrappedChest : EntityRendererRegister { - val MODEL = "minecraft:models/block/entities/trapped_chest".toResourceLocation() - val TEXTURE = "minecraft:entity/chest/trapped".toResourceLocation().texture() + val NAME = minecraft("block/entities/trapped_chest") + val TEXTURE = minecraft("entity/chest/trapped").texture() - override fun register(context: RenderContext, modelLoader: ModelLoader) { - register(context, modelLoader, TEXTURE, MODEL) + override fun register(loader: ModelLoader) { + register(loader, NAME, TEXTURE) } } object EnderChest : EntityRendererRegister { - val MODEL = "minecraft:models/block/entities/ender_chest".toResourceLocation() - val TEXTURE = "minecraft:entity/chest/ender".toResourceLocation().texture() + val NAME = minecraft("block/entities/ender_chest") + val TEXTURE = minecraft("entity/chest/ender").texture() - override fun register(context: RenderContext, modelLoader: ModelLoader) { - register(context, modelLoader, TEXTURE, MODEL) + override fun register(loader: ModelLoader) { + register(loader, NAME, TEXTURE) } } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/StorageBlockEntityRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/StorageBlockEntityRenderer.kt index e5ebe0719..9a91fad43 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/StorageBlockEntityRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/entities/renderer/storage/StorageBlockEntityRenderer.kt @@ -26,19 +26,16 @@ abstract class StorageBlockEntityRenderer( ) : BlockEntityRenderer { override fun draw(context: RenderContext) { - skeletal?.light = light - skeletal?.draw() + skeletal?.draw(light) } - fun open() { - val skeletal = this.skeletal ?: return - skeletal.clearAnimation() - skeletal.playAnimation("animation.chest.opening") + @Deprecated("refactor") + fun playOpen() { + TODO() } - fun close() { - val skeletal = this.skeletal ?: return - skeletal.clearAnimation() - skeletal.playAnimation("animation.chest.closing") + @Deprecated("refactor") + fun playClose() { + TODO() } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/EntityRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/EntityRenderer.kt index f762de24e..0700ec2ad 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/EntityRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/EntityRenderer.kt @@ -30,7 +30,6 @@ import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.entity.models.EntityModel -import de.bixilon.minosoft.gui.rendering.entity.models.minecraft.player.LocalPlayerModel import de.bixilon.minosoft.gui.rendering.events.VisibilityGraphChangeEvent import de.bixilon.minosoft.gui.rendering.renderer.renderer.RendererBuilder import de.bixilon.minosoft.gui.rendering.renderer.renderer.world.LayerSettings @@ -54,7 +53,6 @@ class EntityRenderer( val profile = connection.profiles.entity val visibilityGraph = context.camera.visibilityGraph private val models: LockMap> = lockMapOf() - private lateinit var localModel: LocalPlayerModel private var toUnload: MutableList> = synchronizedListOf() var hitboxes = profile.hitbox.enabled @@ -99,9 +97,9 @@ class EntityRenderer( } override fun postAsyncInit(latch: AbstractLatch) { - localModel = context.connection.player.createModel(this) + // localModel = context.connection.player.createModel(this) - models[connection.player] = localModel + // models[connection.player] = localModel } private fun unloadUnused() { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/SkeletalEntityModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/SkeletalEntityModel.kt deleted file mode 100644 index 8f6a9ea57..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/SkeletalEntityModel.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.entity.models - -import de.bixilon.minosoft.data.entities.entities.Entity -import de.bixilon.minosoft.gui.rendering.entity.EntityRenderer -import de.bixilon.minosoft.gui.rendering.skeletal.baked.SkeletalModelStates -import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance - -abstract class SkeletalEntityModel(renderer: EntityRenderer, entity: E) : EntityModel(renderer, entity) { - abstract val instance: SkeletalInstance? - open val hideSkeletalModel: Boolean get() = false - - - override fun prepare() { - super.prepare() - if (instance?.model?.state != SkeletalModelStates.LOADED) { - instance?.model?.preload(context) // ToDo: load async - instance?.model?.load() - } - } - - override fun draw() { - super.draw() - if (!hideSkeletalModel) { - instance?.updatePosition(entity.renderInfo.position, entity.renderInfo.rotation) - instance?.draw() - } - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/ArmAnimator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/ArmAnimator.kt deleted file mode 100644 index c299e8b85..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/ArmAnimator.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.entity.models.minecraft.player - -import de.bixilon.kotlinglm.func.deg -import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.minosoft.data.entities.entities.player.Arms -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.AnimationLoops -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.animator.keyframes.KeyframeChannels -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.outliner.SkeletalOutliner -import kotlin.math.PI -import kotlin.math.cos - -class ArmAnimator( - model: PlayerModel, -) : ExtremitiesAnimator("arm_animator", model) { - override val loop: AnimationLoops = AnimationLoops.LOOP - override val length: Float = 2.0f - - override fun get(channel: KeyframeChannels, outliner: SkeletalOutliner, time: Float): Vec3? { - if (channel != KeyframeChannels.ROTATION) { - return null - } - if (outliner.name == "LEFT_ARM") { - return calculateAngle(time) - } - if (outliner.name == "RIGHT_ARM") { - return calculateAngle(time - 1.0f) - } - return null - } - - private fun calculateAngle(time: Float): Vec3 { - val angle = cos(time * PI) * 1.4 * velocityMultiplier - return Vec3(angle.deg, 0, 0) - } - - fun swingArm(arm: Arms) { - - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/ExtremitiesAnimator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/ExtremitiesAnimator.kt deleted file mode 100644 index 4c0827966..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/ExtremitiesAnimator.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.entity.models.minecraft.player - -import de.bixilon.kutil.math.interpolation.FloatInterpolation.interpolateLinear -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.CustomSkeletalAnimation -import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition - -abstract class ExtremitiesAnimator( - name: String, - val model: PlayerModel, -) : CustomSkeletalAnimation(name) { - protected var previousVelocityMultiplier = 0.0f - protected var _velocityMultiplier = 0.0f - var velocityMultiplier = 0.0f - private set - - override fun tick() { - previousVelocityMultiplier = _velocityMultiplier - _velocityMultiplier = _getVelocityMultiplier() - } - - override fun draw(millis: Long) { - val lastTick = lastTick - super.draw(millis) - velocityMultiplier = interpolateLinear((millis - lastTick) / ProtocolDefinition.TICK_TIMEf * 3, previousVelocityMultiplier, _velocityMultiplier) - } - - - private fun _getVelocityMultiplier(): Float { - //TODO var velocity = model.entity.deltaMovement.xz.length().toFloat() - var velocity = 0.0f - if (velocity > 1.0f) { - velocity = 1.0f - } - return velocity - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/LegAnimator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/LegAnimator.kt deleted file mode 100644 index 8be0b943d..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/LegAnimator.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.entity.models.minecraft.player - -import de.bixilon.kotlinglm.func.deg -import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.AnimationLoops -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.animator.keyframes.KeyframeChannels -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.outliner.SkeletalOutliner -import kotlin.math.PI -import kotlin.math.cos - -class LegAnimator( - model: PlayerModel, -) : ExtremitiesAnimator("leg_animator", model) { - override val loop: AnimationLoops = AnimationLoops.LOOP - override val length: Float = 2.0f - - override fun get(channel: KeyframeChannels, outliner: SkeletalOutliner, time: Float): Vec3? { - if (channel != KeyframeChannels.ROTATION) { - return null - } - if (outliner.name == "LEFT_LEG") { - return calculateAngle(time) - } - if (outliner.name == "RIGHT_LEG") { - return calculateAngle(time - 1.0f) - } - return null - } - - private fun calculateAngle(time: Float): Vec3 { - val angle = cos(time * PI) * velocityMultiplier - return Vec3(angle.deg, 0, 0) - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/LocalPlayerModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/LocalPlayerModel.kt deleted file mode 100644 index 601203e2a..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/LocalPlayerModel.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.entity.models.minecraft.player - -import de.bixilon.kutil.observer.DataObserver.Companion.observe -import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity -import de.bixilon.minosoft.gui.rendering.entity.EntityRenderer -import de.bixilon.minosoft.gui.rendering.entity.models.DamageableModel - -open class LocalPlayerModel(renderer: EntityRenderer, player: PlayerEntity) : PlayerModel(renderer, player), DamageableModel { - - override val hideSkeletalModel: Boolean - get() = super.hideSkeletalModel || !context.camera.view.view.renderSelf - - init { - renderer.profile.hitbox::showLocal.observe(this, true) { updateHitbox(it) } - renderer.context.camera.view::view.observe(this) { updateHitbox(it.renderSelf) } - } - - private fun updateHitbox(config: Boolean = renderer.profile.hitbox.showLocal, view: Boolean = renderer.context.camera.view.view.renderSelf) { - hitbox.enabled = config || view - } - - override fun onDamage() { - renderer.context.camera.matrixHandler.shaking.onDamage() - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/PlayerModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/PlayerModel.kt deleted file mode 100644 index b6ab53f1a..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entity/models/minecraft/player/PlayerModel.kt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.entity.models.minecraft.player - -import de.bixilon.kutil.observer.DataObserver.Companion.observe -import de.bixilon.kutil.observer.set.SetObserver.Companion.observeSet -import de.bixilon.minosoft.data.entities.entities.player.Arms -import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity -import de.bixilon.minosoft.data.entities.entities.player.SkinParts -import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties -import de.bixilon.minosoft.data.entities.entities.player.properties.textures.metadata.SkinModel -import de.bixilon.minosoft.gui.rendering.entity.EntityRenderer -import de.bixilon.minosoft.gui.rendering.entity.models.SkeletalEntityModel -import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader.Companion.bbModel -import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.SkeletalAnimation -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.elements.SkeletalElement -import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicStateChangeCallback -import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTexture -import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTextureState -import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.PlayerSkin -import de.bixilon.minosoft.util.KUtil.toResourceLocation - -open class PlayerModel(renderer: EntityRenderer, player: PlayerEntity) : SkeletalEntityModel(renderer, player), DynamicStateChangeCallback { - private var properties = player.additional.properties - var skin: PlayerSkin? = null - private set - protected var refreshModel = false - - private val legAnimator = LegAnimator(this) - private val armAnimator = ArmAnimator(this) - private val animations: MutableList = mutableListOf(legAnimator, armAnimator) - - - private var _instance: SkeletalInstance? = null - override var instance = createModel(properties) - - - init { - entity::skinParts.observeSet(this) { refreshModel = true } - player.additional::properties.observe(this) { this.properties = it; refreshModel = true } - } - - - private fun createModel(properties: PlayerProperties?): SkeletalInstance? { - val skin = context.textures.skins.getSkin(entity, properties) ?: return null - val skinModel = skin.model - val unbaked = context.models.entities.loadUnbakedModel(if (skinModel == SkinModel.SLIM) SLIM_MODEL else WIDE_MODEL) - - val elements: MutableList = mutableListOf() - elementLoop@ for (element in unbaked.elements) { - for (skinPart in SkinParts.VALUES) { - if (skinPart.name == element.name) { - elements += element.skinCopy(entity.skinParts, skinPart) - continue@elementLoop - } - } - elements += element - } - skin.texture.usages.incrementAndGet() - this.skin?.texture?.usages?.decrementAndGet() - this.skin = skin - skin.texture += this - - val skinTexture = if (skin.texture.state != DynamicTextureState.LOADED) context.textures.skins.default[entity.uuid] ?: return null else skin - - val model = unbaked.copy(elements = elements, animations = animations).bake(context, mapOf(0 to skinTexture.texture)) - - val instance = SkeletalInstance(context, model) - - for (animation in animations) { - instance.playAnimation(animation) - } - - refreshModel = false - this.properties = properties - - return instance - } - - override fun prepareAsync() { - if (refreshModel) { - _instance = instance - instance = createModel(properties) - } - super.prepareAsync() - } - - override fun prepare() { - _instance?.unload() - _instance = null - super.prepare() - } - - private fun SkeletalElement.skinCopy(parts: Set, part: SkinParts): SkeletalElement { - if (part in parts) { - return this - } - return this.copy(visible = false) - } - - override fun onStateChange(texture: DynamicTexture, state: DynamicTextureState) { - if (skin?.texture === texture) { - refreshModel = true - } - } - - override fun unload() { - skin?.texture?.usages?.decrementAndGet() - } - - fun swingArm(arm: Arms) { - armAnimator.swingArm(arm) - } - - - companion object { - private val WIDE_MODEL = "minecraft:entities/player/wide".toResourceLocation().bbModel() - private val SLIM_MODEL = "minecraft:entities/player/slim".toResourceLocation().bbModel() - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/WorldGUIConsumer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/WorldGUIConsumer.kt index 388b2639b..be4db1ff5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/WorldGUIConsumer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/WorldGUIConsumer.kt @@ -23,7 +23,7 @@ import de.bixilon.minosoft.gui.rendering.font.renderer.properties.FormattingProp import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions -import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderIdentifiable +import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture @@ -31,7 +31,7 @@ class WorldGUIConsumer(val mesh: SingleChunkMesh, val transform: Mat4, val light private val whiteTexture = mesh.context.textures.whiteTexture override val order: IntArray get() = mesh.order - override fun addVertex(position: Vec2, texture: ShaderIdentifiable?, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) { + override fun addVertex(position: Vec2, texture: ShaderTexture?, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) { val transformed = transform.fastTimes(position.x / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION, -position.y / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION) mesh.addVertex(transformed, uv, (texture as Texture?) ?: whiteTexture.texture, tint.rgb, light) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/DefaultOverlays.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/DefaultOverlays.kt index 378e96b7b..c9bcc9369 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/DefaultOverlays.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/DefaultOverlays.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 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. * @@ -13,13 +13,11 @@ package de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays -import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays.arm.ArmOverlay import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays.simple.* import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays.weather.WeatherOverlay object DefaultOverlays { val OVERLAYS = listOf( - ArmOverlay, WallOverlay, WaterOverlay, PumpkinOverlay, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmMesh.kt deleted file mode 100644 index 2e20b77df..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmMesh.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.framebuffer.world.overlay.overlays.arm - -import de.bixilon.kotlinglm.vec2.Vec2 -import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.minosoft.data.entities.entities.player.Arms -import de.bixilon.minosoft.gui.rendering.RenderContext -import de.bixilon.minosoft.gui.rendering.skeletal.SkeletalVertexConsumer -import de.bixilon.minosoft.gui.rendering.skeletal.model.SkeletalModel -import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes -import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture -import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh -import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap - -open class ArmMesh(context: RenderContext, primitiveType: PrimitiveTypes = context.system.quadType) : Mesh(context, ArmMeshStruct, primitiveType, initialCacheSize = 2 * 3 * ArmMeshStruct.FLOATS_PER_VERTEX), SkeletalVertexConsumer { - - - fun addVertex(position: FloatArray, uv: Vec2) { - data.add(position) - data.add(uv.array) - } - - override fun addVertex(position: FloatArray, transformedUV: Vec2, transform: Float, textureShaderId: Float, flags: Float) { - addVertex(position, transformedUV) - } - - override fun addVertex(position: FloatArray, uv: Vec2, transform: Int, texture: ShaderTexture, flags: Int) { - addVertex(position, uv) - } - - - fun addArm(model: SkeletalModel, arm: Arms, skin: ShaderTexture) { - val elements = model.elements.filter { - when (arm) { - Arms.LEFT -> it.name == "LEFT_ARM" || it.name == "LEFT_SLEEVE" - Arms.RIGHT -> it.name == "RIGHT_ARM" || it.name == "RIGHT_SLEEVE" - } - } - val textures = Int2ObjectOpenHashMap() - textures[0] = skin - for (element in elements) { - element.bake(model, textures, emptyMap(), this) - } - } - - - data class ArmMeshStruct( - val position: Vec3, - val uv: Vec2, - ) { - companion object : MeshStruct(ArmMeshStruct::class) - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmOverlay.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmOverlay.kt deleted file mode 100644 index cf7cc6277..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmOverlay.kt +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.framebuffer.world.overlay.overlays.arm - -import de.bixilon.kotlinglm.GLM -import de.bixilon.kotlinglm.func.rad -import de.bixilon.kotlinglm.mat4x4.Mat4 -import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.kutil.cast.CastUtil.nullCast -import de.bixilon.kutil.cast.CastUtil.unsafeNull -import de.bixilon.kutil.observer.DataObserver.Companion.observe -import de.bixilon.minosoft.data.entities.entities.player.Arms -import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft -import de.bixilon.minosoft.gui.rendering.RenderContext -import de.bixilon.minosoft.gui.rendering.camera.CameraDefinition -import de.bixilon.minosoft.gui.rendering.entity.models.minecraft.player.PlayerModel -import de.bixilon.minosoft.gui.rendering.events.ResizeWindowEvent -import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.Overlay -import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.OverlayFactory -import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel.Companion.fromBlockCoordinates -import de.bixilon.minosoft.gui.rendering.system.base.IntegratedBufferTypes -import de.bixilon.minosoft.gui.rendering.system.base.RenderingCapabilities -import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.PlayerSkin -import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen - -class ArmOverlay(private val context: RenderContext) : Overlay { - private val config = context.connection.profiles.rendering.overlay - private val shader = context.system.createShader(minosoft("arm")) { ArmOverlayShader(it) } - override val render: Boolean - get() = context.camera.view.view.renderArm && config.arm.render - private var arm = context.connection.player.mainArm // TODO: camera player entity - private var skin: PlayerSkin? = null - private var model: PlayerModel? = null - private var mesh: ArmMesh = unsafeNull() - - private var refresh = false - - private var refreshTransform = true - - override fun init() { - context.connection.profiles.connection::mainArm.observe(this, true) { this.arm = it; refresh = true;refreshTransform = true } - context.connection.events.listen { this.refreshTransform = true } - } - - private fun poll() { - val model = context.connection.player.model.nullCast() - val skin = model?.skin - // TODO: check skin parts - if (this.model == model && this.skin == skin) { - return - } - this.model = model - skin?.texture?.usages?.incrementAndGet() - this.skin?.texture?.usages?.decrementAndGet() - this.skin = skin - - refresh = true - } - - override fun postInit() { - shader.load() - createMesh() - } - - private fun createMesh() { - this.mesh = ArmMesh(context) - val skin = this.skin - val model = this.model?.instance?.model?.model - if (model != null && skin != null) { - this.mesh.addArm(model, arm, skin.texture) - } - this.mesh.load() - } - - - override fun update() { - poll() - if (!refresh) { - return - } - this.mesh.unload() - createMesh() - this.refresh = false - } - - private fun calculateTransform(): Mat4 { - val screen = context.window.sizef - val aspect = screen.x / screen.y - val projection = GLM.perspective(60.0f.rad, aspect, CameraDefinition.NEAR_PLANE, CameraDefinition.FAR_PLANE) - - val model = this.model ?: return Mat4() - val outliner = model.instance?.model?.model?.outliner?.find { it.name == if (arm == Arms.LEFT) "LEFT_ARM" else "RIGHT_ARM" } ?: return Mat4() - - val matrix = FirstPersonArmAnimator(model).calculateTransform(outliner, 0.0f) - val screenMatrix = Mat4() - - val translation = Vec3(if (arm == Arms.LEFT) -0.08f else 0.08f, 0, 0) - - if (aspect > 1.8f) { - translation.x *= aspect * 1.8f - } - screenMatrix.translateAssign(translation) // move inner side of arm to 0|0|0 - - screenMatrix.translateAssign(Vec3(if (arm == Arms.LEFT) -18 else -12, -38, -10).fromBlockCoordinates()) - - this.refreshTransform = false - return projection * screenMatrix * matrix - } - - override fun draw() { - val skin = this.skin ?: return - context.system.clear(IntegratedBufferTypes.DEPTH_BUFFER) - - context.system.disable(RenderingCapabilities.FACE_CULLING) - context.system.enable(RenderingCapabilities.DEPTH_TEST) - context.system.enable(RenderingCapabilities.BLENDING) - context.system.depthMask = true - - shader.use() - shader.textureIndexLayer = skin.texture.shaderId - - if (refreshTransform) { - shader.transform = calculateTransform() - } - - mesh.draw() - context.system.clear(IntegratedBufferTypes.DEPTH_BUFFER) - } - - - companion object : OverlayFactory { - override fun build(context: RenderContext): ArmOverlay { - return ArmOverlay(context) - } - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmOverlayShader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmOverlayShader.kt deleted file mode 100644 index fe0721915..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/ArmOverlayShader.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.framebuffer.world.overlay.overlays.arm - -import de.bixilon.kotlinglm.mat4x4.Mat4 -import de.bixilon.minosoft.gui.rendering.shader.Shader -import de.bixilon.minosoft.gui.rendering.shader.types.TextureShader -import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader -import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager - -class ArmOverlayShader( - override val native: NativeShader, -) : Shader(), TextureShader { - override var textures: TextureManager by textureManager() - - var textureIndexLayer by uniform("uIndexLayer", 0, NativeShader::setUInt) - - var transform by uniform("uTransform", Mat4()) -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/FirstPersonArmAnimator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/FirstPersonArmAnimator.kt deleted file mode 100644 index 6e6ed5b25..000000000 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/arm/FirstPersonArmAnimator.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 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.framebuffer.world.overlay.overlays.arm - -import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.minosoft.data.entities.entities.player.Arms -import de.bixilon.minosoft.gui.rendering.entity.models.minecraft.player.PlayerModel -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.AnimationLoops -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.SkeletalAnimation -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.animations.animator.keyframes.KeyframeChannels -import de.bixilon.minosoft.gui.rendering.skeletal.model.legacy.outliner.SkeletalOutliner - -class FirstPersonArmAnimator(private val player: PlayerModel) : SkeletalAnimation { - override val name: String = "" - override val loop = AnimationLoops.LOOP - override val length: Float = 100.0f - - // TODO (swinging: move arm to front, rotate) - - override fun get(channel: KeyframeChannels, outliner: SkeletalOutliner, time: Float): Vec3? { - if (channel != KeyframeChannels.ROTATION) { - return null - } - if (player.entity.mainArm == Arms.LEFT) { - return Vec3(-120, -20, 0) - } - return Vec3(-120, 20, 10) - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/primitive/DynamicImageElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/primitive/DynamicImageElement.kt index 27fa57eb2..b1becbe56 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/primitive/DynamicImageElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/primitive/DynamicImageElement.kt @@ -24,7 +24,7 @@ import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicStateChangeCallback import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTexture import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTextureState -import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderIdentifiable +import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util.EMPTY open class DynamicImageElement( @@ -82,7 +82,7 @@ open class DynamicImageElement( this.parent = parent } - private fun getAvailableTexture(): ShaderIdentifiable { + private fun getAvailableTexture(): ShaderTexture { val texture = texture ?: return context.textures.whiteTexture.texture if (texture.state != DynamicTextureState.LOADED) { return context.textures.whiteTexture.texture diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt index 4e80d89c0..35f6d9e6f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt @@ -19,6 +19,7 @@ import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderIdentifiable +import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList @@ -30,7 +31,7 @@ class GUIMesh( ) : Mesh(context, GUIMeshStruct, initialCacheSize = 40000, clearOnLoad = false, data = data), GUIVertexConsumer { private val whiteTexture = context.textures.whiteTexture - override fun addVertex(position: Vec2, texture: ShaderIdentifiable?, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) { + override fun addVertex(position: Vec2, texture: ShaderTexture?, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) { addVertex(data, halfSize, position, texture ?: whiteTexture.texture, uv, tint, options) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt index 8a89a3679..a4cc1a519 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt @@ -18,7 +18,7 @@ import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.kutil.collections.primitive.floats.HeapArrayFloatList import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.RenderContext -import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderIdentifiable +import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util.EMPTY class GUIMeshCache( @@ -42,7 +42,7 @@ class GUIMeshCache( } } - override fun addVertex(position: Vec2, texture: ShaderIdentifiable?, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) { + override fun addVertex(position: Vec2, texture: ShaderTexture?, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) { GUIMesh.addVertex(data, halfSize, position, texture ?: whiteTexture.texture, uv, tint, options) revision++ } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/loader/ModelLoader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/loader/ModelLoader.kt index ee8eeb87c..357bd50d5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/loader/ModelLoader.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/loader/ModelLoader.kt @@ -17,7 +17,7 @@ import de.bixilon.kutil.latch.AbstractLatch import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.data.registries.identified.ResourceLocationUtil.extend import de.bixilon.minosoft.gui.rendering.RenderContext -import de.bixilon.minosoft.gui.rendering.chunk.entities.EntityModels +import de.bixilon.minosoft.gui.rendering.chunk.entities.DefaultEntityModels import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType @@ -27,16 +27,17 @@ class ModelLoader( ) { val packFormat = context.connection.assetsManager.properties.pack.format val fluids = FluidModelLoader(this) - val entities = EntityModels(this) val block = BlockLoader(this) val item = ItemLoader(this) + val skeletal = SkeletalLoader(this) fun load(latch: AbstractLatch) { + DefaultEntityModels.load(this, latch) fluids.load(latch) - entities.load(latch) block.load(latch) item.load(latch) + skeletal.load(latch) Log.log(LogMessageType.LOADING, LogLevels.VERBOSE) { "Loaded all models!" } } @@ -44,7 +45,7 @@ class ModelLoader( fun bake(latch: AbstractLatch) { block.bake(latch) item.bake(latch) - entities.bake() + skeletal.bake(latch) Log.log(LogMessageType.LOADING, LogLevels.VERBOSE) { "Baked models!" } } @@ -52,6 +53,7 @@ class ModelLoader( fun cleanup() { block.cleanup() item.cleanup() + skeletal.cleanup() } companion object { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/loader/SkeletalLoader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/loader/SkeletalLoader.kt new file mode 100644 index 000000000..e30e1a2c9 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/loader/SkeletalLoader.kt @@ -0,0 +1,39 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 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.loader + +import de.bixilon.kutil.latch.AbstractLatch +import de.bixilon.minosoft.data.registries.identified.ResourceLocation +import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel +import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture + +class SkeletalLoader(private val loader: ModelLoader) { + + fun load(latch: AbstractLatch?) { + } + + fun bake(latch: AbstractLatch?) { + } + + fun cleanup() { + } + + operator fun get(name: ResourceLocation): BakedSkeletalModel? { + TODO() + } + + fun register(name: ResourceLocation, template: ResourceLocation = name, override: Map) { + TODO() + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/SkeletalManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/SkeletalManager.kt index 0df382152..b3548bdfe 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/SkeletalManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/SkeletalManager.kt @@ -46,14 +46,14 @@ class SkeletalManager( fun draw(instance: SkeletalInstance, light: Int) { prepareDraw() shader.light = light - val transforms = instance.calculateTransforms() - var stride = 0 - for (transform in transforms) { - for (float in transform.array) { - uniformBuffer.buffer.put(stride++, float) - } - } - uniformBuffer.upload(0 until (transforms.size * MAT4_SIZE)) + // val transforms = instance.calculateTransforms() + // var stride = 0 + // for (transform in transforms) { + // for (float in transform.array) { + // uniformBuffer.buffer.put(stride++, float) + // } + // } + // uniformBuffer.upload(0 until (transforms.size * MAT4_SIZE)) instance.model.mesh.draw() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/BakedSkeletalModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/BakedSkeletalModel.kt similarity index 96% rename from src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/BakedSkeletalModel.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/BakedSkeletalModel.kt index 9193bab00..08ff30016 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/BakedSkeletalModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/BakedSkeletalModel.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.skeletal.bake +package de.bixilon.minosoft.gui.rendering.skeletal.baked import de.bixilon.kotlinglm.mat4x4.Mat4 import de.bixilon.kotlinglm.vec3.Vec3 @@ -40,6 +40,6 @@ data class BakedSkeletalModel( } fun createInstance(context: RenderContext, position: Vec3, transform: Mat4 = Mat4()): SkeletalInstance { - + TODO() } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalBakeContext.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalBakeContext.kt similarity index 97% rename from src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalBakeContext.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalBakeContext.kt index be786163c..b99a8c4e5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalBakeContext.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalBakeContext.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.skeletal.bake +package de.bixilon.minosoft.gui.rendering.skeletal.baked import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.minosoft.data.registries.identified.ResourceLocation diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalModelStates.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalModelStates.kt similarity index 93% rename from src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalModelStates.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalModelStates.kt index 9fd67057a..0f2e53182 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalModelStates.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalModelStates.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.skeletal.bake +package de.bixilon.minosoft.gui.rendering.skeletal.baked enum class SkeletalModelStates { DECLARED, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalTransform.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalTransform.kt similarity index 93% rename from src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalTransform.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalTransform.kt index aea480bae..7415442b9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/bake/SkeletalTransform.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/baked/SkeletalTransform.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.skeletal.bake +package de.bixilon.minosoft.gui.rendering.skeletal.baked class SkeletalTransform( val id: Int, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/SkeletalInstance.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/SkeletalInstance.kt index 8c9177924..2adc82848 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/SkeletalInstance.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/SkeletalInstance.kt @@ -13,8 +13,18 @@ package de.bixilon.minosoft.gui.rendering.skeletal.instance -import de.bixilon.minosoft.gui.rendering.skeletal.bake.BakedSkeletalModel +import de.bixilon.minosoft.gui.rendering.shader.Shader +import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel class SkeletalInstance( val model: BakedSkeletalModel, -) +) { + + fun draw(light: Int = 0xFF) { + TODO() + } + + fun draw(shader: Shader? = null) { + TODO() + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/SkeletalModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/SkeletalModel.kt index def9763c0..a14e66931 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/SkeletalModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/SkeletalModel.kt @@ -16,8 +16,8 @@ package de.bixilon.minosoft.gui.rendering.skeletal.model import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.skeletal.SkeletalMesh -import de.bixilon.minosoft.gui.rendering.skeletal.bake.BakedSkeletalModel -import de.bixilon.minosoft.gui.rendering.skeletal.bake.SkeletalTransform +import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel +import de.bixilon.minosoft.gui.rendering.skeletal.baked.SkeletalTransform import de.bixilon.minosoft.gui.rendering.skeletal.model.animations.SkeletalAnimation import de.bixilon.minosoft.gui.rendering.skeletal.model.elements.SkeletalElement import de.bixilon.minosoft.gui.rendering.skeletal.model.textures.SkeletalTexture diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalElement.kt index dcbfc8955..68f2550fd 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalElement.kt @@ -17,8 +17,8 @@ import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.minosoft.data.direction.Directions import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.gui.rendering.skeletal.SkeletalMesh -import de.bixilon.minosoft.gui.rendering.skeletal.bake.SkeletalBakeContext -import de.bixilon.minosoft.gui.rendering.skeletal.bake.SkeletalTransform +import de.bixilon.minosoft.gui.rendering.skeletal.baked.SkeletalBakeContext +import de.bixilon.minosoft.gui.rendering.skeletal.baked.SkeletalTransform import de.bixilon.minosoft.gui.rendering.skeletal.model.textures.SkeletalTextureInstance import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalFace.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalFace.kt index d3087b5d1..512927083 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalFace.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/model/elements/SkeletalFace.kt @@ -20,7 +20,7 @@ import de.bixilon.minosoft.data.direction.Directions import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.gui.rendering.models.block.element.face.FaceUV import de.bixilon.minosoft.gui.rendering.models.block.legacy.ModelBakeUtil -import de.bixilon.minosoft.gui.rendering.skeletal.bake.SkeletalBakeContext +import de.bixilon.minosoft.gui.rendering.skeletal.baked.SkeletalBakeContext import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.rotateAssign diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt index 318efe413..52af99ae5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt @@ -89,7 +89,7 @@ abstract class Mesh( } - fun addXQuad(start: Vec2, x: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addXQuad(start: Vec2, x: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val positions = arrayOf( Vec3(x, start.x, start.y), Vec3(x, start.x, end.y), @@ -99,7 +99,7 @@ abstract class Mesh( addQuad(positions, uvStart, uvEnd, vertexConsumer) } - fun addYQuad(start: Vec2, y: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addYQuad(start: Vec2, y: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val positions = arrayOf( Vec3(start.x, y, end.y), Vec3(end.x, y, end.y), @@ -109,7 +109,7 @@ abstract class Mesh( addQuad(positions, uvStart, uvEnd, vertexConsumer) } - fun addZQuad(start: Vec2, z: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addZQuad(start: Vec2, z: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val positions = arrayOf( Vec3(start.x, start.y, z), Vec3(start.x, end.y, z), @@ -119,7 +119,7 @@ abstract class Mesh( addQuad(positions, uvStart, uvEnd, vertexConsumer) } - fun addQuad(positions: Array, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { + inline fun addQuad(positions: Array, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) { val texturePositions = arrayOf( uvStart, Vec2(uvStart.x, uvEnd.y), diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/BlockActionS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/BlockActionS2CP.kt index ef1623703..c3af0bae2 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/BlockActionS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/block/BlockActionS2CP.kt @@ -30,8 +30,8 @@ class BlockActionS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { } else { buffer.readBlockPosition() } - val data1: Byte = buffer.readByte() - val data2: Byte = buffer.readByte() + val data1 = buffer.readByte().toInt() + val data2 = buffer.readByte().toInt() val block: Block = if (buffer.versionId < FLATTENING_VERSION) buffer.readRegistryItem(buffer.connection.registries.blockState)!!.block else buffer.readRegistryItem(buffer.connection.registries.block) override fun handle(connection: PlayConnection) {