Skip to content
Draft
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
18 changes: 14 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id 'java'
id "com.gradleup.shadow" version "9.6.1"
id "io.papermc.paperweight.userdev" version "${paperWeightUserDevVersion}"
}

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

repositories {
mavenCentral()
Expand All @@ -17,6 +18,8 @@ repositories {
maven {url = "https://repo.papermc.io/repository/maven-public/" }
// * ItemsAdder
maven {url "https://maven.devs.beer/"}
// * Jitpack
maven { url = "https://jitpack.io" }
}

dependencies {
Expand All @@ -28,6 +31,8 @@ dependencies {
compileOnly "org.geysermc.geyser:api:${geyserApiVersion}"
compileOnly "org.geysermc.floodgate:api:${floodgateApiVersion}"

implementation("com.github.minecraft-library:asset-renderer:master-SNAPSHOT")

compileOnly files("libs/OpenMC.jar")
implementation "org.jetbrains:annotations:${jetbrainsAnnotationsVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
Expand Down Expand Up @@ -59,12 +64,17 @@ tasks.jar {
destinationDirectory.set(file('./builds/'))
}

tasks.shadowJar {
destinationDirectory.set(file('./builds/'))
archiveFileName.set('RiftEngine.jar')
}

tasks.register('copyJarToServer', Copy) {
dependsOn tasks.jar
dependsOn tasks.shadowJar

from tasks.jar
from tasks.shadowJar

if (localProperties.getProperty('minecraftServerDir')) {
into file("${localProperties.getProperty('minecraftServerDir')}/plugins")
}
}
}
Binary file modified libs/OpenMC.jar
Binary file not shown.
5 changes: 4 additions & 1 deletion src/main/java/fr/openmc/riftengine/core/RiftLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ public enum RiftLog {
GLYPH_NOT_FOUND("Glyph {} introuvable", LogType.WARN),
FLIPBOOK_NULL("Flipbook est null pour ce tooltip {}", LogType.WARN),
NULL("{} est null", LogType.WARN),
ENTRY_EQUIPMENT_NULL("{} est null, item qui se fait passer pour une piece d'armure mais que la texture/model est géré autrement ", LogType.WARN),

MODEL_PARENT("le model ({}) convertit est null, le model hérite surement de parent et doit etre géré autrement", LogType.WARN),

PATH_CANT_REDUCED_TO_TEXTURES("resource {} ne peut pas etre réduite à un chemin de texture", LogType.WARN),
;

public static void logBanner(String pluginVersion, String server, String javaVersion) {
OMCLogger.info("\u001B[1;35m██████╗ ██╗███████╗████████╗ \u001B[0;95mRIFT v{}\u001B[0m", pluginVersion);
OMCLogger.info("\u001B[1;35m██████╗ ██╗███████╗████████╗ \u001B[0;95mRiftEngine v{}\u001B[0m", pluginVersion);
OMCLogger.info("\u001B[1;35m██╔══██╗██║██╔════╝╚══██╔══╝ \u001B[0;90mPaper {}\u001B[0m", server);
OMCLogger.info("\u001B[1;95m██████╔╝██║█████╗ ██║ \u001B[0;90mJava {}\u001B[0m", javaVersion);
OMCLogger.info("\u001B[1;95m██╔══██╗██║██╔══╝ ██║ \u001B[0m");
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fr/openmc/riftengine/core/RiftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void onDisable() {
RiftLog.RIFT_DISABLE.send();
}

public Path getOutputDir() {
return this.getDataFolder().toPath().resolve("output");
}

public void updateBedrockResourcePack() {
try {
Path generatedBedrockPack = converterManager.generateConvertedPack();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package fr.openmc.riftengine.core.converter;

import com.comphenix.protocol.ProtocolLibrary;
import dev.simplified.image.ImageData;
import dev.simplified.image.ImageFactory;
import dev.simplified.image.ImageFormat;
import dev.simplified.image.pixel.Background;
import fr.openmc.core.OMCRegistry;
import fr.openmc.core.bootstrap.integration.OMCLogger;
import fr.openmc.core.utils.FilesUtils;
Expand All @@ -20,6 +24,12 @@
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.items.specials.armor.CustomArmorAttachableWriter;
import fr.openmc.riftengine.core.converter.writers.items.specials.armor.CustomArmorTextureWriter;
import fr.openmc.riftengine.core.converter.writers.items.specials.model.ItemModelAnimationWriter;
import fr.openmc.riftengine.core.converter.writers.items.specials.model.ItemModelAttachableWriter;
import fr.openmc.riftengine.core.converter.writers.items.specials.model.ItemModelGeometryWriter;
import fr.openmc.riftengine.core.converter.writers.items.specials.model.ItemModelTextureWriter;
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;
Expand All @@ -36,6 +46,9 @@
import fr.openmc.riftengine.core.resolvers.mcmeta.animation.AnimationMcMetaResolver;
import fr.openmc.riftengine.core.resolvers.mcmeta.gui.GuiMcMetaResolver;
import fr.openmc.riftengine.core.resolvers.tooltip.TooltipResourceResolver;
import fr.openmc.riftengine.core.utils.AssetRender;
import lib.minecraft.renderer.AtlasRenderer;
import lib.minecraft.renderer.call.request.AtlasOptions;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand All @@ -47,6 +60,7 @@
public class ConverterManager {

private final RiftPlugin plugin;
private AssetRender assetRender;

private final List<PackWriter> writers = new ArrayList<>();

Expand Down Expand Up @@ -85,6 +99,14 @@ public ConverterManager(RiftPlugin plugin) {
register("Fichiers de textures", new ItemsTextureWriter(items, itemResolver));
register("Mappings des items", new ItemsMappingWriter(items, itemResolver));

register("Textures des armures", new CustomArmorTextureWriter(items));
register("Génération des attachables pour les armures", new CustomArmorAttachableWriter(items, itemResolver));

register("Textures des items 3d", new ItemModelTextureWriter(items));
register("Génération des fichiers de géometrie", new ItemModelGeometryWriter(items));
register("Générations des attachables pour les items 3D", new ItemModelAttachableWriter(items, itemResolver));
register("Générations des animations pour les items 3D", new ItemModelAnimationWriter(items));

register("Textures des tooltips", new TooltipTextureWriter(items, guiResolver, tooltipResolver));
register("Assignations des glyphs pour les tooltips",
new TooltipGlyphAssignatorWriter(items, tooltipResolver));
Expand Down Expand Up @@ -112,13 +134,27 @@ private void register(String name, PackWriter writer) {
public Path generateConvertedPack() throws Exception {
Path javaPackPath = getJavaPackPath(RiftPlugin.getInstance());

Path outputDir = plugin.getDataFolder().toPath().resolve("output");
this.assetRender = new AssetRender(javaPackPath.toFile());

AtlasOptions options = AtlasOptions.builder()
.filter(id -> !id.startsWith("minecraft:")) // omit for every block and item in the game
.tileSize(128)
.columns(100)
.background(Background.checkerboard())
.progressLogging(false) // on by default; a library consumer wants it off
.build();

ImageData sheet = new AtlasRenderer(assetRender.getContext()).render(options).image();

Path outputDir = plugin.getOutputDir();

FilesUtils.deleteDirectory(outputDir.toFile());
Files.createDirectories(outputDir);

Path workDir = outputDir.resolve("internal");
Path javaExtractDir = workDir.resolve("java");
Path bedrockBuildDir = workDir.resolve("bedrock");
ImageFactory.toFile(sheet, ImageFormat.PNG, outputDir.resolve("aywenite_block.png").toFile());

Path javaExtractDir = outputDir.resolve("java");
Path bedrockBuildDir = outputDir.resolve("bedrock");
Files.createDirectories(bedrockBuildDir);

ZipUtils.unzip(javaPackPath, javaExtractDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws Exception {

List<ResolvedItemResource> resources = resolver.resolve(javaRootPath, item);

String parentModel = item.getGraphics().parent();
BlockStateScanner.CustomBlockState state = blockBehaviour.blockState();

JsonObject def = new JsonObject();
def.addProperty("name", item.getKey());
def.addProperty("geometry", "minecraft:geometry.full_block");
def.addProperty("geometry", getGeometryBlockFromParent(parentModel));
def.add("material_instances", createMaterialInstance(resources));

blockStatesByBlock.computeIfAbsent(state.javaBlock(), _ -> new JsonObject())
Expand All @@ -69,6 +70,7 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws Exception {

Files.deleteIfExists(outputFile);
this.writeJsonFile(outputFile, root);
this.writeJsonFile(RiftPlugin.getInstance().getOutputDir().resolve(OUTPUT_FILE), root);
}

private JsonObject createMaterialInstance(List<ResolvedItemResource> faceResources) {
Expand Down Expand Up @@ -103,4 +105,15 @@ private JsonObject materialObj(String texture) {
m.addProperty("ambient_occlusion", true);
return m;
}

private String getGeometryBlockFromParent(String parentModel) {
String defaultGeometry = "minecraft:geometry.full_block";
if (parentModel == null) return defaultGeometry;
String parent = IdentifierUtils.normalizeId(parentModel);

if (!parent.startsWith("minecraft:")) return defaultGeometry;
if (parentModel.contains("block/cross"))
return "minecraft:geometry.cross";
return defaultGeometry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,45 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws Exception {
for (ItemEntry item : items) {
List<ResolvedItemResource> resources = resolver.resolve(javaRootPath, item);

String material = item.getMaterial().getKey().asString();

if (material.equals("minecraft:tripwire"))
material = "minecraft:tripwire_hook";

JsonArray definitions = byMaterial.computeIfAbsent(
item.getMaterial().getKey().asString(),
material,
_ -> new JsonArray()
);

if (resources.size() == 1) {
// * Gestion des items a une texture
definitions.add(handleUniqueTexture(item, resources.getFirst()));
} else if (resources.size() > 1) {
definitions.add(handleUniqueTexture(item, resolver, resources.getFirst()));
} else if (resources.size() > 1 && item.getBehaviour().isItem()) {
// * Gestion des items a plusieurs textures
JsonObject def = new JsonObject();
def.addProperty("type", "group");
def.addProperty("model", resources.getFirst().modelResourceId());
def.add("definitions", handleMultipleTexture(item, resources));

definitions.add(def);
} else if (resources.size() > 1 && !item.getBehaviour().isItem()) {
// * Gestion des non items (ex block qui sont géré par le block mapping)
JsonObject def = new JsonObject();
String bedrockIdentifier = resources.getFirst().bedrockIdentifier();
def.addProperty("type", "definition");
def.addProperty("model", resources.getFirst().modelResourceId());
def.addProperty("bedrock_identifier", bedrockIdentifier);

if (item.getBehaviour().isItem()) {
JsonObject options = new JsonObject();
options.addProperty("icon", bedrockIdentifier);
def.add("bedrock_options", options);
}

definitions.add(def);
} else {
// * Gestion des items qui n'a pas de textures (donc dans notre cas model)
definitions.add(handleUniqueTexture(item, resolver, null));
}
}

Expand All @@ -63,23 +86,27 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws Exception {
.resolve(OUTPUT_FILE);
Files.deleteIfExists(outputFile);
this.writeJsonFile(outputFile, root);
this.writeJsonFile(RiftPlugin.getInstance().getOutputDir().resolve(OUTPUT_FILE), root);
}

private JsonObject handleUniqueTexture(ItemEntry item, ResolvedItemResource resource) {
private JsonObject handleUniqueTexture(ItemEntry item, ItemResourceResolver resolver, ResolvedItemResource resource) {
JsonObject def = new JsonObject();
if (item.getCustomModelData() != null) {
def.addProperty("type", "legacy");
def.addProperty("custom_model_data", item.getCustomModelData());
} else {
} else if (resource != null) {
def.addProperty("type", "definition");
def.addProperty("model", resource.modelResourceId());
}

def.addProperty("bedrock_identifier", resource.bedrockIdentifier());
String bedrockIdentifier = resolver.resolveBedrockIdentifier(item);
if (resource != null)
bedrockIdentifier = resource.bedrockIdentifier();
def.addProperty("bedrock_identifier", bedrockIdentifier);

if (item.getBehaviour().isItem()) {
JsonObject options = new JsonObject();
options.addProperty("icon", resource.bedrockIdentifier());
options.addProperty("icon", bedrockIdentifier);
def.add("bedrock_options", options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException {
for (ItemEntry itemEntry : items) {
List<ResolvedItemResource> resolvedItemResources = resolver.resolve(javaRootPath, itemEntry);

if (resolvedItemResources.isEmpty()) {
JsonObject itemData = new JsonObject();
itemData.addProperty("textures", "textures/misc/missing_texture");
textureData.add(resolver.resolveBedrockIdentifier(itemEntry), itemData);
continue;
}

for (ResolvedItemResource resource : resolvedItemResources) {
JsonObject itemData = new JsonObject();
itemData.addProperty("textures", resource.bedrockTexturePath());
Expand Down
Loading
Loading