Skip to content

Commit

Permalink
clean up reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Jul 22, 2022
1 parent 3c12845 commit 5747b45
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 98 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ apiPackage =

# Specify the configuration file for Forge's access transformers here. I must be placed into /src/main/resources/META-INF/
# Example value: mymodid_at.cfg
accessTransformersFile =
accessTransformersFile = ae2fc_at.cfg

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor {
private static final String CRAFTMODE_CRFTING = "1";
private static final String CRAFTMODE_PROCESSING = "0";

public final FCBasePartContainer container;
public FCBasePartContainer container;

private GuiTabButton tabCraftButton;
private GuiTabButton tabProcessButton;
Expand All @@ -44,7 +44,7 @@ public GuiBaseFluidPatternTerminal(final InventoryPlayer inventoryPlayer, final
{
super( inventoryPlayer, te, new FCBasePartContainer( inventoryPlayer, te ) );
this.container = (FCBasePartContainer) this.inventorySlots;
Ae2ReflectClient.setReservedSpace(this, 81);
setReservedSpace(81);
}

@Override
Expand Down Expand Up @@ -137,7 +137,7 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
}

super.drawFG( offsetX, offsetY, mouseX, mouseY );
this.fontRendererObj.drawString(StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL), 8, this.ySize - 96 + 2 - Ae2ReflectClient.getReservedSpace(this), 4210752 );
this.fontRendererObj.drawString(StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL), 8, this.ySize - 96 + 2 - getReservedSpace(), 4210752 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GuiBaseFluidPatternTerminalEx(final InventoryPlayer inventoryPlayer, fina
{
super( inventoryPlayer, te, new FCBasePartContainerEx( inventoryPlayer, te ) );
this.container = (FCBasePartContainerEx) this.inventorySlots;
Ae2ReflectClient.setReservedSpace(this, 81);
setReservedSpace(81);
}

@Override
Expand Down Expand Up @@ -106,7 +106,7 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
}

super.drawFG( offsetX, offsetY, mouseX, mouseY );
this.fontRendererObj.drawString( StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL_EX), 8, this.ySize - 96 + 2 - Ae2ReflectClient.getReservedSpace(this), 4210752 );
this.fontRendererObj.drawString( StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL_EX), 8, this.ySize - 96 + 2 - getReservedSpace(), 4210752 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
private final boolean viewCell;
private final ItemStack[] myCurrentViewCells = new ItemStack[5];
public FCBaseMonitorContain monitorableContainer;
private GuiTabButton craftingStatusBtn;
public GuiTabButton craftingStatusBtn;
private GuiImgButton craftingStatusImgBtn;
private FCGuiTextField searchField;
private int perRow = 9;
Expand Down Expand Up @@ -711,12 +711,12 @@ public void updateSetting( final IConfigManager manager, final Enum settingName,
this.repo.updateView();
}

int getReservedSpace()
public int getReservedSpace()
{
return this.reservedSpace;
}

