From e421dbfda518ec5723008c427e00b34bb7b69d93 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 22 Mar 2023 21:11:11 +0100 Subject: [PATCH] wip block model testing --- .../gui/rendering/models/BlockModelTest.kt | 52 ++++++++++++++----- .../rendering/models/BlockStateModelTest.kt | 49 +++++++++++++++++ .../rendering/models/raw/block/BlockModel.kt | 2 +- .../raw/block/state/DirectBlockModel.kt | 1 + .../state/condition/ConditionBlockModel.kt | 1 + .../raw/block/state/variant/BlockVariant.kt | 4 +- .../block/state/variant/VariantBlockModel.kt | 2 +- 7 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockStateModelTest.kt diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockModelTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockModelTest.kt index 6d22c4065..05c6786ab 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockModelTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockModelTest.kt @@ -13,22 +13,50 @@ package de.bixilon.minosoft.gui.rendering.models +import de.bixilon.minosoft.gui.rendering.models.raw.block.BlockModel +import de.bixilon.minosoft.gui.rendering.models.raw.light.GUILights +import de.bixilon.minosoft.test.IT.OBJENESIS +import org.testng.Assert.assertEquals import org.testng.annotations.Test @Test(groups = ["models"]) class BlockModelTest { - private val block = """{"gui_light":"side","display":{"gui":{"rotation":[30,225,0],"translation":[0,0,0],"scale":[0.625,0.625,0.625]},"ground":{"rotation":[0,0,0],"translation":[0,3,0],"scale":[0.25,0.25,0.25]},"fixed":{"rotation":[0,0,0],"translation":[0,0,0],"scale":[0.5,0.5,0.5]},"thirdperson_righthand":{"rotation":[75,45,0],"translation":[0,2.5,0],"scale":[0.375,0.375,0.375]},"firstperson_righthand":{"rotation":[0,45,0],"translation":[0,0,0],"scale":[0.4,0.4,0.4]},"firstperson_lefthand":{"rotation":[0,225,0],"translation":[0,0,0],"scale":[0.4,0.4,0.4]}}}""" - private val cube = """{"parent":"block/block","elements":[{"from":[0,0,0],"to":[16,16,16],"faces":{"down":{"texture":"#down","cullface":"down"},"up":{"texture":"#up","cullface":"up"},"north":{"texture":"#north","cullface":"north"},"south":{"texture":"#south","cullface":"south"},"west":{"texture":"#west","cullface":"west"},"east":{"texture":"#east","cullface":"east"}}}]}""" - private val cube_all = """{"parent":"block/cube","textures":{"particle":"#all","down":"#all","up":"#all","north":"#all","east":"#all","south":"#all","west":"#all"}}""" - fun redWool() { - val state = """{"variants":{"":{"model":"minecraft:block/red_wool"}}}""" - val models = mapOf( - "block/red_wool" to """{"parent":"minecraft:block/cube_all","textures": {"all":"minecraft:block/red_wool"}}""", - "block/cube_all" to cube_all, - "bloc/cube" to cube, - "block/block" to block - ) - val model = TODO() + private fun createLoader(): ModelLoader { + val instance = OBJENESIS.newInstance(ModelLoader::class.java) + + + return instance + } + + private fun loadModel(json: String): BlockModel = TODO() + + fun emptyModel() { + val json = """{}""" + + val model = loadModel(json) + + assertEquals(model, BlockModel(GUILights.SIDE, null, null, null, true)) + } + + fun basicModel() { + val json = """{"gui_scale":"front", "ambientocclusion":false}""" + + val model = loadModel(json) + + assertEquals(model, BlockModel(GUILights.FRONT, null, null, null, true)) + } + + fun cubeAll() { + TODO() + } + + companion object { + const val BLOCK = """{"gui_light":"side","display":{"gui":{"rotation":[30,225,0],"translation":[0,0,0],"scale":[0.625,0.625,0.625]},"ground":{"rotation":[0,0,0],"translation":[0,3,0],"scale":[0.25,0.25,0.25]},"fixed":{"rotation":[0,0,0],"translation":[0,0,0],"scale":[0.5,0.5,0.5]},"thirdperson_righthand":{"rotation":[75,45,0],"translation":[0,2.5,0],"scale":[0.375,0.375,0.375]},"firstperson_righthand":{"rotation":[0,45,0],"translation":[0,0,0],"scale":[0.4,0.4,0.4]},"firstperson_lefthand":{"rotation":[0,225,0],"translation":[0,0,0],"scale":[0.4,0.4,0.4]}}}""" + const val CUBE = """{"parent":"block/block","elements":[{"from":[0,0,0],"to":[16,16,16],"faces":{"down":{"texture":"#down","cullface":"down"},"up":{"texture":"#up","cullface":"up"},"north":{"texture":"#north","cullface":"north"},"south":{"texture":"#south","cullface":"south"},"west":{"texture":"#west","cullface":"west"},"east":{"texture":"#east","cullface":"east"}}}]}""" + const val CUBE_ALL = """{"parent":"block/cube","textures":{"particle":"#all","down":"#all","up":"#all","north":"#all","east":"#all","south":"#all","west":"#all"}}""" + + + val CUBE_ALL_MODEL: BlockModel = TODO() } } diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockStateModelTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockStateModelTest.kt new file mode 100644 index 000000000..b48146633 --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/BlockStateModelTest.kt @@ -0,0 +1,49 @@ +/* + * 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 + +import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.minosoft.gui.rendering.models.BlockModelTest.Companion.BLOCK +import de.bixilon.minosoft.gui.rendering.models.BlockModelTest.Companion.CUBE +import de.bixilon.minosoft.gui.rendering.models.BlockModelTest.Companion.CUBE_ALL +import de.bixilon.minosoft.gui.rendering.models.raw.block.state.DirectBlockModel +import de.bixilon.minosoft.gui.rendering.models.raw.block.state.apply.BlockStateModel +import de.bixilon.minosoft.gui.rendering.models.raw.block.state.variant.SingleVariantBlockModel +import org.testng.Assert.assertEquals +import org.testng.annotations.Test + +@Test(groups = ["models"]) +class BlockStateModelTest { + + private fun loadModel(state: String, files: Map): DirectBlockModel = TODO() + + fun redWool() { + val state = """{"variants":{"":{"model":"minecraft:block/red_wool"}}}""" + val models = mapOf( + "block/red_wool" to """{"parent":"minecraft:block/cube_all","textures":{"all":"minecraft:block/red_wool"}}""", + "block/cube_all" to CUBE_ALL, + "bloc/cube" to CUBE, + "block/block" to BLOCK, + ) + val model = loadModel(state, models) + + assertEquals(model.unsafeCast().apply, BlockStateModel( + model = BlockModelTest.CUBE_ALL_MODEL, + x = 0, + y = 0, + uvLock = false, + weight = 1, + )) + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/BlockModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/BlockModel.kt index d21371e0b..03960264b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/BlockModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/BlockModel.kt @@ -30,7 +30,7 @@ data class BlockModel( val display: Map?, val elements: List?, val textures: Map?, - val ambientOcclusion: Boolean?, + val ambientOcclusion: Boolean, ) { companion object { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/DirectBlockModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/DirectBlockModel.kt index a4a50d6c7..cb0def0f2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/DirectBlockModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/DirectBlockModel.kt @@ -21,6 +21,7 @@ import de.bixilon.minosoft.gui.rendering.models.raw.block.state.variant.VariantB interface DirectBlockModel { companion object { + fun deserialize(data: JsonObject): DirectBlockModel? { data["variants"]?.toJsonObject()?.let { return VariantBlockModel.deserialize(it) } data["multipart"]?.toJsonObject()?.let { return ConditionBlockModel.deserialize(it) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/condition/ConditionBlockModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/condition/ConditionBlockModel.kt index 76290d980..2b1e10ff1 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/condition/ConditionBlockModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/condition/ConditionBlockModel.kt @@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.models.raw.block.state.condition import de.bixilon.kutil.json.JsonObject import de.bixilon.minosoft.gui.rendering.models.raw.block.state.DirectBlockModel +@Deprecated("TODO") class ConditionBlockModel : DirectBlockModel { companion object { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/BlockVariant.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/BlockVariant.kt index 50f82b5f1..fbaca501a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/BlockVariant.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/BlockVariant.kt @@ -15,6 +15,4 @@ package de.bixilon.minosoft.gui.rendering.models.raw.block.state.variant import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties -class BlockVariant( - val properties: Map -) +typealias BlockVariant = Map diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/VariantBlockModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/VariantBlockModel.kt index 573f48d9a..74eaa96c6 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/VariantBlockModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/raw/block/state/variant/VariantBlockModel.kt @@ -32,7 +32,7 @@ interface VariantBlockModel : DirectBlockModel { properties[property] = value } - return BlockVariant(properties) + return properties } fun deserialize(data: JsonObject): VariantBlockModel? {