Removed ASMTweaker and replaced it with AT. (#2636)

Added appeng_at.cfg and updated build.gradle to correctly include the AT when building.
Deleted the now useless ASMTweaker.
Moved the coremod from package transformer to coremod as a better matching name.
Updated the old 1.7.10 code using reflection to drop it where forge or vanilla now exposes that functionality directly.
This commit is contained in:
yueh 2016-11-26 14:08:10 +01:00 committed by GitHub
parent a665200c31
commit 887339f7b8
17 changed files with 49 additions and 236 deletions

View File

@ -103,7 +103,7 @@ Providing as many details as possible does help us to find and resolve the issue
- Eclipse: execute `gradlew eclipse`
5. For add-on developer: Core-Mod Detection
- In order to have FML detect AE from your dev environment, add the following VM Option to your run profile
- `-Dfml.coreMods.load=appeng.transformer.AppEngCore`
- `-Dfml.coreMods.load=appeng.coremod.AppEngCore`
## Contribution

View File

@ -53,6 +53,7 @@ archivesBaseName = aebasename
jar {
manifest {
attributes 'FMLCorePluginContainsFMLMod': 'true'
attributes 'FMLAT': 'appeng_at.cfg'
}
from sourceSets.api.output
@ -63,10 +64,11 @@ jar {
include "assets/**"
include "mcmod.info"
include "pack.mcmeta"
include "META-INF/appeng_at.cfg"
}
minecraft {
coreMod = "appeng.transformer.AppEngCore"
coreMod = "appeng.coremod.AppEngCore"
version = minecraft_version + "-" + forge_version
@ -117,4 +119,7 @@ processResources
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
// move access transformer to META-INF
rename '(.+_at.cfg)', 'META-INF/$1'
}

View File

@ -62,6 +62,7 @@ import appeng.core.CommonHelper;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketAssemblerAnimation;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.coremod.MissingCoreMod;
import appeng.entity.EntityFloatingItem;
import appeng.entity.EntityTinyTNTPrimed;
import appeng.entity.RenderFloatingItem;
@ -70,7 +71,6 @@ import appeng.helpers.IMouseWheelItem;
import appeng.hooks.TickHandler;
import appeng.hooks.TickHandler.PlayerColor;
import appeng.server.ServerHelper;
import appeng.transformer.MissingCoreMod;
import appeng.util.Platform;

View File

@ -539,16 +539,7 @@ public abstract class AEBaseGui extends GuiContainer
@Override
protected boolean checkHotbarKeys( final int keyCode )
{
final Slot theSlot;
try
{
theSlot = ObfuscationReflectionHelper.getPrivateValue( GuiContainer.class, this, "theSlot", "field_147006_u", "f" );
}
catch( final Throwable t )
{
return false;
}
final Slot theSlot = this.getSlotUnderMouse();
if( this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null )
{
@ -701,7 +692,8 @@ public abstract class AEBaseGui extends GuiContainer
/**
* This overrides the base-class method through some access transformer hackery...
*/
public void drawSlot( final Slot s )
@Override
public void drawSlot( Slot s )
{
if( s instanceof SlotME )
{
@ -720,7 +712,7 @@ public abstract class AEBaseGui extends GuiContainer
this.itemRender.zLevel = 0.0F;
// Annoying but easier than trying to splice into render item
this.safeDrawSlot( new Size1Slot( s ) );
super.drawSlot( new Size1Slot( s ) );
stackSizeRenderer.renderStackSize( fontRendererObj, ( (SlotME) s ).getAEStack(), s.getStack(), s.xDisplayPosition, s.yDisplayPosition );
@ -822,11 +814,11 @@ public abstract class AEBaseGui extends GuiContainer
if( s instanceof AppEngSlot )
{
( (AppEngSlot) s ).setDisplay( true );
this.safeDrawSlot( s );
super.drawSlot( s );
}
else
{
this.safeDrawSlot( s );
super.drawSlot( s );
}
return;
@ -837,7 +829,7 @@ public abstract class AEBaseGui extends GuiContainer
}
}
// do the usual for non-ME Slots.
this.safeDrawSlot( s );
super.drawSlot( s );
}
protected boolean isPowered()
@ -845,17 +837,6 @@ public abstract class AEBaseGui extends GuiContainer
return true;
}
private void safeDrawSlot( final Slot s )
{
try
{
GuiContainer.class.getDeclaredMethod( "func_146977_a_original", Slot.class ).invoke( this, s );
}
catch( final Exception err )
{
}
}
public void bindTexture( final String file )
{
final ResourceLocation loc = new ResourceLocation( AppEng.MOD_ID, "textures/" + file );

View File

@ -16,7 +16,7 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.transformer;
package appeng.coremod;
import java.util.Map;
@ -64,13 +64,13 @@ public final class AppEngCore extends DummyModContainer implements IFMLLoadingPl
@Override
public String[] getASMTransformerClass()
{
return new String[] { "appeng.transformer.asm.ASMIntegration" };
return new String[] { "appeng.coremod.asm.ASMIntegration" };
}
@Override
public String getModContainerClass()
{
return "appeng.transformer.AppEngCore";
return "appeng.coremod.AppEngCore";
}
@Nullable
@ -89,7 +89,7 @@ public final class AppEngCore extends DummyModContainer implements IFMLLoadingPl
@Override
public String getAccessTransformerClass()
{
return "appeng.transformer.asm.ASMTweaker";
return null;
}
@Override

View File

@ -16,7 +16,7 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.transformer;
package appeng.coremod;
import net.minecraft.client.gui.FontRenderer;
@ -68,7 +68,7 @@ public final class MissingCoreMod extends CustomModLoadingErrorDisplayException
this.drawCenteredString( fontRenderer, "In a developer environment add the following too your args,", errorScreen.width / 2, offset, COLOR_WHITE );
offset += SCREEN_OFFSET;
this.drawCenteredString( fontRenderer, "-Dfml.coreMods.load=appeng.transformer.AppEngCore", errorScreen.width / 2, offset, SHADOW_WHITE );
this.drawCenteredString( fontRenderer, "-Dfml.coreMods.load=appeng.coremod.AppEngCore", errorScreen.width / 2, offset, SHADOW_WHITE );
}
else
{

View File

@ -16,7 +16,7 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.transformer.annotations;
package appeng.coremod.annotations;
import java.lang.annotation.ElementType;

View File

@ -16,7 +16,7 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.transformer.asm;
package appeng.coremod.asm;
import java.util.Iterator;
@ -34,10 +34,10 @@ import org.objectweb.asm.tree.MethodNode;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraftforge.fml.relauncher.FMLRelaunchLog;
import appeng.coremod.annotations.Integration;
import appeng.helpers.Reflected;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.Integration;
@Reflected
@ -71,7 +71,7 @@ public final class ASMIntegration implements IClassTransformer
@Override
public byte[] transform( final String name, final String transformedName, final byte[] basicClass )
{
if( basicClass == null || transformedName.startsWith( "appeng.transformer" ) )
if( basicClass == null || transformedName.startsWith( "appeng.coremod" ) )
{
return basicClass;
}

View File

@ -26,10 +26,10 @@ import ic2.api.item.IElectricItemManager;
import ic2.api.item.ISpecialElectricItem;
import appeng.api.config.PowerUnits;
import appeng.coremod.annotations.Integration.Interface;
import appeng.coremod.annotations.Integration.InterfaceList;
import appeng.coremod.annotations.Integration.Method;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.Integration.Interface;
import appeng.transformer.annotations.Integration.InterfaceList;
import appeng.transformer.annotations.Integration.Method;
@InterfaceList( value = {

View File

@ -24,8 +24,8 @@ import net.minecraft.item.ItemStack;
import cofh.api.energy.IEnergyContainerItem;
import appeng.api.config.PowerUnits;
import appeng.coremod.annotations.Integration.Interface;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.Integration.Interface;
@Interface( iface = "cofh.api.energy.IEnergyContainerItem", iname = IntegrationType.RFItem )

View File

@ -33,12 +33,12 @@ import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource;
import appeng.api.config.PowerUnits;
import appeng.coremod.annotations.Integration.Interface;
import appeng.coremod.annotations.Integration.InterfaceList;
import appeng.integration.IntegrationType;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.transformer.annotations.Integration.Interface;
import appeng.transformer.annotations.Integration.InterfaceList;
import appeng.util.Platform;

View File

@ -44,8 +44,8 @@ package appeng.parts.p2p;
//import appeng.api.networking.events.MENetworkPowerStatusChange;
//import appeng.integration.IntegrationRegistry;
//import appeng.integration.IntegrationType;
//import appeng.transformer.annotations.Integration.Interface;
//import appeng.transformer.annotations.Integration.InterfaceList;
//import appeng.coremod.annotations.Integration.Interface;
//import appeng.coremod.annotations.Integration.InterfaceList;
//
//
//@InterfaceList( value = { @Interface( iface = "li.cil.oc.api.network.Environment", iname = IntegrationType.OpenComputers ), @Interface( iface = "li.cil.oc.api.network.SidedEnvironment", iname = IntegrationType.OpenComputers ) } )

View File

@ -36,8 +36,8 @@ package appeng.parts.p2p;
//import appeng.integration.IntegrationType;
//import appeng.integration.modules.helpers.NullRFHandler;
//import appeng.me.GridAccessException;
//import appeng.transformer.annotations.Integration.Interface;
//import appeng.transformer.annotations.Integration.InterfaceList;
//import appeng.coremod.annotations.Integration.Interface;
//import appeng.coremod.annotations.Integration.InterfaceList;
//import appeng.util.Platform;
//
//

View File

@ -24,8 +24,8 @@ import net.minecraft.util.EnumFacing;
import cofh.api.energy.IEnergyReceiver;
import appeng.api.config.PowerUnits;
import appeng.coremod.annotations.Integration.Interface;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.Integration.Interface;
@Interface( iname = IntegrationType.RF, iface = "cofh.api.energy.IEnergyReceiver" )

View File

@ -1,171 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.transformer.asm;
import java.util.Iterator;
import javax.annotation.Nullable;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnNode;
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.minecraftforge.fml.relauncher.FMLRelaunchLog;
import appeng.helpers.Reflected;
@Reflected
public final class ASMTweaker implements IClassTransformer
{
private static final String[] EXCEPTIONS = new String[0];
private final Multimap<String, PublicLine> privateToPublicMethods = HashMultimap.create();
@Reflected
public ASMTweaker()
{
this.privateToPublicMethods.put( "net.minecraft.client.gui.inventory.GuiContainer", new PublicLine( "drawSlot", "(Lnet/minecraft/inventory/Slot;)V" ) );
this.privateToPublicMethods.put( "net.minecraft.client.gui.inventory.GuiContainer", new PublicLine( "func_146977_a", "(Lnet/minecraft/inventory/Slot;)V" ) );
this.privateToPublicMethods.put( "net.minecraft.client.gui.inventory.GuiContainer", new PublicLine( "a", "(Lzk;)V" ) );
this.privateToPublicMethods.put( "appeng.tile.AEBaseTile", new PublicLine( "writeToNBT", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
this.privateToPublicMethods.put( "appeng.tile.AEBaseTile", new PublicLine( "func_145841_b", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
this.privateToPublicMethods.put( "appeng.tile.AEBaseTile", new PublicLine( "b", "(Ldh;)V" ) );
this.privateToPublicMethods.put( "appeng.tile.AEBaseTile", new PublicLine( "readFromNBT", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
this.privateToPublicMethods.put( "appeng.tile.AEBaseTile", new PublicLine( "func_145839_a", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
this.privateToPublicMethods.put( "appeng.tile.AEBaseTile", new PublicLine( "a", "(Ldh;)V" ) );
}
@Nullable
@Override
public byte[] transform( final String name, final String transformedName, final byte[] basicClass )
{
if( basicClass == null )
{
return null;
}
try
{
if( transformedName != null && this.privateToPublicMethods.containsKey( transformedName ) )
{
final ClassNode classNode = new ClassNode();
final ClassReader classReader = new ClassReader( basicClass );
classReader.accept( classNode, 0 );
for( final PublicLine set : this.privateToPublicMethods.get( transformedName ) )
{
this.makePublic( classNode, set );
}
// CALL VIRTUAL!
if( transformedName.equals( "net.minecraft.client.gui.inventory.GuiContainer" ) )
{
for( final MethodNode mn : classNode.methods )
{
if( mn.name.equals( "drawSlot" ) || mn.name.equals( "func_146977_a" ) || ( mn.name.equals( "a" ) && mn.desc.equals( "(Lzk;)V" ) ) )
{
final MethodNode newNode = new MethodNode( Opcodes.ACC_PUBLIC, "func_146977_a_original", mn.desc, mn.signature, EXCEPTIONS );
newNode.instructions.add( new VarInsnNode( Opcodes.ALOAD, 0 ) );
newNode.instructions.add( new VarInsnNode( Opcodes.ALOAD, 1 ) );
newNode.instructions.add( new MethodInsnNode( Opcodes.INVOKESPECIAL, classNode.name, mn.name, mn.desc, false ) );
newNode.instructions.add( new InsnNode( Opcodes.RETURN ) );
this.log( newNode.name + newNode.desc + " - New Method" );
classNode.methods.add( newNode );
break;
}
}
for( final MethodNode mn : classNode.methods )
{
if( mn.name.equals( "func_73863_a" ) || mn.name.equals( "drawScreen" ) || ( mn.name.equals( "a" ) && mn.desc.equals( "(IIF)V" ) ) )
{
final Iterator<AbstractInsnNode> i = mn.instructions.iterator();
while( i.hasNext() )
{
final AbstractInsnNode in = i.next();
if( in.getOpcode() == Opcodes.INVOKESPECIAL )
{
final MethodInsnNode n = (MethodInsnNode) in;
if( n.name.equals( "drawSlot" ) || n.name.equals( "func_146977_a" ) || ( n.name.equals( "a" ) && n.desc.equals( "(Lzk;)V" ) ) )
{
this.log( n.name + n.desc + " - Invoke Virtual" );
mn.instructions.insertBefore( n, new MethodInsnNode( Opcodes.INVOKEVIRTUAL, n.owner, n.name, n.desc, false ) );
mn.instructions.remove( in );
break;
}
}
}
}
}
}
final ClassWriter writer = new ClassWriter( ClassWriter.COMPUTE_MAXS );
classNode.accept( writer );
return writer.toByteArray();
}
}
catch( final Throwable ignored )
{
}
return basicClass;
}
private void makePublic( final ClassNode classNode, final PublicLine set )
{
for( final MethodNode mn : classNode.methods )
{
if( mn.name.equals( set.name ) && mn.desc.equals( set.desc ) )
{
mn.access = ( mn.access & ( ~( Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED ) ) ) | Opcodes.ACC_PUBLIC;
this.log( mn.name + mn.desc + " - Transformed" );
}
}
}
private void log( final String string )
{
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
}
private static final class PublicLine
{
private final String name;
private final String desc;
public PublicLine( final String name, final String desc )
{
this.name = name;
this.desc = desc;
}
}
}

View File

@ -155,7 +155,7 @@ public class Platform
*/
private static final Random RANDOM_GENERATOR = new Random();
private static final WeakHashMap<World, EntityPlayer> FAKE_PLAYERS = new WeakHashMap<World, EntityPlayer>();
private static Method getEntry;
// private static Method getEntry;
private static final ItemComparisonHelper ITEM_COMPARISON_HELPER = new ItemComparisonHelper();
@ -1185,7 +1185,9 @@ public class Platform
final Vec3d vec31 = vec3.addVector( f7 * d3, f6 * d3, f8 * d3 );
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ), Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ), Math.max( vec3.zCoord, vec31.zCoord ) ).expand( 16, 16, 16 );
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ), Math.min( vec3.zCoord,
vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ), Math.max( vec3.zCoord, vec31.zCoord ) ).expand(
16, 16, 16 );
Entity entity = null;
double closest = 9999999.0D;
@ -1491,7 +1493,8 @@ public class Platform
if( AEConfig.instance().isFeatureEnabled( AEFeature.LOG_SECURITY_AUDITS ) )
{
AELog.info( "Audit: " + a_isSecure + " : " + b_isSecure + " @ " + a.getLastSecurityKey() + " vs " + b.getLastSecurityKey() + " & " + a.getPlayerID() + " vs " + b.getPlayerID() );
AELog.info(
"Audit: " + a_isSecure + " : " + b_isSecure + " @ " + a.getLastSecurityKey() + " vs " + b.getLastSecurityKey() + " & " + a.getPlayerID() + " vs " + b.getPlayerID() );
}
// can't do that son...
@ -1649,7 +1652,8 @@ public class Platform
for( final IAEItemStack x : items )
{
final ItemStack sh = x.getItemStack();
if( ( Platform.itemComparisons().isEqualItemType( providedTemplate, sh ) || ae_req.sameOre( x ) ) && !Platform.itemComparisons().isEqualItem( sh, output ) )
if( ( Platform.itemComparisons().isEqualItemType( providedTemplate,
sh ) || ae_req.sameOre( x ) ) && !Platform.itemComparisons().isEqualItem( sh, output ) )
{ // Platform.isSameItemType( sh, providedTemplate )
final ItemStack cp = Platform.cloneItemStack( sh );
cp.stackSize = 1;
@ -1774,19 +1778,11 @@ public class Platform
{
final WorldServer ws = (WorldServer) c.getWorld();
final PlayerChunkMap pm = ws.getPlayerChunkMap();
final PlayerChunkMapEntry playerInstance = pm.getEntry( c.xPosition, c.zPosition );
if( getEntry == null )
if( playerInstance != null )
{
getEntry = ReflectionHelper.findMethod( PlayerChunkMap.class, pm, new String[] { "getEntry", "func_187301_b" }, int.class, int.class );
}
if( getEntry != null )
{
final PlayerChunkMapEntry playerInstance = (PlayerChunkMapEntry) getEntry.invoke( pm, c.xPosition, c.zPosition );
if( playerInstance != null )
{
playerInstance.sendPacket( new SPacketChunkData( c, verticalBits ) );
}
playerInstance.sendPacket( new SPacketChunkData( c, verticalBits ) );
}
}
catch( final Throwable t )

View File

@ -0,0 +1,2 @@
# GUI rendering
public net.minecraft.client.gui.inventory.GuiContainer func_146977_a(Lnet/minecraft/inventory/Slot;)V # drawSlot