Skip to content

Commit

Permalink
Port to Fabric
Browse files Browse the repository at this point in the history
Tested on 1.16 and 1.16.5
  • Loading branch information
SizableShrimp authored and RecursiveG committed Feb 14, 2021
1 parent b65d28c commit 00798c1
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 209 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ build
# other
eclipse
run
logs

# Files from Forge MDK
forge*changelog.txt
176 changes: 52 additions & 124 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,149 +1,77 @@
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
plugins {
id 'fabric-loom' version '0.6-SNAPSHOT'
id 'maven-publish'
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.0'
group = 'me.recursiveg' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'Mc122477Fix'

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20201028-1.16.3'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
source sourceSets.main
}
}
}
archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

server {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
source sourceSets.main
}
}
}
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}"

data {
workingDirectory project.file('run')
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
processResources {
inputs.property "version", project.version

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}

mods {
examplemod {
source sourceSets.main
}
}
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.16.4-35.1.28'

// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"

// Real examples
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

// The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
// provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'

// These dependencies get remapped to your current MCP mappings
// deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'

// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}

// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
"Specification-Title": "mc122477fix",
"Specification-Vendor": "recursiveg",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"recursiveg",
// "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
from "LICENSE"
}

// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}

// select the repositories you want to publish to
repositories {
maven {
url "file:///${project.projectDir}/mcmodsrepo"
}
// uncomment to publish to the local maven
// mavenLocal()
}
}
}
21 changes: 17 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16
yarn_mappings=1.16+build.4
loader_version=0.11.1

# Mod Properties
mod_version=1.0.0
maven_group=me.sizableshrimp
archives_base_name=Mc122477Fix

# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.13.1+build.370-1.16
10 changes: 10 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}
27 changes: 0 additions & 27 deletions src/main/java/me/recursiveg/Mc122477Fix.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.sizableshrimp.mc122477fix;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.util.ActionResult;

/**
* Callback for typing a character in a GUI.
* Called before the character is processed.
*
* <p>Upon return:
* <ul><li>SUCCESS cancels further listener processing and forwards the character to be processed by the client.
* <li>PASS falls back to further processing.
* <li>FAIL cancels further processing and does not forward the character.</ul>
*/
public interface GuiCharTypedCallback {
Event<GuiCharTypedCallback> EVENT = EventFactory.createArrayBacked(GuiCharTypedCallback.class,
listeners -> (chr, modifiers) -> {
for (GuiCharTypedCallback listener : listeners) {
ActionResult result = listener.onCharTyped(chr, modifiers);

if (result != ActionResult.PASS)
return result;
}

return ActionResult.PASS;
});

ActionResult onCharTyped(char chr, int modifiers);
}
31 changes: 31 additions & 0 deletions src/main/java/me/sizableshrimp/mc122477fix/GuiOpenCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.sizableshrimp.mc122477fix;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ActionResult;

/**
* Callback for opening a GUI.
* Called before the GUI is opened.
*
* <p>Upon return:
* <ul><li>SUCCESS cancels further listener processing and opens the GUI.
* <li>PASS falls back to further processing.
* <li>FAIL cancels further processing and does not open the GUI.</ul>
*/
public interface GuiOpenCallback {
Event<GuiOpenCallback> EVENT = EventFactory.createArrayBacked(GuiOpenCallback.class,
listeners -> screen -> {
for (GuiOpenCallback listener : listeners) {
ActionResult result = listener.onGuiOpen(screen);

if (result != ActionResult.PASS)
return result;
}

return ActionResult.PASS;
});

ActionResult onGuiOpen(Screen screen);
}
30 changes: 30 additions & 0 deletions src/main/java/me/sizableshrimp/mc122477fix/Mc122477Fix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.sizableshrimp.mc122477fix;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.util.ActionResult;

@Environment(EnvType.CLIENT)
public class Mc122477Fix implements ClientModInitializer {
private long chatOpenMillis;

@Override
public void onInitializeClient() {
GuiOpenCallback.EVENT.register(screen -> {
if (screen instanceof ChatScreen)
this.chatOpenMillis = System.currentTimeMillis();

return ActionResult.PASS;
});
GuiCharTypedCallback.EVENT.register((chr, modifiers) -> {
if (System.currentTimeMillis() - this.chatOpenMillis < 50) {
// If less than 50ms has occurred since the chat box has opened, cancel to fix GLFW/glfw#1794 on Unix-based systems.
return ActionResult.FAIL;
}

return ActionResult.PASS;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.sizableshrimp.mc122477fix.mixin;

import me.sizableshrimp.mc122477fix.GuiCharTypedCallback;
import net.minecraft.client.Keyboard;
import net.minecraft.client.gui.Element;
import net.minecraft.util.ActionResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Keyboard.class)
public class MixinKeyboard {
@Inject(method = "method_1458(Lnet/minecraft/client/gui/Element;II)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Element;charTyped(CI)Z"), cancellable = true)
private static void injectOnCharLambda1(Element element, int i, int j, CallbackInfo ci) {
internal((char) i, j, ci);
}

@Inject(method = "method_1473(Lnet/minecraft/client/gui/Element;CI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Element;charTyped(CI)Z"), cancellable = true)
private static void injectOnCharLambda2(Element element, char c, int j, CallbackInfo ci) {
internal(c, j, ci);
}

private static void internal(char chr, int modifiers, CallbackInfo ci) {
ActionResult result = GuiCharTypedCallback.EVENT.invoker().onCharTyped(chr, modifiers);

if (result == ActionResult.FAIL)
ci.cancel();
}
}
Loading

0 comments on commit 00798c1

Please sign in to comment.