bb5 decoskimmed parser, only supports bb5 models
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.razz.dfashion;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.ModContainer;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
|
||||
@Mod(DecoFashion.MODID)
|
||||
public class DecoFashion {
|
||||
public static final String MODID = "decofashion";
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
public DecoFashion(IEventBus modEventBus, ModContainer modContainer) {
|
||||
modEventBus.addListener(this::commonSetup);
|
||||
}
|
||||
|
||||
private void commonSetup(FMLCommonSetupEvent event) {
|
||||
LOGGER.info("DecoFashion common setup complete");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.razz.dfashion;
|
||||
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
||||
@Mod(value = DecoFashion.MODID, dist = Dist.CLIENT)
|
||||
@EventBusSubscriber(modid = DecoFashion.MODID, value = Dist.CLIENT)
|
||||
public class DecoFashionClient {
|
||||
|
||||
@SubscribeEvent
|
||||
static void onClientSetup(FMLClientSetupEvent event) {
|
||||
DecoFashion.LOGGER.info("DecoFashion client setup complete");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.razz.dfashion.bbmodel;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public record BbCube (
|
||||
String uuid,
|
||||
String name,
|
||||
Vector3f from,
|
||||
Vector3f to,
|
||||
float inflate,
|
||||
Vector3f origin,
|
||||
Vector3f rotation,
|
||||
Map<String, BbFace> faces){}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.razz.dfashion.bbmodel;
|
||||
|
||||
public record BbFace (float[] uv, int texture, int rotation){
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.razz.dfashion.bbmodel;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public record BbGroup(
|
||||
String uuid,
|
||||
String name,
|
||||
Vector3f origin,
|
||||
Vector3f rotation
|
||||
) {}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.razz.dfashion.bbmodel;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public record BbLocator(
|
||||
String uuid,
|
||||
String name,
|
||||
Vector3f position,
|
||||
Vector3f rotation
|
||||
) {}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.razz.dfashion.bbmodel;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BbModelParser {
|
||||
private static final Gson GSON = new GsonBuilder()
|
||||
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
||||
.registerTypeAdapter(Vector3f.class, new Vector3fDeserializer())
|
||||
.registerTypeAdapter(BbOutlinerNode.class, new BbOutlinerNode.BbOutlinerNodeDeserializer())
|
||||
.create();
|
||||
|
||||
public static Bbmodel parse(Reader in) {
|
||||
JsonObject root = JsonParser.parseReader(in).getAsJsonObject();
|
||||
|
||||
List<BbCube> cubes = new ArrayList<>();
|
||||
List<BbLocator> locators = new ArrayList<>();
|
||||
|
||||
for (JsonElement e : root.getAsJsonArray("elements")) {
|
||||
JsonObject obj = e.getAsJsonObject();
|
||||
String type = obj.has("type") ? obj.get("type").getAsString() : "cube";
|
||||
switch (type) {
|
||||
case "cube" -> cubes.add(GSON.fromJson(obj, BbCube.class));
|
||||
case "locator" -> locators.add(GSON.fromJson(obj, BbLocator.class));
|
||||
// meshes, texture_meshes, null_objects, etc. silently dropped — renderer ignores them
|
||||
}
|
||||
}
|
||||
|
||||
List<BbGroup> groups = GSON.fromJson(
|
||||
root.getAsJsonArray("groups"),
|
||||
new TypeToken<List<BbGroup>>(){}.getType()
|
||||
);
|
||||
|
||||
List<BbOutlinerNode> outliner = GSON.fromJson(
|
||||
root.getAsJsonArray("outliner"),
|
||||
new TypeToken<List<BbOutlinerNode>>(){}.getType()
|
||||
);
|
||||
|
||||
return new Bbmodel(cubes, locators, groups, outliner);
|
||||
}
|
||||
|
||||
|
||||
public static class Vector3fDeserializer implements JsonDeserializer<Vector3f> {
|
||||
@Override
|
||||
public Vector3f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
JsonArray arr = json.getAsJsonArray();
|
||||
float x = arr.get(0).getAsFloat();
|
||||
float y = arr.get(1).getAsFloat();
|
||||
float z = arr.get(2).getAsFloat();
|
||||
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.razz.dfashion.bbmodel;
|
||||
import com.google.gson.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public sealed interface BbOutlinerNode permits BbOutlinerNode.GroupRef, BbOutlinerNode.ElementRef {
|
||||
record GroupRef(String uuid, List<BbOutlinerNode> children) implements BbOutlinerNode {}
|
||||
record ElementRef(String uuid) implements BbOutlinerNode {}
|
||||
|
||||
|
||||
public static class BbOutlinerNodeDeserializer implements JsonDeserializer<BbOutlinerNode> {
|
||||
@Override
|
||||
public BbOutlinerNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
|
||||
// Case 1: the JSON element is a bare string → it's a cube UUID
|
||||
if (json.isJsonPrimitive()) {
|
||||
return new BbOutlinerNode.ElementRef(json.getAsString());
|
||||
}
|
||||
|
||||
// Case 2: the JSON element is an object → it's a group reference with children
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
String uuid = obj.get("uuid").getAsString();
|
||||
|
||||
// Recursively deserialize each child — Gson calls *this same deserializer* back via context
|
||||
List<BbOutlinerNode> children = new ArrayList<>();
|
||||
for (JsonElement child : obj.getAsJsonArray("children")) {
|
||||
children.add(context.deserialize(child, BbOutlinerNode.class));
|
||||
}
|
||||
|
||||
return new BbOutlinerNode.GroupRef(uuid, children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.razz.dfashion.bbmodel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Bbmodel(
|
||||
List<BbCube> elements,
|
||||
List<BbLocator> locators,
|
||||
List<BbGroup> groups,
|
||||
List<BbOutlinerNode> outliner
|
||||
) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"_comment": "DecoFashion translation keys — populated as features are added"
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
# This is an example neoforge.mods.toml file. It contains the data relating to the loading mods.
|
||||
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
|
||||
# The overall format is standard TOML format, v0.5.0.
|
||||
# Note that there are a couple of TOML lists in this file.
|
||||
# Find more information on toml format here: https://github.com/toml-lang/toml
|
||||
|
||||
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
|
||||
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
|
||||
license="${mod_license}"
|
||||
|
||||
# A URL to refer people to when problems occur with this mod
|
||||
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
|
||||
|
||||
# A list of mods - how many allowed here is determined by the individual mod loader
|
||||
[[mods]] #mandatory
|
||||
|
||||
# The modid of the mod
|
||||
modId="${mod_id}" #mandatory
|
||||
|
||||
# The version number of the mod
|
||||
version="${mod_version}" #mandatory
|
||||
|
||||
# A display name for the mod
|
||||
displayName="${mod_name}" #mandatory
|
||||
|
||||
# A URL to query for updates for this mod. See the JSON update specification https://docs.neoforged.net/docs/misc/updatechecker/
|
||||
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
|
||||
|
||||
# A URL for the "homepage" for this mod, displayed in the mod UI
|
||||
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
|
||||
|
||||
# A file name (in the root of the mod JAR) containing a logo for display
|
||||
#logoFile="examplemod.png" #optional
|
||||
|
||||
# A text field displayed in the mod UI
|
||||
#credits="" #optional
|
||||
|
||||
# The authors of the mod, displayed in the mod UI (optional)
|
||||
#authors=""
|
||||
|
||||
# The description text for the mod (multi line!) (#mandatory)
|
||||
description='''
|
||||
Example mod description.
|
||||
'''
|
||||
|
||||
# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded.
|
||||
#[[mixins]]
|
||||
#config="${mod_id}.mixins.json"
|
||||
|
||||
# The [[accessTransformers]] block allows you to declare where your AT file is.
|
||||
# If this block is omitted, a fallback attempt will be made to load an AT from META-INF/accesstransformer.cfg
|
||||
#[[accessTransformers]]
|
||||
#file="META-INF/accesstransformer.cfg"
|
||||
|
||||
# The coremods config file path is not configurable and is always loaded from META-INF/coremods.json
|
||||
|
||||
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
|
||||
[[dependencies.${mod_id}]] #optional
|
||||
# the modid of the dependency
|
||||
modId="neoforge" #mandatory
|
||||
# The type of the dependency. Can be one of "required", "optional", "incompatible" or "discouraged" (case insensitive).
|
||||
# 'required' requires the mod to exist, 'optional' does not
|
||||
# 'incompatible' will prevent the game from loading when the mod exists, and 'discouraged' will show a warning
|
||||
type="required" #mandatory
|
||||
# Optional field describing why the dependency is required or why it is incompatible
|
||||
# reason="..."
|
||||
# The version range of the dependency
|
||||
versionRange="[${neo_version},)" #mandatory
|
||||
# An ordering relationship for the dependency.
|
||||
# BEFORE - This mod is loaded BEFORE the dependency
|
||||
# AFTER - This mod is loaded AFTER the dependency
|
||||
ordering="NONE"
|
||||
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
|
||||
side="BOTH"
|
||||
|
||||
# Here's another dependency
|
||||
[[dependencies.${mod_id}]]
|
||||
modId="minecraft"
|
||||
type="required"
|
||||
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
||||
versionRange="${minecraft_version_range}"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
# Features are specific properties of the game environment, that you may want to declare you require. This example declares
|
||||
# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
|
||||
# stop your mod loading on the server for example.
|
||||
#[features.${mod_id}]
|
||||
#openGLVersion="[3.2,)"
|
||||
Reference in New Issue
Block a user