Skip to content

Commit

Permalink
ported to forge
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticpasta1 committed Jun 21, 2022
1 parent 5c6daf0 commit 3d07a74
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 53 deletions.
16 changes: 11 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}

Expand Down Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# 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
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
21 changes: 17 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
17 changes: 8 additions & 9 deletions src/main/java/net/montoyo/mcef/MCEF.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -60,7 +59,7 @@ public void onInitialize() {
this.onInit(); // old init
}

@Environment(EnvType.CLIENT)
@OnlyIn(Dist.CLIENT)
public void setupProxy(){
PROXY = new ClientProxy();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/montoyo/mcef/api/MCEFApi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.montoyo.mcef.api;

import net.fabricmc.loader.api.FabricLoader;
import net.minecraftforge.fml.ModList;

public class MCEFApi {

Expand All @@ -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");
}

}
29 changes: 18 additions & 11 deletions src/main/java/net/montoyo/mcef/client/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/montoyo/mcef/coremod/ShutdownPatcher.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/net/montoyo/mcef/example/ExampleMod.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

}
40 changes: 40 additions & 0 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 7 additions & 8 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "net.montoyo.mcef.mixins",
"refmap": "forgecef-refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
Expand Down

0 comments on commit 3d07a74

Please sign in to comment.