mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-11-25 22:34:40 +00:00
transfer EnchantementHelper ASM to MixinItem_EnchantabilityEvent
This commit is contained in:
1 parent
80931f0eb7
commit
1cb6c8781f
4 files changed
+26
-56
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package com.enderio.core.common.mixins.early;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
import com.enderio.core.common.event.ItemStackEvent;
|
||||
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||
|
||||
@Mixin(Item.class)
|
||||
public class MixinItem_EnchantabilityEvent {
|
||||
|
||||
@ModifyReturnValue(
|
||||
method = "getItemEnchantability(Lnet/minecraft/item/ItemStack;)I",
|
||||
at = @At("RETURN"),
|
||||
remap = false)
|
||||
private int fireItemEnchantabilityEvent(int original, ItemStack stack) {
|
||||
ItemStackEvent.ItemEnchantabilityEvent event = new ItemStackEvent.ItemEnchantabilityEvent(stack, original);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.enchantability;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
import com.enderio.core.common.event.ArrowUpdateEvent;
|
||||
import com.enderio.core.common.event.ItemStackEvent.ItemEnchantabilityEvent;
|
||||
import com.enderio.core.common.event.ItemStackEvent.ItemRarityEvent;
|
||||
|
||||
public class EnderCoreMethods {
|
||||
@@ -33,12 +32,6 @@ public class EnderCoreMethods {
|
||||
return ConfigHandler.anvilMaxLevel;
|
||||
}
|
||||
|
||||
public static int getItemEnchantability(ItemStack stack, int base) {
|
||||
ItemEnchantabilityEvent event = new ItemEnchantabilityEvent(stack, base);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.enchantability;
|
||||
}
|
||||
|
||||
public static EnumRarity getItemRarity(ItemStack stack) {
|
||||
ItemRarityEvent event = new ItemRarityEvent(stack, stack.getItem().getRarity(stack));
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
@@ -52,6 +52,7 @@ public class EnderCorePlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
@Override
|
||||
public List<String> getMixins(Set<String> loadedCoreMods) {
|
||||
final List<String> mixins = new ArrayList<>();
|
||||
mixins.add("MixinItem_EnchantabilityEvent");
|
||||
return mixins;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,8 @@ import static org.objectweb.asm.Opcodes.ARETURN;
|
||||
import static org.objectweb.asm.Opcodes.ILOAD;
|
||||
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
|
||||
import static org.objectweb.asm.Opcodes.IRETURN;
|
||||
import static org.objectweb.asm.Opcodes.ISTORE;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
@@ -24,9 +21,6 @@ import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
|
||||
|
||||
@MCVersion(value = "1.7.10")
|
||||
public class EnderCoreTransformer implements IClassTransformer {
|
||||
|
||||
protected static class ObfSafeName {
|
||||
@@ -151,49 +145,6 @@ public class EnderCoreTransformer implements IClassTransformer {
|
||||
}
|
||||
});
|
||||
}
|
||||
// Item Enchantability Event
|
||||
else if (transformedName.equals(enchantHelperClass)) {
|
||||
final Map<String, int[]> data = new HashMap<String, int[]>();
|
||||
data.put(buildEnchantListMethod.getName(), new int[] { 1, 4 });
|
||||
data.put(calcEnchantabilityMethod.getName(), new int[] { 3, 5 });
|
||||
Transform transformer = new Transform() {
|
||||
|
||||
@Override
|
||||
void transform(Iterator<MethodNode> methods) {
|
||||
while (methods.hasNext()) {
|
||||
MethodNode m = methods.next();
|
||||
if (data.keySet().contains(m.name)) {
|
||||
int[] indeces = data.get(m.name);
|
||||
for (int i = 0; i < m.instructions.size(); i++) {
|
||||
AbstractInsnNode next = m.instructions.get(i);
|
||||
if (next instanceof VarInsnNode) {
|
||||
VarInsnNode varNode = (VarInsnNode) next;
|
||||
if (varNode.getOpcode() == ISTORE && varNode.var == indeces[1]) {
|
||||
InsnList toAdd = new InsnList();
|
||||
toAdd.add(new VarInsnNode(ALOAD, indeces[0]));
|
||||
toAdd.add(new VarInsnNode(ILOAD, indeces[1]));
|
||||
toAdd.add(
|
||||
new MethodInsnNode(
|
||||
INVOKESTATIC,
|
||||
"com/enderio/core/common/transform/EnderCoreMethods",
|
||||
"getItemEnchantability",
|
||||
enchantHelperMethodSig,
|
||||
false));
|
||||
toAdd.add(new VarInsnNode(ISTORE, indeces[1]));
|
||||
m.instructions.insert(next, toAdd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
basicClass = transform(basicClass, enchantHelperClass, buildEnchantListMethod, transformer);
|
||||
}
|
||||
// ItemRarity Event
|
||||
else if (transformedName.equals(itemStackClass)) {
|
||||
basicClass = transform(basicClass, itemStackClass, itemStackMethod, new Transform() {
|
||||
|
||||
Reference in new issue
Block a user