Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ plugins {
}

group = 'fr.openmc.riftengine'
version = '0.2-SNAPSHOT'
version = '0.3-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 {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/fr/openmc/riftengine/core/RiftRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<LifecycleRegistry> LOADED = new ArrayList<>();

private static final List<RegistryContext> ALL = List.of(
new RegistryContext(
() -> MAPPINGS = new MappingRegistry(),
RegistryLoadingType.RUNTIME),
new RegistryContext(
() -> GLYPHS = new GlyphsRegistry(),
RegistryLoadingType.RUNTIME),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -38,14 +44,21 @@ public ConverterManager(RiftPlugin plugin) {

try {
identity = PackIdentity.loadOrCreate(plugin);
List<ItemEntry> 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(items)
));
} catch (Exception e) {
throw new RuntimeException("Erreur lors d'initialisation du ConverterManager", e);
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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.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<ItemEntry> items;

public ItemsMappingWriter(List<ItemEntry> items) {
this.items = items;
}

@Override
public void write(Path bedrockRootPath, Path javaRootPath) throws Exception {
JsonObject root = new JsonObject();
root.addProperty("format_version", 2);

Map<String, JsonArray> byMaterial = new HashMap<>();

for (ItemEntry item : items) {
JsonObject def = new JsonObject();

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());
}

def.addProperty("bedrock_identifier", item.namespacedId());

JsonObject options = new JsonObject();
options.addProperty("icon", item.namespacedId());
def.add("bedrock_options", options);

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())
.resolve("custom_mappings").resolve("ia-injected.json");
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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.IdentifierUtils;
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;
import java.util.Locale;

public class ItemsTextureJsonWriter implements PackWriter {
private final List<ItemEntry> items;

private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();

public ItemsTextureJsonWriter(List<ItemEntry> 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) {
String resourceId = itemEntry.getBestResourceId();
String texture = null;

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("\\.[^/.]+$", "");
}
}

if (texture == null) {
OMCLogger.warn("Item {} : impossible de déterminer la texture", itemEntry.namespacedId());
continue;
}

JsonObject itemData = new JsonObject();
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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.IdentifierUtils;
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<ItemEntry> items;

public ItemsTextureWriter(List<ItemEntry> 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;
}

if (ressouceId.split(":")[0].equals("minecraft")) continue;

Path resourcePath = itemEntry.getResourcePath().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(
IdentifierUtils.toBedrockTexturePath(reducedPath.toString()));
Files.createDirectories(outputFile.getParent());
Files.copy(resourcePath, outputFile, StandardCopyOption.REPLACE_EXISTING);
}
}
}

This file was deleted.

Loading
Loading