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
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ plugins {
}

group = 'fr.openmc.riftengine'
version = '0.5-SNAPSHOT'
version = '0.6-SNAPSHOT'

repositories {
mavenCentral()

// * ProtocolLib
maven {url "https://repo.dmulloy2.net/repository/public/"}
// * GeyserMC
maven {url "https://repo.opencollab.dev/main/"}
// * PaperMC
maven { url = "https://repo.papermc.io/repository/maven-public/" }
maven {url = "https://repo.papermc.io/repository/maven-public/" }
// * ItemsAdder
maven {url "https://maven.devs.beer/"}
}
Expand All @@ -20,8 +23,10 @@ dependencies {
paperweight.paperDevBundle "${minecraftVersion}.build.${paperVersion}"

// Dependancies
compileOnly "net.dmulloy2:ProtocolLib:${protocolLibVersion}"
compileOnly "beer.devs:itemsadder-api:${itemsAdderVersion}"
compileOnly "org.geysermc.geyser:api:${geyserApiVersion}"
compileOnly "org.geysermc.floodgate:api:${floodgateApiVersion}"

compileOnly files("libs/OpenMC.jar")
implementation "org.jetbrains:annotations:${jetbrainsAnnotationsVersion}"
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ minecraftVersion = 26.3
paperVersion = 180-stable

# Dependencies versions
protocolLibVersion = 5.4.0
itemsAdderVersion = 4.0.18-beta-10
geyserApiVersion = 2.10.0-SNAPSHOT
floodgateApiVersion = 2.2.5-SNAPSHOT

jetbrainsAnnotationsVersion = 26.1.0
lombokVersion = 1.18.46
Binary file modified libs/OpenMC.jar
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/java/fr/openmc/riftengine/core/RiftLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public enum RiftLog {
IMAGE_NOT_FOUND("Image introuvable pour {} dans le path {} (skip)", LogType.ERROR),
ERROR_READING("Erreur de lecture pour {} (skip) : ", LogType.ERROR),
ICON_TYPE_NOT_RECOGNIZED("Icon type {} : n'est pas reconnu", LogType.ERROR),
DETECTED_AS_MENU_GUI("Glyph {} detécté comme MENU_GUI, il ne sera donc pas en glyph, vu que les menus sont géré autrement", LogType.WARN),
ICON_SKIPPED("Image manquante pour {} emoji(s)/icon(s) sur {}.", LogType.INFO),
DETECTED_AS("{} ({}x{}) détecté comme {}", LogType.INFO),
SYMBOL_KEY_NOT_FOUND("Clé {} introuvable dans {}.", LogType.WARN),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.openmc.riftengine.core.converter;

import com.comphenix.protocol.ProtocolLibrary;
import fr.openmc.core.OMCRegistry;
import fr.openmc.core.bootstrap.integration.OMCLogger;
import fr.openmc.core.utils.FilesUtils;
Expand All @@ -11,6 +12,8 @@
import fr.openmc.riftengine.core.converter.writers.PackWriter;
import fr.openmc.riftengine.core.converter.writers.blocks.BlocksMappingWriter;
import fr.openmc.riftengine.core.converter.writers.blocks.TerrainTextureJsonWriter;
import fr.openmc.riftengine.core.converter.writers.glyph.chestgui.ChestGuiTextureWriter;
import fr.openmc.riftengine.core.converter.writers.glyph.chestgui.ChestScreenWriter;
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;
Expand All @@ -28,6 +31,7 @@
import fr.openmc.riftengine.core.converter.writers.tooltip.textures.TooltipTextureWriter;
import fr.openmc.riftengine.core.converter.writers.translations.TranslationInjector;
import fr.openmc.riftengine.core.converter.writers.ui.ScoreboardUiWriter;
import fr.openmc.riftengine.core.listeners.ChestGuiTitleListener;
import fr.openmc.riftengine.core.resolvers.items.ItemResourceResolver;
import fr.openmc.riftengine.core.resolvers.mcmeta.animation.AnimationMcMetaResolver;
import fr.openmc.riftengine.core.resolvers.mcmeta.gui.GuiMcMetaResolver;
Expand Down Expand Up @@ -74,6 +78,9 @@ public ConverterManager(RiftPlugin plugin) {
register("Icônes ItemsAdder", new IconsWriter(itemsAdderContents));
register("Mappings des symboles", new SymbolWriter());

register("Textures des Chest GUI", new ChestGuiTextureWriter());
register("Génération du JSON UI pour les Chest GUI", new ChestScreenWriter());

register("Textures des items", new ItemsTextureJsonWriter(items, itemResolver));
register("Fichiers de textures", new ItemsTextureWriter(items, itemResolver));
register("Mappings des items", new ItemsMappingWriter(items, itemResolver));
Expand Down Expand Up @@ -116,6 +123,11 @@ public Path generateConvertedPack() throws Exception {

ZipUtils.unzip(javaPackPath, javaExtractDir);

ProtocolLibrary.getProtocolManager().addPacketListener(
new ChestGuiTitleListener(javaExtractDir,
getItemsAdderContents(RiftPlugin.getInstance()).getParent(),
RiftPlugin.getInstance()));

for (PackWriter writer : writers) {
writer.write(bedrockBuildDir, javaExtractDir);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import fr.openmc.riftengine.api.scanner.items.ItemEntry;
import fr.openmc.riftengine.api.scanner.items.entry.behaviours.IABehaviour;
import fr.openmc.riftengine.api.scanner.items.entry.behaviours.block.BlocksBehaviour;
import fr.openmc.riftengine.api.utils.IdentifierUtils;
import fr.openmc.riftengine.core.RiftPlugin;
import fr.openmc.riftengine.core.converter.writers.PackWriter;
import fr.openmc.riftengine.core.resolvers.items.ItemResourceResolver;
import fr.openmc.riftengine.core.resolvers.items.ResolvedItemResource;
import fr.openmc.riftengine.core.utils.IdentifierUtils;
import fr.openmc.riftengine.core.utils.PathUtils;

import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.openmc.riftengine.core.converter.writers.glyph.chestgui;

import fr.openmc.riftengine.core.converter.writers.PackWriter;
import fr.openmc.riftengine.core.utils.ImageUtils;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Path;

public class ChestGuiTextureWriter implements PackWriter {
@Override
public void write(Path bedrockRootPath, Path javaRootPath) throws IOException {
for (ResolvedChestGui chestGui : ChestScreenWriter.chestGuis) {
BufferedImage src = ImageUtils.read(chestGui.javaTexturePath(javaRootPath));
Path target = bedrockRootPath.resolve(chestGui.bedrockTexturePath(javaRootPath));

ImageUtils.writePng(ImageUtils.center(src), target);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package fr.openmc.riftengine.core.converter.writers.glyph.chestgui;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import fr.openmc.core.utils.JsonUtils;
import fr.openmc.riftengine.core.converter.writers.PackWriter;
import fr.openmc.riftengine.core.utils.ImageUtils;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

public class ChestScreenWriter implements PackWriter {
public static final List<ResolvedChestGui> chestGuis = new ArrayList<>();
private static final String OUTPUT_FILE = "ui/chest_screen.json";
public static final String PREFIX = "rift";
private final String namespace = "chest";

private final String TEMPLATE_CHEST_SCREEN = """
{
"namespace": <namespace>,

"chest_label": {
"type": "label",
"layer": 2,
"offset": [7, -1],
"size": ["90%", "default"],
"anchor_from": "top_left",
"anchor_to": "top_left",
"text": "$container_title",
"color": "$title_text_color",
"localize": "$localize_title",
"enable_profanity_filter": true,
"$atext": "$container_title",
"visible": "($atext - '<prefix>:' = $atext)"
}
}
""";

@Override
public void write(Path bedrockRootPath, Path javaRootPath) throws IOException {
JsonObject root = JsonUtils.parseJson(TEMPLATE_CHEST_SCREEN
.replace("<namespace>", namespace)
.replace("<prefix>", PREFIX));

this.handleChestGui(javaRootPath, root);
this.handlePanelTopHalf(root);


Path outputFile = bedrockRootPath.resolve(OUTPUT_FILE);
this.writeJsonFile(outputFile, root);
}

private final String TEMPLATE_CHEST_GUI = """
{
"type": "image",
"texture": "<texture_path>",
"size": [<width>, <height>],
"keep_ratio": false,
"offset": [<offset_x>, <offset_y>],
"anchor_from": "top_middle",
"anchor_to": "top_middle",
"layer": 4,
"$atext": "$container_title",
"visible": "<visible_condition>"
}
""";

private void handleChestGui(Path javaRootPath, JsonObject root) throws IOException {
for (ResolvedChestGui chestGui : chestGuis) {
BufferedImage src = ImageUtils.read(chestGui.javaTexturePath(javaRootPath));
BufferedImage centered = ImageUtils.center(src);

int shift = ImageUtils.centerShiftY(src);
int offsetY = 5 - chestGui.entry().yPosition() - shift;

int gridLeft = ImageUtils.findGridLeft(centered);
int offsetX = gridLeft == -1 ? 0 : 7 - gridLeft - (176 - centered.getWidth()) / 2;

root.add(PREFIX + "_" + chestGui.key(), JsonUtils.parseJson(TEMPLATE_CHEST_GUI
.replace("<texture_path>", chestGui.bedrockTexturePath(javaRootPath).toString())
.replace("<width>", String.valueOf(chestGui.width()))
.replace("<height>", String.valueOf(chestGui.height()))
.replace("<offset_y>", String.valueOf(offsetY))
.replace("<offset_x>", String.valueOf(offsetX))
.replace("<visible_condition>",
"(not ($atext - '" + PREFIX + ":" + chestGui.key() + "' = $atext))")));
}
}

private final String TEMPLATE_PANEL_TOP_HALF = """
{
"modifications": [
{
"array_name": "controls",
"operation": "insert_front",
"value": []
}
]
}
""";

private void handlePanelTopHalf(JsonObject root) {
JsonObject panelTopHalf = JsonUtils.parseJson(TEMPLATE_PANEL_TOP_HALF);

JsonArray modifications = panelTopHalf.getAsJsonArray("modifications");

for (JsonElement modification : modifications) {
if (!(modification instanceof JsonObject obj)) continue;

JsonArray value = obj.getAsJsonArray("value");

for (ResolvedChestGui chestGui : chestGuis) {
JsonObject chestGuiValue = new JsonObject();
chestGuiValue.add(PREFIX + "_" + chestGui.key()
+ "@" + namespace + "." + PREFIX + "_" + chestGui.key(), new JsonObject());
value.add(chestGuiValue);
}
}

for (String prefix : new String[] {"large_chest", "small_chest"}) {
root.add(prefix + "_panel_top_half", panelTopHalf);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.openmc.riftengine.core.converter.writers.glyph.chestgui;

import fr.openmc.riftengine.api.scanner.icons.IconEntry;
import fr.openmc.riftengine.core.utils.PathUtils;

import java.nio.file.Path;

public record ResolvedChestGui(IconEntry entry, int width, int height) {
public String key() {
return entry.key();
}

public Path javaTexturePath(Path javaRootPath) {
return entry.path().apply(javaRootPath);
}

public Path bedrockTexturePath(Path javaRootPath) {
return PathUtils.getPathFromRoot(javaTexturePath(javaRootPath), "textures") ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import fr.openmc.riftengine.api.utils.IdentifierUtils;
import fr.openmc.riftengine.core.RiftRegistry;
import fr.openmc.riftengine.core.converter.writers.PackWriter;
import fr.openmc.riftengine.core.registry.glyphs.types.FontGlyph;
import fr.openmc.riftengine.core.utils.IdentifierUtils;
import fr.openmc.riftengine.core.utils.ScanUtils;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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.chestgui.ChestScreenWriter;
import fr.openmc.riftengine.core.converter.writers.glyph.chestgui.ResolvedChestGui;
import fr.openmc.riftengine.core.registry.glyphs.GlyphsRegistry;
import fr.openmc.riftengine.core.registry.glyphs.types.IconGlyph;

Expand Down Expand Up @@ -77,7 +79,7 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException {
}

if (type.equals(IconsType.MENU_GUI)) {
RiftLog.DETECTED_AS_MENU_GUI.send(entry.namespacedId());
ChestScreenWriter.chestGuis.add(new ResolvedChestGui(entry, image.getWidth(), image.getHeight()));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package fr.openmc.riftengine.core.converter.writers.items;

import fr.openmc.riftengine.api.scanner.items.ItemEntry;
import fr.openmc.riftengine.api.utils.IdentifierUtils;
import fr.openmc.riftengine.core.converter.writers.PackWriter;
import fr.openmc.riftengine.core.resolvers.items.ItemResourceResolver;
import fr.openmc.riftengine.core.resolvers.items.ResolvedItemResource;
import fr.openmc.riftengine.core.utils.IdentifierUtils;

import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -26,7 +26,6 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException {

for (ResolvedItemResource resource : resources) {
if (resource.isVanilla()) continue;

Path outputFile = bedrockRootPath.resolve(IdentifierUtils.toBedrockTexturePath(resource.bedrockTexturePath()));
this.copyFile(resource.sourcePath(), outputFile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package fr.openmc.riftengine.core.converter.writers.tooltip.textures;

import fr.openmc.riftengine.api.scanner.items.ItemEntry;
import fr.openmc.riftengine.api.utils.IdentifierUtils;
import fr.openmc.riftengine.core.RiftLog;
import fr.openmc.riftengine.core.converter.writers.PackWriter;
import fr.openmc.riftengine.core.resolvers.mcmeta.gui.GuiMcMetaResolver;
import fr.openmc.riftengine.core.resolvers.mcmeta.gui.ResolvedGuiMcMeta;
import fr.openmc.riftengine.core.resolvers.tooltip.ResolvedTooltipResource;
import fr.openmc.riftengine.core.resolvers.tooltip.TooltipResourceResolver;
import fr.openmc.riftengine.core.utils.IdentifierUtils;

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


// - ecrire les textures dans le resourcepack bedrock
// * faire un scanner pour savoir les frames, fps, et tt chose qui sont relié entre les textures et ui_common.json
// - allouer un glyph pour chaque "type" de tooltip + le mettre dans l'item name + demander reload ia
// - ecrire le ui/ui_common.json (une giga template que j'adapte en fonction des textures)
public class TooltipTextureWriter implements PackWriter {
private final List<ItemEntry> items;
private final GuiMcMetaResolver guiResolver;
Expand Down
Loading
Loading