diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/IBlockState.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/IBlockState.kt new file mode 100644 index 0000000..fb44b4c --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/IBlockState.kt @@ -0,0 +1,30 @@ +package net.easecation.bedrockloader.bedrock.block.state + +import com.google.gson.JsonDeserializationContext +import com.google.gson.JsonDeserializer +import com.google.gson.JsonElement +import com.google.gson.JsonParseException +import java.lang.reflect.Type + +sealed interface IBlockState { + class Deserializer : JsonDeserializer { + override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): IBlockState = + when { + json.isJsonObject -> context.deserialize(json, StateRange::class.java) + json.isJsonArray -> json.asJsonArray.let { array -> + when { + !array.isEmpty && array[0].isJsonPrimitive -> array[0].asJsonPrimitive.let { first -> + when { + first.isBoolean -> context.deserialize(json, StateBoolean::class.java) + first.isString -> context.deserialize(json, StateString::class.java) + first.isNumber -> context.deserialize(json, StateInt::class.java) + else -> throw JsonParseException("Unexpected JSON type for IBlockState") + } + } + else -> throw JsonParseException("Unexpected JSON type for IBlockState") + } + } + else -> throw JsonParseException("Unexpected JSON type for IBlockState") + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateBoolean.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateBoolean.kt new file mode 100644 index 0000000..acde7c1 --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateBoolean.kt @@ -0,0 +1,3 @@ +package net.easecation.bedrockloader.bedrock.block.state + +class StateBoolean : IBlockState, ArrayList() \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateInt.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateInt.kt new file mode 100644 index 0000000..68a96ca --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateInt.kt @@ -0,0 +1,3 @@ +package net.easecation.bedrockloader.bedrock.block.state + +class StateInt : IBlockState, ArrayList() \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateRange.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateRange.kt new file mode 100644 index 0000000..d3712d2 --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateRange.kt @@ -0,0 +1,5 @@ +package net.easecation.bedrockloader.bedrock.block.state + +data class StateRange(val values: RangeValues) : IBlockState { + data class RangeValues(val min: Int, val max: Int) +} \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateString.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateString.kt new file mode 100644 index 0000000..a192619 --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateString.kt @@ -0,0 +1,3 @@ +package net.easecation.bedrockloader.bedrock.block.state + +class StateString : IBlockState, ArrayList() \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/BlockTraits.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/BlockTraits.kt new file mode 100644 index 0000000..8c706c2 --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/BlockTraits.kt @@ -0,0 +1,8 @@ +package net.easecation.bedrockloader.bedrock.block.traits + +import com.google.gson.annotations.SerializedName + +data class BlockTraits( + @SerializedName("minecraft:placement_direction") val minecraftPlacementDirection: TraitPlacementDirection?, + @SerializedName("minecraft:placement_position") val minecraftPlacementPosition: TraitPlacementPosition?, +) \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/IBlockTrait.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/IBlockTrait.kt new file mode 100644 index 0000000..06a6d2d --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/IBlockTrait.kt @@ -0,0 +1,5 @@ +package net.easecation.bedrockloader.bedrock.block.traits + +interface IBlockTrait { + +} diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementDirection.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementDirection.kt new file mode 100644 index 0000000..f06a4dc --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementDirection.kt @@ -0,0 +1,15 @@ +package net.easecation.bedrockloader.bedrock.block.traits + +import com.google.gson.annotations.SerializedName + +data class TraitPlacementDirection( + val enabled_states: Set, + val y_rotation_offset: Int +) : IBlockTrait { + enum class State { + @SerializedName("minecraft:cardinal_direction") + MINECRAFT_CARDINAL_DIRECTION, + @SerializedName("minecraft:facing_direction") + MINECRAFT_FACING_DIRECTION + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementPosition.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementPosition.kt new file mode 100644 index 0000000..6b1e4e3 --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementPosition.kt @@ -0,0 +1,14 @@ +package net.easecation.bedrockloader.bedrock.block.traits + +import com.google.gson.annotations.SerializedName + +data class TraitPlacementPosition( + val enabled_states: Set +) : IBlockTrait { + enum class State { + @SerializedName("minecraft:block_face") + MINECRAFT_BLOCK_FACE, + @SerializedName("minecraft:vertical_half") + MINECRAFT_VERTICAL_HALF + } +} diff --git a/src/main/kotlin/net/easecation/bedrockloader/bedrock/definition/BlockBehaviourDefinition.kt b/src/main/kotlin/net/easecation/bedrockloader/bedrock/definition/BlockBehaviourDefinition.kt index 205adf6..b55a9c6 100644 --- a/src/main/kotlin/net/easecation/bedrockloader/bedrock/definition/BlockBehaviourDefinition.kt +++ b/src/main/kotlin/net/easecation/bedrockloader/bedrock/definition/BlockBehaviourDefinition.kt @@ -3,6 +3,8 @@ package net.easecation.bedrockloader.bedrock.definition import com.google.gson.JsonElement import com.google.gson.annotations.SerializedName import net.easecation.bedrockloader.bedrock.block.component.BlockComponents +import net.easecation.bedrockloader.bedrock.block.state.IBlockState +import net.easecation.bedrockloader.bedrock.block.traits.BlockTraits import net.minecraft.util.Identifier data class BlockBehaviourDefinition( @@ -18,9 +20,10 @@ data class BlockBehaviourDefinition( ) data class Description( - val identifier: Identifier, - val states: Map>, - val menu_category: MenuCategory + val identifier: Identifier, + val menu_category: MenuCategory?, + val states: Map?, + val traits: BlockTraits? ) data class MenuCategory( diff --git a/src/main/kotlin/net/easecation/bedrockloader/block/BedrockBooleanProperty.kt b/src/main/kotlin/net/easecation/bedrockloader/block/BedrockBooleanProperty.kt new file mode 100644 index 0000000..67b620f --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/block/BedrockBooleanProperty.kt @@ -0,0 +1,21 @@ +package net.easecation.bedrockloader.block + +import net.minecraft.state.property.Property +import java.util.* + +data class BedrockBooleanProperty( + private val name: String, + private val values: Set +) : Property(name, Boolean::class.java) { + companion object { + fun of(name: String, values: Set): BedrockBooleanProperty { + return BedrockBooleanProperty(name, values) + } + } + + override fun getValues(): Collection = values + + override fun parse(name: String): Optional = Optional.ofNullable(values.find { it.toString() == name }) + + override fun name(value: Boolean): String = value.toString() +} \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/block/BedrockIntProperty.kt b/src/main/kotlin/net/easecation/bedrockloader/block/BedrockIntProperty.kt new file mode 100644 index 0000000..b17ff45 --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/block/BedrockIntProperty.kt @@ -0,0 +1,21 @@ +package net.easecation.bedrockloader.block + +import net.minecraft.state.property.Property +import java.util.* + +data class BedrockIntProperty( + private val name: String, + private val values: Set +) : Property(name, Int::class.java) { + companion object { + fun of(name: String, values: Set): BedrockIntProperty { + return BedrockIntProperty(name, values) + } + } + + override fun getValues(): Collection = values + + override fun parse(name: String): Optional = Optional.ofNullable(values.find { it.toString() == name }) + + override fun name(value: Int): String = value.toString() +} \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/block/BedrockStringProperty.kt b/src/main/kotlin/net/easecation/bedrockloader/block/BedrockStringProperty.kt new file mode 100644 index 0000000..f9de006 --- /dev/null +++ b/src/main/kotlin/net/easecation/bedrockloader/block/BedrockStringProperty.kt @@ -0,0 +1,21 @@ +package net.easecation.bedrockloader.block + +import net.minecraft.state.property.Property +import java.util.* + +data class BedrockStringProperty( + private val name: String, + private val values: Set +) : Property(name, String::class.java) { + companion object { + fun of(name: String, values: Set): BedrockStringProperty { + return BedrockStringProperty(name, values) + } + } + + override fun getValues(): Collection = values + + override fun parse(name: String): Optional = Optional.ofNullable(values.find { it == name }) + + override fun name(value: String): String = value.toString() +} \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/block/BlockDataDriven.kt b/src/main/kotlin/net/easecation/bedrockloader/block/BlockDataDriven.kt index 5dbf71b..ec6e3bc 100644 --- a/src/main/kotlin/net/easecation/bedrockloader/block/BlockDataDriven.kt +++ b/src/main/kotlin/net/easecation/bedrockloader/block/BlockDataDriven.kt @@ -1,34 +1,85 @@ package net.easecation.bedrockloader.block -import net.easecation.bedrockloader.bedrock.block.component.BlockComponents import net.easecation.bedrockloader.bedrock.block.component.ComponentCollisionBox +import net.easecation.bedrockloader.bedrock.block.state.StateBoolean +import net.easecation.bedrockloader.bedrock.block.state.StateInt +import net.easecation.bedrockloader.bedrock.block.state.StateRange +import net.easecation.bedrockloader.bedrock.block.state.StateString +import net.easecation.bedrockloader.bedrock.block.traits.TraitPlacementDirection +import net.easecation.bedrockloader.bedrock.block.traits.TraitPlacementPosition +import net.easecation.bedrockloader.bedrock.definition.BlockBehaviourDefinition +import net.minecraft.block.AbstractBlock.Settings import net.minecraft.block.Block import net.minecraft.block.BlockState import net.minecraft.block.ShapeContext +import net.minecraft.block.enums.BlockHalf +import net.minecraft.item.ItemPlacementContext +import net.minecraft.state.StateManager +import net.minecraft.state.property.DirectionProperty +import net.minecraft.state.property.EnumProperty +import net.minecraft.state.property.Property import net.minecraft.util.Identifier import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction import net.minecraft.util.shape.VoxelShape import net.minecraft.util.shape.VoxelShapes import net.minecraft.world.BlockView -class BlockDataDriven private constructor(val identifier: Identifier, val components: BlockComponents, settings: Settings) : Block(settings) { - +data class BlockContext( + val identifier: Identifier, + val behaviour: BlockBehaviourDefinition.BlockBehaviour, + val states: Map> +) { companion object { - fun create(identifier: Identifier, components: BlockComponents): BlockDataDriven { + // minecraft:placement_direction + val MINECRAFT_CARDINAL_DIRECTION = DirectionProperty.of("minecraft_cardinal_direction", Direction.Type.HORIZONTAL) + val MINECRAFT_FACING_DIRECTION = DirectionProperty.of("minecraft_facing_direction", Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP, Direction.DOWN) + // minecraft:placement_position + val MINECRAFT_BLOCK_FACE = DirectionProperty.of("minecraft_block_face", Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP, Direction.DOWN) + val MINECRAFT_VERTICAL_HALF = EnumProperty.of("minecraft_vertical_half", BlockHalf::class.java) + + fun create(identifier: Identifier, behaviour: BlockBehaviourDefinition.BlockBehaviour): BlockDataDriven { // 在这里进行逻辑计算 - val settings = calculateSettings(components) - return BlockDataDriven(identifier, components, settings) + val settings = calculateSettings(behaviour) + val states = calculateStates(behaviour) + return BlockContext(identifier, behaviour, states).BlockDataDriven(settings) + } + + private fun calculateStates(behaviour: BlockBehaviourDefinition.BlockBehaviour): Map> { + val placementDirection = behaviour.description.traits?.minecraftPlacementDirection?.enabled_states?.map { state -> + when (state) { + TraitPlacementDirection.State.MINECRAFT_CARDINAL_DIRECTION -> MINECRAFT_CARDINAL_DIRECTION + TraitPlacementDirection.State.MINECRAFT_FACING_DIRECTION -> MINECRAFT_FACING_DIRECTION + } + }?.associateBy { it.name } ?: emptyMap() + val placementPosition = behaviour.description.traits?.minecraftPlacementPosition?.enabled_states?.map { state -> + when (state) { + TraitPlacementPosition.State.MINECRAFT_BLOCK_FACE -> MINECRAFT_BLOCK_FACE + TraitPlacementPosition.State.MINECRAFT_VERTICAL_HALF -> MINECRAFT_VERTICAL_HALF + } + }?.associateBy { it.name } ?: emptyMap() + val states = behaviour.description.states?.map { (key, state) -> + val name = key.replace(':', '_').lowercase() + when (state) { + is StateBoolean -> BedrockBooleanProperty.of(name, state.toSet()) + is StateInt -> BedrockIntProperty.of(name, state.toSet()) + is StateString -> BedrockStringProperty.of(name, state.toSet()) + is StateRange -> BedrockIntProperty.of(name, (state.values.min..state.values.max).toSet()) + } + }?.associateBy { it.name } ?: emptyMap() + return placementDirection + placementPosition + states } - private fun calculateSettings(components: BlockComponents): Settings { + private fun calculateSettings(behaviour: BlockBehaviourDefinition.BlockBehaviour): Settings { val settings = Settings.create().hardness(4.0f).nonOpaque() // TODO hardness - components.minecraftCollisionBox?.let { + behaviour.components.minecraftCollisionBox?.let { when (it) { is ComponentCollisionBox.ComponentCollisionBoxBoolean -> { if (!it.value) { settings.noCollision() } } + is ComponentCollisionBox.ComponentCollisionBoxCustom -> { if (it.size.all { e -> e == 0f }) { settings.noCollision() @@ -38,33 +89,79 @@ class BlockDataDriven private constructor(val identifier: Identifier, val compon } // TODO SelectionBox - components.minecraftLightEmission?.let { + behaviour.components.minecraftLightEmission?.let { settings.luminance { _ -> it } } return settings } } - override fun getOutlineShape(state: BlockState?, view: BlockView?, pos: BlockPos?, context: ShapeContext?): VoxelShape { - if (components.minecraftCollisionBox != null) { - val it = components.minecraftCollisionBox - when (it) { - is ComponentCollisionBox.ComponentCollisionBoxBoolean -> { - return super.getOutlineShape(state, view, pos, context) - } - is ComponentCollisionBox.ComponentCollisionBoxCustom -> { - return VoxelShapes.cuboid( + inner class BlockDataDriven(settings: Settings) : Block(settings) { + init { + defaultState = stateManager.defaultState + .withIfExists(MINECRAFT_CARDINAL_DIRECTION, Direction.SOUTH) + .withIfExists(MINECRAFT_FACING_DIRECTION, Direction.DOWN) + .withIfExists(MINECRAFT_BLOCK_FACE, Direction.DOWN) + .withIfExists(MINECRAFT_VERTICAL_HALF, BlockHalf.BOTTOM) + } + + private fun rotateDirection(direction: Direction, yRotationOffset: Int): Direction { + if (direction.axis.isVertical) return direction + val offset = (yRotationOffset / 90 % 4).let { if (it < 0) it + 4 else it } + return when (offset) { + 1 -> direction.rotateYClockwise() + 2 -> direction.opposite + 3 -> direction.rotateYCounterclockwise() + else -> direction + } + } + override fun getPlacementState(ctx: ItemPlacementContext): BlockState { + val yRotationOffset = behaviour.description.traits?.minecraftPlacementDirection?.y_rotation_offset ?: 0 + return defaultState + .withIfExists(MINECRAFT_CARDINAL_DIRECTION, rotateDirection(ctx.horizontalPlayerFacing, yRotationOffset)) + .withIfExists(MINECRAFT_FACING_DIRECTION, rotateDirection(ctx.playerLookDirection, yRotationOffset)) + .withIfExists(MINECRAFT_BLOCK_FACE, ctx.side) + .withIfExists( + MINECRAFT_VERTICAL_HALF, when { + ctx.side == Direction.DOWN -> BlockHalf.TOP + ctx.side == Direction.UP -> BlockHalf.BOTTOM + ctx.hitPos.y - ctx.blockPos.y > 0.5 -> BlockHalf.TOP + else -> BlockHalf.BOTTOM + } + ) + } + + override fun appendProperties(builder: StateManager.Builder) { + states.values.forEach { builder.add(it) } + } + + override fun getOutlineShape( + state: BlockState?, + view: BlockView?, + pos: BlockPos?, + context: ShapeContext? + ): VoxelShape { + if (behaviour.components.minecraftCollisionBox != null) { + val it = behaviour.components.minecraftCollisionBox + when (it) { + is ComponentCollisionBox.ComponentCollisionBoxBoolean -> { + return super.getOutlineShape(state, view, pos, context) + } + + is ComponentCollisionBox.ComponentCollisionBoxCustom -> { + return VoxelShapes.cuboid( (it.origin[0].toDouble() + 8) / 16, it.origin[1].toDouble() / 16, (it.origin[2].toDouble() + 8) / 16, (it.origin[0].toDouble() + 8) / 16 + it.size[0].toDouble() / 16, it.origin[1].toDouble() / 16 + it.size[1].toDouble() / 16, (it.origin[2].toDouble() + 8) / 16 + it.size[2].toDouble() / 16 - ) + ) + } } + } else { + return super.getOutlineShape(state, view, pos, context) } - } else { - return super.getOutlineShape(state, view, pos, context) } } } \ No newline at end of file diff --git a/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockAddonsLoader.kt b/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockAddonsLoader.kt index 7f607ce..8d2ff91 100644 --- a/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockAddonsLoader.kt +++ b/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockAddonsLoader.kt @@ -72,12 +72,13 @@ object BedrockAddonsLoader { // load resource pack BedrockLoader.logger.info("Loading resource pack...") - BedrockResourcePackLoader(BedrockLoader.getTmpResourceDir(), context).load() + val resourcePackLoader = BedrockResourcePackLoader(BedrockLoader.getTmpResourceDir(), context) + resourcePackLoader.load() // load behaviour pack BedrockLoader.logger.info("Loading behaviour pack...") - val loader = BedrockBehaviorPackLoader(context) - loader.load() + val behaviorPackLoader = BedrockBehaviorPackLoader(context) + behaviorPackLoader.load() BedrockLoader.logger.info("Loading pack finished! ${BedrockAddonsRegistry.blocks.size} blocks, ${BedrockAddonsRegistry.items.size} items, ${BedrockAddonsRegistry.entities.size} entities") } diff --git a/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockBehaviorPackLoader.kt b/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockBehaviorPackLoader.kt index 8dd4b43..8e4f3f2 100644 --- a/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockBehaviorPackLoader.kt +++ b/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockBehaviorPackLoader.kt @@ -2,7 +2,7 @@ package net.easecation.bedrockloader.loader import net.easecation.bedrockloader.BedrockLoader import net.easecation.bedrockloader.bedrock.block.component.ComponentMaterialInstances -import net.easecation.bedrockloader.block.BlockDataDriven +import net.easecation.bedrockloader.block.BlockContext import net.easecation.bedrockloader.loader.context.BedrockPackContext import net.easecation.bedrockloader.entity.EntityDataDriven import net.fabricmc.api.EnvType @@ -23,7 +23,7 @@ class BedrockBehaviorPackLoader( val env = FabricLoader.getInstance().environmentType // Block context.behavior.blocks.forEach { (id, beh) -> - val block = BlockDataDriven.create(id, beh.components) + val block = BlockContext.create(id, beh) Registry.register(Registries.BLOCK, id, block) BedrockAddonsRegistry.blocks[id] = block if (env == EnvType.CLIENT) { diff --git a/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockResourcePackLoader.kt b/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockResourcePackLoader.kt index 14f6add..3e1ec60 100644 --- a/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockResourcePackLoader.kt +++ b/src/main/kotlin/net/easecation/bedrockloader/loader/BedrockResourcePackLoader.kt @@ -50,7 +50,6 @@ class BedrockResourcePackLoader( // Blocks for (block in context.resource.blocks) { val identifier = block.key - val dir = namespaceDir(identifier.namespace) createBlockTextures(identifier, block.value.textures, context.behavior.blocks[identifier]?.components?.minecraftMaterialInstances) createBlockModel( identifier, @@ -63,12 +62,6 @@ class BedrockResourcePackLoader( context.behavior.blocks[identifier]?.components?.minecraftGeometry, context.behavior.blocks[identifier]?.components?.minecraftMaterialInstances, ) - createBlockState( - dir.resolve("blockstates/${identifier.path}.json"), - identifier, - context.behavior.blocks[identifier]?.components?.minecraftGeometry, - context.behavior.blocks[identifier]?.components?.minecraftMaterialInstances - ) } // Entity for (entity in context.resource.entities) { @@ -165,35 +158,6 @@ class BedrockResourcePackLoader( return namespaceDir } - /** - * 创建一个方块状态文件,内部包含model路径(附带命名空间) - * 如果方块带模型,则详见createBlockModel,在创建的方块模型中,继承与自定义基岩版geometry模型,从而调用自定义渲染器和烘焙器来渲染基岩版模型 - */ - private fun createBlockState( - file: File, - identifier: Identifier, - geometry: ComponentGeometry?, - materialInstances: ComponentMaterialInstances? - ) { - // TODO block state - // 带有模型的方块情况:通过行为包定义模型和贴图 -// val model = when (geometry) { -// is ComponentGeometry.ComponentGeometrySimple -> geometry.identifier -// is ComponentGeometry.ComponentGeometryFull -> geometry.identifier -// null -> "${identifier.namespace}:block/${identifier.path}" -// } - // 方块模型更改为在BedrockModelLoadingPlugin中通过registerBlockStateResolver注册 -// val model = "${identifier.namespace}:block/${identifier.path}" -// val blockState = JavaBlockStatesDefinition( -// variants = mapOf( -// "" to JavaBlockStatesDefinition.Variant(model) -// ) -// ) -// FileWriter(file).use { writer -> -// GsonUtil.GSON.toJson(blockState, writer) -// } - } - /** * 根据方块材质包中的定义,创建一个方块贴图文件(附带命名空间) */ diff --git a/src/main/kotlin/net/easecation/bedrockloader/render/BedrockModelLoadingPlugin.kt b/src/main/kotlin/net/easecation/bedrockloader/render/BedrockModelLoadingPlugin.kt index 9d9485c..dca02ff 100644 --- a/src/main/kotlin/net/easecation/bedrockloader/render/BedrockModelLoadingPlugin.kt +++ b/src/main/kotlin/net/easecation/bedrockloader/render/BedrockModelLoadingPlugin.kt @@ -24,7 +24,9 @@ object BedrockModelLoadingPlugin : ModelLoadingPlugin { BedrockAddonsRegistry.blocks.forEach { (id, block) -> pluginContext.registerBlockStateResolver(block) { context -> val model = context.getOrLoadModel(id.withPath { "block/${it}" }) - context.setModel(context.block().defaultState, model) + context.block().stateManager.states.forEach { + context.setModel(it, model) + } } } } diff --git a/src/main/kotlin/net/easecation/bedrockloader/util/GsonUtil.kt b/src/main/kotlin/net/easecation/bedrockloader/util/GsonUtil.kt index 63806f1..ce77bf4 100644 --- a/src/main/kotlin/net/easecation/bedrockloader/util/GsonUtil.kt +++ b/src/main/kotlin/net/easecation/bedrockloader/util/GsonUtil.kt @@ -1,10 +1,8 @@ package net.easecation.bedrockloader.util import com.google.gson.* -import net.easecation.bedrockloader.bedrock.block.component.ComponentCollisionBox -import net.easecation.bedrockloader.bedrock.block.component.ComponentGeometry -import net.easecation.bedrockloader.bedrock.block.component.ComponentPlacementFilter -import net.easecation.bedrockloader.bedrock.block.component.ComponentSelectionBox +import net.easecation.bedrockloader.bedrock.block.component.* +import net.easecation.bedrockloader.bedrock.block.state.IBlockState import net.easecation.bedrockloader.bedrock.pack.SemVersion import net.easecation.bedrockloader.bedrock.definition.BlockResourceDefinition import net.easecation.bedrockloader.bedrock.definition.GeometryDefinition @@ -24,6 +22,8 @@ object GsonUtil { // file .registerTypeAdapter(BlockResourceDefinition::class.java, BlockResourceDefinition.Deserializer()) .registerTypeAdapter(BlockResourceDefinition.Textures::class.java, BlockResourceDefinition.Textures.Deserializer()) + // block state + .registerTypeAdapter(IBlockState::class.java, IBlockState.Deserializer()) // block component .registerTypeAdapter(ComponentGeometry::class.java, ComponentGeometry.Deserializer()) .registerTypeAdapter(ComponentSelectionBox::class.java, ComponentSelectionBox.Deserializer())