feat(D-01): parse component configs from item JSON definitions

Add componentConfigs field (Map<ComponentType, JsonObject>) to
DataDrivenItemDefinition record. The parser now reads an optional
"components" JSON block, resolves each key via ComponentType.fromKey(),
and stores the raw JsonObject configs for later instantiation.
This commit is contained in:
NotEvil
2026-04-14 01:44:19 +02:00
parent 1b70041c36
commit 750be66d80
2 changed files with 42 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
package com.tiedup.remake.v2.bondage.datadriven; package com.tiedup.remake.v2.bondage.datadriven;
import com.google.gson.JsonObject;
import com.tiedup.remake.v2.BodyRegionV2; import com.tiedup.remake.v2.BodyRegionV2;
import com.tiedup.remake.v2.bondage.component.ComponentType;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -97,5 +99,14 @@ public record DataDrivenItemDefinition(
* *
* <p>This field is required in the JSON definition. Never null, never empty.</p> * <p>This field is required in the JSON definition. Never null, never empty.</p>
*/ */
Map<String, Set<String>> animationBones Map<String, Set<String>> animationBones,
) {}
/** Raw component configs from JSON, keyed by ComponentType. */
Map<ComponentType, JsonObject> componentConfigs
) {
/** Check whether this definition declares a given component type. */
public boolean hasComponent(ComponentType type) {
return componentConfigs != null && componentConfigs.containsKey(type);
}
}

View File

@@ -5,12 +5,14 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.tiedup.remake.v2.BodyRegionV2; import com.tiedup.remake.v2.BodyRegionV2;
import com.tiedup.remake.v2.bondage.component.ComponentType;
import com.tiedup.remake.v2.bondage.movement.MovementModifier; import com.tiedup.remake.v2.bondage.movement.MovementModifier;
import com.tiedup.remake.v2.bondage.movement.MovementStyle; import com.tiedup.remake.v2.bondage.movement.MovementStyle;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -266,6 +268,31 @@ public final class DataDrivenItemParser {
return null; return null;
} }
// Optional: components (per-component JSON configs)
Map<ComponentType, JsonObject> componentConfigs =
new EnumMap<>(ComponentType.class);
if (root.has("components")) {
JsonObject componentsObj = root.getAsJsonObject("components");
for (Map.Entry<String, JsonElement> entry :
componentsObj.entrySet()) {
ComponentType compType = ComponentType.fromKey(
entry.getKey()
);
if (compType != null) {
JsonObject config = entry.getValue().isJsonObject()
? entry.getValue().getAsJsonObject()
: new JsonObject();
componentConfigs.put(compType, config);
} else {
LOGGER.warn(
"[DataDrivenItemParser] Unknown component type '{}' in item '{}'",
entry.getKey(),
fileId
);
}
}
}
// Build the item ID from the file path // Build the item ID from the file path
// fileId is like "tiedup:tiedup_items/leather_armbinder.json" // fileId is like "tiedup:tiedup_items/leather_armbinder.json"
// We want "tiedup:leather_armbinder" // We want "tiedup:leather_armbinder"
@@ -302,7 +329,8 @@ public final class DataDrivenItemParser {
movementStyle, movementStyle,
movementModifier, movementModifier,
creator, creator,
animationBones animationBones,
componentConfigs
); );
} }