void setReservedSpace( final int reservedSpace )
public void setReservedSpace( final int reservedSpace )
{
this.reservedSpace = reservedSpace;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public GuiFluidPatternTerminal(InventoryPlayer inventoryPlayer, ITerminalHost te
ContainerFluidPatternTerminal container = new ContainerFluidPatternTerminal(inventoryPlayer, te);
container.setGui(this);
this.inventorySlots = container;
Ae2ReflectClient.setGuiContainer(this, container);
this.container = container;
this.monitorableContainer = container;
this.configSrc = container.getConfigManager();
}

@Override
public void initGui() {
super.initGui();
craftingStatusBtn = Ae2ReflectClient.getCraftingStatusButton(this);
craftingStatusBtn = super.craftingStatusBtn;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public GuiFluidPatternTerminalEx(InventoryPlayer inventoryPlayer, ITerminalHost
@Override
public void initGui() {
super.initGui();
craftingStatusBtn = Ae2ReflectClient.getCraftingStatusButton(this);
craftingStatusBtn = super.craftingStatusBtn;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
import com.glodblock.github.inventory.FluidConvertingInventoryCrafting;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.SetBackedMachineSet;
import com.glodblock.github.util.Util;
import com.google.common.collect.Sets;
Expand All @@ -33,7 +32,7 @@
public class CoreModHooks {

public static InventoryCrafting wrapCraftingBuffer(InventoryCrafting inv) {
return new FluidConvertingInventoryCrafting(Ae2Reflect.getCraftContainer(inv), Ae2Reflect.getCraftWidth(inv), inv.getSizeInventory()/Ae2Reflect.getCraftWidth(inv));
return new FluidConvertingInventoryCrafting(inv.eventHandler, inv.inventoryWidth, inv.getSizeInventory()/inv.inventoryWidth);
}

public static IAEItemStack wrapFluidPacketStack(IAEItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void addRegion(int x, int y, int width, int height, Handler handler) {
}

public boolean onClick(int mX, int mY, int button) {
mX -= Ae2ReflectClient.getGuiLeft(gui);
mY -= Ae2ReflectClient.getGuiTop(gui);
mX -= gui.guiLeft;
mY -= gui.guiTop;
for (Region region : regions) {
if (region.containsMouse(mX, mY) && region.handler.onClick(button)) {
gui.mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1F));
Expand All @@ -34,8 +34,8 @@ public boolean onClick(int mX, int mY, int button) {
}

public void render(int mX, int mY) {
mX -= Ae2ReflectClient.getGuiLeft(gui);
mY -= Ae2ReflectClient.getGuiTop(gui);
mX -= gui.guiLeft;
mY -= gui.guiTop;
for (Region region : regions) {
if (region.containsMouse(mX, mY)) {
List<String> tooltip = region.handler.getTooltip();
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/com/glodblock/github/util/Ae2Reflect.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,20 @@
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.storage.IMEInventory;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.implementations.GuiCraftingStatus;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.render.AppEngRenderItem;
import appeng.container.implementations.ContainerUpgradeable;
import appeng.container.implementations.CraftingCPURecord;
import appeng.me.storage.MEInventoryHandler;
import appeng.me.storage.MEPassThrough;
import appeng.util.inv.ItemSlot;
import appeng.util.prioitylist.IPartitionList;
import com.glodblock.github.client.gui.GuiBaseFluidPatternTerminal;
import com.glodblock.github.client.gui.GuiFCBaseMonitor;
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class Ae2Reflect {

private static final Field fInventory_container;
private static final Field fInventory_containerUpgrade;
private static final Field fInventory_width;
private static final Field fAEPass_internal;
private static final Field fAEInv_partitionList;
private static final Field fCPU_cpu;
Expand All @@ -43,9 +27,7 @@ public class Ae2Reflect {

static {
try {
fInventory_container = reflectField(InventoryCrafting.class, "eventHandler", "field_70465_c", "c");
fInventory_containerUpgrade = reflectField(ContainerUpgradeable.class, "upgradeable");
fInventory_width = reflectField(InventoryCrafting.class, "inventoryWidth", "field_70464_b", "b");
fAEPass_internal = reflectField(MEPassThrough.class, "internal");
fAEInv_partitionList = reflectField(MEInventoryHandler.class, "myPartitionList");
fCPU_cpu = Ae2Reflect.reflectField(CraftingCPURecord.class, "cpu");
Expand Down Expand Up @@ -104,14 +86,6 @@ public static IMEInventory<?> getInternal(MEPassThrough<?> me) {
return Ae2Reflect.readField(me, fAEPass_internal);
}

public static Container getCraftContainer(InventoryCrafting inv) {
return Ae2Reflect.readField(inv, fInventory_container);
}

public static int getCraftWidth(InventoryCrafting inv) {
return Ae2Reflect.readField(inv, fInventory_width);
}

public static void setItemSlotExtractable(ItemSlot slot, boolean extractable) {
try {
mItemSlot_setExtractable.invoke(slot, extractable);
Expand Down
54 changes: 0 additions & 54 deletions src/main/java/com/glodblock/github/util/Ae2ReflectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
import appeng.client.gui.implementations.GuiCraftingStatus;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.render.AppEngRenderItem;
import com.glodblock.github.client.gui.GuiBaseFluidPatternTerminal;
import com.glodblock.github.client.gui.GuiFCBaseMonitor;
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

Expand All @@ -23,34 +19,18 @@ public class Ae2ReflectClient {

private static final Field fAEBaseGui_stackSizeRenderer;
private static final Field fGuiCraftingStatus_originalGuiBtn;
private static final Field fGuiPatternTerm_container;
private static final Field fGuiCPUStatus_icon;
private static final Field fGuiMEMonitorable_monitorableContainer;
private static final Field fGuiMEMonitorable_configSrc;
private static final Field fGuiMEMonitorable_craftingStatusBtn;
private static final Field fGuiContainer_guiLeft;
private static final Field fGuiContainer_guiTop;
private static final Field fGui_drag;
private static final Method mGuiPatternTerm_inventorySlots;
private static final Method mGuiPatternTerm_reservedSpace;
private static final Method mGuiPatternTerm_reservedSpaceSetter;


static {
try {
fAEBaseGui_stackSizeRenderer = Ae2Reflect.reflectField(AEBaseGui.class, "aeRenderItem");
fGuiCraftingStatus_originalGuiBtn = Ae2Reflect.reflectField(GuiCraftingStatus.class, "originalGuiBtn");
fGuiPatternTerm_container = Ae2Reflect.reflectField(GuiBaseFluidPatternTerminal.class, "container");
fGuiMEMonitorable_monitorableContainer = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "monitorableContainer");
fGuiMEMonitorable_configSrc = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "configSrc");
fGuiMEMonitorable_craftingStatusBtn = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "craftingStatusBtn");
fGuiCPUStatus_icon = Ae2Reflect.reflectField(GuiCraftingStatus.class, "myIcon");
fGuiContainer_guiLeft = Ae2Reflect.reflectField(GuiContainer.class, "guiLeft", "field_147003_i", "i");
fGuiContainer_guiTop = Ae2Reflect.reflectField(GuiContainer.class, "guiTop", "field_147009_r", "r");
fGui_drag = Ae2Reflect.reflectField(AEBaseGui.class, "drag_click");
mGuiPatternTerm_inventorySlots = Ae2Reflect.reflectMethod(AEBaseGui.class, "getInventorySlots");
mGuiPatternTerm_reservedSpace = Ae2Reflect.reflectMethod(GuiFCBaseMonitor.class, "getReservedSpace");
mGuiPatternTerm_reservedSpaceSetter = Ae2Reflect.reflectMethod(GuiFCBaseMonitor.class, "setReservedSpace", int.class);
} catch (NoSuchFieldException | NoSuchMethodException e) {
throw new IllegalStateException("Failed to initialize AE2 reflection hacks!", e);
}
Expand All @@ -73,30 +53,6 @@ public static Set<Slot> getDragClick(AEBaseGui gui) {
return Ae2Reflect.readField(gui, fGui_drag);
}

public static int getGuiLeft(GuiContainer gui) {
return Ae2Reflect.readField(gui, fGuiContainer_guiLeft);
}

public static int getGuiTop(GuiContainer gui) {
return Ae2Reflect.readField(gui, fGuiContainer_guiTop);
}

public static void setReservedSpace(GuiFCBaseMonitor gui, int size) {
try {
mGuiPatternTerm_reservedSpaceSetter.invoke(gui, size);
} catch (Exception e) {
throw new IllegalStateException("Failed to invoke method: " + mGuiPatternTerm_reservedSpaceSetter, e);
}
}

public static int getReservedSpace(GuiFCBaseMonitor gui) {
try {
return (int) mGuiPatternTerm_reservedSpace.invoke(gui);
} catch (Exception e) {
throw new IllegalStateException("Failed to invoke method: " + mGuiPatternTerm_reservedSpace, e);
}
}

public static AppEngRenderItem getStackSizeRenderer(AEBaseGui gui) {
return Ae2Reflect.readField(gui, fAEBaseGui_stackSizeRenderer);
}
Expand All @@ -105,14 +61,4 @@ public static GuiTabButton getOriginalGuiButton(GuiCraftingStatus gui) {
return Ae2Reflect.readField(gui, fGuiCraftingStatus_originalGuiBtn);
}

public static void setGuiContainer(GuiBaseFluidPatternTerminal instance, ContainerFluidPatternTerminal container) {
Ae2Reflect.writeField(instance, fGuiPatternTerm_container, container);
Ae2Reflect.writeField(instance, fGuiMEMonitorable_monitorableContainer, container);
Ae2Reflect.writeField(instance, fGuiMEMonitorable_configSrc, container.getConfigManager());
}

public static GuiTabButton getCraftingStatusButton(GuiFCBaseMonitor gui) {
return Ae2Reflect.readField(gui, fGuiMEMonitorable_craftingStatusBtn);
}

}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/ae2fc_at.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public net.minecraft.inventory.InventoryCrafting field_70465_c # eventHandler
public net.minecraft.inventory.InventoryCrafting field_70464_b # inventoryWidth

public net.minecraft.client.gui.inventory.GuiContainer field_147003_i # guiLeft
public net.minecraft.client.gui.inventory.GuiContainer field_147009_r # guiTop

0 comments on commit 5747b45

Please sign in to comment.