Removed the ASM hackery as the necessary hooks are now in FML
This commit is contained in:
parent
c39824c00f
commit
9a35ac97b1
7 changed files with 6 additions and 197 deletions
|
@ -75,8 +75,8 @@ processResources {
|
|||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'FMLCorePlugin': 'biomesoplenty.asm.BOPLoadingPlugin'
|
||||
attributes 'FMLCorePluginContainsFMLMod': 'true'
|
||||
//attributes 'FMLCorePlugin': 'biomesoplenty.asm.BOPLoadingPlugin'
|
||||
//attributes 'FMLCorePluginContainsFMLMod': 'true'
|
||||
}
|
||||
classifier = 'universal'
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
minecraft_version=1.8
|
||||
forge_version=8.0.2.1009-1.8
|
||||
forge_version=8.0.2.1011-1.8
|
||||
mod_version=3.0.0
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.asm;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
public class ASMUtil
|
||||
{
|
||||
public static ClassNode getClassNode(byte[] classBytes)
|
||||
{
|
||||
ClassReader reader = new ClassReader(classBytes);
|
||||
ClassNode node = new ClassNode();
|
||||
reader.accept(node, 0);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
public static byte[] getBytes(ClassNode classNode)
|
||||
{
|
||||
ClassWriter writer = new ClassWriter(0);
|
||||
classNode.accept(writer);
|
||||
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
public static MethodNode getMethodNode(ClassNode classNode, String methodName, String desc)
|
||||
{
|
||||
for (MethodNode method : classNode.methods)
|
||||
{
|
||||
if (method.name.equals(methodName) && method.desc.equals(desc)) return method;
|
||||
}
|
||||
|
||||
throw new RuntimeException(methodName + " doesn't exist in " + classNode.name + "!");
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.asm;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
|
||||
|
||||
//TODO: Remove this or the BOPTransformer. It shouldn't be needed.
|
||||
@TransformerExclusions("biomesoplenty.asm")
|
||||
public class BOPLoadingPlugin implements IFMLLoadingPlugin
|
||||
{
|
||||
@Override
|
||||
public String[] getASMTransformerClass()
|
||||
{
|
||||
return new String[] { BOPTransformer.class.getName() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModContainerClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSetupClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.asm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
public class BOPTransformer implements IClassTransformer
|
||||
{
|
||||
private static final boolean isObfuscated;
|
||||
private static final String modelBakeryName;
|
||||
private static final String variantNamesName;
|
||||
private static final String registerVariantNamesName;
|
||||
|
||||
static
|
||||
{
|
||||
boolean obfuscated = true;
|
||||
|
||||
try
|
||||
{
|
||||
obfuscated = Launch.classLoader.getClassBytes("net.minecraft.world.World") == null;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
isObfuscated = obfuscated;
|
||||
modelBakeryName = isObfuscated ? "cxh" : "net/minecraft/client/resources/model/ModelBakery";
|
||||
variantNamesName = isObfuscated ? "u" : "variantNames";
|
||||
registerVariantNamesName = isObfuscated ? "e" : "registerVariantNames";
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass)
|
||||
{
|
||||
if (name.equals(modelBakeryName.replace("/", ".")))
|
||||
{
|
||||
ClassNode classNode = ASMUtil.getClassNode(basicClass);
|
||||
MethodNode variantsMethodNode = ASMUtil.getMethodNode(classNode, registerVariantNamesName, "()V");
|
||||
|
||||
InsnList instructions = new InsnList();
|
||||
|
||||
instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
instructions.add(new FieldInsnNode(Opcodes.GETFIELD, modelBakeryName, variantNamesName, "Ljava/util/Map;"));
|
||||
instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, "biomesoplenty/client/util/ModelHelper", "customVariantNames", "Ljava/util/HashMap;"));
|
||||
instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/Map", "putAll", "(Ljava/util/Map;)V", true));
|
||||
|
||||
variantsMethodNode.instructions.insertBefore(getRegisterVariantsInsertionPoint(variantsMethodNode), instructions);
|
||||
|
||||
return ASMUtil.getBytes(classNode);
|
||||
}
|
||||
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
private AbstractInsnNode getRegisterVariantsInsertionPoint(MethodNode methodNode)
|
||||
{
|
||||
Iterator<AbstractInsnNode> iterator = methodNode.instructions.iterator();
|
||||
AbstractInsnNode returnNode = null;
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
AbstractInsnNode currentNode = iterator.next();
|
||||
|
||||
if (currentNode.getOpcode() == Opcodes.RETURN) returnNode = currentNode;
|
||||
}
|
||||
|
||||
if (returnNode != null) return returnNode;
|
||||
|
||||
throw new RuntimeException("The insertion point for registerVariantsNames() in ModelBakery was not found");
|
||||
}
|
||||
}
|
|
@ -29,14 +29,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
@SideOnly(Side.CLIENT)
|
||||
public class ModelHelper
|
||||
{
|
||||
public static HashMap<Item, ArrayList<String>> customVariantNames = new HashMap();
|
||||
|
||||
public static void addVariantName(Item item, String... names)
|
||||
{
|
||||
if (customVariantNames.containsKey(item)) customVariantNames.get(item).addAll(Arrays.asList(names));
|
||||
else customVariantNames.put(item, Lists.newArrayList(names));
|
||||
}
|
||||
|
||||
public static void registerItem(Item item, int metadata, String itemName)
|
||||
{
|
||||
getItemModelMesher().register(item, metadata, new ModelResourceLocation(itemName, "inventory"));
|
||||
|
|
|
@ -10,6 +10,7 @@ package biomesoplenty.common.init;
|
|||
|
||||
import static biomesoplenty.api.block.BOPBlocks.*;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import biomesoplenty.api.block.BOPBlock;
|
||||
|
@ -52,7 +53,7 @@ public class ModBlocks
|
|||
{
|
||||
String variantName = variant.getName() + (variant.getBaseName() != null ? "_" + variant.getBaseName() : "");
|
||||
|
||||
ModelHelper.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + variantName);
|
||||
ModelBakery.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + variantName);
|
||||
BiomesOPlenty.proxy.registerBlockForMeshing(block, variant.getDefaultMetadata(), variantName);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +61,7 @@ public class ModBlocks
|
|||
{
|
||||
GameRegistry.registerBlock(block, name);
|
||||
|
||||
ModelHelper.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + name);
|
||||
ModelBakery.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + name);
|
||||
BiomesOPlenty.proxy.registerBlockForMeshing(block, 0, name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue