Merge pull request #4628 from thiakil/use-access-transformer

Use access transformer instead of reflection
This commit is contained in:
Aidan authored and GitHub committed 2017-08-16 08:49:48 -07:00
commit 4d20348151
11 files changed
+60 -100

No files matched your search

+11
View File
@@ -128,6 +128,13 @@ processResources
exclude 'mcmod.info'
exclude '**/*.blend*'
}
rename '(.+_at.cfg)', 'META-INF/$1'
}
jar {
manifest {
attributes 'FMLAT': 'mekanism_at.cfg'
}
}
task coreJar(type: Jar) {
@@ -143,6 +150,10 @@ task coreJar(type: Jar) {
from zipTree(jar.outputs.getFiles().getSingleFile()).matching {
exclude 'mekanism/tools/**', 'mekanism/generators/**', 'assets/mekanismtools/**', 'assets/mekanismgenerators/**', 'mcmod.info'
}
manifest {
attributes 'FMLAT': 'mekanism_at.cfg'
}
}
task toolsJar(type: Jar) {
@@ -4,7 +4,6 @@ import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER;
import static mekanism.client.sound.SoundHandler.Channel.GASMASK;
import static mekanism.client.sound.SoundHandler.Channel.JETPACK;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -21,7 +20,6 @@ import mekanism.client.sound.SoundHandler;
import mekanism.common.CommonPlayerTickHandler;
import mekanism.common.KeySync;
import mekanism.common.Mekanism;
import mekanism.common.ObfuscatedNames;
import mekanism.common.config.MekanismConfig.client;
import mekanism.common.config.MekanismConfig.general;
import mekanism.common.frequency.Frequency;
@@ -45,7 +43,6 @@ import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
import mekanism.common.util.ListUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.ReflectionUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetworkPlayerInfo;
@@ -484,17 +481,11 @@ public class ClientTickHandler
public static void setCape(AbstractClientPlayer player, ResourceLocation cape)
{
try {
Method m = ReflectionUtils.getPrivateMethod(AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_getPlayerInfo);
Object obj = m.invoke(player);
if(obj instanceof NetworkPlayerInfo)
{
NetworkPlayerInfo info = (NetworkPlayerInfo)obj;
Map<MinecraftProfileTexture.Type, ResourceLocation> map = (Map<MinecraftProfileTexture.Type, ResourceLocation>)ReflectionUtils.getPrivateValue(info, NetworkPlayerInfo.class, ObfuscatedNames.NetworkPlayerInfo_playerTextures);
map.put(MinecraftProfileTexture.Type.CAPE, cape);
}
} catch(Exception e) {}
NetworkPlayerInfo info = player.getPlayerInfo();
if (info != null) {
info.playerTextures.put(MinecraftProfileTexture.Type.CAPE, cape);
}
}
public static void killDeadNetworks()
@@ -4,8 +4,6 @@ import java.awt.Rectangle;
import java.util.List;
import mekanism.client.gui.IGuiWrapper;
import mekanism.common.ObfuscatedNames;
import mekanism.common.util.ReflectionUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -46,12 +44,7 @@ public abstract class GuiElement
{
if(guiObj instanceof GuiContainer)
{
try {
int size = (Integer)ReflectionUtils.getPrivateValue(guiObj, GuiContainer.class, ObfuscatedNames.GuiContainer_xSize);
ReflectionUtils.setPrivateValue(guiObj, size + xSize, GuiContainer.class, ObfuscatedNames.GuiContainer_xSize);
} catch(Exception e) {
e.printStackTrace();
}
((GuiContainer)guiObj).xSize += xSize;
}
}
@@ -59,12 +52,7 @@ public abstract class GuiElement
{
if(guiObj instanceof GuiContainer)
{
try {
int size = (Integer)ReflectionUtils.getPrivateValue(guiObj, GuiContainer.class, ObfuscatedNames.GuiContainer_ySize);
ReflectionUtils.setPrivateValue(guiObj, size + ySize, GuiContainer.class, ObfuscatedNames.GuiContainer_ySize);
} catch(Exception e) {
e.printStackTrace();
}
((GuiContainer)guiObj).ySize += ySize;
}
}
@@ -72,12 +60,7 @@ public abstract class GuiElement
{
if(guiObj instanceof GuiContainer)
{
try {
int left = (Integer)ReflectionUtils.getPrivateValue(guiObj, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft);
ReflectionUtils.setPrivateValue(guiObj, left + guiLeft, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft);
} catch(Exception e) {
e.printStackTrace();
}
((GuiContainer)guiObj).guiLeft += guiLeft;
}
}
@@ -85,12 +68,7 @@ public abstract class GuiElement
{
if(guiObj instanceof GuiContainer)
{
try {
int top = (Integer)ReflectionUtils.getPrivateValue(guiObj, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop);
ReflectionUtils.setPrivateValue(guiObj, top + guiTop, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop);
} catch(Exception e) {
e.printStackTrace();
}
((GuiContainer)guiObj).guiTop += guiTop;
}
}
@@ -18,9 +18,7 @@ import mekanism.client.render.tileentity.RenderFluidTank;
import mekanism.client.render.tileentity.RenderThermalEvaporationController;
import mekanism.client.render.transmitter.RenderLogisticalTransporter;
import mekanism.client.render.transmitter.RenderMechanicalPipe;
import mekanism.common.ObfuscatedNames;
import mekanism.common.base.IMetaItem;
import mekanism.common.util.ReflectionUtils;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
@@ -260,12 +258,12 @@ public class MekanismRenderer
public static boolean isDrawing(Tessellator tess)
{
return isDrawing(tess.getBuffer());
return tess.getBuffer().isDrawing;
}
public static boolean isDrawing(VertexBuffer buffer)
{
return (boolean)ReflectionUtils.getPrivateValue(buffer, VertexBuffer.class, ObfuscatedNames.VertexBuffer_isDrawing);
return buffer.isDrawing;
}
public static class Model3D
@@ -539,12 +537,7 @@ public class MekanismRenderer
public static float getPartialTick()
{
try {
Timer t = (Timer)ReflectionUtils.getPrivateValue(Minecraft.getMinecraft(), Minecraft.class, ObfuscatedNames.Minecraft_timer);
return t.renderPartialTicks;
} catch(Exception e) {}
return 0;
return Minecraft.getMinecraft().timer.renderPartialTicks;
}
public static ResourceLocation getBlocksTexture()
@@ -65,7 +65,7 @@ public abstract class RenderTransmitterBase<T extends TileEntityTransmitter> ext
public void renderTransparency(VertexBuffer renderer, TextureAtlasSprite icon, IBakedModel cc, ColourRGBA color)
{
if(!MekanismRenderer.isDrawing(renderer))
if(!renderer.isDrawing)
{
renderer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
}
@@ -3,9 +3,7 @@ package mekanism.client.sound;
import java.util.HashMap;
import java.util.Map;
import mekanism.common.ObfuscatedNames;
import mekanism.common.config.MekanismConfig.client;
import mekanism.common.util.ReflectionUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ITickableSound;
@@ -118,26 +116,13 @@ public class SoundHandler
public static SoundManager getSoundManager()
{
try {
return (SoundManager)ReflectionUtils.getPrivateValue(mc.getSoundHandler(), net.minecraft.client.audio.SoundHandler.class, ObfuscatedNames.SoundHandler_sndManager);
} catch(Exception e) {
return null;
}
return mc.getSoundHandler().sndManager;
}
//Fudge required because sound thread gets behind and the biMap crashes when rapidly toggling sounds.
public static Map<ISound, String> getSoundMap()
{
if(invPlayingSounds == null)
{
try {
invPlayingSounds = (Map<ISound, String>)ReflectionUtils.getPrivateValue(getSoundManager(), net.minecraft.client.audio.SoundManager.class, ObfuscatedNames.SoundManager_invPlayingSounds);
} catch(Exception e) {
invPlayingSounds = null;
}
}
return invPlayingSounds;
return mc.getSoundHandler().sndManager.invPlayingSounds;
}
public static boolean canRestartSound(ITickableSound sound)
@@ -104,7 +104,7 @@ public class CommonPlayerTickHandler
if(player instanceof EntityPlayerMP)
{
ReflectionUtils.setPrivateValue(((EntityPlayerMP)player).connection, 0, NetHandlerPlayServer.class, ObfuscatedNames.NetHandlerPlayServer_floatingTickCount);
((EntityPlayerMP)player).connection.floatingTickCount = 0;
}
jetpack.useGas(stack);
@@ -1,18 +0,0 @@
package mekanism.common;
public final class ObfuscatedNames
{
public static String[] Minecraft_timer = new String[] {"timer", "field_71428_T"};
public static String[] GuiContainer_xSize = new String[] {"xSize", "field_146999_f"};
public static String[] GuiContainer_ySize = new String[] {"ySize", "field_147000_g"};
public static String[] GuiContainer_guiLeft = new String[] {"guiLeft", "field_147003_i"};
public static String[] GuiContainer_guiTop = new String[] {"guiTop", "field_147009_r"};
public static String[] NetHandlerPlayServer_floatingTickCount = new String[] {"floatingTickCount", "field_147365_f"};
public static String[] SoundHandler_sndManager = new String[] {"sndManager", "field_147694_f"};
public static String[] SoundManager_sndSystem = new String[] {"sndSystem", "field_148620_e"};
public static String[] SoundManager_invPlayingSounds = new String[] {"invPlayingSounds", "field_148630_i"};
public static String[] AbstractClientPlayer_getPlayerInfo = new String[] {"getPlayerInfo", "func_175155_b"};
public static String[] NetworkPlayerInfo_playerTextures = new String[] {"playerTextures", "field_187107_a"};
public static String[] Entity_copyDataFromOld = new String[] {"copyDataFromOld", "func_180432_n"};
public static String[] VertexBuffer_isDrawing = new String[] {"isDrawing", "field_179010_r"};
}
@@ -9,7 +9,6 @@ import java.util.UUID;
import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.ObfuscatedNames;
import mekanism.common.PacketHandler;
import mekanism.common.frequency.Frequency;
import mekanism.common.frequency.FrequencyManager;
@@ -17,12 +16,10 @@ import mekanism.common.item.ItemPortableTeleporter;
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
import mekanism.common.network.PacketPortalFX.PortalFXMessage;
import mekanism.common.tile.TileEntityTeleporter;
import mekanism.common.util.ReflectionUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
@@ -125,7 +122,7 @@ public class PacketPortableTeleporter implements IMessageHandler<PortableTelepor
if(player instanceof EntityPlayerMP)
{
ReflectionUtils.setPrivateValue(((EntityPlayerMP)player).connection, 0, NetHandlerPlayServer.class, ObfuscatedNames.NetHandlerPlayServer_floatingTickCount);
((EntityPlayerMP)player).connection.floatingTickCount = 0;
}
player.closeScreen();
@@ -2,7 +2,6 @@ package mekanism.common.tile;
import io.netty.buffer.ByteBuf;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -14,7 +13,6 @@ import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.ObfuscatedNames;
import mekanism.common.PacketHandler;
import mekanism.common.Upgrade;
import mekanism.common.base.IRedstoneControl;
@@ -35,7 +33,6 @@ import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.tile.prefab.TileEntityElectricBlock;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.ReflectionUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
@@ -441,12 +438,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
if(e != null)
{
try {
Method m = ReflectionUtils.getPrivateMethod(Entity.class, ObfuscatedNames.Entity_copyDataFromOld, Entity.class);
m.invoke(e, entity);
} catch(Exception exception) {
exception.printStackTrace();
}
e.copyDataFromOld(entity);
world.spawnEntity(e);
teleporter.didTeleport.add(e.getPersistentID());
+31
View File
@@ -0,0 +1,31 @@
#net.minecraft.client.Minecraft
public net.minecraft.client.Minecraft field_71428_T #timer
#net.minecraft.client.gui.inventory.GuiContainer
public net.minecraft.client.gui.inventory.GuiContainer field_146999_f #xSize
public net.minecraft.client.gui.inventory.GuiContainer field_147000_g #ySize
public net.minecraft.client.gui.inventory.GuiContainer field_147003_i #guiLeft
public net.minecraft.client.gui.inventory.GuiContainer field_147009_r #guiTop
#net.minecraft.network.NetHandlerPlayServer
public net.minecraft.network.NetHandlerPlayServer field_147365_f #floatingTickCount
#net.minecraft.client.audio.SoundHandler
public net.minecraft.client.audio.SoundHandler field_147694_f #sndManager
#net.minecraft.client.audio.SoundManager
public net.minecraft.client.audio.SoundManager field_148630_i #invPlayingSounds
#unused: public net.minecraft.client.audio.SoundManager field_148620_e #sndSystem
#net.minecraft.client.entity.AbstractClientPlayer
public net.minecraft.client.entity.AbstractClientPlayer func_175155_b()Lnet/minecraft/client/network/NetworkPlayerInfo; #getPlayerInfo
#net.minecraft.client.network.NetworkPlayerInfo
public net.minecraft.client.network.NetworkPlayerInfo field_187107_a #playerTextures
#net.minecraft.entity.Entity
public net.minecraft.entity.Entity func_180432_n(Lnet/minecraft/entity/Entity;)V #copyDataFromOld
#net.minecraft.client.renderer.VertexBuffer
public net.minecraft.client.renderer.VertexBuffer field_179010_r #isDrawing