From 49646337b3cd18a4e05ac95b9b1e8c90391e90df Mon Sep 17 00:00:00 2001 From: Kogepan229 Date: Thu, 30 Oct 2025 15:30:04 +0900 Subject: [PATCH] Universal Gui --- .../gui/GuiWirelessCraftingTerminal.java | 748 ++------------- .../client/gui/WCTPrimaryGui.java | 27 + .../common/WCTGuiHandler.java | 11 +- .../ContainerWirelessCraftingTerminal.java | 893 +----------------- .../sync/packets/PacketInventoryAction.java | 26 +- .../core/sync/packets/PacketNEIRecipe.java | 4 +- .../helpers/WTCGuiObject.java | 27 + .../items/ItemMagnet.java | 6 +- .../items/ItemWirelessCraftingTerminal.java | 10 + .../proxy/CommonProxy.java | 2 +- 10 files changed, 165 insertions(+), 1589 deletions(-) create mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTPrimaryGui.java create mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WTCGuiObject.java diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index b16c97b..b96072d 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -1,342 +1,112 @@ package net.p455w0rd.wirelesscraftingterminal.client.gui; -import java.io.IOException; -import java.lang.reflect.Field; -import java.text.NumberFormat; -import java.util.List; -import java.util.Locale; - -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTrashButton; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotTrash; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketEmptyTrash; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - import appeng.api.config.ActionItems; -import appeng.api.config.SearchBoxMode; import appeng.api.config.Settings; -import appeng.api.config.TerminalFontSize; -import appeng.api.config.TerminalStyle; -import appeng.api.config.YesNo; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IDisplayRepo; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.client.ActionKey; -import appeng.client.gui.AEBaseGui; +import appeng.client.gui.implementations.GuiMEMonitorable; +import appeng.client.gui.slots.VirtualMEPinSlot; import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiScrollbar; import appeng.client.gui.widgets.GuiTabButton; -import appeng.client.gui.widgets.ISortSource; -import appeng.client.gui.widgets.MEGuiTextField; -import appeng.client.me.InternalSlotME; -import appeng.client.me.ItemRepo; -import appeng.client.me.SlotME; -import appeng.container.AEBaseContainer; import appeng.container.slot.AppEngSlot; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotFakeCraftingMatrix; -import appeng.core.AEConfig; -import appeng.core.CommonHelper; -import appeng.core.localization.ButtonToolTips; import appeng.core.localization.GuiText; +import appeng.helpers.ICraftingTerminal; import appeng.helpers.InventoryAction; -import appeng.util.IConfigManagerHost; -import appeng.util.Platform; -import codechicken.nei.TextField; -import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Optional; -import cpw.mods.fml.relauncher.ReflectionHelper; import yalter.mousetweaks.api.IMTModGuiContainer; @Optional.Interface(modid = "MouseTweaks", iface = "yalter.mousetweaks.api.IMTModGuiContainer") -public class GuiWirelessCraftingTerminal extends AEBaseGui - implements ISortSource, IConfigManagerHost, IMTModGuiContainer { +public class GuiWirelessCraftingTerminal extends GuiMEMonitorable implements IMTModGuiContainer { private float xSize_lo; private float ySize_lo; - public static int tick = 0, GUI_HEIGHT = 240, GUI_WIDTH = 230, AE_ROW_HEIGHT = 18, AE_NUM_ROWS = 0, - GUI_UPPER_HEIGHT = 35, GUI_SEARCH_ROW = 35, SEARCH_X = 80, SEARCH_Y = 4, SEARCH_WIDTH = 88, - SEARCH_HEIGHT = 12, SEARCH_MAXCHARS = 15, GUI_LOWER_HEIGHT, AE_TOTAL_ROWS_HEIGHT, - BUTTON_SEARCH_MODE_POS_X = -18, BUTTON_SEARCH_MODE_POS_Y = 68, BUTTON_SIZE = 16, NEI_EXTRA_SPACE = 30, - slotYOffset; - protected static final int BUTTON_SEARCH_MODE_ID = 5; - protected static final long TOOLTIP_UPDATE_INTERVAL = 3000L; - private int currScreenWidth, currScreenHeight; - private static final String bgTexturePath = "gui/crafting_viewcell.png"; + + final ResourceLocation BackgroundTexture = new ResourceLocation( + Reference.MODID, + "textures/gui/crafting_viewcell.png"); private final ContainerWirelessCraftingTerminal containerWCT; - private boolean isFullScreen, init = true, reInit, wasResized = false; - public static GuiWirelessCraftingTerminal INSTANCE; - private static boolean switchingGuis; public static int craftingGridOffsetX = 80; public static int craftingGridOffsetY; - private static String memoryText = ""; - private final IDisplayRepo repo; - private final int offsetX = 8; - private final IConfigManager configSrc; + private GuiTabButton craftingStatusBtn; - private MEGuiTextField searchField; - private int perRow = 9; - private boolean customSortOrder = true; - private GuiImgButton ViewBox; - private GuiImgButton SortByBox; - private GuiImgButton SortDirBox; - private GuiImgButton searchBoxSettings; private GuiImgButton clearBtn; private GuiTrashButton trashBtn; - private GuiImgButton terminalStyleBox; - private GuiImgButton searchStringSave; - private boolean isAutoFocus = false; + private int currentMouseX = 0; private int currentMouseY = 0; - public boolean devicePowered = false; - private boolean isNEIEnabled; - private boolean wasTextboxFocused = false; - private int screenResTicks = 0; - private int reservedSpace = 0; - private int maxRows = Integer.MAX_VALUE; - private int standardSize; private final int lowerTextureOffset = 0; - private int rows = 0; - private final ItemStack[] myCurrentViewCells = new ItemStack[5]; - public GuiWirelessCraftingTerminal(Container container) { - super(container); - GuiWirelessCraftingTerminal.INSTANCE = this; - this.xSize = GUI_WIDTH; - this.ySize = GUI_HEIGHT; - this.standardSize = this.xSize; + public GuiWirelessCraftingTerminal(final InventoryPlayer inventoryPlayer, ICraftingTerminal host) { + super(inventoryPlayer, host, new ContainerWirelessCraftingTerminal(inventoryPlayer, host)); this.setReservedSpace(73); - this.containerWCT = (ContainerWirelessCraftingTerminal) container; - this.setScrollBar(new GuiScrollbar()); - this.repo = new ItemRepo(getScrollBar(), this); - this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager(); - this.devicePowered = containerWCT.isPowered(); + this.offsetRepoX -= 1; + + this.containerWCT = (ContainerWirelessCraftingTerminal) this.inventorySlots; ((ContainerWirelessCraftingTerminal) this.inventorySlots).setGui(this); } - public void postUpdate(final List list) { - for (final IAEItemStack is : list) { - this.repo.postUpdate(is); - } - this.repo.updateView(); - this.setScrollBar(); - } - - private void setScrollBar() { - this.getScrollBar().setTop(18).setLeft(174).setHeight(this.rows * 18 - 2); - this.getScrollBar().setRange( - 0, - (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, - Math.max(1, this.rows / 6)); - } - - @SuppressWarnings("rawtypes") @Override protected void actionPerformed(final GuiButton btn) { - if (btn == this.craftingStatusBtn) { - NetworkHandler.instance.sendToServer(new PacketSwitchGuis(Reference.GUI_CRAFTING_STATUS)); - } - - if (btn instanceof GuiImgButton) { - final boolean backwards = Mouse.isButtonDown(1); - - final GuiImgButton iBtn = (GuiImgButton) btn; - if (iBtn.getSetting() != Settings.ACTIONS) { - final Enum cv = iBtn.getCurrentValue(); - final Enum next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); - - if (btn == this.terminalStyleBox) { - AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); - } - if (btn == this.searchBoxSettings) { - AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); - } else if (btn == this.searchStringSave) { - AEConfig.instance.preserveSearchBar = next == YesNo.YES; - } else { - try { - NetworkHandler.instance - .sendToServer(new PacketValueConfig(iBtn.getSetting().name(), next.name())); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - - iBtn.set(next); - - if (next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class) { - this.reinitalize(); + // if (btn == this.craftingStatusBtn) { + // NetworkHandler.instance.sendToServer(new PacketSwitchGuis(Reference.GUI_CRAFTING_STATUS)); + // } else + if (this.clearBtn == btn) { + Slot s = null; + final Container c = this.inventorySlots; + for (final Object j : c.inventorySlots) { + if (j instanceof SlotCraftingMatrix) { + s = (Slot) j; } } - if (this.clearBtn == btn) { - Slot s = null; - final Container c = this.inventorySlots; - for (final Object j : c.inventorySlots) { - if (j instanceof SlotCraftingMatrix) { - s = (Slot) j; - } - } - if (s != null) { - final PacketInventoryAction p = new PacketInventoryAction( - InventoryAction.MOVE_REGION, - s.slotNumber, - 0); - NetworkHandler.instance.sendToServer(p); - } - } - } - if (btn instanceof GuiTrashButton) { - if (this.trashBtn == btn) { - Slot s = null; - final Container c = this.inventorySlots; - for (final Object j : c.inventorySlots) { - if (j instanceof SlotTrash) { - s = (Slot) j; - } - } - - if (s != null) { - if (s.getHasStack()) { - containerWCT.trashSlot.clearStack(); - NetworkHandler.instance.sendToServer(new PacketEmptyTrash()); - } - } - } - } - } - - @Override - protected void handleMouseClick(Slot slot, int slotIdx, int ctrlDown, int mouseButton) { - // Handle autocraft requests ourselves to spawn the right GUI classes - final EntityPlayer player = Minecraft.getMinecraft().thePlayer; - - if (slot instanceof SlotME) { - InventoryAction action = null; - IAEItemStack stack = null; - - switch (mouseButton) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - stack = ((SlotME) slot).getAEStack(); - - if (stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN - && stack.getStackSize() == 0 - && player.inventory.getItemStack() == null) { - action = InventoryAction.AUTO_CRAFT; - } - - break; - case 3: // creative dupe: - stack = ((SlotME) slot).getAEStack(); - if (stack != null && stack.isCraftable()) { - action = InventoryAction.AUTO_CRAFT; - } - break; - default: - } - if (action == InventoryAction.AUTO_CRAFT) { - ((AEBaseContainer) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction( - action, - this.inventorySlots.inventorySlots.size(), - 0); + if (s != null) { + final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); NetworkHandler.instance.sendToServer(p); - return; } + } else if (this.trashBtn == btn) { + Slot s = null; + final Container c = this.inventorySlots; + for (final Object j : c.inventorySlots) { + if (j instanceof SlotTrash) { + s = (Slot) j; + } + } + + if (s != null) { + if (s.getHasStack()) { + containerWCT.trashSlot.clearStack(); + NetworkHandler.instance.sendToServer(new PacketEmptyTrash()); + } + } + } else { + super.actionPerformed(btn); } - super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); - } - - private void reinitalize() { - this.buttonList.clear(); - this.initGui(); - } - - int getReservedSpace() { - return this.reservedSpace; - } - - void setReservedSpace(final int reservedSpace) { - this.reservedSpace = reservedSpace; - } - - public int getStandardSize() { - return this.standardSize; - } - - void setStandardSize(final int standardSize) { - this.standardSize = standardSize; } /** * Initializes the GUI */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "unchecked" }) @Override public void initGui() { super.initGui(); - Keyboard.enableRepeatEvents(true); - this.maxRows = this.getMaxRows(); - this.perRow = AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL ? 9 - : 9 + ((this.width - this.standardSize) / 18); - this.isNEIEnabled = Loader.isModLoaded("NotEnoughItems"); - int top = isNEIEnabled ? 22 : 0; - final int magicNumber = 114 + 1; - final int extraSpace = this.height - magicNumber - top - this.reservedSpace; - this.rows = (int) Math.floor(extraSpace / 18); - if (this.rows > this.maxRows) { - top += (this.rows - this.maxRows) * 18 / 2; - this.rows = this.maxRows; - } - - if (isNEIEnabled) { - this.rows--; - } - - if (this.rows < 3) { - this.rows = 3; - } - - this.getMeSlots().clear(); - for (int y = 0; y < this.rows; y++) { - for (int x = 0; x < this.perRow; x++) { - this.getMeSlots() - .add(new InternalSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18)); - } - } - if (AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL) { - this.xSize = this.standardSize + ((this.perRow - 9) * 18); - } else { - this.xSize = this.standardSize; - } - super.initGui(); - - this.ySize = magicNumber + this.rows * 18 + this.reservedSpace; - final int unusedSpace = this.height - this.ySize; - this.guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f)); - int offset = this.guiTop + 8; - - this.buttonList.clear(); this.buttonList.add( this.clearBtn = new GuiImgButton( this.guiLeft + 134, @@ -345,58 +115,6 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui ActionItems.STASH)); this.buttonList.add(this.trashBtn = new GuiTrashButton(this.guiLeft + 98, this.guiTop + this.ySize - 104)); this.clearBtn.setHalfSize(true); - if (this.customSortOrder) { - this.buttonList.add( - this.SortByBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SORT_BY, - this.configSrc.getSetting(Settings.SORT_BY))); - offset += 20; - } - - this.buttonList.add( - this.ViewBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.VIEW_MODE, - this.configSrc.getSetting(Settings.VIEW_MODE))); - offset += 20; - - this.buttonList.add( - this.SortDirBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SORT_DIRECTION, - this.configSrc.getSetting(Settings.SORT_DIRECTION))); - offset += 20; - - this.buttonList.add( - this.searchBoxSettings = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SEARCH_MODE, - AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE))); - offset += 20; - - this.buttonList.add( - this.searchStringSave = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SAVE_SEARCH, - AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO)); - offset += 20; - - this.buttonList.add( - this.terminalStyleBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.TERMINAL_STYLE, - AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); - - this.searchField = new MEGuiTextField(SEARCH_WIDTH, SEARCH_HEIGHT); - this.searchField.x = SEARCH_X; - this.searchField.y = SEARCH_Y; this.buttonList.add( this.craftingStatusBtn = new GuiTabButton( @@ -407,20 +125,6 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui itemRender)); this.craftingStatusBtn.setHideEdge(13); - final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); - this.isAutoFocus = SearchBoxMode.AUTOSEARCH == searchMode || SearchBoxMode.NEI_AUTOSEARCH == searchMode; - - this.searchField.setFocused(this.isAutoFocus); - - if (AEConfig.instance.preserveSearchBar || this.isSubGui()) { - this.searchField.setText(memoryText); - this.repo.setSearchString(memoryText); - } - if (this.isSubGui()) { - this.repo.updateView(); - this.setScrollBar(); - } - craftingGridOffsetX = Integer.MAX_VALUE; craftingGridOffsetY = Integer.MAX_VALUE; @@ -441,83 +145,6 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui } } - int getMaxRows() { - return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL ? 6 - : Integer.MAX_VALUE; - } - - protected void repositionSlot(final AppEngSlot s) { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 5; - } - - /** - * Called every tick. It is used in this instance to detect screen size changes to automatically update the gui - * height. - *

- * reInit variable is used to call initGui() on the next tick. It has to be called this way to update correctly. - * - * @author p455w0rd - */ - @Override - public void updateScreen() { - this.devicePowered = containerWCT.isPowered(); - this.repo.setPowered(devicePowered); - - super.updateScreen(); - if (this.init) { - this.currScreenWidth = this.mc.displayWidth; - this.currScreenHeight = this.mc.displayHeight; - this.isFullScreen = this.mc.isFullScreen(); - this.reInit = true; - this.init = false; - } - ++screenResTicks; - if (screenResTicks == 20) { - this.wasTextboxFocused = this.searchField.isFocused(); - screenResTicks = 0; - } - if (this.reInit) { - if (tick != 1) { - tick++; - } else { - this.initGui(); - this.setScrollBar(); - if (this.wasResized) { - this.searchField.setFocused(this.wasTextboxFocused); - this.searchField.setText(this.repo.getSearchString()); - this.wasTextboxFocused = false; - this.wasResized = false; - } - this.reInit = false; - tick = 0; - } - } - if (hasScreenResChanged()) { - this.reInit = true; - this.wasResized = true; - } - if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) { - this.mc.thePlayer.closeScreen(); - } - } - - /** - * Detects if the window has been resized - * - * @return True if window has been resized - * @author p455w0rd - */ - private boolean hasScreenResChanged() { - if ((this.currScreenWidth != this.mc.displayWidth) || (this.currScreenHeight != this.mc.displayHeight) - || (this.isFullScreen != this.mc.isFullScreen())) { - this.currScreenWidth = this.mc.displayWidth; - this.currScreenHeight = this.mc.displayHeight; - this.isFullScreen = this.mc.isFullScreen(); - return true; - } - return false; - } - /** * Draws the screen and tooltips. */ @@ -529,22 +156,21 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui } public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { + String s = LocaleHandler.WirelessTermLabel.getLocal(); this.mc.fontRenderer.drawString(s, 7, 5, 4210752); this.mc.fontRenderer.drawString(I18n.format("container.inventory"), 7, this.ySize - 172 + 3, 4210752); - if (this.searchField != null) { - this.searchField.drawTextBox(); - } + + VirtualMEPinSlot.drawSlotsBackground(this.pinSlots, this.mc, this.zLevel); this.currentMouseX = mouseX; this.currentMouseY = mouseY; } public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.bindMyTexture(bgTexturePath); - final int x_width = 199; - // draw "over inventory area" + this.mc.getTextureManager().bindTexture(BackgroundTexture); + final int x_width = 199; this.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18); for (int x = 0; x < this.rows; x++) { @@ -558,9 +184,9 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui 0, 106 - 18 - 18, x_width, - 99 + this.reservedSpace - this.lowerTextureOffset); + 99 + this.getReservedSpace() - this.lowerTextureOffset); - // draw view cells + // draw view cells background this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 32, 104); if (Reference.WCT_BOOSTER_ENABLED) { @@ -574,275 +200,9 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, this.mc.thePlayer); - boolean update = false; - for (int i = 0; i < 5; i++) { - if (myCurrentViewCells[i] != containerWCT.getCellViewSlot(i).getStack()) { - update = true; - myCurrentViewCells[i] = containerWCT.getCellViewSlot(i).getStack(); - } - } + this.searchField.drawTextBox(); - if (update) { - repo.setViewCell(myCurrentViewCells); - } - } - - @SuppressWarnings("rawtypes") - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - - if (!this.isAutoFocus) { - this.searchField.mouseClicked(xCoord - this.guiLeft, yCoord - this.guiTop, btn); - } - - if (btn == 1 && this.searchField.isMouseIn(xCoord - this.guiLeft, yCoord - this.guiTop)) { - this.searchField.setText(""); - this.repo.setSearchString(""); - this.repo.updateView(); - this.setScrollBar(); - } - - super.mouseClicked(xCoord, yCoord, btn); - } - - @Override - public void onGuiClosed() { - super.onGuiClosed(); - Keyboard.enableRepeatEvents(false); - if (this.searchField.getText() != null) { - memoryText = this.searchField.getText(); - } - } - - protected boolean enableSpaceClicking() { - return true; - } - - @Override - protected void keyTyped(final char character, final int key) { - if (!this.checkHotbarKeys(key)) { - if (isNEIFocused()) { - return; - } - - if (CommonHelper.proxy.isActionKey(ActionKey.TOGGLE_FOCUS, key)) { - this.searchField.setFocused(!this.searchField.isFocused()); - return; - } - - if (this.searchField.isFocused() && key == Keyboard.KEY_RETURN) { - this.searchField.setFocused(false); - return; - } - - if (character == ' ' && this.searchField.getText().isEmpty()) { - return; - } - - final boolean mouseInGui = this - .isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); - if (this.isAutoFocus && !this.searchField.isFocused() && mouseInGui) { - this.searchField.setFocused(true); - } - - if (this.searchField.textboxKeyTyped(character, key)) { - this.repo.setSearchString(this.searchField.getText()); - this.repo.updateView(); - this.setScrollBar(); - } else { - super.keyTyped(character, key); - } - } - } - - @Override - public void handleKeyboardInput() { - super.handleKeyboardInput(); - - // Pause the terminal when holding shift - this.repo.setPaused(hasShiftDown()); - } - - private boolean hasShiftDown() { - return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); - } - - protected boolean isPowered() { - return this.repo.hasPower(); - } - - public void bindMyTexture(final String file) { - final ResourceLocation loc = new ResourceLocation(Reference.MODID, "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - public List handleItemTooltip(final ItemStack stack, final int mouseX, final int mouseY, - final List currentToolTip) { - if (stack != null) { - final Slot s = this.getSlot(mouseX, mouseY); - if (s instanceof SlotME) { - final int BigNumber = AEConfig.instance.getTerminalFontSize() == TerminalFontSize.SMALL ? 9999 : 999; - - IAEItemStack myStack = null; - - try { - final SlotME theSlotField = (SlotME) s; - myStack = theSlotField.getAEStack(); - } catch (final Throwable ignore) {} - - if (myStack != null) { - if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { - final String local = ButtonToolTips.ItemsStored.getLocal(); - final String formattedAmount = NumberFormat.getNumberInstance(Locale.US) - .format(myStack.getStackSize()); - final String format = String.format(local, formattedAmount); - - currentToolTip.add("\u00a77" + format); - } - - if (myStack.getCountRequestable() > 0) { - final String local = ButtonToolTips.ItemsRequestable.getLocal(); - final String formattedAmount = NumberFormat.getNumberInstance(Locale.US) - .format(myStack.getCountRequestable()); - final String format = String.format(local, formattedAmount); - - currentToolTip.add("\u00a77" + format); - } - } else if (stack.stackSize > BigNumber || (stack.stackSize > 1 && stack.isItemDamaged())) { - final String local = ButtonToolTips.ItemsStored.getLocal(); - final String formattedAmount = NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize); - final String format = String.format(local, formattedAmount); - - currentToolTip.add("\u00a77" + format); - } - } - } - return currentToolTip; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void renderToolTip(final ItemStack stack, final int x, final int y) { - final Slot s = this.getSlot(x, y); - if (s instanceof SlotME && stack != null) { - final int BigNumber = AEConfig.instance.getTerminalFontSize() == TerminalFontSize.SMALL ? 9999 : 999; - - IAEItemStack myStack = null; - - try { - final SlotME theSlotField = (SlotME) s; - myStack = theSlotField.getAEStack(); - } catch (final Throwable ignore) {} - - if (myStack != null) { - final List currentToolTip = stack - .getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); - - if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { - currentToolTip.add( - "Items Stored: " - + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize())); - } - - if (myStack.getCountRequestable() > 0) { - currentToolTip.add( - "Items Requestable: " - + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable())); - } - - this.drawTooltip(x, y, 0, join(currentToolTip, "\n")); - } else if (stack.stackSize > BigNumber) { - final List var4 = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); - var4.add("Items Stored: " + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize)); - this.drawTooltip(x, y, 0, join(var4, "\n")); - return; - } - } - super.renderToolTip(stack, x, y); - // super.drawItemStackTooltip( stack, x, y ); - } - - @SuppressWarnings("rawtypes") - @Override - public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) { - if (this.SortByBox != null) { - this.SortByBox.set(this.configSrc.getSetting(Settings.SORT_BY)); - } - - if (this.SortDirBox != null) { - this.SortDirBox.set(this.configSrc.getSetting(Settings.SORT_DIRECTION)); - } - - if (this.ViewBox != null) { - this.ViewBox.set(this.configSrc.getSetting(Settings.VIEW_MODE)); - } - - this.repo.updateView(); - this.setScrollBar(); - } - - public boolean isCustomSortOrder() { - return this.customSortOrder; - } - - void setCustomSortOrder(final boolean customSortOrder) { - this.customSortOrder = customSortOrder; - } - - @SuppressWarnings("rawtypes") - @Override - public Enum getSortBy() { - return this.configSrc.getSetting(Settings.SORT_BY); - } - - @SuppressWarnings("rawtypes") - @Override - public Enum getSortDir() { - return this.configSrc.getSetting(Settings.SORT_DIRECTION); - } - - @SuppressWarnings("rawtypes") - @Override - public Enum getSortDisplay() { - return this.configSrc.getSetting(Settings.VIEW_MODE); - } - - public boolean isOverSearchField(int x, int y) { - return searchField.isMouseIn(x - guiLeft, y - guiTop); - } - - public void setSearchString(String memoryText) { - this.searchField.setText(memoryText); - this.repo.setSearchString(memoryText); - this.repo.updateView(); - this.setScrollBar(); - } - - @SuppressWarnings("SameParameterValue") - protected boolean isPointInRegion(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY) { - int i = this.guiLeft; - int j = this.guiTop; - pointX -= i; - pointY -= j; - return pointX >= rectX - 1 && pointX < rectX + rectWidth + 1 - && pointY >= rectY - 1 - && pointY < rectY + rectHeight + 1; - } - - private boolean isNEIFocused() { - if (!Loader.isModLoaded("NotEnoughItems")) { - return false; - } - try { - final Class c = ReflectionHelper - .getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); - final Field fldSearchField = c.getField("searchField"); - final TextField searchField = (TextField) fldSearchField.get(c); - return searchField.focused(); - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); - } - return false; + this.updateViewCells(); } // MouseTweaks compat diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTPrimaryGui.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTPrimaryGui.java new file mode 100644 index 0000000..778ea9f --- /dev/null +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTPrimaryGui.java @@ -0,0 +1,27 @@ +package net.p455w0rd.wirelesscraftingterminal.client.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; + +import appeng.container.PrimaryGui; + +public class WCTPrimaryGui extends PrimaryGui { + + public WCTPrimaryGui(Object gui, ItemStack guiIcon, TileEntity te, ForgeDirection side) { + super(gui, guiIcon, te, side); + } + + @Override + public void open(EntityPlayer player) { + WCTGuiHandler.launchGui( + (int) this.gui, + player, + player.worldObj, + (int) player.posX, + (int) player.posY, + (int) player.posZ); + } +} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java index cd2d0d2..bdad6bd 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java @@ -14,7 +14,7 @@ import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConf import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerMagnet; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; +import net.p455w0rd.wirelesscraftingterminal.helpers.WTCGuiObject; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import appeng.api.AEApi; @@ -40,7 +40,7 @@ public class WCTGuiHandler implements IGuiHandler { return null; } - final WirelessTerminalGuiObject term = new WirelessTerminalGuiObject( + final WTCGuiObject term = new WTCGuiObject( wh, RandomUtils.getWirelessTerm(player.inventory), player, @@ -51,7 +51,7 @@ public class WCTGuiHandler implements IGuiHandler { return switch (guiId) { case Reference.GUI_WCT -> updateGui( - new ContainerWirelessCraftingTerminal(player, player.inventory), + new ContainerWirelessCraftingTerminal(player.inventory, term), world, x, y, @@ -92,7 +92,7 @@ public class WCTGuiHandler implements IGuiHandler { final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) AEApi.instance().registries().wireless() .getWirelessTerminalHandler(RandomUtils.getWirelessTerm(player.inventory)); if (wh != null) { - final WirelessTerminalGuiObject obj = new WirelessTerminalGuiObject( + final WTCGuiObject obj = new WTCGuiObject( wh, RandomUtils.getWirelessTerm(player.inventory), player, @@ -104,8 +104,7 @@ public class WCTGuiHandler implements IGuiHandler { final IPortableCell terminal = obj; if (guiId == Reference.GUI_WCT) { - return new GuiWirelessCraftingTerminal( - new ContainerWirelessCraftingTerminal(player, player.inventory)); + return new GuiWirelessCraftingTerminal(player.inventory, obj); } if (guiId == Reference.GUI_CRAFTING_STATUS) { diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java index 1f5637a..a74e22f 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java @@ -1,17 +1,9 @@ package net.p455w0rd.wirelesscraftingterminal.common.container; -import java.io.IOException; -import java.nio.BufferOverflowException; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - import javax.annotation.Nonnull; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; @@ -22,11 +14,10 @@ import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; +import net.p455w0rd.wirelesscraftingterminal.client.gui.WCTPrimaryGui; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotArmor; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotBooster; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotMagnet; @@ -38,68 +29,33 @@ import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryMagnet import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryTrash; import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryViewCell; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventoryUpdate; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; -import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; +import net.p455w0rd.wirelesscraftingterminal.helpers.WTCGuiObject; import net.p455w0rd.wirelesscraftingterminal.items.ItemInfinityBooster; import net.p455w0rd.wirelesscraftingterminal.items.ItemMagnet; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.tiles.IViewCellStorage; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.IActionHost; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.client.me.InternalSlotME; -import appeng.client.me.SlotME; -import appeng.container.AEBaseContainer; import appeng.container.ContainerNull; -import appeng.container.slot.AppEngCraftingSlot; +import appeng.container.ContainerOpenContext; +import appeng.container.PrimaryGui; +import appeng.container.implementations.ContainerMEMonitorable; import appeng.container.slot.AppEngSlot; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotCraftingTerm; import appeng.container.slot.SlotDisabled; -import appeng.container.slot.SlotFake; import appeng.container.slot.SlotInaccessible; import appeng.container.slot.SlotPlayerHotBar; import appeng.container.slot.SlotPlayerInv; -import appeng.core.AEConfig; -import appeng.core.localization.PlayerMessages; import appeng.helpers.IContainerCraftingPacket; -import appeng.helpers.InventoryAction; +import appeng.helpers.ICraftingTerminal; +import appeng.helpers.IPrimaryGuiIconProvider; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.IAEAppEngInventory; import appeng.tile.inventory.InvOperation; -import appeng.util.ConfigManager; -import appeng.util.IConfigManagerHost; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.AdaptorPlayerHand; -public class ContainerWirelessCraftingTerminal extends AEBaseContainer - implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IAEAppEngInventory, - IContainerCraftingPacket, IViewCellStorage { +public class ContainerWirelessCraftingTerminal extends ContainerMEMonitorable + implements IAEAppEngInventory, IContainerCraftingPacket, IViewCellStorage { private final ItemStack containerstack; public final WCTInventoryCrafting craftingGrid; @@ -109,7 +65,6 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer public final WCTInventoryTrash trashInventory; public final InventoryPlayer inventoryPlayer; public ItemStack[] craftMatrixInventory; - private final World worldObj; private final EntityPlayer player; public static final int HOTBAR_START = 2, HOTBAR_END = HOTBAR_START + 8, INV_START = HOTBAR_END + 1, INV_END = INV_START + 26, ARMOR_START = INV_END + 1, ARMOR_END = ARMOR_START + 3, @@ -126,21 +81,11 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer private final SlotCraftingTerm craftingSlot; private final SlotViewCell[] viewCellSlot; public SlotTrash trashSlot; - private int firstCraftingSlotNumber = -1, lastCraftingSlotNumber = -1; - private final WirelessTerminalGuiObject obj; - private double powerMultiplier = 0.5; - private final IPortableCell civ; - private int ticks = 0; - private final IMEMonitor monitor; - private final IItemList items = AEApi.instance().storage().createItemList(); - private final IConfigManager clientCM; - private IConfigManager serverCM; + private final ICraftingTerminal ct; - private IConfigManagerHost gui; private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1); private final IWirelessCraftingTerminalItem thisItem; - private final IGridNode networkNode; private IRecipe currentRecipe; /** @@ -148,20 +93,11 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer * * @author p455w0rd */ - public ContainerWirelessCraftingTerminal(EntityPlayer player, InventoryPlayer inventoryPlayer) { - super( - inventoryPlayer, - getGuiObject( - RandomUtils.getWirelessTerm(inventoryPlayer), - player, - player.worldObj, - (int) player.posX, - (int) player.posY, - (int) player.posZ)); - this.clientCM = new ConfigManager(this); - this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME); - this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); + public ContainerWirelessCraftingTerminal(InventoryPlayer inventoryPlayer, ICraftingTerminal host) { + super(inventoryPlayer, host, false); + final EntityPlayer player = inventoryPlayer.player; + this.ct = host; + this.setCustomName("WCTContainer"); this.boosterInventory = new WCTInventoryBooster(RandomUtils.getWirelessTerm(inventoryPlayer)); @@ -169,7 +105,6 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer this.trashInventory = new WCTInventoryTrash(RandomUtils.getWirelessTerm(inventoryPlayer)); this.containerstack = RandomUtils.getWirelessTerm(inventoryPlayer); this.thisItem = (IWirelessCraftingTerminalItem) this.containerstack.getItem(); - this.worldObj = player.worldObj; this.craftingGrid = new WCTInventoryCrafting(this, 3, 3, containerstack); this.viewCellInventory = new WCTInventoryViewCell(RandomUtils.getWirelessTerm(inventoryPlayer)); this.inventoryPlayer = inventoryPlayer; @@ -181,33 +116,6 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer craftMatrixSlot = new SlotCraftingMatrix[9]; viewCellSlot = new SlotViewCell[5]; - this.obj = getGuiObject( - containerstack, - player, - worldObj, - (int) player.posX, - (int) player.posY, - (int) player.posZ); - this.civ = this.obj; - final IGridNode node = ((IGridHost) this.obj).getGridNode(ForgeDirection.UNKNOWN); - this.networkNode = node; - - if (Platform.isServer()) { - this.serverCM = civ.getConfigManager(); - this.monitor = civ.getItemInventory(); - if (this.monitor != null) { - this.monitor.addListener(this, null); - setCellInventory(this.monitor); - if (civ instanceof IPortableCell) { - setPowerSource(this.civ); - } - } else { - this.setValidContainer(false); - } - } else { - this.monitor = null; - } - // Dummy slot at index 0 to work around ME slots all having their slot number set to 0. this.addSlotToContainer(new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, -1000, -1000)); @@ -261,19 +169,15 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer 80 + j * 18, (i * 18) - 76); this.addSlotToContainer(craftMatrixSlot[k]); - if (k == 0) { - this.firstCraftingSlotNumber = craftMatrixSlot[k].slotNumber; - } k++; } } - this.lastCraftingSlotNumber = craftMatrixSlot[8].slotNumber; craftingSlot = new SlotCraftingTerm( this.getPlayerInv().player, this.getActionSource(), this.getPowerSource(), - this.obj, + this.ct, this.craftingGrid, this.craftingGrid, this.output, @@ -349,318 +253,6 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer writeToNBT("crafting"); } - @Override - public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slot, final long id) { - if (slot >= 0 && slot < this.inventorySlots.size()) { - final Slot s = this.getSlot(slot); - - if (s instanceof SlotCraftingTerm) { - switch (action) { - case CRAFT_SHIFT: - case CRAFT_ITEM: - case CRAFT_STACK: - ((SlotCraftingTerm) s).doClick(action, player); - this.updateHeld(player); - break; - default: - break; - } - } - - if (s instanceof SlotFake) { - final ItemStack hand = player.inventory.getItemStack(); - - switch (action) { - case PICKUP_OR_SET_DOWN: - if (hand == null) { - s.putStack(null); - } else { - s.putStack(hand.copy()); - } - - break; - case PLACE_SINGLE: - if (hand != null) { - final ItemStack is = hand.copy(); - is.stackSize = 1; - s.putStack(is); - } - - break; - case SPLIT_OR_PLACE_SINGLE: - ItemStack is = s.getStack(); - if (is != null) { - if (hand == null) { - is.stackSize--; - } else if (hand.isItemEqual(is)) { - is.stackSize = Math.min(is.getMaxStackSize(), is.stackSize + 1); - } else { - is = hand.copy(); - is.stackSize = 1; - } - - s.putStack(is); - } else if (hand != null) { - is = hand.copy(); - is.stackSize = 1; - s.putStack(is); - } - - break; - case CREATIVE_DUPLICATE: - case MOVE_REGION: - case SHIFT_CLICK: - default: - break; - } - } - - if (action == InventoryAction.MOVE_REGION) { - final List from = new LinkedList(); - - for (final Object j : this.inventorySlots) { - if (j instanceof Slot && j.getClass() == s.getClass()) { - from.add((Slot) j); - } - } - - for (final Slot fr : from) { - this.transferStackInSlot(player, fr.slotNumber); - } - } - - return; - } - - // get target item. - final IAEItemStack slotItem = getTargetStack(); - - switch (action) { - case SHIFT_CLICK: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (slotItem != null) { - IAEItemStack ais = slotItem.copy(); - ItemStack myItem = ais.getItemStack(); - - ais.setStackSize(myItem.getMaxStackSize()); - - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN); - myItem.stackSize = (int) ais.getStackSize(); - myItem = adp.simulateAdd(myItem); - - if (myItem != null) { - ais.setStackSize(ais.getStackSize() - myItem.stackSize); - } - - ais = Platform.poweredExtraction( - this.getPowerSource(), - this.getCellInventory(), - ais, - this.getActionSource()); - if (ais != null) { - adp.addItems(ais.getItemStack()); - } - } - break; - case ROLL_DOWN: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - final int releaseQty = 1; - final ItemStack isg = player.inventory.getItemStack(); - - if (isg != null && releaseQty > 0) { - IAEItemStack ais = AEApi.instance().storage().createItemStack(isg); - ais.setStackSize(1); - final IAEItemStack extracted = ais.copy(); - - ais = Platform - .poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais == null) { - final InventoryAdaptor ia = new AdaptorPlayerHand(player); - - final ItemStack fail = ia.removeItems(1, extracted.getItemStack(), null); - if (fail == null) { - this.getCellInventory() - .extractItems(extracted, Actionable.MODULATE, this.getActionSource()); - } - - this.updateHeld(player); - } - } - - break; - case ROLL_UP: - case PICKUP_SINGLE: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (slotItem != null) { - int liftQty = 1; - final ItemStack item = player.inventory.getItemStack(); - - if (item != null) { - if (item.stackSize >= item.getMaxStackSize()) { - liftQty = 0; - } - if (!Platform.isSameItemPrecise(slotItem.getItemStack(), item)) { - liftQty = 0; - } - } - - if (liftQty > 0) { - IAEItemStack ais = slotItem.copy(); - ais.setStackSize(1); - ais = Platform.poweredExtraction( - this.getPowerSource(), - this.getCellInventory(), - ais, - this.getActionSource()); - if (ais != null) { - final InventoryAdaptor ia = new AdaptorPlayerHand(player); - - final ItemStack fail = ia.addItems(ais.getItemStack()); - if (fail != null) { - this.getCellInventory().injectItems(ais, Actionable.MODULATE, this.getActionSource()); - } - - this.updateHeld(player); - } - } - } - break; - case PICKUP_OR_SET_DOWN: - if (getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (player.inventory.getItemStack() == null) { - if (slotItem != null) { - IAEItemStack ais = slotItem.copy(); - ais.setStackSize(ais.getItemStack().getMaxStackSize()); - ais = Platform.poweredExtraction( - this.getPowerSource(), - this.getCellInventory(), - ais, - this.getActionSource()); - if (ais != null) { - player.inventory.setItemStack(ais.getItemStack()); - } else { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - } else { - IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); - ais = Platform - .poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais != null) { - player.inventory.setItemStack(ais.getItemStack()); - } else { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - - break; - case SPLIT_OR_PLACE_SINGLE: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (player.inventory.getItemStack() == null) { - if (slotItem != null) { - IAEItemStack ais = slotItem.copy(); - final long maxSize = ais.getItemStack().getMaxStackSize(); - ais.setStackSize(maxSize); - ais = this.getCellInventory().extractItems(ais, Actionable.SIMULATE, this.getActionSource()); - - if (ais != null) { - final long stackSize = Math.min(maxSize, ais.getStackSize()); - ais.setStackSize((stackSize + 1) >> 1); - ais = Platform.poweredExtraction( - this.getPowerSource(), - this.getCellInventory(), - ais, - this.getActionSource()); - } - - if (ais != null) { - player.inventory.setItemStack(ais.getItemStack()); - } else { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - } else { - IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); - ais.setStackSize(1); - ais = Platform - .poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais == null) { - final ItemStack is = player.inventory.getItemStack(); - is.stackSize--; - if (is.stackSize <= 0) { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - } - - break; - case CREATIVE_DUPLICATE: - if (player.capabilities.isCreativeMode && slotItem != null) { - final ItemStack is = slotItem.getItemStack(); - is.stackSize = is.getMaxStackSize(); - player.inventory.setItemStack(is); - this.updateHeld(player); - } - break; - case MOVE_REGION: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (slotItem != null) { - final int playerInv = 9 * 4; - for (int slotNum = 0; slotNum < playerInv; slotNum++) { - IAEItemStack ais = slotItem.copy(); - ItemStack myItem = ais.getItemStack(); - - ais.setStackSize(myItem.getMaxStackSize()); - - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN); - myItem.stackSize = (int) ais.getStackSize(); - myItem = adp.simulateAdd(myItem); - - if (myItem != null) { - ais.setStackSize(ais.getStackSize() - myItem.stackSize); - } - - ais = Platform.poweredExtraction( - this.getPowerSource(), - this.getCellInventory(), - ais, - this.getActionSource()); - if (ais != null) { - adp.addItems(ais.getItemStack()); - } else { - return; - } - } - } - - break; - default: - break; - } - } - private void updateCraftingMatrix() { if (!this.containerstack.hasTagCompound()) { this.containerstack.setTagCompound(new NBTTagCompound()); @@ -683,11 +275,6 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer // <3 } - @Override - public IGridNode getNetworkNode() { - return this.networkNode; - } - @Override public boolean useRealItems() { return true; @@ -724,115 +311,19 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return viewCellSlot[index]; } - public static WirelessTerminalGuiObject getGuiObject(final ItemStack it, final EntityPlayer player, final World w, - final int x, final int y, final int z) { + public static WTCGuiObject getGuiObject(final ItemStack it, final EntityPlayer player, final World w, final int x, + final int y, final int z) { if (it != null) { final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) AEApi.instance().registries() .wireless().getWirelessTerminalHandler(it); if (wh != null) { - return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z); + return new WTCGuiObject(wh, it, player, w, x, y, z); } } return null; } - @Override - public void detectAndSendChanges() { - // drain 1 ae t - this.ticks++; - if (this.ticks > 10) { - if (!isBoosterInstalled() || !Reference.WCT_BOOSTER_ENABLED) { - this.civ.extractAEPower( - this.getPowerMultiplier() * this.ticks, - Actionable.MODULATE, - PowerMultiplier.CONFIG); - } else { - this.civ.extractAEPower((int) (0.5 * this.ticks), Actionable.MODULATE, PowerMultiplier.CONFIG); - } - this.ticks = 0; - } - - if (Platform.isServer()) { - if (this.monitor != this.civ.getItemInventory()) { - this.setValidContainer(false); - } - - for (final Settings set : this.serverCM.getSettings()) { - final Enum sideLocal = this.serverCM.getSetting(set); - final Enum sideRemote = this.clientCM.getSetting(set); - - if (sideLocal != sideRemote) { - this.clientCM.putSetting(set, sideLocal); - for (final Object crafter : this.crafters) { - try { - NetworkHandler.instance.sendTo( - new PacketValueConfig(set.name(), sideLocal.name()), - (EntityPlayerMP) crafter); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - } - - if (!this.items.isEmpty()) { - try { - final IItemList monitorCache = this.monitor.getStorageList(); - - final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate(); - - for (final IAEItemStack is : this.items) { - final IAEItemStack send = monitorCache.findPrecise(is); - if (send == null) { - is.setStackSize(0); - piu.appendItem(is); - } else { - piu.appendItem(send); - } - } - - if (!piu.isEmpty()) { - this.items.resetStatus(); - - for (final Object c : this.crafters) { - if (c instanceof EntityPlayer) { - NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c); - } - } - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - if (!isInRange()) { - if (!isBoosterInstalled() || !Reference.WCT_BOOSTER_ENABLED) { - if (this.isValidContainer()) { - this.getPlayerInv().player.addChatMessage(PlayerMessages.OutOfRange.toChat()); - } - this.setValidContainer(false); - } - if (!networkIsPowered()) { - if (this.isValidContainer()) { - this.getPlayerInv().player - .addChatMessage(new ChatComponentText(LocaleHandler.NoNetworkPower.getLocal())); - } - this.setValidContainer(false); - } - } else if (!hasAccess(SecurityPermissions.CRAFT, true) || !hasAccess(SecurityPermissions.EXTRACT, true) - || !hasAccess(SecurityPermissions.INJECT, true)) { - if (this.isValidContainer()) { - this.getPlayerInv().player.addChatMessage(PlayerMessages.CommunicationError.toChat()); - } - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance.wireless_getDrainRate(this.obj.getRange())); - } - - super.detectAndSendChanges(); - } - public boolean isBoosterInstalled() { Slot slot = getSlotFromInventory(this.boosterInventory, 0); if (slot == null) { @@ -859,129 +350,11 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return false; } - protected boolean isInRange() { - return this.obj.rangeCheck(Reference.WCT_BOOSTER_ENABLED && this.isBoosterInstalled()); - } - - protected boolean networkIsPowered() { - final IActionHost host = this.getActionHost(); - if (host != null) { - final IGrid grid = this.obj.getTargetGrid(); - if (grid != null) { - final IEnergyGrid eg = grid.getCache(IEnergyGrid.class); - return eg.isNetworkPowered(); - } - } - return false; - } - - @Override - public IConfigManager getConfigManager() { - if (Platform.isServer()) { - return this.serverCM; - } - return this.clientCM; - } - - @SuppressWarnings("rawtypes") - @Override - public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) { - if (this.getGui() != null) { - this.getGui().updateSetting(manager, settingName, newValue); - } - } - - private IConfigManagerHost getGui() { - return this.gui; - } - - public void setGui(@Nonnull final IConfigManagerHost gui) { - this.gui = gui; - } - - @Override - public void onListUpdate() { - for (final Object c : this.crafters) { - if (c instanceof ICrafting) { - final ICrafting cr = (ICrafting) c; - this.queueInventory(cr); - } - } - } - - @Override - public void postChange(final IBaseMonitor monitor, final Iterable change, - final BaseActionSource source) { - for (final IAEItemStack is : change) { - this.items.add(is); - } - } - - @Override - public boolean isValid(final Object verificationToken) { - return true; - } - - @Override - public void onContainerClosed(final EntityPlayer player) { - super.onContainerClosed(player); - if (this.monitor != null) { - this.monitor.removeListener(this); - } - } - - @Override - public void addCraftingToCrafters(final ICrafting c) { - super.addCraftingToCrafters(c); - this.queueInventory(c); - } - - @Override - public void removeCraftingFromCrafters(final ICrafting c) { - super.removeCraftingFromCrafters(c); - - if (this.crafters.isEmpty() && this.monitor != null) { - this.monitor.removeListener(this); - } - } - - private void queueInventory(final ICrafting c) { - if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) { - try { - PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate(); - final IItemList monitorCache = this.monitor.getStorageList(); - - for (final IAEItemStack send : monitorCache) { - try { - piu.appendItem(send); - } catch (final BufferOverflowException boe) { - NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c); - - piu = new PacketMEInventoryUpdate(); - piu.appendItem(send); - } - } - - NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - public boolean isPowered() { double pwr = this.thisItem.getAECurrentPower(this.containerstack); return (pwr > 0.0); } - private double getPowerMultiplier() { - return this.powerMultiplier; - } - - void setPowerMultiplier(final double powerMultiplier) { - this.powerMultiplier = powerMultiplier; - } - /** * Fetches crafting matrix ItemStacks * @@ -1072,223 +445,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer } } - if (Platform.isClient()) { - return null; - } - - boolean hasMETiles = false; - for (final Object is : this.inventorySlots) { - if (is instanceof InternalSlotME) { - hasMETiles = true; - break; - } - } - - if (hasMETiles && Platform.isClient()) { - return null; - } - - if (clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible) { - return null; - } - if (clickSlot != null && clickSlot.getHasStack()) { - - final List selectedSlots = new ArrayList(); - - /** - * Gather a list of valid destinations. - */ - if (clickSlot.isPlayerSide()) { - tis = this.shiftStoreItem(tis); - - // target slots in the container... - for (final Object inventorySlot : this.inventorySlots) { - final AppEngSlot cs = (AppEngSlot) inventorySlot; - - if (!(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof AppEngCraftingSlot)) { - if (cs.isItemValid(tis)) { - selectedSlots.add(cs); - } - } - } - } else { - // target slots in the container... - for (final Object inventorySlot : this.inventorySlots) { - final AppEngSlot cs = (AppEngSlot) inventorySlot; - - if ((cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof AppEngCraftingSlot)) { - if (cs.isItemValid(tis)) { - selectedSlots.add(cs); - } - } - } - } - - /** - * Handle Fake Slot Shift clicking. - */ - if (selectedSlots.isEmpty() && clickSlot.isPlayerSide()) { - if (tis != null) { - // target slots in the container... - for (final Object inventorySlot : this.inventorySlots) { - final AppEngSlot cs = (AppEngSlot) inventorySlot; - final ItemStack destination = cs.getStack(); - - if (!(cs.isPlayerSide()) && cs instanceof SlotFake) { - if (Platform.isSameItemPrecise(destination, tis)) { - return null; - } else if (destination == null) { - cs.putStack(tis.copy()); - cs.onSlotChanged(); - this.updateSlot(cs); - return null; - } - } - } - } - } - - if (tis != null) { - // find partials.. - for (final Slot d : selectedSlots) { - if (d instanceof SlotDisabled || d instanceof SlotME) { - continue; - } - - if (d.isItemValid(tis)) { - if (d.getHasStack()) { - final ItemStack t = d.getStack(); - - if (Platform.isSameItemPrecise(tis, t)) // t.isItemEqual(tis)) - { - int maxSize = t.getMaxStackSize(); - if (maxSize > d.getSlotStackLimit()) { - maxSize = d.getSlotStackLimit(); - } - - int placeAble = maxSize - t.stackSize; - - if (tis.stackSize < placeAble) { - placeAble = tis.stackSize; - } - - t.stackSize += placeAble; - tis.stackSize -= placeAble; - - if (tis.stackSize <= 0) { - clickSlot.putStack(null); - d.onSlotChanged(); - - // if ( hasMETiles ) updateClient(); - - this.updateSlot(clickSlot); - this.updateSlot(d); - return null; - } else { - this.updateSlot(d); - } - } - } - } - } - - // any match.. - for (final Slot d : selectedSlots) { - if (d instanceof SlotDisabled || d instanceof SlotME) { - continue; - } - - if (d.isItemValid(tis)) { - if (d.getHasStack()) { - final ItemStack t = d.getStack(); - - if (Platform.isSameItemPrecise(t, tis)) { - int maxSize = t.getMaxStackSize(); - if (d.getSlotStackLimit() < maxSize) { - maxSize = d.getSlotStackLimit(); - } - - int placeAble = maxSize - t.stackSize; - - if (tis.stackSize < placeAble) { - placeAble = tis.stackSize; - } - - t.stackSize += placeAble; - tis.stackSize -= placeAble; - - if (tis.stackSize <= 0) { - clickSlot.putStack(null); - d.onSlotChanged(); - - // if ( worldEntity != null ) - // worldEntity.markDirty(); - // if ( hasMETiles ) updateClient(); - - this.updateSlot(clickSlot); - this.updateSlot(d); - return null; - } else { - this.updateSlot(d); - } - } - } else { - int maxSize = tis.getMaxStackSize(); - if (maxSize > d.getSlotStackLimit()) { - maxSize = d.getSlotStackLimit(); - } - - final ItemStack tmp = tis.copy(); - if (tmp.stackSize > maxSize) { - tmp.stackSize = maxSize; - } - - tis.stackSize -= tmp.stackSize; - d.putStack(tmp); - - if (tis.stackSize <= 0) { - clickSlot.putStack(null); - d.onSlotChanged(); - - // if ( worldEntity != null ) - // worldEntity.markDirty(); - // if ( hasMETiles ) updateClient(); - - this.updateSlot(clickSlot); - this.updateSlot(d); - return null; - } else { - this.updateSlot(d); - } - } - } - } - } - - clickSlot.putStack(tis != null ? tis.copy() : null); - } - - this.updateSlot(clickSlot); - return null; - } - - private void updateSlot(final Slot clickSlot) { - this.detectAndSendChanges(); - } - - private ItemStack shiftStoreItem(final ItemStack input) { - if (this.getPowerSource() == null || this.civ == null) { - return input; - } - final IAEItemStack ais = Platform.poweredInsert( - this.getPowerSource(), - this.civ, - AEApi.instance().storage().createItemStack(input), - this.getActionSource()); - if (ais == null) { - return null; - } - return ais.getItemStack(); + return super.transferStackInSlot(p, idx); } private boolean isInHotbar(@Nonnull int index) { @@ -1414,4 +571,14 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return flag1; } + + @Override + public PrimaryGui getPrimaryGui() { + ContainerOpenContext context = getOpenContext(); + return new WCTPrimaryGui( + Reference.GUI_WCT, + ((IPrimaryGuiIconProvider) ct).getPrimaryGuiIcon(), + context.getTile(), + context.getSide()); + } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java index 5c0f07f..db4eeed 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java @@ -15,7 +15,6 @@ import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import appeng.api.storage.data.IAEItemStack; import appeng.client.ClientHelper; import appeng.container.AEBaseContainer; -import appeng.container.ContainerOpenContext; import appeng.container.implementations.ContainerCraftAmount; import appeng.helpers.InventoryAction; import appeng.util.Platform; @@ -96,16 +95,8 @@ public class PacketInventoryAction extends WCTPacket { public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { final EntityPlayerMP sender = (EntityPlayerMP) player; Container baseContainer = sender.openContainer; - ContainerOpenContext context = null; - if (baseContainer instanceof AEBaseContainer) { - context = ((AEBaseContainer) baseContainer).getOpenContext(); - } if (this.action == InventoryAction.AUTO_CRAFT) { - // if( context != null ) - // { - // final TileEntity te = context.getTile(); - int x = (int) player.posX; int y = (int) player.posY; int z = (int) player.posZ; @@ -115,25 +106,20 @@ public class PacketInventoryAction extends WCTPacket { if (sender.openContainer instanceof ContainerCraftAmount) { final ContainerCraftAmount cca = (ContainerCraftAmount) sender.openContainer; - if (baseContainer instanceof ContainerWirelessCraftingTerminal) { - if (((ContainerWirelessCraftingTerminal) baseContainer).getTargetStack() != null) { - cca.getCraftingItem().putStack( - ((ContainerWirelessCraftingTerminal) baseContainer).getTargetStack().getItemStack()); - cca.setItemToCraft(((ContainerWirelessCraftingTerminal) baseContainer).getTargetStack()); + if (baseContainer instanceof ContainerWirelessCraftingTerminal container) { + if (container.getTargetStack() != null) { + cca.setItemToCraft(container.getTargetStack()); } } - if (baseContainer instanceof AEBaseContainer) { - if (((AEBaseContainer) baseContainer).getTargetStack() != null) { - cca.getCraftingItem() - .putStack(((AEBaseContainer) baseContainer).getTargetStack().getItemStack()); - cca.setItemToCraft(((AEBaseContainer) baseContainer).getTargetStack()); + if (baseContainer instanceof AEBaseContainer container) { + if (container.getTargetStack() != null) { + cca.setItemToCraft(container.getTargetStack()); } } cca.detectAndSendChanges(); } - // } } else { if (baseContainer instanceof ContainerWirelessCraftingTerminal) { if (RandomUtils.getWirelessTerm(player.inventory) == null) diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java index c43e7cc..ca490de 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java @@ -21,7 +21,7 @@ import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessC import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; +import net.p455w0rd.wirelesscraftingterminal.helpers.WTCGuiObject; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; @@ -93,7 +93,7 @@ public class PacketNEIRecipe extends WCTPacket { IGridNode node = cct.getNetworkNode(); if (node == null) { - WirelessTerminalGuiObject obj = ContainerWirelessCraftingTerminal.getGuiObject( + WTCGuiObject obj = ContainerWirelessCraftingTerminal.getGuiObject( RandomUtils.getWirelessTerm(player.inventory), player, player.worldObj, diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WTCGuiObject.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WTCGuiObject.java new file mode 100644 index 0000000..9d83430 --- /dev/null +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WTCGuiObject.java @@ -0,0 +1,27 @@ +package net.p455w0rd.wirelesscraftingterminal.helpers; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; + +import appeng.api.features.IWirelessTermHandler; +import appeng.api.networking.IGridNode; +import appeng.helpers.WirelessCraftingTerminalGuiObject; + +public class WTCGuiObject extends WirelessCraftingTerminalGuiObject implements WCTIActionHost { + + public WTCGuiObject(IWirelessTermHandler wh, ItemStack is, EntityPlayer ep, World w, int x, int y, int z) { + super(wh, is, ep, w, x, y, z); + } + + @Override + public IGridNode getActionableNode(boolean ignoreRange) { + IGridNode node = this.getActionableNode(); + if (node != null) return node; + if (ignoreRange && this.getGrid() != null) { + return this.getGrid().getPivot(); + } + return null; + } +} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java index 22569d2..36642f5 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java @@ -23,7 +23,7 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMagnetFilter; import net.p455w0rd.wirelesscraftingterminal.handlers.KeybindHandler; import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; +import net.p455w0rd.wirelesscraftingterminal.helpers.WTCGuiObject; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.apache.commons.lang3.text.WordUtils; @@ -54,7 +54,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class ItemMagnet extends Item { private int distanceFromPlayer; - public WirelessTerminalGuiObject obj; + public WTCGuiObject obj; public IPortableCell civ; public IEnergySource powerSrc; public IMEMonitor monitor; @@ -392,7 +392,7 @@ public class ItemMagnet extends Item { if (player.capabilities.isCreativeMode) { return true; } - final IGrid g = obj.getTargetGrid(); + final IGrid g = obj.getGrid(); if (g != null) { if (requirePower) { final IEnergyGrid eg = g.getCache(IEnergyGrid.class); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java index 4f6dbd9..7039ccb 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java @@ -216,6 +216,16 @@ public class ItemWirelessCraftingTerminal extends AERootPoweredItem return getAECurrentPower(is) >= amt; } + @Override + public boolean hasInfinityPower(ItemStack is) { + return false; + } + + @Override + public boolean hasInfinityRange(ItemStack is) { + return this.checkForBooster(is); + } + @Override public IConfigManager getConfigManager(final ItemStack target) { final ConfigManager out = new ConfigManager(new IConfigManagerHost() { diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java index 6f27369..0d9a657 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java @@ -225,7 +225,7 @@ public class CommonProxy { boolean ignoreRange = (magnet.isBoosterInstalled(WCTStack) && Reference.WCT_BOOSTER_ENABLED); boolean hasAxxess = magnet.hasNetworkAccess(SecurityPermissions.INJECT, true, player, WCTStack); - if ((ignoreRange && hasAxxess) || (magnet.obj.rangeCheck(false) && hasAxxess)) { + if ((ignoreRange && hasAxxess) || (magnet.obj.rangeCheck() && hasAxxess)) { if (magnet.isActivated(magnetStack)) { List filteredList = magnet.getFilteredItems(magnetStack); IAEItemStack ais = AEApi.instance().storage().createItemStack(stack);