Skip to content

Commit

Permalink
Entity register and more complex bedrock geometry render and bake.
Browse files Browse the repository at this point in the history
  • Loading branch information
boybook committed Feb 18, 2024
1 parent 2d2406f commit cef0c86
Show file tree
Hide file tree
Showing 48 changed files with 1,857 additions and 318 deletions.
18 changes: 13 additions & 5 deletions src/main/kotlin/net/easecation/bedrockloader/BedrockLoader.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.easecation.bedrockloader

import net.easecation.bedrockloader.loader.BedrockAddonLoader
import net.easecation.bedrockloader.loader.BedrockAddonsLoader
import net.easecation.bedrockloader.loader.BedrockAddonsRegistry
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder
import net.fabricmc.loader.api.FabricLoader
Expand All @@ -24,23 +25,30 @@ object BedrockLoader : ModInitializer {
logger.info("Initializing BedrockLoader...")

logger.info("Loading bedrock addons...")
BedrockAddonLoader.load()
BedrockAddonsLoader.load()

// group
var iconItem = Items.BONE_BLOCK
if (BedrockAddonLoader.registeredItems.isNotEmpty()) {
iconItem = BedrockAddonLoader.registeredItems.entries.first().value
if (BedrockAddonsRegistry.items.isNotEmpty()) {
iconItem = BedrockAddonsRegistry.items.values.first()
}
FabricItemGroupBuilder.create(Identifier("bedrock-loader", "bedrock-loader"))
.icon { ItemStack(iconItem) }
.appendItems { stacks ->
BedrockAddonLoader.registeredItems.forEach { (_, item) ->
BedrockAddonsRegistry.items.forEach { (_, item) ->
stacks.add(ItemStack(item))
}
}
.build()

logger.info("BedrockLoader initialized!")

// 测试
test()
}

private fun test() {

}

fun getGameDir(): File {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.easecation.bedrockloader

import net.easecation.bedrockloader.render.BedrockModelProvider
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry

@Environment(EnvType.CLIENT)
object BedrockLoaderClient : ClientModInitializer {

override fun onInitializeClient() {
ModelLoadingRegistry.INSTANCE.registerResourceProvider { rm -> BedrockModelProvider }
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.easecation.bedrockloader

import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener
import net.fabricmc.fabric.impl.resource.loader.FabricModResourcePack
import net.fabricmc.fabric.mixin.resource.loader.NamespaceResourceManagerAccessor
import net.minecraft.resource.ResourceManager
import net.minecraft.util.Identifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.easecation.bedrockloader.bedrock.block.component
import com.google.gson.annotations.SerializedName

data class BlockComponents(
@SerializedName("minecraft:material_instances") val minecraftMaterialInstances: List<ComponentMaterialInstances>?,
@SerializedName("minecraft:material_instances") val minecraftMaterialInstances: ComponentMaterialInstances?,
@SerializedName("minecraft:collision_box") val minecraftCollisionBox: ComponentCollisionBox?,
@SerializedName("minecraft:selection_box") val minecraftSelectionBox: ComponentSelectionBox?,
@SerializedName("minecraft:display_name") val minecraftDisplayName: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.lang.reflect.Type

sealed class ComponentGeometry : IBlockComponent {

data class ComponentGeometrySimple(val value: String) : ComponentGeometry()
data class ComponentGeometrySimple(val identifier: String) : ComponentGeometry()

data class ComponentGeometryFull(val identifier: String,
val bone_visibility: Map<String, Boolean>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class BlockResourceDefinition(
) {

data class Block(
val textures: Textures,
val textures: Textures?,
val carried_textures: String?,
val sound: String?
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package net.easecation.bedrockloader.bedrock.definition

import com.google.gson.annotations.SerializedName
import net.minecraft.util.Identifier

data class EntityRenderControllerDefinition(
@SerializedName("format_version") val formatVersion: String,
@SerializedName("render_controllers") val renderControllers: Map<String, RenderController>
) {

data class RenderController(
val arrays: Arrays?,
val color: Color?,
val filter_lighting: Boolean?,
val geometry: String,
val ignore_lighting: Boolean?,
val is_hurt_color: IsHurtColor?,
val light_color_multiplier: Any?,
val materials: List<Map<String, String>>,
val on_fire_color: OnFireColor?,
val overlay_color: OverlayColor?,
val part_visibility: List<Map<String, Any>>?,
val rebuild_animation_matrices: Boolean?,
val textures: List<String>?,
val uv_anim: UvAnim?
)

data class Arrays(
val geometries: Map<String, List<String>>?,
val materials: Map<String, List<String>>?,
val textures: Map<String, List<String>>?
)

data class Color(
val r: Any?,
val g: Any?,
val b: Any?,
val a: Any?
)

data class IsHurtColor(
val r: Any?,
val g: Any?,
val b: Any?,
val a: Any?
)

data class OnFireColor(
val r: Any?,
val g: Any?,
val b: Any?,
val a: Any?
)

data class OverlayColor(
val r: Any?,
val g: Any?,
val b: Any?,
val a: Any?
)

data class UvAnim(
val offset: List<Any>,
val scale: List<Any>
)

}
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package net.easecation.bedrockloader.bedrock.definition

import com.google.gson.annotations.SerializedName
import net.minecraft.util.Identifier

data class EntityResourceDefinition(
@SerializedName("format_version") val formatVersion: String,
@SerializedName("minecraft:client_entity") val clientEntity: ClientEntity
) {

data class ClientEntity(
val description: Description
val description: ClientEntityDescription
)

data class Description(
data class ClientEntityDescription(
val animations: Map<String, String>?,
val enable_attachables: Boolean?,
val geometry: Map<String, String>?,
val queryable_geometry: String?,
val hide_armor: Boolean?,
val held_item_ignores_lighting: Boolean?,
val identifier: String,
val identifier: Identifier,
val materials: Map<String, String>?,
val min_engine_version: String?,
val particle_effects: Map<String, String>?,
val particle_emitters: Map<String, String>?,
val render_controllers: List<Any>?,
val render_controllers: List<String>?,
val scripts: Scripts?,
val sound_effects: Map<String, String>?,
val spawn_egg: SpawnEgg?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package net.easecation.bedrockloader.bedrock.definition

import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.annotations.SerializedName
import java.lang.reflect.Type

data class GeometryDefinition(
val debug: Boolean?,
val format_version: String,
val minecraft: Map<String, List<Model>>
@SerializedName("minecraft:geometry") val geometry: List<Model>
) {

data class Model(
Expand All @@ -16,82 +22,76 @@ data class GeometryDefinition(
val identifier: String,
val texture_width: Int?,
val texture_height: Int?,
val visible_bounds_offset: List<Int>?,
val visible_bounds_width: Int?,
val visible_bounds_height: Int?
val visible_bounds_offset: List<Float>?,
val visible_bounds_width: Float?,
val visible_bounds_height: Float?
)

data class Bone(
val binding: String?,
val cubes: List<Cube>?,
val debug: Boolean?,
val inflate: Int?,
val inflate: Float?,
val locators: Map<String, Locator>?,
val mirror: Boolean?,
val name: String,
val parent: String?,
val pivot: List<Int>?,
val pivot: List<Float>?,
val poly_mesh: PolyMesh?,
val render_group_id: Int?,
val rotation: List<Int>?,
val rotation: List<Float>?,
val texture_meshes: List<TextureMeshes>?
)

data class Cube(
val inflate: Int?,
val inflate: Float?,
val mirror: Boolean?,
val origin: List<Int>?,
val pivot: List<Int>?,
val origin: List<Float>?,
val pivot: List<Float>?,
val reset: Boolean?,
val rotation: List<Int>?,
val size: List<Int>?,
val rotation: List<Float>?,
val size: List<Float>?,
val uv: Uv?
)

data class Uv(
val north: North?,
val south: South?,
val east: East?,
val west: West?,
val up: Up?,
val down: Down?
)

data class North(
val uv: List<Int>?,
val uv_size: List<Int>?,
val material_instance: String?
)

data class South(
val uv: List<Int>?,
val uv_size: List<Int>?,
val material_instance: String?
)

data class East(
val uv: List<Int>?,
val uv_size: List<Int>?,
val material_instance: String?
)

data class West(
val uv: List<Int>?,
val uv_size: List<Int>?,
val material_instance: String?
)

data class Up(
val uv: List<Int>?,
val uv_size: List<Int>?,
val material_instance: String?
)

data class Down(
val uv: List<Int>?,
val uv_size: List<Int>?,
val material_instance: String?
)
sealed class Uv {
data class UvBox(
val uv: List<Int>?,
) : Uv()

data class UvPerFace(
val north: UvPerFaceData?,
val south: UvPerFaceData?,
val east: UvPerFaceData?,
val west: UvPerFaceData?,
val up: UvPerFaceData?,
val down: UvPerFaceData?
) : Uv() {
data class UvPerFaceData(
val uv: List<Int>?,
val uv_size: List<Int>?,
val material_instance: String?
)
}

class Deserializer : JsonDeserializer<Uv> {
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Uv {
if (json.isJsonObject) {
val obj = json.asJsonObject
return UvPerFace(
obj["north"]?.let { context.deserialize(it, UvPerFace.UvPerFaceData::class.java) },
obj["south"]?.let { context.deserialize(it, UvPerFace.UvPerFaceData::class.java) },
obj["east"]?.let { context.deserialize(it, UvPerFace.UvPerFaceData::class.java) },
obj["west"]?.let { context.deserialize(it, UvPerFace.UvPerFaceData::class.java) },
obj["up"]?.let { context.deserialize(it, UvPerFace.UvPerFaceData::class.java) },
obj["down"]?.let { context.deserialize(it, UvPerFace.UvPerFaceData::class.java) }
)
} else {
return UvBox(json.asJsonArray.map { it.asInt })
}
}
}
}

data class Locator(
val offset: List<Int>?,
Expand All @@ -101,17 +101,17 @@ data class GeometryDefinition(

data class PolyMesh(
val normalized_uvs: Boolean?,
val normals: List<List<Int>>?,
val polys: List<List<Int>>?,
val positions: List<List<Int>>?,
val normals: List<List<Float>>?,
val polys: List<List<Float>>?,
val positions: List<List<Float>>?,
val uvs: List<List<Int>>?
)

data class TextureMeshes(
val local_pivot: List<Int>?,
val position: List<Int>?,
val rotation: List<Int>?,
val scale: List<Int>?,
val local_pivot: List<Float>?,
val position: List<Float>?,
val rotation: List<Float>?,
val scale: List<Float>?,
val texture: String
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.easecation.bedrockloader.bedrock.definition

import net.easecation.bedrockloader.bedrock.BedrockTexturePath

data class TerrainTextureDefinition(
val resource_pack_name: String?,
val texture_name: String?,
Expand All @@ -8,6 +10,6 @@ data class TerrainTextureDefinition(
val texture_data: Map<String, TextureData>
) {
data class TextureData(
val textures: String
val textures: BedrockTexturePath
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.easecation.bedrockloader.bedrock

import net.minecraft.util.Identifier

typealias BedrockTexturePath = String // 不包含命名空间的路径(如textures/block/stone)
typealias JavaTexturePath = Identifier // 包含命名空间,不包含textures的路径(如minecraft:block/stone)
Loading

0 comments on commit cef0c86

Please sign in to comment.