Introduce a new field_to_instanceof transformer to reduce some simple patches.

This commit is contained in:
LexManos committed 2021-01-14 02:52:52 -08:00
1 parent d8f41adf39
commit 9ffa44f254
23 files changed
+590 -215

No files matched your search

+91 -49
View File
@@ -259,8 +259,9 @@ project(':forge') {
ideaModule "${rootProject.name}.${project.name}.userdev"
source sourceSets.main
source sourceSets.userdev
mods {
forge { source sourceSets.main }
}
}
forge_test_client {
@@ -272,7 +273,8 @@ project(':forge') {
ideaModule "${rootProject.name}.${project.name}.userdev_test"
mods {
TestMods { sources sourceSets.test }
forge { source sourceSets.main }
tests { sources sourceSets.test }
}
}
@@ -294,8 +296,9 @@ project(':forge') {
ideaModule "${rootProject.name}.${project.name}.userdev"
source sourceSets.main
source sourceSets.userdev
mods {
forge { source sourceSets.main }
}
}
forge_test_server {
@@ -307,7 +310,8 @@ project(':forge') {
ideaModule "${rootProject.name}.${project.name}.userdev_test"
mods {
TestMods { sources sourceSets.test }
forge { source sourceSets.main }
tests { sources sourceSets.test }
}
}
@@ -328,8 +332,9 @@ project(':forge') {
ideaModule "${rootProject.name}.${project.name}.userdev"
source sourceSets.main
source sourceSets.userdev
mods {
forge { source sourceSets.main }
}
args '--mod', 'forge', '--all', '--output', rootProject.file('src/generated/resources/'), '--validate',
'--existing', sourceSets.main.resources.srcDirs[0]
@@ -437,12 +442,13 @@ project(':forge') {
installer 'org.ow2.asm:asm-tree:9.0'
installer 'org.ow2.asm:asm-util:9.0'
installer 'org.ow2.asm:asm-analysis:9.0'
installer 'cpw.mods:modlauncher:8.0.6'
installer 'cpw.mods:modlauncher:8.0.9'
installer 'cpw.mods:grossjava9hacks:1.3.+'
installer 'net.minecraftforge:accesstransformers:2.2.+:shadowed'
installer 'net.minecraftforge:eventbus:3.0.+:service'
installer 'net.minecraftforge:accesstransformers:3.0.1'
installer 'org.antlr:antlr4-runtime:4.9.1' //Dep of AccessTransformer
installer 'net.minecraftforge:eventbus:4.0.+'
installer 'net.minecraftforge:forgespi:3.2.+'
installer 'net.minecraftforge:coremods:4.0.2'
installer 'net.minecraftforge:coremods:4.0.+'
installer 'net.minecraftforge:unsafe:0.2.+'
installer 'com.electronwill.night-config:core:3.6.2'
installer 'com.electronwill.night-config:toml:3.6.2'
@@ -454,9 +460,9 @@ project(':forge') {
installer 'net.minecrell:terminalconsoleappender:1.2.+'
installer 'net.sf.jopt-simple:jopt-simple:5.0.4'
installer 'org.spongepowered:mixin:0.8.2'
// This is org.openjdk.nashorn:nashorn-core:15.1.1 repackaged so it doesn't crash on JREs < 15.
// See: https://github.com/LexManos/NashornLegacyPackager
installer 'net.minecraftforge:nashorn-core-compat:15.1.1'
// This is org.openjdk.nashorn:nashorn-core:15.1.1 repackaged so it doesn't crash on JREs < 15.
// See: https://github.com/LexManos/NashornLegacyPackager
installer 'net.minecraftforge:nashorn-core-compat:15.1.1'
fmllauncherImplementation 'com.google.guava:guava:21.0'
fmllauncherImplementation 'com.google.code.gson:gson:2.8.0'
fmllauncherImplementation 'org.lwjgl:lwjgl:3.2.2'
@@ -478,35 +484,35 @@ project(':forge') {
if (changelog.exists())
extraTxts += changelog
task crowdin(type: CrowdinTask) {
key = project.hasProperty('crowdinKey') ? project.crowdinKey : null
//TODO: Merge our english.json?
}
task crowdin(type: CrowdinTask) {
key = project.hasProperty('crowdinKey') ? project.crowdinKey : null
//TODO: Merge our english.json?
}
// We apply the bin patches we just created to make a jar that is JUST our changes
['Client', 'Server', 'Joined'].each { side ->
def gen = tasks.getByName("gen${side}BinPatches")
gen.tool = BINPATCH_TOOL
task "apply${side}BinPatches"(type: ApplyBinPatches, dependsOn: gen) {
clean = { gen.cleanJar }
input = gen.output
tool = BINPATCH_TOOL
}
if (side != 'Joined') {
// Create SRG named Vanilla jars, using the SpecialSource we have in the installer
task "create${side}SRG"(type: RenameJar, dependsOn: gen) {
tool = SPECIAL_SOURCE + ':shaded'
args = ['--stable', '--in-jar', '{input}', '--out-jar', '{output}', '--srg-in', '{mappings}']
mappings = { gen.srg }
input = { gen.cleanJar }
output = file("build/create${name}SRG/output.jar")
}
}
}
['Client', 'Server', 'Joined'].each { side ->
def gen = tasks.getByName("gen${side}BinPatches")
gen.tool = BINPATCH_TOOL
task "apply${side}BinPatches"(type: ApplyBinPatches, dependsOn: gen) {
clean = { gen.cleanJar }
input = gen.output
tool = BINPATCH_TOOL
}
def srgTask = tasks.getByName(patcher.notchObf ? 'createMcp2Obf' : 'createMcp2Srg')
// Create SRG named Vanilla jars, using the SpecialSource we have in the installer
task "create${side}SRG"(type: RenameJar, dependsOn: srgTask) {
tool = SPECIAL_SOURCE + ':shaded'
args = ['--stable', '--in-jar', '{input}', '--out-jar', '{output}', '--srg-in', '{mappings}']
mappings = { srgTask.output }
input = { gen.cleanJar }
output = file("build/create${name}SRG/output.jar")
}
}
task downloadLibraries(type: DownloadLibrariesTask, dependsOn: ':mcp:setupMCP') {
input = VERSION_JSON
output = rootProject.file('build/libraries/')
input = VERSION_JSON
output = rootProject.file('build/libraries/')
}
task extractInheritance(type: ExtractInheritance, dependsOn: [genJoinedBinPatches, downloadLibraries]) {
@@ -514,23 +520,59 @@ project(':forge') {
input { genJoinedBinPatches.cleanJar }
doFirst { downloadLibraries.libraries.each{ addLibrary(it) } }
}
task findFieldInstanceChecks(type: FieldCompareFinder, dependsOn: ['createJoinedSRG']) {
jar = tasks.getByName('createJoinedSRG').output
output = rootProject.file('src/main/resources/coremods/field_to_instanceof.json')
fields {
bows {
cls = 'net/minecraft/item/Items'
name = 'field_151031_f'
replacement = 'net/minecraft/item/BowItem'
}
crossbows {
cls = 'net/minecraft/item/Items'
name = 'field_222114_py'
replacement = 'net/minecraft/item/CrossbowItem'
}
filled_map {
cls = 'net/minecraft/item/Items'
name = 'field_151098_aY'
replacement = 'net/minecraft/item/FilledMapItem'
blacklist 'net/minecraft/client/gui/screen/inventory/CartographyTableScreen', 'func_230450_a_', '(Lcom/mojang/blaze3d/matrix/MatrixStack;FII)V'
blacklist 'net/minecraft/client/renderer/entity/ItemFrameRenderer', 'func_225623_a_', '(Lnet/minecraft/entity/item/ItemFrameEntity;FFLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V'
blacklist 'net/minecraft/item/crafting/MapCloningRecipe'
blacklist 'net/minecraft/item/crafting/MapExtendingRecipe'
}
fishing_rod {
cls = 'net/minecraft/item/Items'
name = 'field_151112_aM'
replacement = 'net/minecraft/item/FishingRodItem'
}
shears {
cls = 'net/minecraft/item/Items'
name = 'field_151097_aZ'
replacement = 'net/minecraft/item/ShearsItem'
}
}
}
task checkATs(type: CheckATs, dependsOn: extractInheritance) {
inheritance = extractInheritance.output
ats = patcher.accessTransformers
ats = patcher.accessTransformers
}
task checkSAS(type: CheckSAS, dependsOn: extractInheritance) {
inheritance = extractInheritance.output
sass = patcher.sideAnnotationStrippers
sass = patcher.sideAnnotationStrippers
}
task checkExcs(type: CheckExcs, dependsOn: jar) {
binary = jar.archivePath
excs = patcher.excs
excs = patcher.excs
}
task checkAll(dependsOn: [checkATs, checkSAS, checkExcs]){}
task checkAll(dependsOn: [checkATs, checkSAS, checkExcs, findFieldInstanceChecks]){}
task checkPatchesAndFix(type: CheckPatches) {
patchDir = file("$rootDir/patches")
@@ -762,7 +804,7 @@ project(':forge') {
// add crowdin locales
from { crowdin.output.exists() ? zipTree(crowdin.output) : null}
dependsOn crowdin
duplicatesStrategy = 'exclude'
duplicatesStrategy = 'exclude'
doFirst {
MANIFESTS.each{ pkg, values ->
+2 -1
View File
@@ -6,5 +6,6 @@ repositories {
}
}
dependencies {
implementation 'org.ow2.asm:asm:7.2'
implementation 'org.ow2.asm:asm:9.0'
implementation 'org.ow2.asm:asm-tree:9.0'
}
@@ -0,0 +1,61 @@
package net.minecraftforge.forge.tasks
import groovy.json.JsonBuilder
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.objectweb.asm.ClassReader
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodNode
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
public abstract class BytecodeFinder extends DefaultTask {
@InputFile File jar
@OutputFile output = project.file("build/${name}/output.json")
@TaskAction
protected void exec() {
Util.init()
if (output.exists())
output.delete()
pre()
jar.withInputStream { i ->
new ZipInputStream(i).withCloseable { zin ->
ZipEntry zein
while ((zein = zin.nextEntry) != null) {
if (zein.name.endsWith('.class')) {
def node = new ClassNode(Opcodes.ASM7)
new ClassReader(zin).accept(node, 0)
process(node)
}
}
}
}
post()
output.text = new JsonBuilder(getData()).toPrettyString()
}
protected process(ClassNode node) {
if (node.fields != null) node.fields.each { process(node, it) }
if (node.methods != null) node.methods.each { process(node, it) }
}
protected pre() {}
protected process(ClassNode parent, FieldNode node) {}
protected process(ClassNode parent, MethodNode node) {}
protected post() {}
protected abstract Object getData()
}
@@ -0,0 +1,31 @@
package net.minecraftforge.forge.tasks
import java.util.function.BiConsumer
public class ClosureHelper {
BiConsumer<String, Closure> callback
public ClosureHelper(Closure cl, BiConsumer<String, Closure> callback) {
this.callback = callback
apply(this, cl)
}
def methodMissing(String name, Object args) {
if (!args.class.isArray()) return
Object[] aargs = (Object[])args
if (aargs.length == 1 && aargs[0] instanceof Closure) {
this.callback.accept(name, (Closure)aargs[0])
} else {
throw new IllegalArgumentException('Unknown method: "' + name + '" with arguments ' + args + ' for ' + this)
}
}
static def apply(def obj, Closure cl) {
cl.delegate = obj
cl.resolveStrategy = Closure.DELEGATE_FIRST
cl()
return obj
}
}
@@ -0,0 +1,108 @@
package net.minecraftforge.forge.tasks
import groovy.transform.EqualsAndHashCode
import java.util.ArrayList
import java.util.HashMap
import java.util.TreeMap
import java.util.TreeSet
import java.util.function.BiConsumer
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodNode
import static org.objectweb.asm.Opcodes.*
public class FieldCompareFinder extends BytecodeFinder {
@Nested
Map<String, Search> fields = [:] as HashMap
Map<Search, String> fieldsReverse = [:] as HashMap
Map<String, Set<ObjectTarget>> targets = [:] as TreeMap
@Override
protected pre() {
//fields.each{ k,v -> logger.lifecycle("Fields: " + k + ' ' + v) }
}
@Override
protected process(ClassNode parent, MethodNode node) {
def last = null
def parentInstance = new ObjectTarget(owner: parent.name, name: '', desc: '')
for (int x = 0; x < node.instructions.size(); x++) {
def current = node.instructions.get(x)
if (current.opcode == IF_ACMPEQ || current.opcode == IF_ACMPNE) {
if (last != null && (last.opcode == GETSTATIC || last.opcode == GETFIELD)) {
def target = new Search(cls: last.owner, name: last.name)
def wanted = fieldsReverse.get(target)
def original = fields.get(wanted)
def instance = new ObjectTarget(owner: parent.name, name: node.name, desc: node.desc)
if (wanted != null && (original.blacklist == null || (!original.blacklist.contains(instance) && !original.blacklist.contains(parentInstance)))) {
targets.computeIfAbsent(wanted, { k -> new TreeSet() }).add(instance)
}
}
}
last = current
}
}
@Override
protected Object getData() {
def ret = [:] as HashMap
targets.forEach{ k, v ->
def e = fields.get(k)
ret[k] = [
cls: e.cls,
name: e.name,
replacement: e.replacement,
targets: v
]
}
return ret
}
@EqualsAndHashCode(excludes = ['replacement', 'blacklist'])
public static class Search {
@Input
String cls
@Input
String name
@Input
String replacement
@Nested
@Optional
Set<ObjectTarget> blacklist
@Override
String toString() {
return cls + '.' + name
}
def blacklist(def owner, def name, def desc) {
if (blacklist == null)
blacklist = new HashSet()
blacklist.add(new ObjectTarget(owner: owner, name: name, desc: desc))
}
def blacklist(def owner) {
blacklist(owner, '', '')
}
}
def fields(Closure cl) {
new ClosureHelper(cl, {name, ccl ->
def search = ClosureHelper.apply(new Search(), ccl)
this.fields.put(name, search)
this.fieldsReverse.put(search, name)
})
}
}
@@ -0,0 +1,32 @@
package net.minecraftforge.forge.tasks
import groovy.transform.EqualsAndHashCode
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
@EqualsAndHashCode
public class ObjectTarget implements Comparable<ObjectTarget> {
@Input
String owner
@Input
String name
@Input
@Optional
String desc
@Override
String toString() {
if (desc == null)
return owner + '.' + name
return owner + '.' + name + desc
}
@Override
int compareTo(ObjectTarget o) {
return toString().compareTo(o.toString())
}
}
@@ -8,12 +8,3 @@
int i = list1.size();
for(BeeEntity beeentity : list) {
@@ -105,7 +106,7 @@
int i = p_225533_1_.func_177229_b(field_226873_c_);
boolean flag = false;
if (i >= 5) {
- if (itemstack.func_77973_b() == Items.field_151097_aZ) {
+ if (itemstack.func_77973_b() instanceof net.minecraft.item.ShearsItem) {
p_225533_2_.func_184148_a(p_225533_4_, p_225533_4_.func_226277_ct_(), p_225533_4_.func_226278_cu_(), p_225533_4_.func_226281_cx_(), SoundEvents.field_226133_ah_, SoundCategory.NEUTRAL, 1.0F, 1.0F);
func_226878_a_(p_225533_2_, p_225533_3_);
itemstack.func_222118_a(1, p_225533_4_, (p_226874_1_) -> {
@@ -1,11 +0,0 @@
--- a/net/minecraft/block/PumpkinBlock.java
+++ b/net/minecraft/block/PumpkinBlock.java
@@ -20,7 +20,7 @@
public ActionResultType func_225533_a_(BlockState p_225533_1_, World p_225533_2_, BlockPos p_225533_3_, PlayerEntity p_225533_4_, Hand p_225533_5_, BlockRayTraceResult p_225533_6_) {
ItemStack itemstack = p_225533_4_.func_184586_b(p_225533_5_);
- if (itemstack.func_77973_b() == Items.field_151097_aZ) {
+ if (itemstack.func_77973_b() instanceof net.minecraft.item.ShearsItem) {
if (!p_225533_2_.field_72995_K) {
Direction direction = p_225533_6_.func_216354_b();
Direction direction1 = direction.func_176740_k() == Direction.Axis.Y ? p_225533_4_.func_174811_aO().func_176734_d() : direction;
@@ -1,11 +0,0 @@
--- a/net/minecraft/block/TripWireBlock.java
+++ b/net/minecraft/block/TripWireBlock.java
@@ -67,7 +67,7 @@
}
public void func_176208_a(World p_176208_1_, BlockPos p_176208_2_, BlockState p_176208_3_, PlayerEntity p_176208_4_) {
- if (!p_176208_1_.field_72995_K && !p_176208_4_.func_184614_ca().func_190926_b() && p_176208_4_.func_184614_ca().func_77973_b() == Items.field_151097_aZ) {
+ if (!p_176208_1_.field_72995_K && !p_176208_4_.func_184614_ca().func_190926_b() && p_176208_4_.func_184614_ca().func_77973_b() instanceof net.minecraft.item.ShearsItem) {
p_176208_1_.func_180501_a(p_176208_2_, p_176208_3_.func_206870_a(field_176295_N, Boolean.valueOf(true)), 4);
}
@@ -1,14 +1,5 @@
--- a/net/minecraft/client/entity/player/AbstractClientPlayerEntity.java
+++ b/net/minecraft/client/entity/player/AbstractClientPlayerEntity.java
@@ -114,7 +114,7 @@
f = 1.0F;
}
- if (this.func_184587_cr() && this.func_184607_cu().func_77973_b() == Items.field_151031_f) {
+ if (this.func_184587_cr() && this.func_184607_cu().func_77973_b() instanceof net.minecraft.item.BowItem) {
int i = this.func_184612_cw();
float f1 = (float)i / 20.0F;
if (f1 > 1.0F) {
@@ -126,6 +126,6 @@
f *= 1.0F - f1 * 0.15F;
}
@@ -9,28 +9,6 @@
flag = p_228396_4_.func_184600_cs() == Hand.MAIN_HAND;
flag1 = !flag;
}
@@ -216,18 +216,18 @@
Hand hand1 = p_228396_4_.func_184600_cs();
if (hand1 == Hand.MAIN_HAND) {
ItemStack itemstack1 = p_228396_4_.func_184592_cb();
- if (itemstack1.func_77973_b() == Items.field_222114_py && CrossbowItem.func_220012_d(itemstack1)) {
+ if (itemstack1.func_77973_b() instanceof CrossbowItem && CrossbowItem.func_220012_d(itemstack1)) {
flag1 = false;
}
}
} else {
ItemStack itemstack2 = p_228396_4_.func_184614_ca();
ItemStack itemstack3 = p_228396_4_.func_184592_cb();
- if (itemstack2.func_77973_b() == Items.field_222114_py && CrossbowItem.func_220012_d(itemstack2)) {
+ if (itemstack2.func_77973_b() instanceof CrossbowItem && CrossbowItem.func_220012_d(itemstack2)) {
flag1 = !flag;
}
- if (itemstack3.func_77973_b() == Items.field_222114_py && CrossbowItem.func_220012_d(itemstack3)) {
+ if (itemstack3.func_77973_b() instanceof CrossbowItem && CrossbowItem.func_220012_d(itemstack3)) {
flag = !itemstack2.func_190926_b();
flag1 = !flag;
}
@@ -240,12 +240,14 @@
if (flag) {
float f5 = hand == Hand.MAIN_HAND ? f : 0.0F;
@@ -46,22 +24,6 @@
this.func_228405_a_(p_228396_4_, p_228396_1_, f1, Hand.OFF_HAND, f6, this.field_187468_e, f7, p_228396_2_, p_228396_3_, p_228396_5_);
}
@@ -260,13 +262,13 @@
if (flag && !p_228405_1_.func_82150_aj()) {
this.func_228401_a_(p_228405_8_, p_228405_9_, p_228405_10_, p_228405_7_, p_228405_5_, handside);
}
- } else if (p_228405_6_.func_77973_b() == Items.field_151098_aY) {
+ } else if (p_228405_6_.func_77973_b() instanceof FilledMapItem) {
if (flag && this.field_187468_e.func_190926_b()) {
this.func_228400_a_(p_228405_8_, p_228405_9_, p_228405_10_, p_228405_3_, p_228405_7_, p_228405_5_);
} else {
this.func_228402_a_(p_228405_8_, p_228405_9_, p_228405_10_, p_228405_7_, handside, p_228405_5_, p_228405_6_);
}
- } else if (p_228405_6_.func_77973_b() == Items.field_222114_py) {
+ } else if (p_228405_6_.func_77973_b() instanceof CrossbowItem) {
boolean flag1 = CrossbowItem.func_220012_d(p_228405_6_);
boolean flag2 = handside == HandSide.RIGHT;
int i = flag2 ? 1 : -1;
@@ -410,8 +412,16 @@
this.field_187471_h = MathHelper.func_76131_a(this.field_187471_h - 0.4F, 0.0F, 1.0F);
} else {
@@ -1,11 +0,0 @@
--- a/net/minecraft/client/renderer/entity/FishRenderer.java
+++ b/net/minecraft/client/renderer/entity/FishRenderer.java
@@ -48,7 +48,7 @@
p_225623_4_.func_227865_b_();
int i = playerentity.func_184591_cq() == HandSide.RIGHT ? 1 : -1;
ItemStack itemstack = playerentity.func_184614_ca();
- if (itemstack.func_77973_b() != Items.field_151112_aM) {
+ if (!(itemstack.func_77973_b() instanceof net.minecraft.item.FishingRodItem)) {
i = -i;
}
@@ -1,20 +0,0 @@
--- a/net/minecraft/client/renderer/entity/model/SkeletonModel.java
+++ b/net/minecraft/client/renderer/entity/model/SkeletonModel.java
@@ -44,7 +44,7 @@
this.field_187076_m = BipedModel.ArmPose.EMPTY;
this.field_187075_l = BipedModel.ArmPose.EMPTY;
ItemStack itemstack = p_212843_1_.func_184586_b(Hand.MAIN_HAND);
- if (itemstack.func_77973_b() == Items.field_151031_f && p_212843_1_.func_213398_dR()) {
+ if (itemstack.func_77973_b() instanceof net.minecraft.item.BowItem && p_212843_1_.func_213398_dR()) {
if (p_212843_1_.func_184591_cq() == HandSide.RIGHT) {
this.field_187076_m = BipedModel.ArmPose.BOW_AND_ARROW;
} else {
@@ -58,7 +58,7 @@
public void func_225597_a_(T p_225597_1_, float p_225597_2_, float p_225597_3_, float p_225597_4_, float p_225597_5_, float p_225597_6_) {
super.func_225597_a_(p_225597_1_, p_225597_2_, p_225597_3_, p_225597_4_, p_225597_5_, p_225597_6_);
ItemStack itemstack = p_225597_1_.func_184614_ca();
- if (p_225597_1_.func_213398_dR() && (itemstack.func_190926_b() || itemstack.func_77973_b() != Items.field_151031_f)) {
+ if (p_225597_1_.func_213398_dR() && (itemstack.func_190926_b() || !(itemstack.func_77973_b() instanceof net.minecraft.item.BowItem))) {
float f = MathHelper.func_76126_a(this.field_217112_c * (float)Math.PI);
float f1 = MathHelper.func_76126_a((1.0F - (1.0F - this.field_217112_c) * (1.0F - this.field_217112_c)) * (float)Math.PI);
this.field_178723_h.field_78808_h = 0.0F;
@@ -1,10 +0,0 @@
--- a/net/minecraft/enchantment/EfficiencyEnchantment.java
+++ b/net/minecraft/enchantment/EfficiencyEnchantment.java
@@ -22,6 +22,6 @@
}
public boolean func_92089_a(ItemStack p_92089_1_) {
- return p_92089_1_.func_77973_b() == Items.field_151097_aZ ? true : super.func_92089_a(p_92089_1_);
+ return p_92089_1_.func_77973_b() instanceof net.minecraft.item.ShearsItem ? true : super.func_92089_a(p_92089_1_);
}
}
@@ -1,11 +0,0 @@
--- a/net/minecraft/entity/item/ItemFrameEntity.java
+++ b/net/minecraft/entity/item/ItemFrameEntity.java
@@ -216,7 +216,7 @@
}
private void func_110131_b(ItemStack p_110131_1_) {
- if (p_110131_1_.func_77973_b() == Items.field_151098_aY) {
+ if (p_110131_1_.func_77973_b() instanceof net.minecraft.item.FilledMapItem) {
MapData mapdata = FilledMapItem.func_195950_a(p_110131_1_, this.field_70170_p);
mapdata.func_212441_a(this.field_174861_a, this.func_145782_y());
mapdata.func_76186_a(true);
@@ -1,14 +1,5 @@
--- a/net/minecraft/entity/monster/AbstractSkeletonEntity.java
+++ b/net/minecraft/entity/monster/AbstractSkeletonEntity.java
@@ -155,7 +155,7 @@
this.field_70714_bg.func_85156_a(this.field_85038_e);
this.field_70714_bg.func_85156_a(this.field_85037_d);
ItemStack itemstack = this.func_184586_b(ProjectileHelper.func_221274_a(this, Items.field_151031_f));
- if (itemstack.func_77973_b() == Items.field_151031_f) {
+ if (itemstack.func_77973_b() instanceof net.minecraft.item.BowItem) {
int i = 20;
if (this.field_70170_p.func_175659_aa() != Difficulty.HARD) {
i = 40;
@@ -173,6 +173,8 @@
public void func_82196_d(LivingEntity p_82196_1_, float p_82196_2_) {
ItemStack itemstack = this.func_213356_f(this.func_184586_b(ProjectileHelper.func_221274_a(this, Items.field_151031_f)));
@@ -1,16 +1,5 @@
--- a/net/minecraft/entity/projectile/FishingBobberEntity.java
+++ b/net/minecraft/entity/projectile/FishingBobberEntity.java
@@ -233,8 +233,8 @@
private boolean func_234600_a_(PlayerEntity p_234600_1_) {
ItemStack itemstack = p_234600_1_.func_184614_ca();
ItemStack itemstack1 = p_234600_1_.func_184592_cb();
- boolean flag = itemstack.func_77973_b() == Items.field_151112_aM;
- boolean flag1 = itemstack1.func_77973_b() == Items.field_151112_aM;
+ boolean flag = itemstack.func_77973_b() instanceof net.minecraft.item.FishingRodItem;
+ boolean flag1 = itemstack1.func_77973_b() instanceof net.minecraft.item.FishingRodItem;
if (!p_234600_1_.field_70128_L && p_234600_1_.func_70089_S() && (flag || flag1) && !(this.func_70068_e(p_234600_1_) > 1024.0D)) {
return false;
} else {
@@ -300,7 +300,7 @@
double d1 = (double)((float)MathHelper.func_76128_c(this.func_226278_cu_()) + 1.0F);
double d2 = this.func_226281_cx_() + (double)(f2 * (float)this.field_146038_az * 0.1F);
@@ -56,4 +56,9 @@ public class CoreModFile implements ICoreModFile {
public String getOwnerId() {
return this.file.getModInfos().get(0).getModId();
}
@Override
public String toString() {
return "{Name: " + name + ", Owner: " + getOwnerId() + " @ " + getPath() + "}";
}
}
@@ -71,6 +71,7 @@ import static net.minecraftforge.fml.loading.LogMarkers.SCAN;
public class ModDiscoverer {
private static final Path INVALID_PATH = Paths.get("This", "Path", "Should", "Never", "Exist", "Because", "That", "Would", "Be", "Stupid", "CON", "AUX", "/dev/null");
private static final Logger LOGGER = LogManager.getLogger();
private final ServiceLoader<IModLocator> locators;
private final List<IModLocator> locatorList;
@@ -172,20 +173,23 @@ public class ModDiscoverer {
@Override
public Path findPath(final IModFile modFile, final String... path) {
String[] newPath = Arrays.copyOf(path, path.length);
if (path.length == 2 && Objects.equals(path[1], "mods.toml")) {
final URI jarFileURI;
try {
jarFileURI = getClass().getClassLoader().getResource("minecraftmod.toml").toURI();
if (Objects.equals(jarFileURI.getScheme(), "jar")) {
// Initialize the filesystem for the forge jar, because otherwise this barfs?
FileSystems.newFileSystem(jarFileURI, new HashMap<>());
if (path.length == 2 && Objects.equals(path[0], "META-INF")) {
if (Objects.equals(path[1], "mods.toml")) {
final URI jarFileURI;
try {
jarFileURI = getClass().getClassLoader().getResource("minecraftmod.toml").toURI();
if (Objects.equals(jarFileURI.getScheme(), "jar")) {
// Initialize the filesystem for the forge jar, because otherwise this barfs?
FileSystems.newFileSystem(jarFileURI, new HashMap<>());
}
} catch (URISyntaxException | IOException e) {
LOGGER.fatal(SCAN, "Unable to read minecraft default mod");
throw new RuntimeException(e);
}
} catch (URISyntaxException | IOException e) {
LOGGER.fatal(SCAN, "Unable to read minecraft default mod");
throw new RuntimeException(e);
return Paths.get(jarFileURI);
} else if (Objects.equals(path[1], "coremods.json")) {
return INVALID_PATH;
}
return Paths.get(jarFileURI);
}
if (Files.isDirectory(mcJar)) return findPathDirectory(modFile, path);
return findPathJar(modFile, path);
+2 -1
View File
@@ -1,3 +1,4 @@
{
"fieldtomethodtransformers": "META-INF/fieldtomethodtransformers.js"
"fieldtomethodtransformers": "META-INF/fieldtomethodtransformers.js",
"field_to_instanceof": "coremods/field_to_instanceof.js"
}
+2 -2
View File
@@ -10,8 +10,8 @@ license="LGPL v2.1"
version="${global.forgeVersion}"
updateJSONURL="https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json"
displayName="Forge"
credits="LexManos,cpw,Mezz,fry,tterrag,gigaherz,illy"
authors="LexManos,cpw,Mezz,fry,Spacetoad,Eloraam"
credits="Anyone who has contributed on Github and supports our development"
authors="LexManos,cpw"
description='''
Forge, a broad compatibility API.
'''
@@ -0,0 +1,58 @@
var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI')
var Opcodes = Java.type('org.objectweb.asm.Opcodes')
function initializeCoreMod() {
var data = ASMAPI.loadData('coremods/field_to_instanceof.json')
//ASMAPI.log('DEBUG', JSON.stringify(data, null, 2))
var ret = {}
for (name in data) {
addTargets(ret, name, data[name])
}
return ret
}
function addTargets(ret, name, data) {
var owner = data.cls
var field = ASMAPI.mapField(data.name)
var replacement = data.replacement
for (x = 0; x < data.targets.length; x++) {
var key = name + '.' + x
var entry = data.targets[x]
//ASMAPI.log('DEBUG', 'Entry ' + key + ' ' + JSON.stringify(entry))
ret[key] = {
'target': {
'type': 'METHOD',
'class': entry.owner,
'methodName': entry.name,
'methodDesc': entry.desc
},
'transformer': function(entry) { return function(node) {
return transform(node, entry.owner, owner, field, replacement)
}}(entry) // We have to do this annoying double function imediate call, so that JS will capture the entry value
}
}
}
function transform(node, parent, owner, field, replacement) {
var count = 0
var last = null
for (x = 0; x < node.instructions.size(); x++) {
var current = node.instructions.get(x)
if (current.getOpcode() == Opcodes.IF_ACMPEQ || current.getOpcode() == Opcodes.IF_ACMPNE) {
if (last != null && (last.getOpcode() == Opcodes.GETSTATIC || last.getOpcode() == Opcodes.GETFIELD)) {
if (last.owner.equals(owner) && last.name.equals(field)) {
node.instructions.set(last, new org.objectweb.asm.tree.TypeInsnNode(Opcodes.INSTANCEOF, replacement))
node.instructions.set(current, new org.objectweb.asm.tree.JumpInsnNode(current.getOpcode() == Opcodes.IF_ACMPEQ ? Opcodes.IFNE: Opcodes.IFEQ, current.label))
count++
}
}
}
last = current
}
//ASMAPI.log('DEBUG', 'Transforming: ' + parent + '.' + node.name + node.desc)
//ASMAPI.log('DEBUG', 'field_to_instance: Replaced {} checks', count)
return node
}
@@ -0,0 +1,182 @@
{
"bows": {
"cls": "net/minecraft/item/Items",
"name": "field_151031_f",
"replacement": "net/minecraft/item/BowItem",
"targets": [
{
"owner": "net/minecraft/client/entity/player/AbstractClientPlayerEntity",
"name": "func_175156_o",
"desc": "()F"
},
{
"owner": "net/minecraft/client/renderer/FirstPersonRenderer",
"name": "func_228396_a_",
"desc": "(FLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer$Impl;Lnet/minecraft/client/entity/player/ClientPlayerEntity;I)V"
},
{
"owner": "net/minecraft/client/renderer/entity/model/SkeletonModel",
"name": "func_212843_a_",
"desc": "(Lnet/minecraft/entity/MobEntity;FFF)V"
},
{
"owner": "net/minecraft/client/renderer/entity/model/SkeletonModel",
"name": "func_225597_a_",
"desc": "(Lnet/minecraft/entity/MobEntity;FFFFF)V"
},
{
"owner": "net/minecraft/entity/monster/AbstractSkeletonEntity",
"name": "func_230280_a_",
"desc": "(Lnet/minecraft/item/ShootableItem;)Z"
},
{
"owner": "net/minecraft/entity/monster/AbstractSkeletonEntity",
"name": "func_85036_m",
"desc": "()V"
}
]
},
"crossbows": {
"cls": "net/minecraft/item/Items",
"name": "field_222114_py",
"replacement": "net/minecraft/item/CrossbowItem",
"targets": [
{
"owner": "net/minecraft/client/renderer/FirstPersonRenderer",
"name": "func_228396_a_",
"desc": "(FLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer$Impl;Lnet/minecraft/client/entity/player/ClientPlayerEntity;I)V"
},
{
"owner": "net/minecraft/client/renderer/FirstPersonRenderer",
"name": "func_228405_a_",
"desc": "(Lnet/minecraft/client/entity/player/AbstractClientPlayerEntity;FFLnet/minecraft/util/Hand;FLnet/minecraft/item/ItemStack;FLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V"
},
{
"owner": "net/minecraft/client/renderer/entity/PlayerRenderer",
"name": "func_241741_a_",
"desc": "(Lnet/minecraft/client/entity/player/AbstractClientPlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/client/renderer/entity/model/BipedModel$ArmPose;"
},
{
"owner": "net/minecraft/entity/monster/PillagerEntity",
"name": "func_230280_a_",
"desc": "(Lnet/minecraft/item/ShootableItem;)Z"
},
{
"owner": "net/minecraft/entity/monster/PillagerEntity",
"name": "func_241844_w",
"desc": "(F)V"
},
{
"owner": "net/minecraft/entity/monster/piglin/PiglinEntity",
"name": "func_208003_a",
"desc": "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"
},
{
"owner": "net/minecraft/entity/monster/piglin/PiglinEntity",
"name": "func_230280_a_",
"desc": "(Lnet/minecraft/item/ShootableItem;)Z"
},
{
"owner": "net/minecraft/item/CrossbowItem",
"name": "func_220013_l",
"desc": "(Lnet/minecraft/item/ItemStack;)F"
},
{
"owner": "net/minecraft/item/Item",
"name": "func_219970_i",
"desc": "(Lnet/minecraft/item/ItemStack;)Z"
}
]
},
"filled_map": {
"cls": "net/minecraft/item/Items",
"name": "field_151098_aY",
"replacement": "net/minecraft/item/FilledMapItem",
"targets": [
{
"owner": "net/minecraft/client/renderer/FirstPersonRenderer",
"name": "func_228405_a_",
"desc": "(Lnet/minecraft/client/entity/player/AbstractClientPlayerEntity;FFLnet/minecraft/util/Hand;FLnet/minecraft/item/ItemStack;FLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V"
},
{
"owner": "net/minecraft/entity/item/ItemFrameEntity",
"name": "func_110131_b",
"desc": "(Lnet/minecraft/item/ItemStack;)V"
},
{
"owner": "net/minecraft/inventory/container/CartographyContainer$3",
"name": "func_75214_a",
"desc": "(Lnet/minecraft/item/ItemStack;)Z"
},
{
"owner": "net/minecraft/inventory/container/CartographyContainer",
"name": "func_82846_b",
"desc": "(Lnet/minecraft/entity/player/PlayerEntity;I)Lnet/minecraft/item/ItemStack;"
},
{
"owner": "net/minecraft/item/ItemStack",
"name": "func_82840_a",
"desc": "(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/client/util/ITooltipFlag;)Ljava/util/List;"
}
]
},
"fishing_rod": {
"cls": "net/minecraft/item/Items",
"name": "field_151112_aM",
"replacement": "net/minecraft/item/FishingRodItem",
"targets": [
{
"owner": "net/minecraft/client/renderer/entity/FishRenderer",
"name": "func_225623_a_",
"desc": "(Lnet/minecraft/entity/projectile/FishingBobberEntity;FFLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V"
},
{
"owner": "net/minecraft/entity/projectile/FishingBobberEntity",
"name": "func_234600_a_",
"desc": "(Lnet/minecraft/entity/player/PlayerEntity;)Z"
}
]
},
"shears": {
"cls": "net/minecraft/item/Items",
"name": "field_151097_aZ",
"replacement": "net/minecraft/item/ShearsItem",
"targets": [
{
"owner": "net/minecraft/block/BeehiveBlock",
"name": "func_225533_a_",
"desc": "(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/math/BlockRayTraceResult;)Lnet/minecraft/util/ActionResultType;"
},
{
"owner": "net/minecraft/block/PumpkinBlock",
"name": "func_225533_a_",
"desc": "(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/math/BlockRayTraceResult;)Lnet/minecraft/util/ActionResultType;"
},
{
"owner": "net/minecraft/block/TripWireBlock",
"name": "func_176208_a",
"desc": "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V"
},
{
"owner": "net/minecraft/enchantment/EfficiencyEnchantment",
"name": "func_92089_a",
"desc": "(Lnet/minecraft/item/ItemStack;)Z"
},
{
"owner": "net/minecraft/entity/passive/MooshroomEntity",
"name": "func_230254_b_",
"desc": "(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResultType;"
},
{
"owner": "net/minecraft/entity/passive/SheepEntity",
"name": "func_230254_b_",
"desc": "(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResultType;"
},
{
"owner": "net/minecraft/entity/passive/SnowGolemEntity",
"name": "func_230254_b_",
"desc": "(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResultType;"
}
]
}
}