From 3d07a74f8977923d23f6168ef77d8bc6f211287b Mon Sep 17 00:00:00 2001 From: Mysticpasta1 Date: Tue, 21 Jun 2022 14:23:36 -0500 Subject: [PATCH] ported to forge --- build.gradle | 16 +++++--- gradle.properties | 5 ++- settings.gradle | 21 ++++++++-- src/main/java/net/montoyo/mcef/MCEF.java | 17 ++++---- .../java/net/montoyo/mcef/api/MCEFApi.java | 4 +- .../net/montoyo/mcef/client/ClientProxy.java | 29 +++++++++----- .../montoyo/mcef/coremod/ShutdownPatcher.java | 4 +- .../net/montoyo/mcef/example/ExampleMod.java | 24 ++++++----- src/main/resources/META-INF/mods.toml | 40 +++++++++++++++++++ src/main/resources/fabric.mod.json | 15 ++++--- ...ricef.mixins.json => forgecef.mixins.json} | 1 + 11 files changed, 123 insertions(+), 53 deletions(-) create mode 100644 src/main/resources/META-INF/mods.toml rename src/main/resources/{fabricef.mixins.json => forgecef.mixins.json} (86%) diff --git a/build.gradle b/build.gradle index 6cff0d8d..d358df59 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { - id 'fabric-loom' version '0.12-SNAPSHOT' + id 'dev.architectury.loom' version '0.12.0-SNAPSHOT' + id 'io.github.juuxel.loom-quiltflower' version '1.6.0' id 'maven-publish' } @@ -35,13 +36,18 @@ dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + forge "net.minecraftforge:forge:${project.forge_version}" +} +loom { + forge { + mixinConfigs = [ + "forgecef.mixins.json" + ] + } } + processResources { inputs.property "version", project.version diff --git a/gradle.properties b/gradle.properties index de13c9c3..643b3a31 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,12 +2,13 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false +loom.platform=forge # Fabric Properties (above are from forge) # check these on https://fabricmc.net/develop minecraft_version=1.18.2 yarn_mappings=1.18.2+build.3 -loader_version=0.14.6 +loader_version=0.14.8 # Mod Properties mod_version = 1.0.0 @@ -15,4 +16,4 @@ maven_group = io.github.javaarchive.fabricef archives_base_name = mcef # Dependencies -fabric_version=0.53.0+1.18.2 +forge_version=1.18.2-40.1.52 diff --git a/settings.gradle b/settings.gradle index b02216ba..18010b41 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,23 @@ pluginManagement { repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' + pluginManagement { + repositories { + //jcenter() // jcenter will be stopped in 2022 + mavenCentral() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + maven { url "https://maven.architectury.dev/" } + maven { url "https://files.minecraftforge.net/maven/" } + maven { + name = 'Cotton' + url = 'https://server.bbkr.space/artifactory/libs-release/' + } + gradlePluginPortal() + } } mavenCentral() gradlePluginPortal() } -} +} \ No newline at end of file diff --git a/src/main/java/net/montoyo/mcef/MCEF.java b/src/main/java/net/montoyo/mcef/MCEF.java index 283f457c..6e81b1de 100644 --- a/src/main/java/net/montoyo/mcef/MCEF.java +++ b/src/main/java/net/montoyo/mcef/MCEF.java @@ -1,16 +1,16 @@ package net.montoyo.mcef; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.common.Mod; import net.montoyo.mcef.client.ClientProxy; import net.montoyo.mcef.easy_forge_compat.Configuration; import net.montoyo.mcef.utilities.Log; -import net.fabricmc.api.ModInitializer; -public class MCEF implements ModInitializer{ +@Mod("forgecef") +public class MCEF { - public static final String VERSION = "1.33"; + public static final String VERSION = "1.0.0"; public static boolean ENABLE_EXAMPLE; public static boolean SKIP_UPDATES; public static boolean WARN_UPDATES; @@ -26,8 +26,7 @@ public class MCEF implements ModInitializer{ public static BaseProxy PROXY; - @Override - public void onInitialize() { + public MCEF() { System.out.println("MCEF Initalizing..."); Log.info("Loading MCEF config..."); Configuration cfg = new Configuration(); @@ -60,7 +59,7 @@ public void onInitialize() { this.onInit(); // old init } - @Environment(EnvType.CLIENT) + @OnlyIn(Dist.CLIENT) public void setupProxy(){ PROXY = new ClientProxy(); } diff --git a/src/main/java/net/montoyo/mcef/api/MCEFApi.java b/src/main/java/net/montoyo/mcef/api/MCEFApi.java index 532e498b..fab8e038 100644 --- a/src/main/java/net/montoyo/mcef/api/MCEFApi.java +++ b/src/main/java/net/montoyo/mcef/api/MCEFApi.java @@ -1,6 +1,6 @@ package net.montoyo.mcef.api; -import net.fabricmc.loader.api.FabricLoader; +import net.minecraftforge.fml.ModList; public class MCEFApi { @@ -24,7 +24,7 @@ public static API getAPI() { * @return true if it is loaded. false otherwise. */ public static boolean isMCEFLoaded() { - return FabricLoader.getInstance().isModLoaded("fabricef"); + return ModList.get().isLoaded("forgecef"); } } diff --git a/src/main/java/net/montoyo/mcef/client/ClientProxy.java b/src/main/java/net/montoyo/mcef/client/ClientProxy.java index f9aeed86..3f4143c5 100644 --- a/src/main/java/net/montoyo/mcef/client/ClientProxy.java +++ b/src/main/java/net/montoyo/mcef/client/ClientProxy.java @@ -1,7 +1,15 @@ package net.montoyo.mcef.client; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.client.MinecraftClient; +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.text.TextColor; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.montoyo.mcef.BaseProxy; import net.montoyo.mcef.MCEF; import net.montoyo.mcef.api.IBrowser; @@ -155,8 +163,6 @@ public boolean doClose(CefBrowser browser) { exampleMod.onInit(); Log.info("MCEF loaded successfuly."); - - ClientTickEvents.START_CLIENT_TICK.register(client -> this.onTickStart()); } public CefApp getCefApp() { @@ -217,7 +223,8 @@ public boolean isSchemeRegistered(String name) { return appHandler.isSchemeRegistered(name); } - public void onTickStart() { + @SubscribeEvent + public void onTickStart(TickEvent.ClientTickEvent event) { mc.getProfiler().push("MCEF"); if (cefApp != null) @@ -230,19 +237,19 @@ public void onTickStart() { mc.getProfiler().pop(); } - /*@SubscribeEvent + @SubscribeEvent public void onLogin(PlayerEvent.PlayerLoggedInEvent ev) { if (updateStr == null || !MCEF.WARN_UPDATES) return; - Style cs = new Style(); - cs.setColor(TextFormatting.LIGHT_PURPLE); + Style cs = Style.EMPTY; + cs.withColor(Formatting.LIGHT_PURPLE); - TextComponentString cct = new TextComponentString(updateStr); - cct.setStyle(cs); + MutableText cct = (MutableText) Text.of(updateStr); + cct.getWithStyle(cs); - ev.player.sendMessage(cct); - }*/ + ev.getPlayer().sendMessage(cct, true); + } public void removeBrowser(CefBrowserOsr b) { browsers.remove(b); diff --git a/src/main/java/net/montoyo/mcef/coremod/ShutdownPatcher.java b/src/main/java/net/montoyo/mcef/coremod/ShutdownPatcher.java index fe76e774..1dce2d79 100644 --- a/src/main/java/net/montoyo/mcef/coremod/ShutdownPatcher.java +++ b/src/main/java/net/montoyo/mcef/coremod/ShutdownPatcher.java @@ -1,6 +1,6 @@ -/*package net.montoyo.mcef.coremod; +package net.montoyo.mcef.coremod; -import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; +/*import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; import net.minecraft.launchwrapper.IClassTransformer; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; diff --git a/src/main/java/net/montoyo/mcef/example/ExampleMod.java b/src/main/java/net/montoyo/mcef/example/ExampleMod.java index 8e87112a..ed6433dc 100644 --- a/src/main/java/net/montoyo/mcef/example/ExampleMod.java +++ b/src/main/java/net/montoyo/mcef/example/ExampleMod.java @@ -1,10 +1,14 @@ package net.montoyo.mcef.example; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraftforge.client.ClientRegistry; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.montoyo.mcef.utilities.Log; import net.montoyo.mcef.api.API; @@ -50,15 +54,14 @@ public void onInit() { INSTANCE = this; // Register key binding via fabric api - KeyBindingHelper.registerKeyBinding(key); + ClientRegistry.registerKeyBinding(key); // We used to register to event bus here if(api != null) { //Register this class to handle onAddressChange and onQuery events api.registerDisplayHandler(this); api.registerJSQueryHandler(this); } - - ClientTickEvents.START_CLIENT_TICK.register(client -> this.onTickStart()); + MinecraftForge.EVENT_BUS.register(this); } public void setBackup(BrowserScreen bu) { @@ -88,8 +91,9 @@ else if(backup != null) else return null; } - - public void onTickStart() { + + @SubscribeEvent + public void onTickStart(TickEvent.ClientTickEvent event) { // Check if our key was pressed if(key.isPressed() && !(mc.currentScreen instanceof BrowserScreen)) { //Display the web browser UI. @@ -150,10 +154,10 @@ public boolean handleQuery(IBrowser b, long queryId, String query, boolean persi public void cancelQuery(IBrowser b, long queryId) { } - /*@SubscribeEvent + @SubscribeEvent public void onDrawHUD(RenderGameOverlayEvent.Post ev) { if(hudBrowser != null) - hudBrowser.drawScreen(0, 0, 0.f); - }*/ + hudBrowser.drawTexture(new MatrixStack(), 0, 0, 0, 0, 20, 20); + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 00000000..f0ebf7e2 --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,40 @@ +modLoader="javafml" #mandatory + +loaderVersion="[40,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. + +license="BSD-3-Clause" + +issueTrackerURL="" #optional + +[[mods]] #mandatory + +modId="forgecef" #mandatory + +version="1.0.0" #mandatory + +displayName="MCEF" #mandatory + +displayURL="https://github.com/Mysticpasta1/mcef-forge" #optional + +logoFile= "" #optional + +credits="" #optional + +authors="Mysticpasta1, WaterPicker, Montoyo, javaarchive" #optional + +description=''' +''' + +[[dependencies.mcef]] #optional +modId="forge" #mandatory +mandatory=true #mandatory +versionRange="[40,)" #mandatory +ordering="NONE" +side="BOTH" + +[[dependencies.mcef]] +modId="minecraft" +mandatory=true +versionRange="[1.18.2,1.19)" +ordering="NONE" +side="BOTH" \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c0b6c953..963daf10 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,20 +1,19 @@ { "schemaVersion": 1, - "id": "fabricef", + "id": "forgecef", "version": "${version}", - "name": "Fabric MCEF", + "name": "Forge MCEF", "description": "Port of the MCEF project. ", "authors": [ "javaarchive" ], "contact": { - "homepage": "https://github.com/javaarchive/mcef-fabric", - "sources": "https://github.com/javaarchive/mcef-fabric" + "homepage": "", + "sources": "https://github.com/Mysticpasta1/mcef-forge" }, "license": "BSD-3-Clause", - "icon": "assets/fabricef/icon.png", "environment": "*", "entrypoints": { @@ -23,13 +22,13 @@ ] }, "mixins": [ - "fabricef.mixins.json" + "forgecef.mixins.json" ], "depends": { - "fabricloader": ">=0.14.6", + "fabricloader": ">=0.14.8", "fabric": "*", "minecraft": "~1.18.2", - "java": ">=16" + "java": ">=17" } } \ No newline at end of file diff --git a/src/main/resources/fabricef.mixins.json b/src/main/resources/forgecef.mixins.json similarity index 86% rename from src/main/resources/fabricef.mixins.json rename to src/main/resources/forgecef.mixins.json index b2864665..3cc27203 100644 --- a/src/main/resources/fabricef.mixins.json +++ b/src/main/resources/forgecef.mixins.json @@ -2,6 +2,7 @@ "required": true, "minVersion": "0.8", "package": "net.montoyo.mcef.mixins", + "refmap": "forgecef-refmap.json", "compatibilityLevel": "JAVA_17", "mixins": [ ],