From 789a380e7d360a393810ba2c96287f4f56e80898 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sun, 25 Jun 2017 11:43:35 -0500 Subject: [PATCH] Move things to AT so we know when they break immediately --- build.gradle | 7 + .../core/handler/AstrolabePreviewHandler.java | 12 +- .../handler/BlockHighlightRenderHandler.java | 24 +-- .../core/handler/BoundTileRenderer.java | 12 +- .../core/handler/ClientMethodHandles.java | 57 ------ .../handler/CorporeaAutoCompleteHandler.java | 5 +- .../client/core/handler/HUDHandler.java | 2 +- .../core/handler/MultiblockRenderHandler.java | 12 +- .../core/handler/RedStringRenderer.java | 12 +- .../client/core/proxy/ClientProxy.java | 5 +- .../tile/RenderTileCorporeaCrystalCube.java | 9 +- .../render/tile/RenderTileEnchanter.java | 6 +- .../render/world/SkyblockSkyRenderer.java | 19 +- .../subtile/functional/SubTileDaffomill.java | 10 +- .../functional/SubTileHeiseiDream.java | 4 +- .../subtile/functional/SubTileHopperhock.java | 10 +- .../functional/SubTilePollidisiac.java | 12 +- .../functional/SubTileRannuncarpus.java | 12 +- .../functional/SubTileSpectranthemum.java | 10 +- .../subtile/functional/SubTileTigerseye.java | 10 +- .../subtile/generating/SubTileEndoflame.java | 10 +- .../generating/SubTileGourmaryllis.java | 10 +- .../subtile/generating/SubTileSpectrolus.java | 10 +- .../common/block/tile/TileOpenCrate.java | 9 +- .../common/block/tile/TileSpawnerClaw.java | 180 +++++++----------- .../common/block/tile/mana/TilePool.java | 12 +- .../common/core/handler/MethodHandles.java | 94 --------- .../common/entity/EntityMagicMissile.java | 4 +- .../common/entity/EntityThrownItem.java | 18 +- .../botania/common/item/ItemCraftingHalo.java | 14 +- .../vazkii/botania/common/item/ItemVirus.java | 2 +- .../item/equipment/bauble/ItemDivaCharm.java | 2 +- .../bauble/ItemSuperLavaPendant.java | 14 +- .../common/item/relic/ItemAesirRing.java | 14 +- .../common/item/relic/ItemInfiniteFruit.java | 2 +- .../botania/common/lib/LibObfuscation.java | 68 ------- src/main/resources/META-INF/botania_at.cfg | 43 +++++ 37 files changed, 188 insertions(+), 568 deletions(-) delete mode 100644 src/main/java/vazkii/botania/client/core/handler/ClientMethodHandles.java delete mode 100644 src/main/java/vazkii/botania/common/core/handler/MethodHandles.java create mode 100644 src/main/resources/META-INF/botania_at.cfg diff --git a/build.gradle b/build.gradle index b35fa39ca..9238e821d 100644 --- a/build.gradle +++ b/build.gradle @@ -64,6 +64,13 @@ configurations { //End of the SCP config +jar { + classifier = 'universal' + manifest { + attributes 'FMLAT': 'botania_at.cfg' + } +} + dependencies { compile files( 'Baubles-deobf.jar' diff --git a/src/main/java/vazkii/botania/client/core/handler/AstrolabePreviewHandler.java b/src/main/java/vazkii/botania/client/core/handler/AstrolabePreviewHandler.java index d7ae79a8f..d33cbbc19 100644 --- a/src/main/java/vazkii/botania/client/core/handler/AstrolabePreviewHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/AstrolabePreviewHandler.java @@ -75,15 +75,9 @@ public final class AstrolabePreviewHandler { private static void renderBlockAt(Block block, int meta, BlockPos pos) { IBlockState state = block.getStateFromMeta(meta); - double renderPosX, renderPosY, renderPosZ; - - try { - renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - } catch (Throwable t) { - return; - } + double renderPosX = Minecraft.getMinecraft().getRenderManager().renderPosX; + double renderPosY = Minecraft.getMinecraft().getRenderManager().renderPosY; + double renderPosZ = Minecraft.getMinecraft().getRenderManager().renderPosZ; GlStateManager.pushMatrix(); GlStateManager.translate(-renderPosX, -renderPosY, -renderPosZ); diff --git a/src/main/java/vazkii/botania/client/core/handler/BlockHighlightRenderHandler.java b/src/main/java/vazkii/botania/client/core/handler/BlockHighlightRenderHandler.java index 64bd1dabe..f30ae9aa7 100644 --- a/src/main/java/vazkii/botania/client/core/handler/BlockHighlightRenderHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/BlockHighlightRenderHandler.java @@ -107,15 +107,9 @@ public final class BlockHighlightRenderHandler { } private static void renderRectangle(AxisAlignedBB aabb, boolean inner, Color color, byte alpha) { - double renderPosX, renderPosY, renderPosZ; - - try { - renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - } catch (Throwable t) { - return; - } + double renderPosX = Minecraft.getMinecraft().getRenderManager().renderPosX; + double renderPosY = Minecraft.getMinecraft().getRenderManager().renderPosY; + double renderPosZ = Minecraft.getMinecraft().getRenderManager().renderPosZ; GlStateManager.pushMatrix(); GlStateManager.translate(aabb.minX - renderPosX, aabb.minY - renderPosY, aabb.minZ - renderPosZ); @@ -154,15 +148,9 @@ public final class BlockHighlightRenderHandler { } private static void renderCircle(BlockPos center, double radius) { - double renderPosX, renderPosY, renderPosZ; - - try { - renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - } catch (Throwable t) { - return; - } + double renderPosX = Minecraft.getMinecraft().getRenderManager().renderPosX; + double renderPosY = Minecraft.getMinecraft().getRenderManager().renderPosY; + double renderPosZ = Minecraft.getMinecraft().getRenderManager().renderPosZ; GlStateManager.pushMatrix(); double x = center.getX() + 0.5; diff --git a/src/main/java/vazkii/botania/client/core/handler/BoundTileRenderer.java b/src/main/java/vazkii/botania/client/core/handler/BoundTileRenderer.java index 227e7c713..4eebce9b1 100644 --- a/src/main/java/vazkii/botania/client/core/handler/BoundTileRenderer.java +++ b/src/main/java/vazkii/botania/client/core/handler/BoundTileRenderer.java @@ -95,15 +95,9 @@ public final class BoundTileRenderer { } private static void renderBlockOutlineAt(BlockPos pos, int color, float thickness) { - double renderPosX, renderPosY, renderPosZ; - - try { - renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - } catch (Throwable t) { - return; - } + double renderPosX = Minecraft.getMinecraft().getRenderManager().renderPosX; + double renderPosY = Minecraft.getMinecraft().getRenderManager().renderPosY; + double renderPosZ = Minecraft.getMinecraft().getRenderManager().renderPosZ; GlStateManager.pushMatrix(); GlStateManager.translate(pos.getX() - renderPosX, pos.getY() - renderPosY, pos.getZ() - renderPosZ + 1); diff --git a/src/main/java/vazkii/botania/client/core/handler/ClientMethodHandles.java b/src/main/java/vazkii/botania/client/core/handler/ClientMethodHandles.java deleted file mode 100644 index bc2b71722..000000000 --- a/src/main/java/vazkii/botania/client/core/handler/ClientMethodHandles.java +++ /dev/null @@ -1,57 +0,0 @@ -package vazkii.botania.client.core.handler; - -import com.google.common.base.Throwables; -import net.minecraft.client.renderer.RenderGlobal; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraftforge.fml.relauncher.ReflectionHelper; -import vazkii.botania.common.Botania; -import vazkii.botania.common.lib.LibObfuscation; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; - -public final class ClientMethodHandles { - - public static final MethodHandle - renderPosX_getter, renderPosY_getter, renderPosZ_getter, // RenderManager - starGLCallList_getter, starVBO_getter, glSkyList_getter, skyVBO_getter; // RenderGlobal - - static { - try { - Field f = ReflectionHelper.findField(RenderManager.class, LibObfuscation.RENDERPOSX); - f.setAccessible(true); - renderPosX_getter = MethodHandles.publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(RenderManager.class, LibObfuscation.RENDERPOSY); - f.setAccessible(true); - renderPosY_getter = MethodHandles.publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(RenderManager.class, LibObfuscation.RENDERPOSZ); - f.setAccessible(true); - renderPosZ_getter = MethodHandles.publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(RenderGlobal.class, LibObfuscation.STAR_GL_CALL_LIST); - f.setAccessible(true); - starGLCallList_getter = MethodHandles.publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(RenderGlobal.class, LibObfuscation.STAR_VBO); - f.setAccessible(true); - starVBO_getter = MethodHandles.publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(RenderGlobal.class, LibObfuscation.GL_SKY_LIST); - f.setAccessible(true); - glSkyList_getter = MethodHandles.publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(RenderGlobal.class, LibObfuscation.SKY_VBO); - f.setAccessible(true); - skyVBO_getter = MethodHandles.publicLookup().unreflectGetter(f); - } catch (IllegalAccessException e) { - Botania.LOGGER.fatal("Couldn't initialize client methodhandles! Things will be broken!"); - e.printStackTrace(); - throw Throwables.propagate(e); - } - } - - private ClientMethodHandles() {} -} diff --git a/src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java b/src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java index 0c98c98a0..f23f0f45c 100644 --- a/src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java @@ -92,11 +92,10 @@ public class CorporeaAutoCompleteHandler { if(!CorporeaHelper.shouldAutoComplete()) return; - GuiTextField inputField = ReflectionHelper.getPrivateValue(GuiChat.class, chat, LibObfuscation.INPUT_FIELD); if(!isAutoCompleted) - buildAutoCompletes(inputField, chat); + buildAutoCompletes(chat.inputField, chat); if(isAutoCompleted && !completions.isEmpty()) - advanceAutoComplete(inputField, chat); + advanceAutoComplete(chat.inputField, chat); } private void advanceAutoComplete(GuiTextField inputField, GuiChat chat) { diff --git a/src/main/java/vazkii/botania/client/core/handler/HUDHandler.java b/src/main/java/vazkii/botania/client/core/handler/HUDHandler.java index 8faedee4c..6fd5ec734 100644 --- a/src/main/java/vazkii/botania/client/core/handler/HUDHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/HUDHandler.java @@ -264,7 +264,7 @@ public final class HUDHandler { Profiler profiler = mc.mcProfiler; profiler.startSection("wandMode"); - int ticks = ReflectionHelper.getPrivateValue(GuiIngame.class, mc.ingameGUI, LibObfuscation.REMAINING_HIGHLIGHT_TICKS); + int ticks = mc.ingameGUI.remainingHighlightTicks; ticks -= 15; if(ticks > 0) { int alpha = Math.min(255, (int) (ticks * 256.0F / 10.0F)); diff --git a/src/main/java/vazkii/botania/client/core/handler/MultiblockRenderHandler.java b/src/main/java/vazkii/botania/client/core/handler/MultiblockRenderHandler.java index e2a659e97..450036430 100644 --- a/src/main/java/vazkii/botania/client/core/handler/MultiblockRenderHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/MultiblockRenderHandler.java @@ -138,15 +138,9 @@ public final class MultiblockRenderHandler { } private static boolean renderComponentInWorld(World world, Multiblock mb, MultiblockComponent comp, BlockPos anchorPos) { - double renderPosX, renderPosY, renderPosZ; - - try { - renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - } catch (Throwable t) { - return true; - } + double renderPosX = Minecraft.getMinecraft().getRenderManager().renderPosX; + double renderPosY = Minecraft.getMinecraft().getRenderManager().renderPosY; + double renderPosZ = Minecraft.getMinecraft().getRenderManager().renderPosZ; BlockPos pos = comp.getRelativePosition(); BlockPos pos_ = pos.add(anchorPos); diff --git a/src/main/java/vazkii/botania/client/core/handler/RedStringRenderer.java b/src/main/java/vazkii/botania/client/core/handler/RedStringRenderer.java index 8a03e8271..f0dcf04ce 100644 --- a/src/main/java/vazkii/botania/client/core/handler/RedStringRenderer.java +++ b/src/main/java/vazkii/botania/client/core/handler/RedStringRenderer.java @@ -64,15 +64,9 @@ public final class RedStringRenderer { } private static void renderTile(TileRedString tile) { - double renderPosX, renderPosY, renderPosZ; - - try { - renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - } catch (Throwable t) { - return; - } + double renderPosX = Minecraft.getMinecraft().getRenderManager().renderPosX; + double renderPosY = Minecraft.getMinecraft().getRenderManager().renderPosY; + double renderPosZ = Minecraft.getMinecraft().getRenderManager().renderPosZ; EnumFacing dir = tile.getOrientation(); BlockPos bind = tile.getBinding(); diff --git a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java index 51d23cd7f..01a50ace7 100644 --- a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java @@ -12,6 +12,7 @@ package vazkii.botania.client.core.proxy; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.client.network.NetHandlerPlayClient; @@ -298,10 +299,10 @@ public class ClientProxy implements IProxy { @Override public void setExtraReach(EntityLivingBase entity, float reach) { Minecraft mc = Minecraft.getMinecraft(); - EntityPlayer player = mc.player; + EntityPlayerSP player = mc.player; if(entity == player) { if(!(mc.playerController instanceof IExtendedPlayerController)) { - NetHandlerPlayClient net = ReflectionHelper.getPrivateValue(PlayerControllerMP.class, mc.playerController, LibObfuscation.NET_CLIENT_HANDLER); + NetHandlerPlayClient net = player.connection; BotaniaPlayerController controller = new BotaniaPlayerController(mc, net); boolean isFlying = player.capabilities.isFlying; boolean allowFlying = player.capabilities.allowFlying; diff --git a/src/main/java/vazkii/botania/client/render/tile/RenderTileCorporeaCrystalCube.java b/src/main/java/vazkii/botania/client/render/tile/RenderTileCorporeaCrystalCube.java index 1dcb33342..659a28055 100644 --- a/src/main/java/vazkii/botania/client/render/tile/RenderTileCorporeaCrystalCube.java +++ b/src/main/java/vazkii/botania/client/render/tile/RenderTileCorporeaCrystalCube.java @@ -39,7 +39,6 @@ import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import vazkii.botania.client.core.handler.ClientTickHandler; import vazkii.botania.common.block.tile.corporea.TileCorporeaCrystalCube; -import vazkii.botania.common.core.handler.MethodHandles; import javax.annotation.Nonnull; @@ -63,12 +62,8 @@ public class RenderTileCorporeaCrystalCube extends TileEntitySpecialRenderer items = supertile.getWorld().getEntitiesWithinAABB(EntityItem.class, axis); int slowdown = getSlowdownFactor(); for(EntityItem item : items) { - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(!item.isDead && age >= slowdown) { + if(!item.isDead && item.age >= slowdown) { item.motionX += orientation.getFrontOffsetX() * 0.05; item.motionY += orientation.getFrontOffsetY() * 0.05; item.motionZ += orientation.getFrontOffsetZ() * 0.05; diff --git a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java index 5707adae5..f9922a78c 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java +++ b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java @@ -88,8 +88,8 @@ public class SubTileHeiseiDream extends SubTileFunctional { } private static void messWithGetTargetAI(EntityAINearestAttackableTarget aiEntry, EntityLivingBase target) { - ReflectionHelper.setPrivateValue(EntityAINearestAttackableTarget.class, aiEntry, Entity.class, LibObfuscation.TARGET_CLASS); - ReflectionHelper.setPrivateValue(EntityAINearestAttackableTarget.class, aiEntry, Predicates.equalTo(target), LibObfuscation.TARGET_ENTITY_SELECTOR); // todo 1.8 will this leak `target`? + aiEntry.targetClass = Entity.class; + aiEntry.targetEntitySelector = e -> e == target; // todo will this leak target? } @Override diff --git a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHopperhock.java b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHopperhock.java index f5a44b1c7..907261f35 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHopperhock.java +++ b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHopperhock.java @@ -35,7 +35,6 @@ import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.mana.IManaItem; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileFunctional; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.core.helper.InventoryHelper; import vazkii.botania.common.lexicon.LexiconData; @@ -69,14 +68,7 @@ public class SubTileHopperhock extends SubTileFunctional { int slowdown = getSlowdownFactor(); for(EntityItem item : items) { - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(age < 60 + slowdown || age >= 105 && age < 110 || item.isDead || item.getItem().isEmpty()) + if(item.age < 60 + slowdown || item.age >= 105 && item.age < 110 || item.isDead || item.getItem().isEmpty()) continue; ItemStack stack = item.getItem(); diff --git a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTilePollidisiac.java b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTilePollidisiac.java index 9d6729313..c889bd0a2 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTilePollidisiac.java +++ b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTilePollidisiac.java @@ -18,7 +18,6 @@ import net.minecraftforge.fml.relauncher.ReflectionHelper; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileFunctional; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.lexicon.LexiconData; import vazkii.botania.common.lib.LibObfuscation; @@ -45,14 +44,7 @@ public class SubTilePollidisiac extends SubTileFunctional { if(animal.getGrowingAge() == 0 && !animal.isInLove()) { for(EntityItem item : items) { - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(age < 60 + slowdown || item.isDead) + if(item.age < 60 + slowdown || item.isDead) continue; ItemStack stack = item.getItem(); @@ -61,7 +53,7 @@ public class SubTilePollidisiac extends SubTileFunctional { mana -= manaCost; - ReflectionHelper.setPrivateValue(EntityAnimal.class, animal, 1200, LibObfuscation.IN_LOVE); + animal.inLove = 1200; supertile.getWorld().setEntityState(animal, (byte)18); } } diff --git a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileRannuncarpus.java b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileRannuncarpus.java index 8b268704f..c6a91fcc8 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileRannuncarpus.java +++ b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileRannuncarpus.java @@ -39,7 +39,6 @@ import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileEntity; import vazkii.botania.api.subtile.SubTileFunctional; import vazkii.botania.common.core.handler.ConfigHandler; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.item.block.ItemBlockSpecialFlower; import vazkii.botania.common.lexicon.LexiconData; import vazkii.botania.common.lib.LibObfuscation; @@ -80,14 +79,7 @@ public class SubTileRannuncarpus extends SubTileFunctional { List items = supertile.getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(supertile.getPos().add(-RANGE, -RANGE_Y, -RANGE), supertile.getPos().add(RANGE + 1, RANGE_Y + 1, RANGE + 1))); int slowdown = getSlowdownFactor(); for(EntityItem item : items) { - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(age < 60 + slowdown || item.isDead || item.getItem().isEmpty()) + if(item.age < 60 + slowdown || item.isDead || item.getItem().isEmpty()) continue; ItemStack stack = item.getItem(); @@ -123,7 +115,7 @@ public class SubTileRannuncarpus extends SubTileFunctional { stateToPlace = ((ItemBlock) stackItem).getBlock().getStateFromMeta(blockMeta); } else if(stackItem instanceof ItemBlockSpecial) - stateToPlace = ((Block) ReflectionHelper.getPrivateValue(ItemBlockSpecial.class, (ItemBlockSpecial) stackItem, LibObfuscation.REED_ITEM)).getDefaultState(); + stateToPlace = ((ItemBlockSpecial) stackItem).getBlock().getDefaultState(); else if(stackItem instanceof ItemRedstone) stateToPlace = Blocks.REDSTONE_WIRE.getDefaultState(); diff --git a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileSpectranthemum.java b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileSpectranthemum.java index 1746a411d..84cc23554 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileSpectranthemum.java +++ b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileSpectranthemum.java @@ -26,7 +26,6 @@ import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.mana.IManaItem; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileFunctional; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.lexicon.LexiconData; import vazkii.botania.common.network.PacketBotaniaEffect; import vazkii.botania.common.network.PacketHandler; @@ -60,14 +59,7 @@ public class SubTileSpectranthemum extends SubTileFunctional { int slowdown = getSlowdownFactor(); for(EntityItem item : items) { - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(age < 60 + slowdown || item.isDead || item.getEntityData().getBoolean(TAG_TELEPORTED)) + if(item.age < 60 + slowdown || item.isDead || item.getEntityData().getBoolean(TAG_TELEPORTED)) continue; ItemStack stack = item.getItem(); diff --git a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileTigerseye.java b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileTigerseye.java index 7cafa7b77..f9d90bc52 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileTigerseye.java +++ b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileTigerseye.java @@ -62,7 +62,7 @@ public class SubTileTigerseye extends SubTileFunctional { } if(entity instanceof EntityCreeper) { - ReflectionHelper.setPrivateValue(EntityCreeper.class, (EntityCreeper) entity, 2, LibObfuscation.TIME_SINCE_IGNITED); + ((EntityCreeper) entity).timeSinceIgnited = 2; entity.setAttackTarget(null); } @@ -75,16 +75,16 @@ public class SubTileTigerseye extends SubTileFunctional { } private boolean messWithRunAwayAI(EntityAIAvoidEntity aiEntry) { - if(ReflectionHelper.getPrivateValue(EntityAIAvoidEntity.class, aiEntry, LibObfuscation.TARGET_ENTITY_CLASS) == EntityOcelot.class) { - ReflectionHelper.setPrivateValue(EntityAIAvoidEntity.class, aiEntry, EntityPlayer.class, LibObfuscation.TARGET_ENTITY_CLASS); + if(aiEntry.classToAvoid == EntityOcelot.class) { + aiEntry.classToAvoid = EntityPlayer.class; return true; } return false; } private void messWithGetTargetAI(EntityAINearestAttackableTarget aiEntry) { - if(ReflectionHelper.getPrivateValue(EntityAINearestAttackableTarget.class, aiEntry, LibObfuscation.TARGET_CLASS) == EntityPlayer.class) - ReflectionHelper.setPrivateValue(EntityAINearestAttackableTarget.class, aiEntry, EntityEnderCrystal.class, LibObfuscation.TARGET_CLASS); // Something random that won't be around + if(aiEntry.targetClass == EntityPlayer.class) + aiEntry.targetClass = EntityEnderCrystal.class; // Something random that won't be around } @Override diff --git a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileEndoflame.java b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileEndoflame.java index 92c647120..afb7bb927 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileEndoflame.java +++ b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileEndoflame.java @@ -22,7 +22,6 @@ import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileGenerating; import vazkii.botania.common.block.ModBlocks; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.core.handler.ModSounds; import vazkii.botania.common.lexicon.LexiconData; @@ -49,14 +48,7 @@ public class SubTileEndoflame extends SubTileGenerating { List items = supertile.getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(supertile.getPos().add(-RANGE, -RANGE, -RANGE), supertile.getPos().add(RANGE + 1, RANGE + 1, RANGE + 1))); for(EntityItem item : items) { - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(age >= 59 + slowdown && !item.isDead) { + if(item.age >= 59 + slowdown && !item.isDead) { ItemStack stack = item.getItem(); if(stack.isEmpty() || stack.getItem().hasContainerItem(stack)) continue; diff --git a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java index 3db0ba405..2e8355e31 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java +++ b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java @@ -23,7 +23,6 @@ import net.minecraft.world.WorldServer; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileGenerating; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.lexicon.LexiconData; import java.util.List; @@ -59,14 +58,7 @@ public class SubTileGourmaryllis extends SubTileGenerating { for(EntityItem item : items) { ItemStack stack = item.getItem(); - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(!stack.isEmpty() && stack.getItem() instanceof ItemFood && !item.isDead && age >= slowdown) { + if(!stack.isEmpty() && stack.getItem() instanceof ItemFood && !item.isDead && item.age >= slowdown) { if(cooldown <= 0) { int val = Math.min(12, ((ItemFood) stack.getItem()).getHealAmount(stack)); storedMana = val * val * 64; diff --git a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java index 02a7f3901..70de14d66 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java +++ b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileSpectrolus.java @@ -28,7 +28,6 @@ import org.lwjgl.opengl.GL11; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileGenerating; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.lexicon.LexiconData; import java.awt.Color; @@ -57,14 +56,7 @@ public class SubTileSpectrolus extends SubTileGenerating { for(EntityItem item : items) { ItemStack stack = item.getItem(); - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable t) { - continue; - } - - if(!stack.isEmpty() && stack.getItem() == wool && !item.isDead && age >= slowdown) { + if(!stack.isEmpty() && stack.getItem() == wool && !item.isDead && item.age >= slowdown) { int meta = stack.getItemDamage(); if(meta == nextColor) { mana = Math.min(getMaxMana(), mana + 300); diff --git a/src/main/java/vazkii/botania/common/block/tile/TileOpenCrate.java b/src/main/java/vazkii/botania/common/block/tile/TileOpenCrate.java index cd3b0eb78..7584421cf 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileOpenCrate.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileOpenCrate.java @@ -20,7 +20,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import vazkii.botania.api.state.BotaniaStateProps; import vazkii.botania.common.block.ModBlocks; -import vazkii.botania.common.core.handler.MethodHandles; import javax.annotation.Nonnull; @@ -72,13 +71,7 @@ public class TileOpenCrate extends TileSimpleInventory { item.motionX = 0; item.motionY = 0; item.motionZ = 0; - - if(redstone) { - try { - MethodHandles.itemAge_setter.invokeExact(item, -200); - } catch (Throwable ignored) {} - } - + item.age = -200; itemHandler.setStackInSlot(0, ItemStack.EMPTY); world.spawnEntity(item); diff --git a/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java b/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java index b888e8ea5..67e0c9c27 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java @@ -2,22 +2,22 @@ * This class was created by . It's distributed as * part of the Botania Mod. Get the Source Code in github: * https://github.com/Vazkii/Botania - * + *

* Botania is Open Source and distributed under the * Botania License: http://botaniamod.net/license.php - * + *

* File Created @ [Jul 23, 2014, 5:32:11 PM (GMT)] */ package vazkii.botania.common.block.tile; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.IEntityLivingData; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.MobSpawnerBaseLogic; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityMobSpawner; -import net.minecraft.util.WeightedRandom; import net.minecraft.util.WeightedSpawnerEntity; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; @@ -25,9 +25,6 @@ import net.minecraft.world.World; import net.minecraft.world.chunk.storage.AnvilChunkLoader; import vazkii.botania.api.mana.IManaReceiver; import vazkii.botania.common.Botania; -import vazkii.botania.common.core.handler.MethodHandles; - -import java.util.List; public class TileSpawnerClaw extends TileMod implements IManaReceiver { @@ -42,119 +39,84 @@ public class TileSpawnerClaw extends TileMod implements IManaReceiver { TileEntityMobSpawner spawner = (TileEntityMobSpawner) tileBelow; MobSpawnerBaseLogic logic = spawner.getSpawnerBaseLogic(); - try { - // Directly drawn from MobSpawnerBaseLogic, with inverted isActivated check and mana consumption - if(!((boolean) MethodHandles.isActivated.invokeExact(logic))) { - if(!world.isRemote) - mana -= 6; + BlockPos blockpos = logic.getSpawnerPosition(); - if(logic.getSpawnerWorld().isRemote) { - int delay = (int) MethodHandles.spawnDelay_getter.invokeExact(logic); - if(delay > 0) - MethodHandles.spawnDelay_setter.invokeExact(logic, delay - 1); + // Directly drawn from MobSpawnerBaseLogic, with inverted isActivated check and mana consumption + if(!logic.isActivated()) { + if(!world.isRemote) + mana -= 6; - if(Math.random() > 0.5) - Botania.proxy.wispFX(getPos().getX() + 0.3 + Math.random() * 0.5, getPos().getY() - 0.3 + Math.random() * 0.25, getPos().getZ() + Math.random(), 0.6F - (float) Math.random() * 0.3F, 0.1F, 0.6F - (float) Math.random() * 0.3F, (float) Math.random() / 3F, -0.025F - 0.005F * (float) Math.random(), 2F); - - MethodHandles.prevMobRotation_setter.invokeExact(logic, logic.getMobRotation()); - MethodHandles.mobRotation_setter.invokeExact(logic, (logic.getMobRotation() + 1000.0F / ((int) MethodHandles.spawnDelay_getter.invokeExact(logic) + 200.0F)) % 360.0D); - } else { - if((int) MethodHandles.spawnDelay_getter.invokeExact(logic) == -1) - resetTimer(logic); - int delay = (int) MethodHandles.spawnDelay_getter.invokeExact(logic); - if(delay > 0) { - MethodHandles.spawnDelay_setter.invokeExact(logic, delay - 1); - return; - } - - if(logic.getSpawnerWorld().isRemote) - return; - - boolean flag = false; - - int spawnCount = (int) MethodHandles.spawnCount_getter.invokeExact(logic); - int spawnRange = (int) MethodHandles.spawnRange_getter.invokeExact(logic); - int maxNearbyEntities = (int) MethodHandles.maxNearbyEntities_getter.invokeExact(logic); - WeightedSpawnerEntity randomEntity = (WeightedSpawnerEntity) MethodHandles.randomEntity_getter.invokeExact(logic); - - BlockPos blockpos = logic.getSpawnerPosition(); - for(int i = 0; i < spawnCount; ++i) { - NBTTagCompound nbttagcompound = randomEntity.getNbt(); - NBTTagList nbttaglist = nbttagcompound.getTagList("Pos", 6); - World world = logic.getSpawnerWorld(); - int j = nbttaglist.tagCount(); - double d0 = j >= 1 ? nbttaglist.getDoubleAt(0) : blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * spawnRange + 0.5D; - double d1 = j >= 2 ? nbttaglist.getDoubleAt(1) : (double)(blockpos.getY() + world.rand.nextInt(3) - 1); - double d2 = j >= 3 ? nbttaglist.getDoubleAt(2) : blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * spawnRange + 0.5D; - Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, false); - - if (entity == null) - { - return; - } - - int k = world.getEntitiesWithinAABB(entity.getClass(), new AxisAlignedBB(blockpos.getX(), blockpos.getY(), blockpos.getZ(), blockpos.getX() + 1, blockpos.getY() + 1, blockpos.getZ() + 1).grow(spawnRange)).size(); - - if (k >= maxNearbyEntities) - { - resetTimer(logic); - return; - } - - EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null; - entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, world.rand.nextFloat() * 360.0F, 0.0F); - - if (entityliving == null || net.minecraftforge.event.ForgeEventFactory.canEntitySpawnSpawner(entityliving, logic.getSpawnerWorld(), (float)entity.posX, (float)entity.posY, (float)entity.posZ)) - { - if (randomEntity.getNbt().getSize() == 1 && randomEntity.getNbt().hasKey("id", 8) && entity instanceof EntityLiving) - { - if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(entityliving, logic.getSpawnerWorld(), (float)entity.posX, (float)entity.posY, (float)entity.posZ)) - ((EntityLiving)entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), null); - } - - AnvilChunkLoader.spawnEntity(entity, world); - world.playEvent(2004, blockpos, 0); - - if (entityliving != null) - { - entityliving.spawnExplosionParticle(); - } - - flag = true; - } - } - - if (flag) - resetTimer(logic); + if(logic.getSpawnerWorld().isRemote) { + if(logic.spawnDelay > 0) { + --logic.spawnDelay; } + if(Math.random() > 0.5) + Botania.proxy.wispFX(getPos().getX() + 0.3 + Math.random() * 0.5, getPos().getY() - 0.3 + Math.random() * 0.25, getPos().getZ() + Math.random(), 0.6F - (float) Math.random() * 0.3F, 0.1F, 0.6F - (float) Math.random() * 0.3F, (float) Math.random() / 3F, -0.025F - 0.005F * (float) Math.random(), 2F); + logic.prevMobRotation = logic.mobRotation; + logic.mobRotation = (logic.mobRotation + (double) (1000.0F / ((float) logic.spawnDelay + 200.0F))) % 360.0D; + } else { + if(logic.spawnDelay == -1) { + logic.resetTimer(); + } + + if(logic.spawnDelay > 0) { + --logic.spawnDelay; + return; + } + + boolean flag = false; + + for(int i = 0; i < logic.spawnCount; ++i) { + NBTTagCompound nbttagcompound = logic.spawnData.getNbt(); + NBTTagList nbttaglist = nbttagcompound.getTagList("Pos", 6); + World world = logic.getSpawnerWorld(); + int j = nbttaglist.tagCount(); + double d0 = j >= 1 ? nbttaglist.getDoubleAt(0) : (double) blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) logic.spawnRange + 0.5D; + double d1 = j >= 2 ? nbttaglist.getDoubleAt(1) : (double) (blockpos.getY() + world.rand.nextInt(3) - 1); + double d2 = j >= 3 ? nbttaglist.getDoubleAt(2) : (double) blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) logic.spawnRange + 0.5D; + Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, false); + + if(entity == null) { + return; + } + + int k = world.getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB((double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), (double) (blockpos.getX() + 1), (double) (blockpos.getY() + 1), (double) (blockpos.getZ() + 1))).grow((double) logic.spawnRange)).size(); + + if(k >= logic.maxNearbyEntities) { + logic.resetTimer(); + return; + } + + EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving) entity : null; + entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, world.rand.nextFloat() * 360.0F, 0.0F); + + if(entityliving == null || net.minecraftforge.event.ForgeEventFactory.canEntitySpawnSpawner(entityliving, world, (float) entity.posX, (float) entity.posY, (float) entity.posZ)) { + if(logic.spawnData.getNbt().getSize() == 1 && logic.spawnData.getNbt().hasKey("id", 8) && entity instanceof EntityLiving) { + if(!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(entityliving, logic.getSpawnerWorld(), (float) entity.posX, (float) entity.posY, (float) entity.posZ)) + ((EntityLiving) entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData) null); + } + + AnvilChunkLoader.spawnEntity(entity, world); + world.playEvent(2004, blockpos, 0); + + if(entityliving != null) { + entityliving.spawnExplosionParticle(); + } + + flag = true; + } + } + + if(flag) { + logic.resetTimer(); + } } - } catch (Throwable t) { - t.printStackTrace(); } } } - // Direct copy of MobSpawnerBaseLogic.resetTimer() - private void resetTimer(MobSpawnerBaseLogic logic) throws Throwable { - int maxSpawnDelay = (int) MethodHandles.maxSpawnDelay_getter.invokeExact(logic); - int minSpawnDelay = (int) MethodHandles.minSpawnDelay_getter.invokeExact(logic); - List potentialEntitySpawns = (List) MethodHandles.potentialSpawns_getter.invokeExact(logic); - - if(maxSpawnDelay <= minSpawnDelay) - MethodHandles.spawnDelay_setter.invokeExact(logic, minSpawnDelay); - else { - int i = maxSpawnDelay - minSpawnDelay; - MethodHandles.spawnDelay_setter.invokeExact(logic, minSpawnDelay + logic.getSpawnerWorld().rand.nextInt(i)); - } - - if(potentialEntitySpawns != null && potentialEntitySpawns.size() > 0) - logic.setNextSpawnData((WeightedSpawnerEntity)WeightedRandom.getRandomItem(logic.getSpawnerWorld().rand, potentialEntitySpawns)); - - logic.broadcastEvent(1); - } - @Override public void writePacketNBT(NBTTagCompound cmp) { cmp.setInteger(TAG_MANA, mana); diff --git a/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java b/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java index 0162bcfcf..340557b00 100644 --- a/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java +++ b/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java @@ -55,7 +55,6 @@ import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.block.tile.TileMod; import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.handler.ManaNetworkHandler; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.core.handler.ModSounds; import vazkii.botania.common.item.ItemManaTablet; import vazkii.botania.common.item.ModItems; @@ -167,12 +166,7 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt ((IManaDissolvable) stack.getItem()).onDissolveTick(this, stack, item); } - int age; - try { - age = (int) MethodHandles.itemAge_getter.invokeExact(item); - } catch (Throwable throwable) { return false; } - - if(age > 100 && age < 130) + if(item.age > 100 && item.age < 130) return false; RecipeManaInfusion recipe = getMatchingRecipe(stack, world.getBlockState(pos.down())); @@ -186,9 +180,7 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt ItemStack output = recipe.getOutput().copy(); EntityItem outputItem = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output); - try { - MethodHandles.itemAge_setter.invokeExact(outputItem, 105); - } catch (Throwable ignored) {} + outputItem.age = 105; world.spawnEntity(outputItem); craftingFanciness(); diff --git a/src/main/java/vazkii/botania/common/core/handler/MethodHandles.java b/src/main/java/vazkii/botania/common/core/handler/MethodHandles.java deleted file mode 100644 index d258566b0..000000000 --- a/src/main/java/vazkii/botania/common/core/handler/MethodHandles.java +++ /dev/null @@ -1,94 +0,0 @@ -package vazkii.botania.common.core.handler; - -import com.google.common.base.Throwables; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.tileentity.MobSpawnerBaseLogic; -import net.minecraftforge.fml.relauncher.ReflectionHelper; -import vazkii.botania.common.Botania; -import vazkii.botania.common.lib.LibObfuscation; - -import java.lang.invoke.MethodHandle; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import static java.lang.invoke.MethodHandles.publicLookup; - -// MethodHandles for frequently reflected fields and methods. -// Handles suffixed with _getter and _setter are for fields, while those without suffixes are normal methods. -public final class MethodHandles { - - public static final MethodHandle - itemAge_getter, itemAge_setter, pickupDelay_getter, // EntityItem, pickup delay already has setter in vanilla - spawnRange_getter, spawnCount_getter, maxNearbyEntities_getter, - maxSpawnDelay_getter, minSpawnDelay_getter, - spawnDelay_getter, spawnDelay_setter, prevMobRotation_setter, mobRotation_setter, potentialSpawns_getter, - randomEntity_getter, isActivated; // MobSpawnerBaseLogic - - - static { - try { - Field f = ReflectionHelper.findField(EntityItem.class, LibObfuscation.AGE); - f.setAccessible(true); - itemAge_getter = publicLookup().unreflectGetter(f); - itemAge_setter = publicLookup().unreflectSetter(f); - - f = ReflectionHelper.findField(EntityItem.class, LibObfuscation.PICKUP_DELAY); - f.setAccessible(true); - pickupDelay_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.SPAWN_RANGE); - f.setAccessible(true); - spawnRange_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.SPAWN_COUNT); - f.setAccessible(true); - spawnCount_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.MAX_NEARBY_ENTITIES); - f.setAccessible(true); - maxNearbyEntities_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.MAX_SPAWN_DELAY); - f.setAccessible(true); - maxSpawnDelay_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.MIN_SPAWN_DELAY); - f.setAccessible(true); - minSpawnDelay_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.SPAWN_DELAY); - f.setAccessible(true); - spawnDelay_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.SPAWN_DELAY); - f.setAccessible(true); - spawnDelay_setter = publicLookup().unreflectSetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.PREV_MOB_ROTATION); - f.setAccessible(true); - prevMobRotation_setter = publicLookup().unreflectSetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.MOB_ROTATION); - f.setAccessible(true); - mobRotation_setter = publicLookup().unreflectSetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.POTENTIAL_ENTITY_SPAWNS); - f.setAccessible(true); - potentialSpawns_getter = publicLookup().unreflectGetter(f); - - f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.RANDOM_ENTITY); - f.setAccessible(true); - randomEntity_getter = publicLookup().unreflectGetter(f); - - Method m = ReflectionHelper.findMethod(MobSpawnerBaseLogic.class, null, LibObfuscation.IS_ACTIVATED); - m.setAccessible(true); - isActivated = publicLookup().unreflect(m); - } catch (Throwable t) { - Botania.LOGGER.fatal("Couldn't initialize methodhandles! Things will be broken!"); - t.printStackTrace(); - throw Throwables.propagate(t); - } - } - - private MethodHandles() {} -} diff --git a/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java b/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java index bdb9cdffa..590a82d36 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java +++ b/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java @@ -50,8 +50,8 @@ public class EntityMagicMissile extends EntityThrowable { } public EntityMagicMissile(EntityLivingBase thrower, boolean evil) { - this(thrower.world); - ReflectionHelper.setPrivateValue(EntityThrowable.class, this, thrower, LibObfuscation.THROWER); + super(thrower.world, thrower); + setSize(0F, 0F); setEvil(evil); } diff --git a/src/main/java/vazkii/botania/common/entity/EntityThrownItem.java b/src/main/java/vazkii/botania/common/entity/EntityThrownItem.java index 02248f0b6..99410b5f3 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityThrownItem.java +++ b/src/main/java/vazkii/botania/common/entity/EntityThrownItem.java @@ -19,7 +19,6 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.core.helper.Vector3; import javax.annotation.Nonnull; @@ -34,13 +33,7 @@ public class EntityThrownItem extends EntityItem { public EntityThrownItem(World world, double x, double y, double z, EntityItem item) { super(world, x, y, z, item.getItem()); - - int pickupDelay = 0; - try { - pickupDelay = (int) MethodHandles.pickupDelay_getter.invokeExact(item); - } catch (Throwable ignored) {} - - setPickupDelay(pickupDelay); + setPickupDelay(item.delayBeforeCanPickup); motionX = item.motionX; motionY = item.motionY; motionZ = item.motionZ; @@ -67,14 +60,7 @@ public class EntityThrownItem extends EntityItem { double d0 = 0.0D; for (Entity entity1 : list) { - int pickupDelay; - try { - pickupDelay = (int) MethodHandles.pickupDelay_getter.invokeExact(this); - } catch (Throwable ignored) { - continue; - } - - if (entity1.canBeCollidedWith() && (!(entity1 instanceof EntityPlayer) || pickupDelay == 0)) { + if (entity1.canBeCollidedWith() && (!(entity1 instanceof EntityPlayer) || delayBeforeCanPickup == 0)) { float f = 1.0F; AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f, f, f); RayTraceResult RayTraceResult1 = axisalignedbb.calculateIntercept(vec3, vec31); diff --git a/src/main/java/vazkii/botania/common/item/ItemCraftingHalo.java b/src/main/java/vazkii/botania/common/item/ItemCraftingHalo.java index c53331898..eaf9b476f 100644 --- a/src/main/java/vazkii/botania/common/item/ItemCraftingHalo.java +++ b/src/main/java/vazkii/botania/common/item/ItemCraftingHalo.java @@ -50,7 +50,6 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; import org.lwjgl.opengl.GL11; -import vazkii.botania.client.core.handler.ClientMethodHandles; import vazkii.botania.client.core.handler.ClientTickHandler; import vazkii.botania.client.gui.crafting.InventoryCraftingHalo; import vazkii.botania.client.lib.LibResources; @@ -411,16 +410,9 @@ public class ItemCraftingHalo extends ItemMod { Minecraft mc = Minecraft.getMinecraft(); Tessellator tess = Tessellator.getInstance(); - double renderPosX, renderPosY, renderPosZ; - - try { - renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager()); - } catch (Throwable t) { - t.printStackTrace(); - return; - } + double renderPosX = mc.getRenderManager().renderPosX; + double renderPosY = mc.getRenderManager().renderPosY; + double renderPosZ = mc.getRenderManager().renderPosZ; GlStateManager.pushMatrix(); GlStateManager.enableBlend(); diff --git a/src/main/java/vazkii/botania/common/item/ItemVirus.java b/src/main/java/vazkii/botania/common/item/ItemVirus.java index d0085005a..4df876a8e 100644 --- a/src/main/java/vazkii/botania/common/item/ItemVirus.java +++ b/src/main/java/vazkii/botania/common/item/ItemVirus.java @@ -95,7 +95,7 @@ public class ItemVirus extends ItemMod { IAttributeInstance health = attributes.getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH); health.applyModifier(new AttributeModifier("Ermergerd Virus D:", health.getBaseValue(), 0)); - IAttributeInstance jumpHeight = attributes.getAttributeInstance(ReflectionHelper.getPrivateValue(AbstractHorse.class, null, LibObfuscation.HORSE_JUMP_STRENGTH)); + IAttributeInstance jumpHeight = attributes.getAttributeInstance(AbstractHorse.JUMP_STRENGTH); jumpHeight.applyModifier(new AttributeModifier("Ermergerd Virus D:", jumpHeight.getBaseValue() * 0.5, 0)); newHorse.playSound(SoundEvents.ENTITY_ZOMBIE_VILLAGER_CURE, 1.0F + living.world.rand.nextFloat(), living.world.rand.nextFloat() * 0.7F + 1.3F); diff --git a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemDivaCharm.java b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemDivaCharm.java index 9c98fe237..e3606a852 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemDivaCharm.java +++ b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemDivaCharm.java @@ -63,7 +63,7 @@ public class ItemDivaCharm extends ItemBauble implements IManaUsingItem, IBauble if(mobs.size() > 1) { if(SubTileHeiseiDream.brainwashEntity((EntityLiving) event.getEntityLiving(), (List) mobs)) { if(event.getEntityLiving() instanceof EntityCreeper) - ReflectionHelper.setPrivateValue(EntityCreeper.class, (EntityCreeper) event.getEntityLiving(), 2, LibObfuscation.TIME_SINCE_IGNITED); + ((EntityCreeper) event.getEntityLiving()).timeSinceIgnited = 2; event.getEntityLiving().heal(event.getEntityLiving().getMaxHealth()); if(event.getEntityLiving().isDead) event.getEntityLiving().isDead = false; diff --git a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemSuperLavaPendant.java b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemSuperLavaPendant.java index 56977b350..91e8e8d4b 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemSuperLavaPendant.java +++ b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemSuperLavaPendant.java @@ -21,14 +21,12 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.relauncher.ReflectionHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import vazkii.botania.api.item.IBaubleRender; import vazkii.botania.client.core.handler.MiscellaneousIcons; import vazkii.botania.client.core.helper.IconHelper; import vazkii.botania.common.lib.LibItemNames; -import vazkii.botania.common.lib.LibObfuscation; public class ItemSuperLavaPendant extends ItemBauble implements IBaubleRender { @@ -37,17 +35,13 @@ public class ItemSuperLavaPendant extends ItemBauble implements IBaubleRender { } @Override - public void onWornTick(ItemStack stack, EntityLivingBase player) { - setImmunity(player, true); + public void onWornTick(ItemStack stack, EntityLivingBase living) { + living.isImmuneToFire = true; } @Override - public void onUnequipped(ItemStack stack, EntityLivingBase player) { - setImmunity(player, false); - } - - private void setImmunity(Entity entity, boolean immune) { - ReflectionHelper.setPrivateValue(Entity.class, entity, immune, LibObfuscation.IS_IMMUNE_TO_FIRE); + public void onUnequipped(ItemStack stack, EntityLivingBase living) { + living.isImmuneToFire = false; } @Override diff --git a/src/main/java/vazkii/botania/common/item/relic/ItemAesirRing.java b/src/main/java/vazkii/botania/common/item/relic/ItemAesirRing.java index c2ec871b7..e229e0e09 100644 --- a/src/main/java/vazkii/botania/common/item/relic/ItemAesirRing.java +++ b/src/main/java/vazkii/botania/common/item/relic/ItemAesirRing.java @@ -25,7 +25,6 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import vazkii.botania.api.item.IWireframeCoordinateListProvider; -import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.lib.LibItemNames; @@ -56,17 +55,8 @@ public class ItemAesirRing extends ItemRelicBauble implements IWireframeCoordina entity.motionX = event.getEntityItem().motionX; entity.motionY = event.getEntityItem().motionY; entity.motionZ = event.getEntityItem().motionZ; - - try { - MethodHandles.itemAge_setter.invokeExact(entity, MethodHandles.itemAge_getter.invokeExact(entity)); - } catch (Throwable ignored) {} - - int pickupDelay = 0; - try { - pickupDelay = (int) MethodHandles.pickupDelay_getter.invokeExact(event.getEntityItem()); - } catch (Throwable ignored) {} - entity.setPickupDelay(pickupDelay); - + entity.age = event.getEntityItem().age; + entity.setPickupDelay(event.getEntityItem().delayBeforeCanPickup); entity.world.spawnEntity(entity); } } diff --git a/src/main/java/vazkii/botania/common/item/relic/ItemInfiniteFruit.java b/src/main/java/vazkii/botania/common/item/relic/ItemInfiniteFruit.java index 22c189289..f64183e60 100644 --- a/src/main/java/vazkii/botania/common/item/relic/ItemInfiniteFruit.java +++ b/src/main/java/vazkii/botania/common/item/relic/ItemInfiniteFruit.java @@ -70,7 +70,7 @@ public class ItemInfiniteFruit extends ItemRelic implements IManaUsingItem { if(count == 5) if(player.canEat(false)) - ReflectionHelper.setPrivateValue(EntityLivingBase.class, player, 20, LibObfuscation.ITEM_IN_USE_COUNT); + player.activeItemStackUseCount = 20; } } diff --git a/src/main/java/vazkii/botania/common/lib/LibObfuscation.java b/src/main/java/vazkii/botania/common/lib/LibObfuscation.java index 2c5ab2754..0792ef4f9 100644 --- a/src/main/java/vazkii/botania/common/lib/LibObfuscation.java +++ b/src/main/java/vazkii/botania/common/lib/LibObfuscation.java @@ -11,74 +11,6 @@ package vazkii.botania.common.lib; public final class LibObfuscation { - - // RenderManager - public static final String[] RENDERPOSX = { "renderPosX", "field_78725_b", "o" }; - public static final String[] RENDERPOSY = { "renderPosY", "field_78726_c", "p" }; - public static final String[] RENDERPOSZ = { "renderPosZ", "field_78723_d", "q" }; - - // EntityItem - public static final String[] AGE = { "age", "field_70292_b", "d" }; - public static final String[] PICKUP_DELAY = { "delayBeforeCanPickup", "field_145804_b", "e" }; - - // EntityAINearestAttackableTarget - public static final String[] TARGET_CLASS = { "targetClass", "field_75307_b", "a" }; - public static final String[] TARGET_ENTITY_SELECTOR = { "targetEntitySelector", "field_82643_g", "c" }; - - // EntityAIAvoidEntity - public static final String[] TARGET_ENTITY_CLASS = { "classToAvoid", "field_181064_i", "i" }; - - // EntityCreeper - public static final String[] TIME_SINCE_IGNITED = { "timeSinceIgnited", "field_70833_d", "bw" }; - - // Entity - public static final String[] IS_IMMUNE_TO_FIRE = { "isImmuneToFire", "field_70178_ae", "Y" }; - - // ItemBlockSpecial - public static final String[] REED_ITEM = { "block", "field_150935_a", "a" }; - - // EntityAnimal - public static final String[] IN_LOVE = { "inLove", "field_70881_d", "bv" }; - - // EntityLivingBase - public static final String[] ITEM_IN_USE_COUNT = { "activeItemStackUseCount", "field_184628_bn", "bn" }; - - // AbstractHorse - public static final String[] HORSE_JUMP_STRENGTH = { "JUMP_STRENGTH", "field_110271_bv", "bw" }; - - // PlayerControllerMP - public static final String[] NET_CLIENT_HANDLER = { "connection", "field_78774_b", "b" }; - - // MobSpawnerBaseLogic - public static final String[] IS_ACTIVATED = { "isActivated" ,"func_98279_f", "h" }; - public static final String[] SPAWN_RANGE = { "spawnRange", "field_98290_m", "l" }; - public static final String[] SPAWN_COUNT = { "spawnCount", "field_98294_i", "h" }; - public static final String[] MAX_NEARBY_ENTITIES = { "maxNearbyEntities", "field_98292_k", "j" }; - public static final String[] MAX_SPAWN_DELAY = { "maxSpawnDelay", "field_98293_h", "g" }; - public static final String[] MIN_SPAWN_DELAY = { "minSpawnDelay", "field_98283_g", "f" }; - public static final String[] POTENTIAL_ENTITY_SPAWNS = { "potentialSpawns", "field_98285_e", "b" }; - public static final String[] SPAWN_DELAY = { "spawnDelay", "field_98286_b", "a" }; - public static final String[] PREV_MOB_ROTATION = { "prevMobRotation", "field_98284_d", "e" }; - public static final String[] MOB_ROTATION = { "mobRotation", "field_98287_c", "d" }; - public static final String[] RANDOM_ENTITY = { "randomEntity", "field_98282_f", "c" }; - - // GuiIngame - public static final String[] REMAINING_HIGHLIGHT_TICKS = { "remainingHighlightTicks", "field_92017_k", "q" }; - - // EntityThrowable - public static final String[] THROWER = { "thrower", "field_70192_c", "h" }; - - // GuiChat - public static final String[] INPUT_FIELD = { "inputField", "field_146415_a", "a" }; - // todo 1.9+ public static final String[] COMPLETE_FLAG = { "waitingOnAutocomplete", "field_146414_r", "r" }; - // Entityliving public static final String[] GET_LIVING_SOUND = { "getAmbientSound", "func_184639_G", "G" }; - - // RenderGlobal - public static final String[] STAR_GL_CALL_LIST = { "starGLCallList", "field_72772_v", "p" }; - public static final String[] STAR_VBO = { "starVBO", "field_175013_s", "t" }; - public static final String[] GL_SKY_LIST = { "glSkyList", "field_72771_w", "q" }; - public static final String[] SKY_VBO = { "skyVBO", "field_175012_t", "u" }; - } diff --git a/src/main/resources/META-INF/botania_at.cfg b/src/main/resources/META-INF/botania_at.cfg new file mode 100644 index 000000000..19c6edbec --- /dev/null +++ b/src/main/resources/META-INF/botania_at.cfg @@ -0,0 +1,43 @@ +public net.minecraft.client.renderer.entity.RenderManager field_78725_b # renderPosX +public net.minecraft.client.renderer.entity.RenderManager field_78726_c # renderPosY +public net.minecraft.client.renderer.entity.RenderManager field_78723_d # renderPosZ + +public net.minecraft.client.renderer.RenderGlobal field_72772_v # starGLCallList +public net.minecraft.client.renderer.RenderGlobal field_175013_s # starVBO +public net.minecraft.client.renderer.RenderGlobal field_72771_w # glSkyList +public net.minecraft.client.renderer.RenderGlobal field_175012_t # skyVBO + +public net.minecraft.entity.item.EntityItem field_70292_b # age +public net.minecraft.entity.item.EntityItem field_145804_b # delayBeforeCanPickup + +public-f net.minecraft.entity.ai.EntityAINearestAttackableTarget field_75307_b # targetClass +public-f net.minecraft.entity.ai.EntityAINearestAttackableTarget field_82643_g # targetEntitySelector + +public-f net.minecraft.entity.ai.EntityAIAvoidEntity field_181064_i # classToAvoid + +public net.minecraft.entity.monster.EntityCreeper field_70833_d # timeSinceIgnited + +public net.minecraft.entity.Entity field_70178_ae # isImmuneToFire + +public net.minecraft.entity.passive.EntityAnimal field_70881_d # inLove + +public net.minecraft.entity.EntityLivingBase field_184628_bn # activeItemStackUseCount + +public net.minecraft.entity.passive.AbstractHorse field_110271_bv # JUMP_STRENGTH + +public net.minecraft.tileentity.MobSpawnerBaseLogic func_98279_f()Z # isActivated +public net.minecraft.tileentity.MobSpawnerBaseLogic func_98273_j()V # resetTimer +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98290_m # spawnRange +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98294_i # spawnCount +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98292_k # maxNearbyEntities +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98293_h # maxSpawnDelay +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98283_g # minSpawnDelay +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98285_e # potentialSpawns +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98286_b # spawnDelay +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98284_d # prevMobRotation +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98287_c # mobRotation +public net.minecraft.tileentity.MobSpawnerBaseLogic field_98282_f # spawnData + +public net.minecraft.client.gui.GuiIngame field_92017_k # remainingHighlightTicks + +public net.minecraft.client.gui.GuiChat field_146415_a # inputField