Deprecate JS CoreMods, remove Forge's usages of them (#10659)

This commit is contained in:
Jonathing authored and GitHub committed 2025-09-16 20:13:30 +01:00
1 parent f06727a205
commit 4c1c3aafdb
16 files changed
+344 -182

No files matched your search

@@ -2,6 +2,7 @@
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.client;
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
@@ -2,6 +2,7 @@
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.client.event;
import net.minecraft.resources.ResourceLocation;
@@ -1,3 +1,8 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.client.gui.overlay;
import net.minecraft.client.DeltaTracker;
@@ -1,4 +0,0 @@
{
"field_to_method": "coremods/field_to_method.js",
"method_redirector": "coremods/method_redirector.js"
}
@@ -1,62 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI')
function initializeCoreMod() {
return {
'biome': {
'target': {
'type': 'CLASS',
'name': 'net.minecraft.world.level.biome.Biome'
},
'transformer': function(classNode) {
ASMAPI.redirectFieldToMethod(classNode, 'climateSettings', 'getModifiedClimateSettings')
ASMAPI.redirectFieldToMethod(classNode, 'specialEffects', 'getModifiedSpecialEffects')
return classNode;
}
},
'potion': {
'target': {
'type': 'CLASS',
'name': 'net.minecraft.world.effect.MobEffectInstance'
},
'transformer': function(classNode) {
ASMAPI.redirectFieldToMethod(classNode, 'effect', 'getEffect')
return classNode;
}
},
'flowing_fluid_block': {
'target': {
'type': 'CLASS',
'name': 'net.minecraft.world.level.block.LiquidBlock'
},
'transformer': function(classNode) {
ASMAPI.redirectFieldToMethod(classNode, 'fluid', 'getFluid')
return classNode;
}
},
'bucketitem': {
'target': {
'type': 'CLASS',
'name': 'net.minecraft.world.item.BucketItem'
},
'transformer': function(classNode) {
ASMAPI.redirectFieldToMethod(classNode, 'content', 'getFluid')
return classNode;
}
},
'flowerpotblock': {
'target': {
'type': 'CLASS',
'name': 'net.minecraft.world.level.block.FlowerPotBlock'
},
'transformer': function(classNode) {
ASMAPI.redirectFieldToMethod(classNode, 'potted', 'getPotted')
return classNode;
}
}
}
}
@@ -1,144 +0,0 @@
[
{
"class": "net/minecraft/server/commands/RaidCommand",
"methods": [
"spawnLeader(Lnet/minecraft/commands/CommandSourceStack;)I"
]
},
{
"class": "net/minecraft/server/commands/SummonCommand",
"methods": [
"createEntity(Lnet/minecraft/commands/CommandSourceStack;Lnet/minecraft/core/Holder$Reference;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/nbt/CompoundTag;Z)Lnet/minecraft/world/entity/Entity;"
]
},
{
"class": "net/minecraft/world/entity/EntityType",
"methods": [
"create(Lnet/minecraft/server/level/ServerLevel;Ljava/util/function/Consumer;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/EntitySpawnReason;ZZ)Lnet/minecraft/world/entity/Entity;"
]
},
{
"class": "net/minecraft/world/entity/ai/village/VillageSiege",
"methods": [
"trySpawn(Lnet/minecraft/server/level/ServerLevel;)V"
]
},
{
"class": "net/minecraft/world/entity/animal/frog/Tadpole",
"methods": [
]
},
{
"class": "net/minecraft/world/entity/animal/horse/SkeletonTrapGoal",
"methods": [
"createHorse(Lnet/minecraft/world/DifficultyInstance;)Lnet/minecraft/world/entity/animal/horse/AbstractHorse;",
"createSkeleton(Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/animal/horse/AbstractHorse;)Lnet/minecraft/world/entity/monster/Skeleton;"
]
},
{
"class": "net/minecraft/world/entity/monster/Evoker$EvokerSummonSpellGoal",
"methods": [
"performSpellCasting()V"
]
},
{
"class": "net/minecraft/world/entity/monster/Spider",
"methods": [
"finalizeSpawn(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/EntitySpawnReason;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;"
]
},
{
"class": "net/minecraft/world/entity/monster/Strider",
"methods": [
"spawnJockey(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/Mob;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;"
]
},
{
"class": "net/minecraft/world/entity/monster/Zombie",
"methods": [
"hurtServer(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/damagesource/DamageSource;F)Z",
"finalizeSpawn(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/EntitySpawnReason;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;"
]
},
{
"class": "net/minecraft/world/entity/monster/ZombieVillager",
"methods": [
]
},
{
"class": "net/minecraft/world/entity/npc/CatSpawner",
"methods": [
"spawnCat(Lnet/minecraft/core/BlockPos;Lnet/minecraft/server/level/ServerLevel;Z)V"
]
},
{
"class": "net/minecraft/world/entity/npc/Villager",
"methods": [
"getBreedOffspring(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/AgeableMob;)Lnet/minecraft/world/entity/npc/Villager;"
]
},
{
"class": "net/minecraft/world/entity/raid/Raid",
"methods": [
"joinRaid(Lnet/minecraft/server/level/ServerLevel;ILnet/minecraft/world/entity/raid/Raider;Lnet/minecraft/core/BlockPos;Z)V"
]
},
{
"class": "net/minecraft/world/level/NaturalSpawner",
"methods": [
"spawnCategoryForPosition(Lnet/minecraft/world/entity/MobCategory;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/chunk/ChunkAccess;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/NaturalSpawner$SpawnPredicate;Lnet/minecraft/world/level/NaturalSpawner$AfterSpawnCallback;)V",
"spawnMobsForChunkGeneration(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/core/Holder;Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/util/RandomSource;)V"
]
},
{
"class": "net/minecraft/world/level/block/entity/trialspawner/TrialSpawner",
"methods": [
"spawnMob(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;)Ljava/util/Optional;"
]
},
{
"class": "net/minecraft/world/level/levelgen/PatrolSpawner",
"methods": [
"spawnPatrolMember(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/util/RandomSource;Z)Z"
]
},
{
"class": "net/minecraft/world/level/levelgen/PhantomSpawner",
"methods": [
"tick(Lnet/minecraft/server/level/ServerLevel;ZZ)V"
]
},
{
"class": "net/minecraft/world/level/levelgen/structure/structures/OceanMonumentPieces$OceanMonumentPiece",
"methods": [
"spawnElder(Lnet/minecraft/world/level/WorldGenLevel;Lnet/minecraft/world/level/levelgen/structure/BoundingBox;III)V"
]
},
{
"class": "net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces$OceanRuinPiece",
"methods": [
"handleDataMarker(Ljava/lang/String;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/util/RandomSource;Lnet/minecraft/world/level/levelgen/structure/BoundingBox;)V"
]
},
{
"class": "net/minecraft/world/level/levelgen/structure/structures/SwampHutPiece",
"methods": [
"postProcess(Lnet/minecraft/world/level/WorldGenLevel;Lnet/minecraft/world/level/StructureManager;Lnet/minecraft/world/level/chunk/ChunkGenerator;Lnet/minecraft/util/RandomSource;Lnet/minecraft/world/level/levelgen/structure/BoundingBox;Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/core/BlockPos;)V",
"spawnCat(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/level/levelgen/structure/BoundingBox;)V"
]
},
{
"class": "net/minecraft/world/level/levelgen/structure/structures/WoodlandMansionPieces$WoodlandMansionPiece",
"methods": [
"handleDataMarker(Ljava/lang/String;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/util/RandomSource;Lnet/minecraft/world/level/levelgen/structure/BoundingBox;)V"
]
},
{
"class": "net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate",
"methods": [
]
}
]
@@ -1,114 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
'use strict';
const ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI');
const Opcodes = Java.type('org.objectweb.asm.Opcodes');
// we can't run ASMAPI.loadData in the global context, so we do it here
// this function is called inside of initializeCoreMod
const replacements = [];
function initReplacements() {
ASMAPI.log('DEBUG', 'Gathering Forge method redirector replacements');
replacements.push({
// finalizeSpawn redirection to ForgeEventFactory.onFinalizeSpawn
'type': ASMAPI.MethodType.VIRTUAL,
'name': 'finalizeSpawn',
'desc': '(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/EntitySpawnReason;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;',
'targets': ASMAPI.loadData('coremods/finalize_spawn_targets.json'),
'factory': function(insn) {
return ASMAPI.buildMethodCall(
ASMAPI.MethodType.STATIC,
'net/minecraftforge/event/ForgeEventFactory',
'onFinalizeSpawn',
'(Lnet/minecraft/world/entity/Mob;Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/EntitySpawnReason;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;');
}
});
}
function initializeCoreMod() {
initReplacements();
return {
'forge_method_redirector': {
'target': {
'type': 'CLASS',
'names': getTargets
},
'transformer': applyMethodRedirects
}
}
}
function getTargets(classes) {
const mergedTargets = [];
for (let replacement of replacements) {
for (let target of replacement.targets) {
mergedTargets.push(target.class);
}
}
return mergedTargets;
}
function applyMethodRedirects(clazz) {
for (let replacement of replacements) {
for (let methodString of getClassTargetMethods(clazz, replacement)) {
// cut up the string since we've put both the name and desc as the target
const splitPos = methodString.indexOf('(');
const methodName = methodString.substring(0, splitPos);
const methodDesc = methodString.substring(splitPos);
const method = ASMAPI.findMethodNode(clazz, methodName, methodDesc);
// if we can't find the method, get out now!
if (method === null) {
ASMAPI.log('ERROR', 'Failed to redirect method call for {}! Method {} not found in class {}! This is a Forge bug, and is likely due to a Minecraft update changing something.', replacement.name, methodString, clazz.name);
continue;
}
for (let insn of method.instructions) {
if (shouldReplace(insn, replacement)) {
const redirection = replacement.factory(insn);
ASMAPI.log('DEBUG', 'Redirecting method call {}{} to {}{} inside of {}.{}', insn.name, insn.desc, redirection.name, redirection.desc, clazz.name, method.name);
ASMAPI.insertInsn(method, insn, redirection, ASMAPI.InsertMode.REMOVE_ORIGINAL);
}
}
}
}
return clazz;
}
/* HELPER FUNCTIONS FOR TARGET SEARCHING */
function shouldReplace(insn, replacement) {
return insn.getOpcode() === replacement.type.toOpcode()
&& insn.name === replacement.name
&& insn.desc === replacement.desc;
}
function getClassTargetMethods(clazz, replacement) {
for (let t of replacement.targets) {
if (t.class === clazz.name) {
const targets = [];
// declared methods
for (let method of t.methods) {
targets.push(method);
}
// synthetic methods
for (let method of clazz.methods) {
if ((method.access & Opcodes.ACC_SYNTHETIC) != 0) {
targets.push(method.name + method.desc);
}
}
return targets;
}
}
}
@@ -2,6 +2,7 @@
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.debug.client;
import net.minecraft.client.renderer.LevelTargetBundle;