From 1a3056f870f9e6f978d9a3573618ae7242b484bd Mon Sep 17 00:00:00 2001 From: iambibi_ <89582596+iambibi@users.noreply.github.com> Date: Fri, 18 Sep 2026 13:59:15 +0200 Subject: [PATCH 1/5] bransch save --- .../registry/scanner/ScannerRegistry.java | 2 + .../core/scanner/items/ItemEntry.java | 62 +++++++++++++++++++ .../core/scanner/items/ItemScanner.java | 42 +++++++++++++ .../scanner/items/entry/ItemGraphics.java | 37 +++++++++++ .../scanner/items/entry/ItemResource.java | 55 ++++++++++++++++ .../riftengine/core/utils/YmlUtils.java | 6 ++ 6 files changed, 204 insertions(+) create mode 100644 src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java create mode 100644 src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java create mode 100644 src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java create mode 100644 src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java diff --git a/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java b/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java index 0622df0..9a4340d 100644 --- a/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java +++ b/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java @@ -5,11 +5,13 @@ import fr.openmc.riftengine.core.scanner.general.YamlNamespaceIAScanner; import fr.openmc.riftengine.core.scanner.general.YamlScanner; import fr.openmc.riftengine.core.scanner.icons.IconScanner; +import fr.openmc.riftengine.core.scanner.items.ItemScanner; public class ScannerRegistry extends Registry> implements KeyedRegistry> { public final IconScanner ICONS = register(new IconScanner()); + public final ItemScanner ITEMS = register(new ItemScanner()); public final YamlNamespaceIAScanner YAML_ITEMSADDER_NAMESPACE = register(new YamlNamespaceIAScanner()); public final YamlScanner YAML = register(new YamlScanner()); diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java new file mode 100644 index 0000000..922703a --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java @@ -0,0 +1,62 @@ +package fr.openmc.riftengine.core.scanner.items; + +import fr.openmc.riftengine.core.scanner.items.entry.ItemGraphics; +import fr.openmc.riftengine.core.scanner.items.entry.ItemResource; +import fr.openmc.riftengine.core.utils.IdentifierUtils; + +import java.nio.file.Path; +import java.util.Map; +import java.util.function.Function; + +public record ItemEntry( + String namespace, + String key, + + // * Méthodes de création d'items (moderne ou legacy) + ItemResource resource, + ItemGraphics graphics, + Function resourcePath, + + Path sourceYml +) { + public static ItemEntry from(Path sourceYml, String namespace, String key, Map data) { + return new ItemEntry( + namespace, + key, + ItemResource.from(data), + ItemGraphics.from(data), + sourceYml + ); + } + + private static Function resolvePathFunction( + String namespace, Map data, ItemGraphics graphics, ItemResource resource) { + + // * Méthode legacy + if (resource != null) { + if (resource.hasTextures()) + // todo: support multiple textures + return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, + IdentifierUtils.normalizeId(resource.textures().getFirst(), namespace)); + else if (resource.hasModel()) + return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, + IdentifierUtils.normalizeId(resource.model(), namespace)); + } + + // * Méthode graphics + if (graphics.hasModel()) { + return javaRoot -> IdentifierUtils.resolveModelId(javaRoot, + IdentifierUtils.normalizeId(graphics.model(), namespace)); + } + if (graphics.hasTexture()) { + return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, + IdentifierUtils.normalizeId(graphics.texture(), namespace)); + } + + return javaRoot -> null; + } + + public String namespacedId() { + return namespace + ":" + key; + } +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java new file mode 100644 index 0000000..a730283 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java @@ -0,0 +1,42 @@ +package fr.openmc.riftengine.core.scanner.items; + +import fr.openmc.riftengine.core.RiftRegistry; +import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; +import fr.openmc.riftengine.core.utils.YmlUtils; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Scan tout les items initialisé par ItemsAdder + */ +public class ItemScanner extends AbstractScanner, Path> { + public List scan(Path itemsAdderContentsPath) throws Exception { + if (!Files.isDirectory(itemsAdderContentsPath)) return new ArrayList<>(); + + List ymlFiles = RiftRegistry.SCANNERS.YAML.scan(itemsAdderContentsPath); + + List result = new ArrayList<>(); + + for (Path ymlFile : ymlFiles) { + Map root = YmlUtils.loadYml(ymlFile); + + Object itemsObj = root.get("items"); + if (!(itemsObj instanceof Map itemsMap)) continue; + + String namespace = RiftRegistry.SCANNERS.YAML_ITEMSADDER_NAMESPACE.scan(root); + + for (Map.Entry entry : itemsMap.entrySet()) { + String key = String.valueOf(entry.getKey()); + if (!(entry.getValue() instanceof Map data)) continue; + + result.add(ItemEntry.from(ymlFile, namespace, key, data)); + } + } + + return result; + } +} diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java new file mode 100644 index 0000000..be85f27 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java @@ -0,0 +1,37 @@ +package fr.openmc.riftengine.core.scanner.items.entry; + +import fr.openmc.riftengine.core.utils.YmlUtils; +import org.bukkit.Material; + +import java.util.Map; + +public record ItemGraphics( + String texture, + String model, + Material material +) { + public static ItemGraphics from(Map data) { + if (!(data.get("graphics") instanceof Map graphics)) { + return new ItemGraphics(null, null, Material.PAPER); + } + + String texture = YmlUtils.getString(graphics.get("texture"), null); + String model = YmlUtils.getString(graphics.get("model"), null); + Material material = Material.valueOf(YmlUtils.getString( + data.get("material"), ItemResource.DEFAULT_MATERIAL).toUpperCase()); + + return new ItemGraphics(texture, model, material); + } + + public boolean hasTexture() { + return texture != null; + } + + public boolean hasModel() { + return model != null; + } + + public boolean isPresent() { + return hasTexture() || hasModel(); + } +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java new file mode 100644 index 0000000..6b12214 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java @@ -0,0 +1,55 @@ +package fr.openmc.riftengine.core.scanner.items.entry; + +import fr.openmc.riftengine.core.utils.YmlUtils; +import org.bukkit.Material; + +import java.util.List; +import java.util.Map; + +public record ItemResource( + Material material, + boolean generate, + List textures, + String model, + Integer modelId +) { + public static final String DEFAULT_MATERIAL = "PAPER"; + + public static ItemResource from(Map data) { + Object resourceObj = data.get("resource"); + if (!(resourceObj instanceof Map resource)) { + return new ItemResource(Material.valueOf(DEFAULT_MATERIAL), false, List.of(), null, null); + } + + Material material = Material.valueOf(YmlUtils.getString( + resource.get("material"), DEFAULT_MATERIAL).toUpperCase()); + + boolean generate = YmlUtils.getBool(resource.get("generate"), false); + + List textures = resource.get("textures") instanceof List list + ? list.stream().map(String::valueOf).toList() + : List.of(); + + String modelPath = resource.get("model_path") != null + ? String.valueOf(resource.get("model_path")) + : null; + + Integer modelId = resource.get("model_id") != null + ? Integer.valueOf(String.valueOf(resource.get("model_id"))) + : null; + + return new ItemResource(material, generate, textures, modelPath, modelId); + } + + public boolean hasCustomModel() { + return model != null; + } + + public boolean hasTextures() { + return !textures.isEmpty(); + } + + public boolean hasModel() { + return !model.isEmpty(); + } +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/utils/YmlUtils.java b/src/main/java/fr/openmc/riftengine/core/utils/YmlUtils.java index 7e3f1f5..f3aeb57 100644 --- a/src/main/java/fr/openmc/riftengine/core/utils/YmlUtils.java +++ b/src/main/java/fr/openmc/riftengine/core/utils/YmlUtils.java @@ -17,6 +17,12 @@ public static Map loadYml(Path path) throws IOException { } } + public static String getString(Object obj, String def) { + if (obj == null) return def; + if (obj instanceof String s) return s; + return String.valueOf(obj); + } + public static Integer getInt(Object obj, Integer def) { if (obj == null) return def; if (obj instanceof Number n) return n.intValue(); From 4b9b0d9ca69ddfdd0d72267911924736cd82b412 Mon Sep 17 00:00:00 2001 From: iambibi <89582596+iambibi@users.noreply.github.com> Date: Sat, 19 Sep 2026 11:16:14 +0200 Subject: [PATCH 2/5] fix build --- build.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 56eda2e..5588a11 100644 --- a/build.gradle +++ b/build.gradle @@ -8,10 +8,12 @@ version = '0.2-SNAPSHOT' repositories { mavenCentral() - // * ItemsAdder - maven {url "https://maven.devs.beer/"} // * GeyserMC maven {url "https://repo.opencollab.dev/main/"} + // * PaperMC + maven { url = "https://repo.papermc.io/repository/maven-public/" } + // * ItemsAdder + maven {url "https://maven.devs.beer/"} } dependencies { From 032bcc9952ecee58acb16bd7037706826eca3cd7 Mon Sep 17 00:00:00 2001 From: iambibi <89582596+iambibi@users.noreply.github.com> Date: Sat, 19 Sep 2026 17:48:51 +0200 Subject: [PATCH 3/5] feat: add support to 2D items --- .../openmc/riftengine/core/RiftRegistry.java | 5 -- .../core/converter/ConverterManager.java | 17 +++- .../core/converter/writers/PackWriter.java | 2 +- .../writers/items/ItemsMappingWriter.java | 61 ++++++++++++++ .../writers/items/ItemsTextureJsonWriter.java | 64 +++++++++++++++ .../writers/items/ItemsTextureWriter.java | 53 ++++++++++++ .../core/registry/mapping/JsonMapping.java | 65 --------------- .../core/registry/mapping/Mapping.java | 15 ---- .../registry/mapping/MappingRegistry.java | 9 --- .../registry/scanner/ScannerRegistry.java | 2 + .../scanner/items/CustomModelDataScanner.java | 55 +++++++++++++ .../core/scanner/items/ItemEntry.java | 80 +++++++++++++++---- .../core/scanner/items/ItemScanner.java | 5 +- .../scanner/items/entry/ItemGraphics.java | 7 +- .../scanner/items/entry/ItemResource.java | 12 +-- .../core/utils/IdentifierUtils.java | 29 +++++++ .../riftengine/core/utils/PathUtils.java | 34 ++++++++ 17 files changed, 395 insertions(+), 120 deletions(-) create mode 100644 src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java create mode 100644 src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java create mode 100644 src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java delete mode 100644 src/main/java/fr/openmc/riftengine/core/registry/mapping/JsonMapping.java delete mode 100644 src/main/java/fr/openmc/riftengine/core/registry/mapping/Mapping.java delete mode 100644 src/main/java/fr/openmc/riftengine/core/registry/mapping/MappingRegistry.java create mode 100644 src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java create mode 100644 src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java diff --git a/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java b/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java index c38bd63..9c06133 100644 --- a/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java +++ b/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java @@ -6,7 +6,6 @@ import fr.openmc.core.bootstrap.registries.RegistryContext; import fr.openmc.core.bootstrap.registries.RegistryLoadingType; import fr.openmc.riftengine.core.registry.glyphs.GlyphsRegistry; -import fr.openmc.riftengine.core.registry.mapping.MappingRegistry; import fr.openmc.riftengine.core.registry.scanner.ScannerRegistry; import java.util.ArrayList; @@ -15,16 +14,12 @@ public final class RiftRegistry { // * Registre globaux - public static MappingRegistry MAPPINGS; public static GlyphsRegistry GLYPHS; public static ScannerRegistry SCANNERS; private static final List LOADED = new ArrayList<>(); private static final List ALL = List.of( - new RegistryContext( - () -> MAPPINGS = new MappingRegistry(), - RegistryLoadingType.RUNTIME), new RegistryContext( () -> GLYPHS = new GlyphsRegistry(), RegistryLoadingType.RUNTIME), diff --git a/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java b/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java index bcbb5df..4ace2f3 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java @@ -1,18 +1,24 @@ package fr.openmc.riftengine.core.converter; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.utils.FilesUtils; import fr.openmc.riftengine.core.RiftConfig; import fr.openmc.riftengine.core.RiftPlugin; +import fr.openmc.riftengine.core.RiftRegistry; import fr.openmc.riftengine.core.converter.writers.PackWriter; import fr.openmc.riftengine.core.converter.writers.glyph.font.FontWriter; import fr.openmc.riftengine.core.converter.writers.glyph.icons.IconsWriter; import fr.openmc.riftengine.core.converter.writers.glyph.icons.SymbolWriter; +import fr.openmc.riftengine.core.converter.writers.items.ItemsMappingWriter; +import fr.openmc.riftengine.core.converter.writers.items.ItemsTextureJsonWriter; +import fr.openmc.riftengine.core.converter.writers.items.ItemsTextureWriter; import fr.openmc.riftengine.core.converter.writers.manifest.IconWriter; import fr.openmc.riftengine.core.converter.writers.manifest.ManifestWriter; import fr.openmc.riftengine.core.converter.writers.manifest.PackIdentity; import fr.openmc.riftengine.core.converter.writers.translations.TranslationInjector; import fr.openmc.riftengine.core.converter.writers.ui.ScoreboardUiWriter; +import fr.openmc.riftengine.core.scanner.items.ItemEntry; import fr.openmc.riftengine.core.utils.ZipUtils; import org.bukkit.plugin.java.JavaPlugin; @@ -38,14 +44,21 @@ public ConverterManager(RiftPlugin plugin) { try { identity = PackIdentity.loadOrCreate(plugin); + List items = RiftRegistry.SCANNERS.ITEMS.scan(itemsAdderContents); writers.addAll(List.of( new IconWriter(), new ManifestWriter(identity), + new TranslationInjector(), new FontWriter(), new ScoreboardUiWriter(config.isHideScoreboardNumberBedrock()), + new IconsWriter(itemsAdderContents), - new SymbolWriter() + new SymbolWriter(), + + new ItemsTextureJsonWriter(items), + new ItemsTextureWriter(items), + new ItemsMappingWriter() )); } catch (Exception e) { throw new RuntimeException("Erreur lors d'initialisation du ConverterManager", e); @@ -55,7 +68,7 @@ public ConverterManager(RiftPlugin plugin) { /** * Prends un pack java et le convertit en pack bedrock */ - public Path generateConvertedPack() throws IOException { + public Path generateConvertedPack() throws Exception { Path javaPackPath = getJavaPackPath(RiftPlugin.getInstance()); Path outputDir = plugin.getDataFolder().toPath().resolve("output"); diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/PackWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/PackWriter.java index 494a14b..952f76f 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/PackWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/PackWriter.java @@ -4,5 +4,5 @@ import java.nio.file.Path; public interface PackWriter { - void write(Path bedrockRootPath, Path javaRootPath) throws IOException; + void write(Path bedrockRootPath, Path javaRootPath) throws Exception; } diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java new file mode 100644 index 0000000..778bc57 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java @@ -0,0 +1,61 @@ +package fr.openmc.riftengine.core.converter.writers.items; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.riftengine.core.RiftPlugin; +import fr.openmc.riftengine.core.RiftRegistry; +import fr.openmc.riftengine.core.converter.writers.PackWriter; +import fr.openmc.riftengine.core.scanner.items.ItemEntry; +import fr.openmc.riftengine.core.utils.PathUtils; +import org.bukkit.Material; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.List; +import java.util.Map; + +public class ItemsMappingWriter implements PackWriter { + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + @Override + public void write(Path bedrockRootPath, Path javaRootPath) throws Exception { + JsonObject root = new JsonObject(); + root.addProperty("format_version", 2); + + JsonObject itemsSetter = new JsonObject(); + Map> mappedCmd = RiftRegistry.SCANNERS.CUSTOM_MODEL_DATA_CACHE.scan(null); + + for (Material material : mappedCmd.keySet()) { + JsonArray itemsDefinitions = new JsonArray(); + Map namespaceCmd = mappedCmd.get(material); + + for (String namespace : namespaceCmd.keySet()) { + JsonObject itemDefinition = new JsonObject(); + itemDefinition.addProperty("type", "legacy"); + itemDefinition.addProperty("custom_model_data", namespaceCmd.get(namespace)); + itemDefinition.addProperty("bedrock_identifier", namespace); + + JsonObject bedrockOptions = new JsonObject(); + bedrockOptions.addProperty("icon", namespace); + itemDefinition.add("bedrock_options", bedrockOptions); + + itemsDefinitions.add(itemDefinition); + } + + itemsSetter.add(material.getKey().asString(), itemsDefinitions); + } + + root.add("items", itemsSetter); + + Path outputFile = PathUtils.getGeyserPath(RiftPlugin.getInstance().getDataPath()) + .resolve("custom_mappings").resolve("ia-injected.json"); + Files.createDirectories(outputFile.getParent()); + Files.writeString(outputFile, GSON.toJson(root), StandardCharsets.UTF_8); + } +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java new file mode 100644 index 0000000..fddeada --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java @@ -0,0 +1,64 @@ +package fr.openmc.riftengine.core.converter.writers.items; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.riftengine.core.converter.writers.PackWriter; +import fr.openmc.riftengine.core.scanner.items.ItemEntry; +import fr.openmc.riftengine.core.utils.PathUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.List; + +public class ItemsTextureJsonWriter implements PackWriter { + private final List items; + + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + public ItemsTextureJsonWriter(List items) { + this.items = items; + } + + @Override + public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { + JsonObject root = new JsonObject(); + + JsonObject textureData = new JsonObject(); + + for (ItemEntry itemEntry : items) { + JsonObject itemData = new JsonObject(); + + Path resourcePath = itemEntry.resourcePath().apply(javaRootPath); + if (resourcePath == null) { + OMCLogger.warn("Item {} a aucune resource (Model ou texture)", itemEntry.namespacedId()); + continue; + } + + Path reducedPath = PathUtils.getPathFromRoot(resourcePath, "textures"); + if (reducedPath == null) { + OMCLogger.warn("Item {} a un Path impossible a réduire {}", itemEntry.namespacedId(), resourcePath.toString()); + continue; + } + + String texture = reducedPath.toString().replaceFirst("\\.[^/.]+$", ""); + + itemData.addProperty("textures", texture); + + textureData.add(itemEntry.namespacedId(), itemData); + } + + root.addProperty("texture_name", "atlas.items"); + root.add("texture_data", textureData); + + Path outputFile = bedrockRootPath.resolve("textures").resolve("item_texture.json"); + Files.createDirectories(outputFile.getParent()); + Files.writeString(outputFile, GSON.toJson(root), StandardCharsets.UTF_8); + } +} diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java new file mode 100644 index 0000000..771498c --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java @@ -0,0 +1,53 @@ +package fr.openmc.riftengine.core.converter.writers.items; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.riftengine.core.converter.writers.PackWriter; +import fr.openmc.riftengine.core.scanner.items.ItemEntry; +import fr.openmc.riftengine.core.utils.PathUtils; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.List; + +public class ItemsTextureWriter implements PackWriter { + private final List items; + + public ItemsTextureWriter(List items) { + this.items = items; + } + + @Override + public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { + for (ItemEntry itemEntry : items) { + String ressouceId = itemEntry.getBestResourceId(); + if (ressouceId == null) { + OMCLogger.warn("Item {} a pas de resource id", itemEntry.namespacedId()); + continue; + } + System.out.println(ressouceId); + if (ressouceId.split(":")[0].equals("minecraft")) continue; + + Path resourcePath = itemEntry.resourcePath().apply(javaRootPath); + if (resourcePath == null) { + OMCLogger.warn("Item {} a aucune resource (Model ou texture)", itemEntry.namespacedId()); + continue; + } + + Path reducedPath = PathUtils.getPathFromRoot(resourcePath, "textures"); + if (reducedPath == null) { + OMCLogger.warn("Item {} a un Path impossible a réduire {}", itemEntry.namespacedId(), resourcePath.toString()); + continue; + } + + Path outputFile = bedrockRootPath.resolve(reducedPath); + Files.createDirectories(outputFile.getParent()); + Files.copy(resourcePath, outputFile, StandardCopyOption.REPLACE_EXISTING); + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/registry/mapping/JsonMapping.java b/src/main/java/fr/openmc/riftengine/core/registry/mapping/JsonMapping.java deleted file mode 100644 index f319b9b..0000000 --- a/src/main/java/fr/openmc/riftengine/core/registry/mapping/JsonMapping.java +++ /dev/null @@ -1,65 +0,0 @@ -package fr.openmc.riftengine.core.registry.mapping; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.riftengine.core.RiftPlugin; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public abstract class JsonMapping implements Mapping { - private final Map entries = new HashMap<>(); - - /** - * Chemin du fichier de mapping JSON, ex: "mappings/langs/mapping_26_2.json". - * @return Chemin relatif en partant de resources - */ - public abstract String getBaseFileName(); - - @Override - public void load() { - entries.clear(); - mergeFrom(getBaseFileName()); - - OMCLogger.infoFormatted(getClass().getSimpleName() + " chargé avec " + entries.size() + " entrées"); - } - - private void mergeFrom(String fileName) { - try (InputStream is = RiftPlugin.getInstance().getResource(fileName)) { - if (is == null) return; - - try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { - JsonObject json = JsonParser.parseReader(reader).getAsJsonObject(); - for (String key : json.keySet()) { - entries.put(key, json.get(key).getAsString()); - } - } - } catch (IOException e) { - OMCLogger.errorFormatted("Erreur de lecture du mapping " + fileName + " : " + e.getMessage()); - } - } - - @Override - public Optional resolve(String javaKey) { - return Optional.ofNullable(entries.get(javaKey)); - } - - @Override - public int size() { - return entries.size(); - } - - @Override - public Map asMap() { - return entries; - } - -} diff --git a/src/main/java/fr/openmc/riftengine/core/registry/mapping/Mapping.java b/src/main/java/fr/openmc/riftengine/core/registry/mapping/Mapping.java deleted file mode 100644 index 38690a8..0000000 --- a/src/main/java/fr/openmc/riftengine/core/registry/mapping/Mapping.java +++ /dev/null @@ -1,15 +0,0 @@ -package fr.openmc.riftengine.core.registry.mapping; - -import java.util.Map; -import java.util.Optional; - -public interface Mapping { - void load(); - Optional resolve(K javaKey); - int size(); - Map asMap(); - - default Mapping get() { - return this; - } -} diff --git a/src/main/java/fr/openmc/riftengine/core/registry/mapping/MappingRegistry.java b/src/main/java/fr/openmc/riftengine/core/registry/mapping/MappingRegistry.java deleted file mode 100644 index 62a810f..0000000 --- a/src/main/java/fr/openmc/riftengine/core/registry/mapping/MappingRegistry.java +++ /dev/null @@ -1,9 +0,0 @@ -package fr.openmc.riftengine.core.registry.mapping; - -import fr.openmc.core.bootstrap.registries.Registry; - -public class MappingRegistry extends Registry> { - // todo: regarder si c'est réelement utile, inutilisé car le systeme initial de translation ds le pack et tt ne marche pas et geyser on deja un support pour ça - - // ** REGISTER MAPPING ** -} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java b/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java index 9a4340d..fe190ee 100644 --- a/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java +++ b/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java @@ -5,6 +5,7 @@ import fr.openmc.riftengine.core.scanner.general.YamlNamespaceIAScanner; import fr.openmc.riftengine.core.scanner.general.YamlScanner; import fr.openmc.riftengine.core.scanner.icons.IconScanner; +import fr.openmc.riftengine.core.scanner.items.CustomModelDataScanner; import fr.openmc.riftengine.core.scanner.items.ItemScanner; public class ScannerRegistry extends Registry> @@ -12,6 +13,7 @@ public class ScannerRegistry extends Registry> public final IconScanner ICONS = register(new IconScanner()); public final ItemScanner ITEMS = register(new ItemScanner()); + public final CustomModelDataScanner CUSTOM_MODEL_DATA_CACHE = register(new CustomModelDataScanner()); public final YamlNamespaceIAScanner YAML_ITEMSADDER_NAMESPACE = register(new YamlNamespaceIAScanner()); public final YamlScanner YAML = register(new YamlScanner()); diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java new file mode 100644 index 0000000..aea4f8b --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java @@ -0,0 +1,55 @@ +package fr.openmc.riftengine.core.scanner.items; + +import fr.openmc.riftengine.core.RiftPlugin; +import fr.openmc.riftengine.core.RiftRegistry; +import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; +import fr.openmc.riftengine.core.utils.PathUtils; +import fr.openmc.riftengine.core.utils.YmlUtils; +import org.bukkit.Material; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Scan le cache des CustomModelData qui sont assignés par ItemsAdder + */ +public class CustomModelDataScanner extends AbstractScanner>, Void> { + private final String CACHE_FILE_NAME = "items_ids_cache.yml"; + + public Map> scan(Void voyd) throws Exception { + Path cmdPath = PathUtils.getItemsAdderPath(RiftPlugin.getInstance().getDataPath()).resolve("storage").resolve(CACHE_FILE_NAME); + + Map root = YmlUtils.loadYml(cmdPath); + Map> mappedCache = new HashMap<>(); + + for (var iterRoot : root.entrySet()) { + String key = iterRoot.getKey(); + Material materialKey = Material.valueOf(key); + + Map value = new HashMap<>(); + + if (!(iterRoot.getValue() instanceof Map valueMap)) continue; + + Map namespacedIdCmdMap = (Map) valueMap; + + for (var entryIdCmd : namespacedIdCmdMap.entrySet()) { + String namespacedId = entryIdCmd.getKey(); + // todo: __manually_handled, qui serait utile lors de l'impl des CustomEmotes et des models par ailleurs + if (namespacedId.startsWith("__")) continue; + + Integer cmd = entryIdCmd.getValue(); + + value.put(namespacedId, cmd); + } + + mappedCache.put(materialKey, value); + } + + System.out.println(mappedCache); + return mappedCache; + } +} diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java index 922703a..0a47c6e 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java @@ -3,6 +3,7 @@ import fr.openmc.riftengine.core.scanner.items.entry.ItemGraphics; import fr.openmc.riftengine.core.scanner.items.entry.ItemResource; import fr.openmc.riftengine.core.utils.IdentifierUtils; +import org.bukkit.Material; import java.nio.file.Path; import java.util.Map; @@ -11,6 +12,7 @@ public record ItemEntry( String namespace, String key, + Integer customModelData, // * Méthodes de création d'items (moderne ou legacy) ItemResource resource, @@ -19,19 +21,64 @@ public record ItemEntry( Path sourceYml ) { - public static ItemEntry from(Path sourceYml, String namespace, String key, Map data) { + public static ItemEntry from(Map> cmdCache, Path sourceYml, String namespace, String key, Map data) { + ItemResource itemResource = ItemResource.from(data); + ItemGraphics itemGraphics = ItemGraphics.from(data); + + Material material = getMaterial(itemResource, itemGraphics); + + Integer customModelData = null; + + Map map = cmdCache.get(material); + if (map != null && map.get(namespace + ":" + key) != null) + customModelData = map.get(namespace + ":" + key); + return new ItemEntry( namespace, key, - ItemResource.from(data), - ItemGraphics.from(data), + customModelData, + itemResource, + itemGraphics, + resolvePathFunction(namespace, itemGraphics, itemResource), sourceYml ); } - private static Function resolvePathFunction( - String namespace, Map data, ItemGraphics graphics, ItemResource resource) { + public String getBestResourceId() { + if (resource != null) { + if (resource.hasTextures()) + return IdentifierUtils.normalizeId(resource.textures().getFirst(), namespace); + else if (resource.hasModel()) + return IdentifierUtils.normalizeId(resource.model(), namespace); + } + + // * Méthode graphics + if (graphics != null) { + if (graphics.hasModel()) { + return IdentifierUtils.normalizeId(graphics.model(), namespace); + } + if (graphics.hasTexture()) { + return IdentifierUtils.normalizeId(graphics.texture(), namespace); + } + } + + return null; + } + + private static Material getMaterial(ItemResource resource, ItemGraphics graphics) { + Material byDefault = Material.valueOf(ItemResource.DEFAULT_MATERIAL); + Material resourceMaterial = resource.material(); + Material graphicsMaterial = graphics.material(); + + if (resourceMaterial != byDefault) + return resourceMaterial; + if (graphicsMaterial != byDefault) + return graphicsMaterial; + return byDefault; + } + + private static Function resolvePathFunction(String namespace, ItemGraphics graphics, ItemResource resource) { // * Méthode legacy if (resource != null) { if (resource.hasTextures()) @@ -39,21 +86,26 @@ private static Function resolvePathFunction( return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, IdentifierUtils.normalizeId(resource.textures().getFirst(), namespace)); else if (resource.hasModel()) - return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, + return javaRoot -> IdentifierUtils.resolveModelId(javaRoot, IdentifierUtils.normalizeId(resource.model(), namespace)); } // * Méthode graphics - if (graphics.hasModel()) { - return javaRoot -> IdentifierUtils.resolveModelId(javaRoot, - IdentifierUtils.normalizeId(graphics.model(), namespace)); - } - if (graphics.hasTexture()) { - return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, - IdentifierUtils.normalizeId(graphics.texture(), namespace)); + if (graphics != null) { + if (graphics.hasModel()) { + return javaRoot -> IdentifierUtils.resolveModelId(javaRoot, + IdentifierUtils.normalizeId(graphics.model(), namespace)); + } + if (graphics.hasTexture()) { + return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, + IdentifierUtils.normalizeId(graphics.texture(), namespace)); + } } - return javaRoot -> null; + System.out.println("NULL BECAUSE (id" + namespace + ")"); + System.out.println("ressource = " + resource); + System.out.println("graphics = " + graphics); + return _ -> null; } public String namespacedId() { diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java index a730283..69b545c 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java @@ -3,10 +3,12 @@ import fr.openmc.riftengine.core.RiftRegistry; import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; import fr.openmc.riftengine.core.utils.YmlUtils; +import org.bukkit.Material; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,12 +30,13 @@ public List scan(Path itemsAdderContentsPath) throws Exception { if (!(itemsObj instanceof Map itemsMap)) continue; String namespace = RiftRegistry.SCANNERS.YAML_ITEMSADDER_NAMESPACE.scan(root); + Map> mappedCache = RiftRegistry.SCANNERS.CUSTOM_MODEL_DATA_CACHE.scan(null); for (Map.Entry entry : itemsMap.entrySet()) { String key = String.valueOf(entry.getKey()); if (!(entry.getValue() instanceof Map data)) continue; - result.add(ItemEntry.from(ymlFile, namespace, key, data)); + result.add(ItemEntry.from(mappedCache, ymlFile, namespace, key, data)); } } diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java index be85f27..18c8eb2 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java @@ -15,6 +15,7 @@ public static ItemGraphics from(Map data) { return new ItemGraphics(null, null, Material.PAPER); } + // todo: pas forcement un string, peut etre une map qui contient d'autres champs String texture = YmlUtils.getString(graphics.get("texture"), null); String model = YmlUtils.getString(graphics.get("model"), null); Material material = Material.valueOf(YmlUtils.getString( @@ -24,11 +25,13 @@ public static ItemGraphics from(Map data) { } public boolean hasTexture() { - return texture != null; + if (texture == null) return false; + return !texture.isEmpty(); } public boolean hasModel() { - return model != null; + if (model == null) return false; + return !model.isEmpty(); } public boolean isPresent() { diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java index 6b12214..754ec07 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java @@ -17,9 +17,8 @@ public record ItemResource( public static ItemResource from(Map data) { Object resourceObj = data.get("resource"); - if (!(resourceObj instanceof Map resource)) { + if (!(resourceObj instanceof Map resource)) return new ItemResource(Material.valueOf(DEFAULT_MATERIAL), false, List.of(), null, null); - } Material material = Material.valueOf(YmlUtils.getString( resource.get("material"), DEFAULT_MATERIAL).toUpperCase()); @@ -30,6 +29,9 @@ public static ItemResource from(Map data) { ? list.stream().map(String::valueOf).toList() : List.of(); + if (textures.isEmpty() && resource.get("textures") instanceof String string) + textures = List.of(string); + String modelPath = resource.get("model_path") != null ? String.valueOf(resource.get("model_path")) : null; @@ -41,15 +43,13 @@ public static ItemResource from(Map data) { return new ItemResource(material, generate, textures, modelPath, modelId); } - public boolean hasCustomModel() { - return model != null; - } - public boolean hasTextures() { + if (textures == null) return false; return !textures.isEmpty(); } public boolean hasModel() { + if (model == null) return false; return !model.isEmpty(); } } \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java b/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java index 3f3890f..6bed501 100644 --- a/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java +++ b/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java @@ -52,4 +52,33 @@ public static Path resolveTextureId(Path rootPath, String id) { .resolve("textures") .resolve(texturePath); } + + /** + * Résout un identifiant en un chemin de fichier dans les assets pour les models + */ + public static Path resolveModelId(Path rootPath, String id) { + String normalizedId = normalizeId(id); + String[] split = normalizedId.split(":", 2); + + String namespace; + String modelPath; + + if (split.length == 2) { + namespace = split[0]; + modelPath = split[1]; + } else { + namespace = "minecraft"; + modelPath = split[0]; + } + + if (!modelPath.endsWith(".json")) { + modelPath += ".json"; + } + + return rootPath + .resolve("assets") + .resolve(namespace) + .resolve("models") + .resolve(modelPath); + } } diff --git a/src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java b/src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java new file mode 100644 index 0000000..c4923e5 --- /dev/null +++ b/src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java @@ -0,0 +1,34 @@ +package fr.openmc.riftengine.core.utils; + +import java.io.File; +import java.nio.file.Path; + +public class PathUtils { + public static Path getPathFromRoot(Path path, String rootName) { + Path reducedPath = null; + for (Path iterPath : path) { + if (reducedPath != null) { + reducedPath = reducedPath.resolve(iterPath); + } + + if (reducedPath == null && iterPath.getFileName().toString().equals(rootName)) + reducedPath = iterPath; + + } + return reducedPath; + } + + public static Path getItemsAdderPath(Path dataPath) { + File pluginsDir = dataPath.toFile().getParentFile(); // * root/plugins + File itemsAdderDir = new File(pluginsDir, "ItemsAdder"); // * root/plugins/ItemsAdder + + return itemsAdderDir.toPath(); + } + + public static Path getGeyserPath(Path dataPath) { + File pluginsDir = dataPath.toFile().getParentFile(); // * root/plugins + File geyserDir = new File(pluginsDir, "Geyser-Spigot"); // * root/plugins/Geyser-Spigot + + return geyserDir.toPath(); + } +} From 56fd8e5176fd21ff444148a6ba1d79c8a773673c Mon Sep 17 00:00:00 2001 From: iambibi <89582596+iambibi@users.noreply.github.com> Date: Sun, 20 Sep 2026 12:03:57 +0200 Subject: [PATCH 4/5] fix: bug related Items 2D --- .../core/converter/ConverterManager.java | 2 +- .../writers/items/ItemsMappingWriter.java | 48 +++++++++++------ .../writers/items/ItemsTextureJsonWriter.java | 31 +++++++---- .../writers/items/ItemsTextureWriter.java | 8 +-- .../scanner/items/CustomModelDataScanner.java | 1 - .../core/scanner/items/ItemEntry.java | 52 ++++++++++++++----- .../scanner/items/entry/ItemGraphics.java | 2 +- .../scanner/items/entry/ItemResource.java | 16 +++--- .../core/utils/IdentifierUtils.java | 9 ++++ 9 files changed, 113 insertions(+), 56 deletions(-) diff --git a/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java b/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java index 4ace2f3..fdbf74e 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java @@ -58,7 +58,7 @@ public ConverterManager(RiftPlugin plugin) { new ItemsTextureJsonWriter(items), new ItemsTextureWriter(items), - new ItemsMappingWriter() + new ItemsMappingWriter(items) )); } catch (Exception e) { throw new RuntimeException("Erreur lors d'initialisation du ConverterManager", e); diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java index 778bc57..a74e178 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java @@ -17,40 +17,50 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class ItemsMappingWriter implements PackWriter { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private final List items; + + public ItemsMappingWriter(List items) { + this.items = items; + } + @Override public void write(Path bedrockRootPath, Path javaRootPath) throws Exception { JsonObject root = new JsonObject(); root.addProperty("format_version", 2); - JsonObject itemsSetter = new JsonObject(); - Map> mappedCmd = RiftRegistry.SCANNERS.CUSTOM_MODEL_DATA_CACHE.scan(null); + Map byMaterial = new HashMap<>(); - for (Material material : mappedCmd.keySet()) { - JsonArray itemsDefinitions = new JsonArray(); - Map namespaceCmd = mappedCmd.get(material); + for (ItemEntry item : items) { + JsonObject def = new JsonObject(); - for (String namespace : namespaceCmd.keySet()) { - JsonObject itemDefinition = new JsonObject(); - itemDefinition.addProperty("type", "legacy"); - itemDefinition.addProperty("custom_model_data", namespaceCmd.get(namespace)); - itemDefinition.addProperty("bedrock_identifier", namespace); + if (item.getCustomModelData() != null) { + def.addProperty("type", "legacy"); + def.addProperty("custom_model_data", item.getCustomModelData()); + } else { + def.addProperty("type", "definition"); + def.addProperty("model", item.getNamespace() + ":ia_auto/" + item.getKey()); + } - JsonObject bedrockOptions = new JsonObject(); - bedrockOptions.addProperty("icon", namespace); - itemDefinition.add("bedrock_options", bedrockOptions); + def.addProperty("bedrock_identifier", item.namespacedId()); - itemsDefinitions.add(itemDefinition); - } + JsonObject options = new JsonObject(); + options.addProperty("icon", item.namespacedId()); + def.add("bedrock_options", options); - itemsSetter.add(material.getKey().asString(), itemsDefinitions); + byMaterial.computeIfAbsent(item.getMaterial().getKey().asString(), _ -> new JsonArray()) + .add(def); } + JsonObject itemsSetter = new JsonObject(); + byMaterial.forEach(itemsSetter::add); root.add("items", itemsSetter); Path outputFile = PathUtils.getGeyserPath(RiftPlugin.getInstance().getDataPath()) @@ -58,4 +68,10 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws Exception { Files.createDirectories(outputFile.getParent()); Files.writeString(outputFile, GSON.toJson(root), StandardCharsets.UTF_8); } + + private ItemEntry getByNamespace(String namespacedId) { + return items.stream(). + filter(item -> item.namespacedId().equals(namespacedId)) + .findFirst().orElse(null); + } } \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java index fddeada..8ff178c 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java @@ -7,6 +7,7 @@ import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.riftengine.core.converter.writers.PackWriter; import fr.openmc.riftengine.core.scanner.items.ItemEntry; +import fr.openmc.riftengine.core.utils.IdentifierUtils; import fr.openmc.riftengine.core.utils.PathUtils; import java.io.IOException; @@ -16,6 +17,7 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.List; +import java.util.Locale; public class ItemsTextureJsonWriter implements PackWriter { private final List items; @@ -33,24 +35,31 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { JsonObject textureData = new JsonObject(); for (ItemEntry itemEntry : items) { - JsonObject itemData = new JsonObject(); + String resourceId = itemEntry.getBestResourceId(); + String texture = null; - Path resourcePath = itemEntry.resourcePath().apply(javaRootPath); - if (resourcePath == null) { - OMCLogger.warn("Item {} a aucune resource (Model ou texture)", itemEntry.namespacedId()); - continue; + if (resourceId == null) { + texture = "textures/items/" + itemEntry.getMaterial().name().toLowerCase();; + } else if (resourceId.startsWith("minecraft:")) { + String path = IdentifierUtils.normalizeId(resourceId).split(":", 2)[1]; + texture = IdentifierUtils.toBedrockTexturePath("textures/" + path); + } else { + Path resourcePath = itemEntry.getResourcePath().apply(javaRootPath); + Path reducedPath = resourcePath == null ? null + : PathUtils.getPathFromRoot(resourcePath, "textures"); + if (reducedPath != null) { + texture = IdentifierUtils.toBedrockTexturePath(reducedPath.toString()) + .replaceFirst("\\.[^/.]+$", ""); + } } - Path reducedPath = PathUtils.getPathFromRoot(resourcePath, "textures"); - if (reducedPath == null) { - OMCLogger.warn("Item {} a un Path impossible a réduire {}", itemEntry.namespacedId(), resourcePath.toString()); + if (texture == null) { + OMCLogger.warn("Item {} : impossible de déterminer la texture", itemEntry.namespacedId()); continue; } - String texture = reducedPath.toString().replaceFirst("\\.[^/.]+$", ""); - + JsonObject itemData = new JsonObject(); itemData.addProperty("textures", texture); - textureData.add(itemEntry.namespacedId(), itemData); } diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java index 771498c..409808f 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java @@ -7,6 +7,7 @@ import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.riftengine.core.converter.writers.PackWriter; import fr.openmc.riftengine.core.scanner.items.ItemEntry; +import fr.openmc.riftengine.core.utils.IdentifierUtils; import fr.openmc.riftengine.core.utils.PathUtils; import java.io.IOException; @@ -30,10 +31,10 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { OMCLogger.warn("Item {} a pas de resource id", itemEntry.namespacedId()); continue; } - System.out.println(ressouceId); + if (ressouceId.split(":")[0].equals("minecraft")) continue; - Path resourcePath = itemEntry.resourcePath().apply(javaRootPath); + Path resourcePath = itemEntry.getResourcePath().apply(javaRootPath); if (resourcePath == null) { OMCLogger.warn("Item {} a aucune resource (Model ou texture)", itemEntry.namespacedId()); continue; @@ -45,7 +46,8 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { continue; } - Path outputFile = bedrockRootPath.resolve(reducedPath); + Path outputFile = bedrockRootPath.resolve( + IdentifierUtils.toBedrockTexturePath(reducedPath.toString())); Files.createDirectories(outputFile.getParent()); Files.copy(resourcePath, outputFile, StandardCopyOption.REPLACE_EXISTING); } diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java index aea4f8b..f0b745d 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java @@ -49,7 +49,6 @@ public Map> scan(Void voyd) throws Exception { mappedCache.put(materialKey, value); } - System.out.println(mappedCache); return mappedCache; } } diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java index 0a47c6e..8affe18 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java @@ -3,24 +3,50 @@ import fr.openmc.riftengine.core.scanner.items.entry.ItemGraphics; import fr.openmc.riftengine.core.scanner.items.entry.ItemResource; import fr.openmc.riftengine.core.utils.IdentifierUtils; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Material; import java.nio.file.Path; import java.util.Map; import java.util.function.Function; -public record ItemEntry( - String namespace, - String key, - Integer customModelData, - - // * Méthodes de création d'items (moderne ou legacy) - ItemResource resource, - ItemGraphics graphics, - Function resourcePath, +@Getter +public class ItemEntry { + private final String namespace; + private final String key; + private final Integer customModelData; + private final Material material; + + private final ItemResource resource; + private final ItemGraphics graphics; + private final Function resourcePath; + + private final Path sourceYml; + + private ItemEntry( + String namespace, + String key, + Integer customModelData, + Material material, + + // * Méthodes de création d'items (moderne ou legacy) + ItemResource resource, + ItemGraphics graphics, + Function resourcePath, + + Path sourceYml + ) { + this.namespace = namespace; + this.key = key; + this.customModelData = customModelData; + this.material = material; + this.resource = resource; + this.graphics = graphics; + this.resourcePath = resourcePath; + this.sourceYml = sourceYml; + } - Path sourceYml -) { public static ItemEntry from(Map> cmdCache, Path sourceYml, String namespace, String key, Map data) { ItemResource itemResource = ItemResource.from(data); ItemGraphics itemGraphics = ItemGraphics.from(data); @@ -37,6 +63,7 @@ public static ItemEntry from(Map> cmdCache, Path namespace, key, customModelData, + material, itemResource, itemGraphics, resolvePathFunction(namespace, itemGraphics, itemResource), @@ -102,9 +129,6 @@ else if (resource.hasModel()) } } - System.out.println("NULL BECAUSE (id" + namespace + ")"); - System.out.println("ressource = " + resource); - System.out.println("graphics = " + graphics); return _ -> null; } diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java index 18c8eb2..4b405f0 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java @@ -15,7 +15,7 @@ public static ItemGraphics from(Map data) { return new ItemGraphics(null, null, Material.PAPER); } - // todo: pas forcement un string, peut etre une map qui contient d'autres champs + // todo: supporter textures (pour block, ou bow, fishing rod, ect) String texture = YmlUtils.getString(graphics.get("texture"), null); String model = YmlUtils.getString(graphics.get("model"), null); Material material = Material.valueOf(YmlUtils.getString( diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java index 754ec07..2c4c203 100644 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java +++ b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java @@ -10,25 +10,27 @@ public record ItemResource( Material material, boolean generate, List textures, - String model, - Integer modelId + String model ) { public static final String DEFAULT_MATERIAL = "PAPER"; public static ItemResource from(Map data) { Object resourceObj = data.get("resource"); if (!(resourceObj instanceof Map resource)) - return new ItemResource(Material.valueOf(DEFAULT_MATERIAL), false, List.of(), null, null); + return new ItemResource(Material.valueOf(DEFAULT_MATERIAL), false, List.of(), null); Material material = Material.valueOf(YmlUtils.getString( resource.get("material"), DEFAULT_MATERIAL).toUpperCase()); boolean generate = YmlUtils.getBool(resource.get("generate"), false); - List textures = resource.get("textures") instanceof List list + List textures = resource.get("textures") instanceof List list && resource.get("textures") != null ? list.stream().map(String::valueOf).toList() : List.of(); + if (resource.get("textures") == null && resource.get("texture") != null && textures.isEmpty()) + textures = List.of(String.valueOf(resource.get("texture"))); + if (textures.isEmpty() && resource.get("textures") instanceof String string) textures = List.of(string); @@ -36,11 +38,7 @@ public static ItemResource from(Map data) { ? String.valueOf(resource.get("model_path")) : null; - Integer modelId = resource.get("model_id") != null - ? Integer.valueOf(String.valueOf(resource.get("model_id"))) - : null; - - return new ItemResource(material, generate, textures, modelPath, modelId); + return new ItemResource(material, generate, textures, modelPath); } public boolean hasTextures() { diff --git a/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java b/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java index 6bed501..aaeaea3 100644 --- a/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java +++ b/src/main/java/fr/openmc/riftengine/core/utils/IdentifierUtils.java @@ -81,4 +81,13 @@ public static Path resolveModelId(Path rootPath, String id) { .resolve("models") .resolve(modelPath); } + + public static String toBedrockTexturePath(String javaPath) { + if (javaPath.startsWith("textures/item/")) + return "textures/items/" + javaPath.substring("textures/item/".length()); + if (javaPath.startsWith("textures/block/")) + return "textures/blocks/" + javaPath.substring("textures/block/".length()); + + return javaPath; + } } From 8d83b7ea33a5232a863fcab1a4bd330290e19c4c Mon Sep 17 00:00:00 2001 From: iambibi <89582596+iambibi@users.noreply.github.com> Date: Sun, 20 Sep 2026 12:04:15 +0200 Subject: [PATCH 5/5] bump version 0.3-SNAPSHOT --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5588a11..2bc86a3 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'fr.openmc.riftengine' -version = '0.2-SNAPSHOT' +version = '0.3-SNAPSHOT' repositories { mavenCentral()