Skip to content
Open
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
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repositories {

changelog {
from '1.0.0'
publishAll = false
}

license {
Expand All @@ -40,7 +41,7 @@ dependencies {
compileOnly(libs.log4j.api)
compileOnly(libs.nulls)
compileOnly(libs.forgespi)

api(libs.bundles.asm)
implementation(libs.nashorn)
}
Expand All @@ -60,6 +61,7 @@ tasks.named('jar', Jar) {

publishing {
publications.register('mavenJava', MavenPublication) {
changelog.publish(it)
pom {
from components.java
artifactId = 'coremods'
Expand All @@ -68,14 +70,14 @@ publishing {
url = 'https://github.com/MinecraftForge/CoreMods'
PomUtils.setGitHubDetails(pom, 'CoreMods')
license PomUtils.Licenses.LGPLv2_1

developers {
developer PomUtils.Developers.LexManos
developer PomUtils.Developers.cpw
}
}
}

repositories {
maven gradleutils.publishingForgeMaven
}
Expand Down
81 changes: 81 additions & 0 deletions coremods-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import net.minecraftforge.gradleutils.PomUtils

plugins {
id 'idea'
id 'eclipse'
id 'java-library'
id 'maven-publish'
alias libs.plugins.license
//alias libs.plugins.versions
alias libs.plugins.gradleutils
}

group = 'net.minecraftforge'
version = rootProject.version
println "Version: $version"

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
withSourcesJar()
}

repositories {
mavenCentral()
maven gradleutils.forgeMaven
mavenLocal()
}

license {
header = rootProject.file('LICENSE-header.txt')
newLine = false
}

dependencies {
compileOnly(libs.modlauncher)
compileOnly(libs.securemodules) // Needed by Modlauncher

compileOnly(libs.nulls)
compileOnly(rootProject)

api(libs.bundles.asm)
}

tasks.named('jar', Jar) {
manifest {
attributes([
'Specification-Title': 'coremods-api',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': '1', // TODO: Use the tag
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor' :'Forge Development LLC'
], 'net/minecraftforge/coremod/api/')
}
}

publishing {
publications.register('mavenJava', MavenPublication) {
pom {
from components.java
artifactId = 'coremods-api'
name = 'Core Mods API'
description = 'API that is useful for Minecraft Transformers'
url = 'https://github.com/MinecraftForge/CoreMods'
PomUtils.setGitHubDetails(pom, 'CoreMods')
license PomUtils.Licenses.LGPLv2_1

developers {
developer PomUtils.Developers.LexManos
developer PomUtils.Developers.cpw
}
}
}

repositories {
maven gradleutils.publishingForgeMaven
}
}

idea.module {
downloadJavadoc = downloadSources = true
}
16 changes: 16 additions & 0 deletions coremods-api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) Forge Development LLC
* SPDX-License-Identifier: LGPL-2.1-only
*/
module net.minecraftforge.coremod.api {
// ASMAPI
exports net.minecraftforge.coremod.api;

requires cpw.mods.modlauncher;

requires static org.jetbrains.annotations;
requires org.objectweb.asm.util;

// JavaScript specific helpers.
requires static net.minecraftforge.coremod;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

import cpw.mods.modlauncher.Launcher;
import cpw.mods.modlauncher.api.INameMappingService;
import net.minecraftforge.coremod.CoreModEngine;
import cpw.mods.modlauncher.api.TypesafeMap;
import net.minecraftforge.coremod.CoreModTracker;

import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;
import org.objectweb.asm.util.TraceMethodVisitor;

import javax.script.ScriptException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand All @@ -31,7 +31,7 @@
* to prevent boilerplate code, excessive imports, unnecessary loops, and to provide a more user-friendly API for
* coremod developers.
*/
@SuppressWarnings({"unused", "exports"}) // annoying IDE warnings
@SuppressWarnings({"exports"}) // annoying IDE warnings
public class ASMAPI {
/* BUILDING INSTRUCTION LISTS */

Expand Down Expand Up @@ -473,7 +473,7 @@ public int get() {
* {@link #findFirstInstructionBefore(MethodNode, int, InsnType, int, boolean)}.
*/
public static @Nullable AbstractInsnNode findFirstInstructionBefore(MethodNode method, int opCode, @Nullable InsnType type, int startIndex) {
return findFirstInstructionBefore(method, opCode, type, startIndex, !CoreModEngine.DO_NOT_FIX_INSNBEFORE);
return findFirstInstructionBefore(method, opCode, type, startIndex, !DO_NOT_FIX_INSNBEFORE);
}

/**
Expand Down Expand Up @@ -1121,6 +1121,7 @@ public static void redirectFieldToMethod(final ClassNode classNode, final String
* still work for sake of backwards-compatibility, you should not be using this method if you are on 1.20.4 or
* later.
*/
@Deprecated(forRemoval = true, since = "5.2")
public static String mapMethod(String name) {
return map(name, INameMappingService.Domain.METHOD);
}
Expand All @@ -1135,6 +1136,7 @@ public static String mapMethod(String name) {
* still work for sake of backwards-compatibility, you should not be using this method if you are on 1.20.4 or
* later.
*/
@Deprecated(forRemoval = true, since = "5.2")
public static String mapField(String name) {
return map(name, INameMappingService.Domain.FIELD);
}
Expand Down Expand Up @@ -1171,8 +1173,11 @@ public static boolean getSystemPropertyFlag(final String propertyName) {
*
* @throws ScriptException If the script engine encounters an error, usually due to a syntax error in the script
* @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file
*
* @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine.
* If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown.
*/
public static boolean loadFile(String file) throws ScriptException, IOException {
public static boolean loadFile(String file) throws IOException {
return CoreModTracker.loadFileByName(file);
}

Expand All @@ -1184,10 +1189,13 @@ public static boolean loadFile(String file) throws ScriptException, IOException
* {@code initializeCoreMod()} or any of the transformer functions returned by it.
*
* @throws ScriptException If the parsed JSON data is malformed
* @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file
* @throws IOException If an I/O error occurs while reading the file, usually due to a corrupt or missing file.
*
* @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine.
* If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown.
*/
@Nullable
public static Object loadData(String file) throws ScriptException, IOException {
public static Object loadData(String file) throws IOException {
return CoreModTracker.loadDataByName(file);
}

Expand All @@ -1202,6 +1210,9 @@ public static Object loadData(String file) throws ScriptException, IOException {
* @param message The message
* @param args Any formatting arguments
* @see CoreModTracker#log(String, String, Object[])
*
* @apiNote This method only functions for JavaScript coremods managed by the main CoreMod engine.
* If using ASMAPI in a normal transformer do not use this method. Unknown exceptions could be thrown.
*/
public static void log(String level, String message, Object... args) {
CoreModTracker.log(level, message, args);
Expand Down Expand Up @@ -1293,4 +1304,29 @@ private static String toString(Textifier text) {
private static int clamp(int value, int min, int max) {
return Math.max(min, Math.min(max, value));
}

// INTERNAL
/**
* Whether to preserve the legacy behavior of
* {@link net.minecraftforge.coremod.api.ASMAPI#findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode, int,
* int)} for backwards-compatibility.
* <p>
* In Forge's case, this is set by FML in Minecraft 1.21.1 and earlier, but not in 1.21.3 and later.
*
* @see net.minecraftforge.coremod.api.ASMAPI#findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode, int,
* int)
*/
private static final boolean DO_NOT_FIX_INSNBEFORE = shouldntFixInsnBefore();

private static final boolean shouldntFixInsnBefore() {
try {
if (Launcher.INSTANCE == null)
return false;

var blackboardVar = Launcher.INSTANCE.blackboard().get(TypesafeMap.Key.getOrCreate(Launcher.INSTANCE.blackboard(), "coremods.use_old_findFirstInstructionBefore", Boolean.class));
return blackboardVar.isPresent() && blackboardVar.get();
} catch (Throwable t) { // If ModLauncher doesn't exist.
return false;
}
}
}
6 changes: 0 additions & 6 deletions coremods-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id 'eclipse'
id 'java-library'
alias libs.plugins.license
alias libs.plugins.modules
//alias libs.plugins.versions
alias libs.plugins.gradleutils
}
Expand Down Expand Up @@ -58,11 +57,6 @@ dependencies {
testCompileOnly(libs.nulls)
}

extraJavaModuleInfo {
failOnMissingModuleInfo = false
automaticModule('jopt-simple-5.0.4.jar', 'jopt.simple')
}

// If we are being told a specific vendor then we are probably being run in parallel
if (project.hasProperty('javaVendor') && project.hasProperty('javaVersion')) {
test.javaLauncher.set(javaToolchains.launcherFor {
Expand Down
3 changes: 1 addition & 2 deletions coremods-test/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) Forge Development LLC
SPDX-License-Identifier: LGPL-3.0-only
SPDX-License-Identifier: LGPL-2.1-only
-->

<Configuration status="OFF" packages="cpw.mods.modlauncher">
<filters>
<MarkerFilter marker="MODLAUNCHER" onMatch="DENY" onMismatch="DENY" />
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.problems=warn
org.gradle.configureondemand=true
18 changes: 10 additions & 8 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ dependencyResolutionManagement {
plugin('gradleutils', 'net.minecraftforge.gradleutils').version('[2.3,2.4)')
plugin('modules', 'org.gradlex.extra-java-module-info').version('1.9')
plugin('versions', 'com.github.ben-manes.versions').version('0.51.0')

version('asm', '9.7.1')
library('asm', 'org.ow2.asm', 'asm' ).versionRef('asm')
library('asm-tree', 'org.ow2.asm', 'asm-tree' ).versionRef('asm')
library('asm-commons', 'org.ow2.asm', 'asm-commons').versionRef('asm')
bundle('asm', ['asm', 'asm-tree', 'asm-commons'])

library('asm-util', 'org.ow2.asm', 'asm-util' ).versionRef('asm')
bundle('asm', ['asm', 'asm-tree', 'asm-commons', 'asm-util'])

version('junit', '5.11.4')
library('junit-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
library('junit-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
Expand All @@ -35,23 +36,24 @@ dependencyResolutionManagement {
library('gson', 'com.google.code.gson:gson:2.10.1')
library('jopt-simple', 'net.sf.jopt-simple:jopt-simple:5.0.4')
*/
library('forgespi', 'net.minecraftforge:forgespi:7.1.0')

library('forgespi', 'net.minecraftforge:forgespi:7.1.0')
library('modlauncher', 'net.minecraftforge:modlauncher:10.1.1') // Needs securemodules
library('nulls', 'org.jetbrains:annotations:26.0.1')
library('nashorn', 'org.openjdk.nashorn:nashorn-core:15.4') // Needed by coremods, because the JRE no longer ships JS

// Used by our test aggrigator scripts
library('ivy', 'org.apache.ivy:ivy:2.5.3')
library('groovy', 'org.codehaus.groovy:groovy-all:3.0.23')

version('log4j', '2.17.0') // Needs to be kept in step with modlauncher because of its config.. TODO: Figure out why?
library('log4j-api', 'org.apache.logging.log4j', 'log4j-api' ).versionRef('log4j')
library('log4j-core', 'org.apache.logging.log4j', 'log4j-core').versionRef('log4j')
}
}
}

rootProject.name = 'CoreMods'
rootProject.name = 'coremods'
include 'coremods-api'
include 'coremods-test'
include 'coremods-test-jar'
2 changes: 0 additions & 2 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
module net.minecraftforge.coremod {
// CoreMods framework
exports net.minecraftforge.coremod;
// ASMAPI
exports net.minecraftforge.coremod.api;

requires cpw.mods.modlauncher;
requires net.minecraftforge.forgespi;
Expand Down
Loading