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 81e4d9e..d10eb52 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -1,14 +1,20 @@ package net.p455w0rd.wirelesscraftingterminal.client.gui; -import appeng.api.config.*; +import appeng.api.config.ActionItems; +import appeng.api.config.SearchBoxMode; +import appeng.api.config.Settings; +import appeng.api.config.TerminalStyle; +import appeng.api.config.YesNo; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigurableObject; import appeng.client.ActionKey; +import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiScrollbar; import appeng.client.gui.widgets.ISortSource; -import appeng.client.gui.widgets.ITooltip; -import appeng.container.slot.SlotRestrictedInput; +import appeng.client.me.InternalSlotME; +import appeng.client.me.ItemRepo; import appeng.core.AEConfig; import appeng.core.CommonHelper; import appeng.core.localization.ButtonToolTips; @@ -17,100 +23,64 @@ import appeng.helpers.InventoryAction; import appeng.util.IConfigManagerHost; import appeng.util.Platform; import codechicken.nei.TextField; -import com.google.common.base.Joiner; -import com.google.common.base.Stopwatch; import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ObfuscationReflectionHelper; import cpw.mods.fml.relauncher.ReflectionHelper; -import java.io.IOException; -import java.lang.reflect.Field; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiInventory; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -import net.p455w0rd.wirelesscraftingterminal.api.WCTApi; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiScrollbar; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTrashButton; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.MEGuiTextField; -import net.p455w0rd.wirelesscraftingterminal.client.me.InternalSlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo; -import net.p455w0rd.wirelesscraftingterminal.client.me.SlotDisconnected; import net.p455w0rd.wirelesscraftingterminal.client.me.SlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.WCTRenderItem; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot.hasCalculatedValidness; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.OptionalSlotFake; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFakeCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotOutput; 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.PacketSwapSlots; 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.integration.IntegrationRegistry; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; -import net.p455w0rd.wirelesscraftingterminal.integration.abstraction.INEI; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSource, IConfigManagerHost { +import java.io.IOException; +import java.lang.reflect.Field; +import java.text.NumberFormat; +import java.util.List; +import java.util.Locale; + +public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSource, IConfigManagerHost { 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 = 81, - SEARCH_Y = 5, - 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; + GUI_HEIGHT = 240, + GUI_WIDTH = 230, + AE_ROW_HEIGHT = 18, + AE_NUM_ROWS = 0, + GUI_UPPER_HEIGHT = 35, + GUI_SEARCH_ROW = 35, + SEARCH_X = 81, + SEARCH_Y = 5, + 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; @@ -119,15 +89,6 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo private boolean isFullScreen, init = true, reInit, wasResized = false; public static GuiWirelessCraftingTerminal INSTANCE; private static boolean switchingGuis; - private final List meSlots = new LinkedList(); - private final Set drag_click = new HashSet(); - private final WCTRenderItem aeRenderItem = new WCTRenderItem(); - private GuiScrollbar scrollBar = null; - private boolean disableShiftClick = false; - private Stopwatch dbl_clickTimer = Stopwatch.createStarted(); - private ItemStack dbl_whichItem; - private Slot bl_clicked; - private boolean subGui; public static int craftingGridOffsetX = 80; public static int craftingGridOffsetY; private static String memoryText = ""; @@ -168,11 +129,8 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.standardSize = this.xSize; this.setReservedSpace(73); this.containerWCT = (ContainerWirelessCraftingTerminal) container; - this.scrollBar = new GuiScrollbar(); - this.subGui = switchingGuis; - switchingGuis = false; - this.setScrollBar(scrollBar); - this.repo = new ItemRepo(scrollBar, this); + this.setScrollBar(new GuiScrollbar()); + this.repo = new ItemRepo(getScrollBar(), this); this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager(); this.devicePowered = containerWCT.isPowered(); ((ContainerWirelessCraftingTerminal) this.inventorySlots).setGui(this); @@ -189,12 +147,8 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo 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)); - } - - protected void setScrollBar(final GuiScrollbar myScrollBar) { - this.scrollBar = myScrollBar; + .setRange( + 0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, Math.max(1, this.rows / 6)); } @SuppressWarnings("rawtypes") @@ -211,7 +165,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (iBtn.getSetting() != Settings.ACTIONS) { final Enum cv = iBtn.getCurrentValue(); final Enum next = - Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); + Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); if (btn == this.terminalStyleBox) { AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); @@ -223,7 +177,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } else { try { NetworkHandler.instance.sendToServer( - new PacketValueConfig(iBtn.getSetting().name(), next.name())); + new PacketValueConfig(iBtn.getSetting().name(), next.name())); } catch (final IOException e) { WCTLog.debug(e.getMessage()); } @@ -246,7 +200,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (s != null) { final PacketInventoryAction p = - new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); + new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); NetworkHandler.instance.sendToServer(p); } } @@ -276,25 +230,6 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.initGui(); } - protected static String join(final Collection toolTip, final String delimiter) { - final Joiner joiner = Joiner.on(delimiter); - - return joiner.join(toolTip); - } - - protected int getQty(final GuiButton btn) { - try { - final DecimalFormat df = new DecimalFormat("+#;-#"); - return df.parse(btn.displayString).intValue(); - } catch (final ParseException e) { - return 0; - } - } - - public boolean isSubGui() { - return this.subGui; - } - int getReservedSpace() { return this.reservedSpace; } @@ -317,15 +252,17 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo @SuppressWarnings({"unchecked", "rawtypes"}) @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); + ? 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 - 0 - top - this.reservedSpace; + 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; @@ -344,7 +281,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo 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)); + .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) { @@ -359,66 +296,54 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f)); int offset = this.guiTop + 8; - final List slots = this.getInventorySlots(); - final Iterator i = slots.iterator(); - while (i.hasNext()) { - if (i.next() instanceof SlotME) { - i.remove(); - } - } - - for (final InternalSlotME me : this.meSlots) { - slots.add(new SlotME(me)); - } - this.buttonList.clear(); this.buttonList.add( - this.clearBtn = new GuiImgButton( - this.guiLeft + 134, this.guiTop + this.ySize - 160, Settings.ACTIONS, ActionItems.STASH)); + this.clearBtn = new GuiImgButton( + this.guiLeft + 134, this.guiTop + this.ySize - 160, Settings.ACTIONS, 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))); + 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))); + 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))); + 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))); + 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)); + 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.terminalStyleBox = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.TERMINAL_STYLE, + AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); this.searchField = new MEGuiTextField(this.fontRendererObj, SEARCH_X, SEARCH_Y, SEARCH_WIDTH, SEARCH_HEIGHT); @@ -429,12 +354,12 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.searchField.setEnabled(true); this.buttonList.add( - this.craftingStatusBtn = new GuiTabButton( - this.guiLeft + 169, - this.guiTop - 4, - 2 + 11 * 16, - GuiText.CraftingStatus.getLocal(), - itemRender)); + this.craftingStatusBtn = new GuiTabButton( + this.guiLeft + 169, + this.guiTop - 4, + 2 + 11 * 16, + GuiText.CraftingStatus.getLocal(), + itemRender)); this.craftingStatusBtn.setHideEdge(13); final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); @@ -471,15 +396,10 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } } - @SuppressWarnings("unchecked") - private List getInventorySlots() { - return this.inventorySlots.inventorySlots; - } - int getMaxRows() { return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL - ? 6 - : Integer.MAX_VALUE; + ? 6 + : Integer.MAX_VALUE; } protected void repositionSlot(final AppEngSlot s) { @@ -489,7 +409,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo /** * 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. * @@ -519,7 +439,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } else { this.initGui(); this.setScrollBar(); - if (this.wasResized == true) { + if (this.wasResized) { this.searchField.setFocused(this.wasTextboxFocused); this.searchField.setText(this.repo.getSearchString()); this.wasTextboxFocused = false; @@ -546,8 +466,8 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo */ private boolean hasScreenResChanged() { if ((this.currScreenWidth != this.mc.displayWidth) - || (this.currScreenHeight != this.mc.displayHeight) - || (this.isFullScreen != this.mc.isFullScreen())) { + || (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(); @@ -559,132 +479,11 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo /** * Draws the screen and tooltips. */ + @Override public void drawScreen(int mouseX, int mouseY, float btn) { super.drawScreen(mouseX, mouseY, btn); this.xSize_lo = (float) mouseX; this.ySize_lo = (float) mouseY; - - final boolean hasClicked = Mouse.isButtonDown(0); - if (hasClicked && this.scrollBar != null) { - this.scrollBar.click(this, mouseX - this.guiLeft, mouseY - this.guiTop); - } - - for (final Object c : this.buttonList) { - if (c instanceof ITooltip) { - final ITooltip tooltip = (ITooltip) c; - final int x = tooltip.xPos(); - int y = tooltip.yPos(); - - if (x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible()) { - if (y < mouseY && y + tooltip.getHeight() > mouseY) { - if (y < 15) { - y = 15; - } - - final String msg = tooltip.getMessage(); - if (msg != null) { - this.drawTooltip(x + 11, y + 4, 0, msg); - } - } - } - } - } - } - - public void drawTooltip(final int par2, final int par3, final int forceWidth, final String message) { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - RenderHelper.disableStandardItemLighting(); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - final String[] var4 = message.split("\n"); - - if (var4.length > 0) { - int var5 = 0; - int var6; - int var7; - - for (var6 = 0; var6 < var4.length; ++var6) { - var7 = this.fontRendererObj.getStringWidth(var4[var6]); - - if (var7 > var5) { - var5 = var7; - } - } - - var6 = par2 + 12; - var7 = par3 - 12; - int var9 = 8; - - if (var4.length > 1) { - var9 += 2 + (var4.length - 1) * 10; - } - - if (this.guiTop + var7 + var9 + 6 > this.height) { - var7 = this.height - var9 - this.guiTop - 6; - } - - if (forceWidth > 0) { - var5 = forceWidth; - } - - this.zLevel = 300.0F; - itemRender.zLevel = 300.0F; - final int var10 = -267386864; - this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); - this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); - final int var11 = 1347420415; - final int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; - this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); - this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); - - for (int var13 = 0; var13 < var4.length; ++var13) { - String var14 = var4[var13]; - - if (var13 == 0) { - var14 = '\u00a7' + Integer.toHexString(15) + var14; - } else { - var14 = "\u00a77" + var14; - } - - this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); - - if (var13 == 0) { - var7 += 2; - } - - var7 += 10; - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - GL11.glPopAttrib(); - } - - public void bindTexture(final String base, final String file) { - final ResourceLocation loc = new ResourceLocation(base, "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - /** - * Draw GUI Labels and item tooltips - */ - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - - if (this.scrollBar != null) { - this.scrollBar.draw(this); - } - this.drawFG(ox, oy, mouseX, mouseY); } public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { @@ -699,48 +498,6 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.currentMouseY = mouseY; } - /** - * Draw and piece together the background texture - */ - @Override - protected void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawBG(ox, oy, x, y); - - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - if (slot instanceof OptionalSlotFake) { - final OptionalSlotFake fs = (OptionalSlotFake) slot; - if (fs.renderDisabled()) { - if (fs.isEnabled()) { - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - } else { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F); - GL11.glEnable(GL11.GL_BLEND); - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPopAttrib(); - } - } - } - } - } - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { this.bindTexture(bgTexturePath); final int x_width = 199; @@ -754,12 +511,12 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo // draw player inv this.drawTexturedModalRect( - offsetX, - offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, - 0, - 106 - 18 - 18, - x_width, - 99 + this.reservedSpace - this.lowerTextureOffset); + offsetX, + offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, + 0, + 106 - 18 - 18, + x_width, + 99 + this.reservedSpace - this.lowerTextureOffset); // draw view cells this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 32, 104); @@ -768,12 +525,12 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.drawTexturedModalRect(this.guiLeft + 132, (this.guiTop + this.rows * 18) + 83, 237, 237, 19, 19); } GuiInventory.func_147046_a( - this.guiLeft + 51, - (this.guiTop + this.rows * 18) + 94, - 32, - (float) (this.guiLeft + 51) - this.xSize_lo, - (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, - this.mc.thePlayer); + this.guiLeft + 51, + (this.guiTop + this.rows * 18) + 94, + 32, + (float) (this.guiLeft + 51) - this.xSize_lo, + (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, + this.mc.thePlayer); boolean update = false; for (int i = 0; i < 5; i++) { @@ -803,500 +560,22 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.setScrollBar(); } - this.drag_click.clear(); - - if (btn == 1) { - for (final Object o : this.buttonList) { - final GuiButton guibutton = (GuiButton) o; - if (guibutton.mousePressed(this.mc, xCoord, yCoord)) { - super.mouseClicked(xCoord, yCoord, 0); - return; - } - } - } - super.mouseClicked(xCoord, yCoord, btn); } - @Override - protected void mouseClickMove(final int x, final int y, final int c, final long d) { - final Slot slot = this.getSlot(x, y); - final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); - - if (slot instanceof SlotFake && itemstack != null) { - this.drag_click.add(slot); - if (this.drag_click.size() > 1) { - for (final Slot dr : this.drag_click) { - final PacketInventoryAction p = new PacketInventoryAction( - c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE, - dr.slotNumber, - 0); - NetworkHandler.instance.sendToServer(p); - } - } - } else { - super.mouseClickMove(x, y, c, d); - } - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int key) { - final EntityPlayer player = Minecraft.getMinecraft().thePlayer; - - if (slot instanceof SlotFake) { - final InventoryAction action = - ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - - if (this.drag_click.size() > 1) { - return; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } else if (slot instanceof SlotCraftingTerm) { - if (key == 6) { - return; // prevent weird double clicks.. - } - - InventoryAction action = null; - if (key == 1) { - action = InventoryAction.CRAFT_SHIFT; - } else { - action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } - - if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { - if (this.enableSpaceClicking()) { - IAEItemStack stack = null; - if (slot instanceof SlotME) { - stack = ((SlotME) slot).getAEStack(); - } - - int slotNum = this.getInventorySlots().size(); - - if (!(slot instanceof SlotME) && slot != null) { - slotNum = slot.slotNumber; - } - - ((ContainerWirelessCraftingTerminal) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0); - NetworkHandler.instance.sendToServer(p); - return; - } - } - - if (slot instanceof SlotDisconnected) { - InventoryAction action = null; - - switch (key) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - break; - - case 3: // creative dupe: - if (player.capabilities.isCreativeMode) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - final PacketInventoryAction p = new PacketInventoryAction( - action, - slot.getSlotIndex(), - ((SlotDisconnected) slot).getSlot().getId()); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (slot instanceof SlotME) { - InventoryAction action = null; - IAEItemStack stack = null; - - switch (key) { - 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 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - stack = ((SlotME) slot).getAEStack(); - break; - - case 3: // creative dupe: - stack = ((SlotME) slot).getAEStack(); - if (stack != null && stack.isCraftable()) { - action = InventoryAction.AUTO_CRAFT; - } else if (player.capabilities.isCreativeMode) { - final IAEItemStack slotItem = ((SlotME) slot).getAEStack(); - if (slotItem != null) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - } - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - ((ContainerWirelessCraftingTerminal) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction( - action, this.getInventorySlots().size(), 0); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (!this.disableShiftClick && isShiftKeyDown()) { - this.disableShiftClick = true; - - if (this.dbl_whichItem == null - || this.bl_clicked != slot - || this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 150) { - // some simple double click logic. - this.bl_clicked = slot; - this.dbl_clickTimer = Stopwatch.createStarted(); - if (slot != null) { - this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null; - } else { - this.dbl_whichItem = null; - } - } else if (this.dbl_whichItem != null) { - // a replica of the weird broken vanilla feature. - - final List slots = this.getInventorySlots(); - for (final Slot inventorySlot : slots) { - if (inventorySlot != null - && inventorySlot.canTakeStack(this.mc.thePlayer) - && inventorySlot.getHasStack() - && inventorySlot.inventory == slot.inventory - && Container.func_94527_a(inventorySlot, this.dbl_whichItem, true)) { - this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, ctrlDown, 1); - } - } - } - - this.disableShiftClick = false; - } - - super.handleMouseClick(slot, slotIdx, ctrlDown, key); - } - - @Override - protected boolean checkHotbarKeys(final int keyCode) { - final Slot theSlot; - - try { - theSlot = ObfuscationReflectionHelper.getPrivateValue( - GuiContainer.class, this, "theSlot", "field_147006_u", "f"); - } catch (final Throwable t) { - return false; - } - - if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) { - for (int j = 0; j < 9; ++j) { - if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) { - final List slots = this.getInventorySlots(); - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory - == ((ContainerWirelessCraftingTerminal) this.inventorySlots).getPlayerInv()) { - if (s.getStack() != null - && s.getStack().getItem() - == WCTApi.instance() - .items() - .WirelessCraftingTerminal - .getItem()) return false; - if (!s.canTakeStack( - ((ContainerWirelessCraftingTerminal) this.inventorySlots).getPlayerInv().player)) - return false; - else break; - } - } - - if (theSlot.getSlotStackLimit() == 64) { - this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2); - return true; - } else { - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory - == ((ContainerWirelessCraftingTerminal) this.inventorySlots) - .getPlayerInv()) { - NetworkHandler.instance.sendToServer( - new PacketSwapSlots(s.slotNumber, theSlot.slotNumber)); - return true; - } - } - } - } - } - } - - return false; - } - @Override public void onGuiClosed() { super.onGuiClosed(); - this.subGui = true; // in case the gui is reopened later ( i'm looking - // at you NEI ) Keyboard.enableRepeatEvents(false); if (this.searchField.getText() != null) { memoryText = this.searchField.getText(); } } - protected Slot getSlot(final int mouseX, final int mouseY) { - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - // isPointInRegion - if (this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) { - return slot; - } - } - - return null; - } - - @Override - public void handleMouseInput() { - super.handleMouseInput(); - - final int i = Mouse.getEventDWheel(); - if (i != 0 && isShiftKeyDown()) { - final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; - final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - this.mouseWheelEvent(x, y, i / Math.abs(i)); - } else if (i != 0 && this.scrollBar != null) { - this.scrollBar.wheel(i); - } - } - - private void mouseWheelEvent(final int x, final int y, final int wheel) { - final Slot slot = this.getSlot(x, y); - if (slot instanceof SlotME) { - final IAEItemStack item = ((SlotME) slot).getAEStack(); - if (item != null) { - ((ContainerWirelessCraftingTerminal) this.inventorySlots).setTargetStack(item); - final InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP; - final int times = Math.abs(wheel); - final int inventorySize = this.getInventorySlots().size(); - for (int h = 0; h < times; h++) { - final PacketInventoryAction p = new PacketInventoryAction(direction, inventorySize, 0); - NetworkHandler.instance.sendToServer(p); - } - } - } - } - protected boolean enableSpaceClicking() { return true; } - protected void drawItem(final int x, final int y, final ItemStack is) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - RenderHelper.enableGUIStandardItemLighting(); - itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.renderEngine, is, x, y); - GL11.glPopAttrib(); - - itemRender.zLevel = 0.0F; - this.zLevel = 0.0F; - } - - protected String getGuiDisplayName(final String in) { - return this.hasCustomInventoryName() ? this.getInventoryName() : in; - } - - private boolean hasCustomInventoryName() { - if (this.inventorySlots instanceof ContainerWirelessCraftingTerminal) { - return ((ContainerWirelessCraftingTerminal) this.inventorySlots).getCustomName() != null; - } - return false; - } - - private String getInventoryName() { - return ((ContainerWirelessCraftingTerminal) this.inventorySlots).getCustomName(); - } - - private void drawSlot(final Slot s) { - if (s instanceof SlotME) { - final RenderItem pIR = this.setItemRender(this.aeRenderItem); - try { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - if (!this.isPowered()) { - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66111111); - GL11.glEnable(GL11.GL_LIGHTING); - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - - this.aeRenderItem.setAeStack(((SlotME) s).getAEStack()); - - this.safeDrawSlot(s); - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - this.setItemRender(pIR); - return; - } else { - GuiWirelessCraftingTerminal.itemRender = new RenderItem(); - try { - final ItemStack is = s.getStack(); - if (s instanceof AppEngSlot - && (((AppEngSlot) s).renderIconWithItem() || is == null) - && (((AppEngSlot) s).shouldDisplay())) { - final AppEngSlot aes = (AppEngSlot) s; - if (aes.getIcon() >= 0) { - this.bindTexture("appliedenergistics2", "guis/states.png"); - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - final Tessellator tessellator = Tessellator.instance; - try { - final int uv_y = (int) Math.floor(aes.getIcon() / 16); - final int uv_x = aes.getIcon() - uv_y * 16; - - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - final float par1 = aes.xDisplayPosition; - final float par2 = aes.yDisplayPosition; - final float par3 = uv_x * 16; - final float par4 = uv_y * 16; - - tessellator.startDrawingQuads(); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()); - final float f1 = 0.00390625F; - final float f = 0.00390625F; - final float par6 = 16; - tessellator.addVertexWithUV( - par1 + 0, par2 + par6, this.zLevel, (par3 + 0) * f, (par4 + par6) * f1); - final float par5 = 16; - tessellator.addVertexWithUV( - par1 + par5, par2 + par6, this.zLevel, (par3 + par5) * f, (par4 + par6) * f1); - tessellator.addVertexWithUV( - par1 + par5, par2 + 0, this.zLevel, (par3 + par5) * f, (par4 + 0) * f1); - tessellator.addVertexWithUV( - par1 + 0, par2 + 0, this.zLevel, (par3 + 0) * f, (par4 + 0) * f1); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, 1.0f); - tessellator.draw(); - } catch (final Exception err) { - } - GL11.glPopAttrib(); - } - } - - if (is != null && s instanceof AppEngSlot) { - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.NotAvailable) { - boolean isValid = s.isItemValid(is) - || s instanceof SlotOutput - || s instanceof AppEngCraftingSlot - || s instanceof SlotDisabled - || s instanceof SlotInaccessible - || s instanceof SlotFake - || s instanceof SlotRestrictedInput - || s instanceof SlotDisconnected; - if (isValid && s instanceof SlotRestrictedInput) { - try { - isValid = ((SlotRestrictedInput) s).isValid(is, this.mc.theWorld); - } catch (final Exception err) { - WCTLog.debug(err.getMessage()); - } - } - ((AppEngSlot) s) - .setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid); - } - - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.Invalid) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66ff6666); - GL11.glEnable(GL11.GL_LIGHTING); - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - } - - if (s instanceof AppEngSlot) { - ((AppEngSlot) s).setDisplay(true); - this.safeDrawSlot(s); - } else { - this.safeDrawSlot(s); - } - - return; - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - } - // do the usual for non-ME Slots. - this.safeDrawSlot(s); - } - - private RenderItem setItemRender(final RenderItem item) { - if (isNEIEnabled) { - return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item); - } else { - final RenderItem ri = itemRender; - itemRender = item; - return ri; - } - } - @Override protected void keyTyped(final char character, final int key) { if (!this.checkHotbarKeys(key)) { @@ -1319,7 +598,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } final boolean mouseInGui = - this.isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); + this.isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); if (this.isAutoFocus && !this.searchField.isFocused() && mouseInGui) { this.searchField.setFocused(true); } @@ -1338,42 +617,13 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo return this.repo.hasPower(); } - private void safeDrawSlot(final Slot s) { - try { - GuiContainer.class - .getDeclaredMethod("func_146977_a_original", Slot.class) - .invoke(this, s); - } catch (final Exception err) { - } - } - public void bindTexture(final String file) { final ResourceLocation loc = new ResourceLocation(Reference.MODID, "textures/" + file); this.mc.getTextureManager().bindTexture(loc); } - public void func_146977_a(final Slot s) { - this.drawSlot(s); - } - - protected GuiScrollbar getScrollBar() { - return this.scrollBar; - } - - protected List getMeSlots() { - return this.meSlots; - } - - public static final synchronized boolean isSwitchingGuis() { - return switchingGuis; - } - - public static final synchronized void setSwitchingGuis(final boolean switchingGuis) { - GuiWirelessCraftingTerminal.switchingGuis = switchingGuis; - } - public List handleItemTooltip( - final ItemStack stack, final int mouseX, final int mouseY, final List currentToolTip) { + 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) { @@ -1391,7 +641,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo 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()); + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize()); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -1400,7 +650,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (myStack.getCountRequestable() > 0) { final String local = ButtonToolTips.ItemsRequestable.getLocal(); final String formattedAmount = - NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable()); + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable()); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -1408,7 +658,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } 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); + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -1435,23 +685,23 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (myStack != null) { final List currentToolTip = - stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); + 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())); + + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize())); } if (myStack.getCountRequestable() > 0) { currentToolTip.add("Items Requestable: " - + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable())); + + 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)); + + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize)); this.drawTooltip(x, y, 0, join(var4, "\n")); return; } @@ -1522,9 +772,9 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo pointX -= i; pointY -= j; return pointX >= rectX - 1 - && pointX < rectX + rectWidth + 1 - && pointY >= rectY - 1 - && pointY < rectY + rectHeight + 1; + && pointX < rectX + rectWidth + 1 + && pointY >= rectY - 1 + && pointY < rectY + rectHeight + 1; } private boolean isNEIFocused() { @@ -1533,7 +783,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } try { final Class c = - ReflectionHelper.getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); + ReflectionHelper.getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); final Field fldSearchField = c.getField("searchField"); final TextField searchField = (TextField) fldSearchField.get(c); return searchField.focused(); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java deleted file mode 100644 index fd8d97b..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java +++ /dev/null @@ -1,820 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.gui; - -import appeng.api.storage.data.IAEItemStack; -import appeng.client.gui.widgets.ITooltip; -import appeng.container.slot.SlotRestrictedInput; -import appeng.helpers.InventoryAction; -import com.google.common.base.Joiner; -import com.google.common.base.Stopwatch; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ObfuscationReflectionHelper; -import java.text.DecimalFormat; -import java.text.ParseException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.entity.player.EntityPlayer; -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.GuiScrollbar; -import net.p455w0rd.wirelesscraftingterminal.client.me.InternalSlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.SlotDisconnected; -import net.p455w0rd.wirelesscraftingterminal.client.me.SlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.WCTRenderItem; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot.hasCalculatedValidness; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.OptionalSlotFake; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotOutput; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; -import net.p455w0rd.wirelesscraftingterminal.integration.abstraction.INEI; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - -public abstract class WCTBaseGui extends GuiContainer { - private static boolean switchingGuis; - private final List meSlots = new LinkedList(); - // drag y - private final Set drag_click = new HashSet(); - private final WCTRenderItem aeRenderItem = new WCTRenderItem(); - private GuiScrollbar scrollBar = null; - private boolean disableShiftClick = false; - private Stopwatch dbl_clickTimer = Stopwatch.createStarted(); - private ItemStack dbl_whichItem; - private Slot bl_clicked; - private boolean subGui; - - public WCTBaseGui(final Container container) { - super(container); - this.subGui = switchingGuis; - switchingGuis = false; - } - - protected static String join(final Collection toolTip, final String delimiter) { - final Joiner joiner = Joiner.on(delimiter); - - return joiner.join(toolTip); - } - - protected int getQty(final GuiButton btn) { - try { - final DecimalFormat df = new DecimalFormat("+#;-#"); - return df.parse(btn.displayString).intValue(); - } catch (final ParseException e) { - return 0; - } - } - - public boolean isSubGui() { - return this.subGui; - } - - @Override - public void initGui() { - super.initGui(); - - final List slots = this.getInventorySlots(); - final Iterator i = slots.iterator(); - while (i.hasNext()) { - if (i.next() instanceof SlotME) { - i.remove(); - } - } - - for (final InternalSlotME me : this.meSlots) { - slots.add(new SlotME(me)); - } - } - - @SuppressWarnings("unchecked") - private List getInventorySlots() { - return this.inventorySlots.inventorySlots; - } - - @Override - public void drawScreen(final int mouseX, final int mouseY, final float btn) { - super.drawScreen(mouseX, mouseY, btn); - - final boolean hasClicked = Mouse.isButtonDown(0); - if (hasClicked && this.scrollBar != null) { - this.scrollBar.click(this, mouseX - this.guiLeft, mouseY - this.guiTop); - } - - for (final Object c : this.buttonList) { - if (c instanceof ITooltip) { - final ITooltip tooltip = (ITooltip) c; - final int x = tooltip.xPos(); // ((GuiImgButton) c).xPosition; - int y = tooltip.yPos(); // ((GuiImgButton) c).yPosition; - - if (x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible()) { - if (y < mouseY && y + tooltip.getHeight() > mouseY) { - if (y < 15) { - y = 15; - } - - final String msg = tooltip.getMessage(); - if (msg != null) { - this.drawTooltip(x + 11, y + 4, 0, msg); - } - } - } - } - } - } - - public void drawTooltip(final int par2, final int par3, final int forceWidth, final String message) { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - RenderHelper.disableStandardItemLighting(); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - final String[] var4 = message.split("\n"); - - if (var4.length > 0) { - int var5 = 0; - int var6; - int var7; - - for (var6 = 0; var6 < var4.length; ++var6) { - var7 = this.fontRendererObj.getStringWidth(var4[var6]); - - if (var7 > var5) { - var5 = var7; - } - } - - var6 = par2 + 12; - var7 = par3 - 12; - int var9 = 8; - - if (var4.length > 1) { - var9 += 2 + (var4.length - 1) * 10; - } - - if (this.guiTop + var7 + var9 + 6 > this.height) { - var7 = this.height - var9 - this.guiTop - 6; - } - - if (forceWidth > 0) { - var5 = forceWidth; - } - - this.zLevel = 300.0F; - itemRender.zLevel = 300.0F; - final int var10 = -267386864; - this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); - this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); - final int var11 = 1347420415; - final int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; - this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); - this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); - - for (int var13 = 0; var13 < var4.length; ++var13) { - String var14 = var4[var13]; - - if (var13 == 0) { - var14 = '\u00a7' + Integer.toHexString(15) + var14; - } else { - var14 = "\u00a77" + var14; - } - - this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); - - if (var13 == 0) { - var7 += 2; - } - - var7 += 10; - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - GL11.glPopAttrib(); - } - - @Override - protected final void drawGuiContainerForegroundLayer(final int x, final int y) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - - if (this.scrollBar != null) { - this.scrollBar.draw(this); - } - - this.drawFG(ox, oy, x, y); - } - - public abstract void drawFG(int offsetX, int offsetY, int mouseX, int mouseY); - - @Override - protected final void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawBG(ox, oy, x, y); - - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - if (slot instanceof OptionalSlotFake) { - final OptionalSlotFake fs = (OptionalSlotFake) slot; - if (fs.renderDisabled()) { - if (fs.isEnabled()) { - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - } else { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F); - GL11.glEnable(GL11.GL_BLEND); - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPopAttrib(); - } - } - } - } - } - - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - this.drag_click.clear(); - - if (btn == 1) { - for (final Object o : this.buttonList) { - final GuiButton guibutton = (GuiButton) o; - if (guibutton.mousePressed(this.mc, xCoord, yCoord)) { - super.mouseClicked(xCoord, yCoord, 0); - return; - } - } - } - - super.mouseClicked(xCoord, yCoord, btn); - } - - @Override - protected void mouseClickMove(final int x, final int y, final int c, final long d) { - final Slot slot = this.getSlot(x, y); - final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); - - if (slot instanceof SlotFake && itemstack != null) { - this.drag_click.add(slot); - if (this.drag_click.size() > 1) { - for (final Slot dr : this.drag_click) { - final PacketInventoryAction p = new PacketInventoryAction( - c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE, - dr.slotNumber, - 0); - NetworkHandler.instance.sendToServer(p); - } - } - } else { - super.mouseClickMove(x, y, c, d); - } - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int key) { - final EntityPlayer player = Minecraft.getMinecraft().thePlayer; - - if (slot instanceof SlotFake) { - final InventoryAction action = - ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - - if (this.drag_click.size() > 1) { - return; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } - - if (slot instanceof SlotCraftingTerm) { - if (key == 6) { - return; // prevent weird double clicks.. - } - - InventoryAction action = null; - if (key == 1) { - action = InventoryAction.CRAFT_SHIFT; - } else { - action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } - - if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { - if (this.enableSpaceClicking()) { - IAEItemStack stack = null; - if (slot instanceof SlotME) { - stack = ((SlotME) slot).getAEStack(); - } - - int slotNum = this.getInventorySlots().size(); - - if (!(slot instanceof SlotME) && slot != null) { - slotNum = slot.slotNumber; - } - - ((WCTBaseContainer) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0); - NetworkHandler.instance.sendToServer(p); - return; - } - } - - if (slot instanceof SlotDisconnected) { - InventoryAction action = null; - - switch (key) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - break; - - case 3: // creative dupe: - if (player.capabilities.isCreativeMode) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - final PacketInventoryAction p = new PacketInventoryAction( - action, - slot.getSlotIndex(), - ((SlotDisconnected) slot).getSlot().getId()); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (slot instanceof SlotME) { - InventoryAction action = null; - IAEItemStack stack = null; - - switch (key) { - 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 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - stack = ((SlotME) slot).getAEStack(); - break; - - case 3: // creative dupe: - stack = ((SlotME) slot).getAEStack(); - if (stack != null && stack.isCraftable()) { - action = InventoryAction.AUTO_CRAFT; - } else if (player.capabilities.isCreativeMode) { - final IAEItemStack slotItem = ((SlotME) slot).getAEStack(); - if (slotItem != null) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - } - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - ((WCTBaseContainer) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction( - action, this.getInventorySlots().size(), 0); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (!this.disableShiftClick && isShiftKeyDown()) { - this.disableShiftClick = true; - - if (this.dbl_whichItem == null - || this.bl_clicked != slot - || this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 150) { - // some simple double click logic. - this.bl_clicked = slot; - this.dbl_clickTimer = Stopwatch.createStarted(); - if (slot != null) { - this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null; - } else { - this.dbl_whichItem = null; - } - } else if (this.dbl_whichItem != null) { - // a replica of the weird broken vanilla feature. - - final List slots = this.getInventorySlots(); - for (final Slot inventorySlot : slots) { - if (inventorySlot != null - && inventorySlot.canTakeStack(this.mc.thePlayer) - && inventorySlot.getHasStack() - && inventorySlot.inventory == slot.inventory - && Container.func_94527_a(inventorySlot, this.dbl_whichItem, true)) { - this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, ctrlDown, 1); - } - } - } - - this.disableShiftClick = false; - } - - super.handleMouseClick(slot, slotIdx, ctrlDown, key); - } - - @Override - protected boolean checkHotbarKeys(final int keyCode) { - final Slot theSlot; - - try { - theSlot = ObfuscationReflectionHelper.getPrivateValue( - GuiContainer.class, this, "theSlot", "field_147006_u", "f"); - } catch (final Throwable t) { - return false; - } - - if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) { - for (int j = 0; j < 9; ++j) { - if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) { - final List slots = this.getInventorySlots(); - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) { - if (!s.canTakeStack(((WCTBaseContainer) this.inventorySlots).getPlayerInv().player)) { - return false; - } - } - } - - if (theSlot.getSlotStackLimit() == 64) { - this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2); - return true; - } else { - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) { - NetworkHandler.instance.sendToServer( - new PacketSwapSlots(s.slotNumber, theSlot.slotNumber)); - return true; - } - } - } - } - } - } - - return false; - } - - @Override - public void onGuiClosed() { - super.onGuiClosed(); - this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI ) - } - - protected Slot getSlot(final int mouseX, final int mouseY) { - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - // isPointInRegion - if (this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) { - return slot; - } - } - - return null; - } - - public abstract void drawBG(int offsetX, int offsetY, int mouseX, int mouseY); - - @Override - public void handleMouseInput() { - super.handleMouseInput(); - - final int i = Mouse.getEventDWheel(); - if (i != 0 && isShiftKeyDown()) { - final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; - final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - this.mouseWheelEvent(x, y, i / Math.abs(i)); - } else if (i != 0 && this.scrollBar != null) { - this.scrollBar.wheel(i); - } - } - - private void mouseWheelEvent(final int x, final int y, final int wheel) { - final Slot slot = this.getSlot(x, y); - if (slot instanceof SlotME) { - final IAEItemStack item = ((SlotME) slot).getAEStack(); - if (item != null) { - ((WCTBaseContainer) this.inventorySlots).setTargetStack(item); - final InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP; - final int times = Math.abs(wheel); - final int inventorySize = this.getInventorySlots().size(); - for (int h = 0; h < times; h++) { - final PacketInventoryAction p = new PacketInventoryAction(direction, inventorySize, 0); - NetworkHandler.instance.sendToServer(p); - } - } - } - } - - protected boolean enableSpaceClicking() { - return true; - } - - public void bindTexture(final String base, final String file) { - final ResourceLocation loc = new ResourceLocation(base, "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - protected void drawItem(final int x, final int y, final ItemStack is) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - RenderHelper.enableGUIStandardItemLighting(); - itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.renderEngine, is, x, y); - GL11.glPopAttrib(); - - itemRender.zLevel = 0.0F; - this.zLevel = 0.0F; - } - - protected String getGuiDisplayName(final String in) { - return this.hasCustomInventoryName() ? this.getInventoryName() : in; - } - - private boolean hasCustomInventoryName() { - if (this.inventorySlots instanceof WCTBaseContainer) { - return ((WCTBaseContainer) this.inventorySlots).getCustomName() != null; - } - return false; - } - - private String getInventoryName() { - return ((WCTBaseContainer) this.inventorySlots).getCustomName(); - } - - private void drawSlot(final Slot s) { - if (s instanceof SlotME) { - final RenderItem pIR = this.setItemRender(this.aeRenderItem); - try { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - if (!this.isPowered()) { - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66111111); - GL11.glEnable(GL11.GL_LIGHTING); - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - - this.aeRenderItem.setAeStack(((SlotME) s).getAEStack()); - - this.safeDrawSlot(s); - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - this.setItemRender(pIR); - return; - } else { - try { - final ItemStack is = s.getStack(); - if (s instanceof AppEngSlot - && (((AppEngSlot) s).renderIconWithItem() || is == null) - && (((AppEngSlot) s).shouldDisplay())) { - final AppEngSlot aes = (AppEngSlot) s; - if (aes.getIcon() >= 0) { - this.bindTexture("guis/states.png"); - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - final Tessellator tessellator = Tessellator.instance; - try { - final int uv_y = (int) Math.floor(aes.getIcon() / 16); - final int uv_x = aes.getIcon() - uv_y * 16; - - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - final float par1 = aes.xDisplayPosition; - final float par2 = aes.yDisplayPosition; - final float par3 = uv_x * 16; - final float par4 = uv_y * 16; - - tessellator.startDrawingQuads(); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()); - final float f1 = 0.00390625F; - final float f = 0.00390625F; - final float par6 = 16; - tessellator.addVertexWithUV( - par1 + 0, par2 + par6, this.zLevel, (par3 + 0) * f, (par4 + par6) * f1); - final float par5 = 16; - tessellator.addVertexWithUV( - par1 + par5, par2 + par6, this.zLevel, (par3 + par5) * f, (par4 + par6) * f1); - tessellator.addVertexWithUV( - par1 + par5, par2 + 0, this.zLevel, (par3 + par5) * f, (par4 + 0) * f1); - tessellator.addVertexWithUV( - par1 + 0, par2 + 0, this.zLevel, (par3 + 0) * f, (par4 + 0) * f1); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, 1.0f); - tessellator.draw(); - } catch (final Exception err) { - } - GL11.glPopAttrib(); - } - } - - if (is != null && s instanceof AppEngSlot) { - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.NotAvailable) { - boolean isValid = s.isItemValid(is) - || s instanceof SlotOutput - || s instanceof AppEngCraftingSlot - || s instanceof SlotDisabled - || s instanceof SlotInaccessible - || s instanceof SlotFake - || s instanceof SlotRestrictedInput - || s instanceof SlotDisconnected; - if (isValid && s instanceof SlotRestrictedInput) { - try { - isValid = ((SlotRestrictedInput) s).isValid(is, this.mc.theWorld); - } catch (final Exception err) { - WCTLog.debug(err.getMessage()); - } - } - ((AppEngSlot) s) - .setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid); - } - - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.Invalid) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66ff6666); - GL11.glEnable(GL11.GL_LIGHTING); - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - } - - if (s instanceof AppEngSlot) { - ((AppEngSlot) s).setDisplay(true); - this.safeDrawSlot(s); - } else { - this.safeDrawSlot(s); - } - - return; - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - } - // do the usual for non-ME Slots. - this.safeDrawSlot(s); - } - - private RenderItem setItemRender(final RenderItem item) { - if (Loader.isModLoaded("NotEnoughItems")) { - return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item); - } else { - final RenderItem ri = itemRender; - itemRender = item; - return ri; - } - } - - protected boolean isPowered() { - return true; - } - - private void safeDrawSlot(final Slot s) { - try { - GuiContainer.class - .getDeclaredMethod("func_146977_a_original", Slot.class) - .invoke(this, s); - } catch (final Exception err) { - } - } - - public void bindTexture(final String file) { - final ResourceLocation loc = new ResourceLocation("appliedenergistics2", "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - public void func_146977_a(final Slot s) { - this.drawSlot(s); - } - - protected GuiScrollbar getScrollBar() { - return this.scrollBar; - } - - protected void setScrollBar(final GuiScrollbar myScrollBar) { - this.scrollBar = myScrollBar; - } - - protected List getMeSlots() { - return this.meSlots; - } - - public static final synchronized boolean isSwitchingGuis() { - return switchingGuis; - } - - public static final synchronized void setSwitchingGuis(final boolean switchingGuis) { - WCTBaseGui.switchingGuis = switchingGuis; - } - - protected void addItemTooltip(ItemStack is, List lineList) { - if (isShiftKeyDown()) { - List l = is.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); - if (!l.isEmpty()) l.remove(0); - lineList.addAll(l); - } else { - // TODO: update AE2 on maven and dependency in build gradle - // lineList.add(GuiText.HoldShiftForTooltip.getLocal()); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiScrollbar.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiScrollbar.java deleted file mode 100644 index bc28939..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiScrollbar.java +++ /dev/null @@ -1,119 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.gui.widgets; - -import appeng.client.gui.widgets.IScrollSource; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.client.gui.WCTBaseGui; -import org.lwjgl.opengl.GL11; - -public class GuiScrollbar implements IScrollSource { - - private int displayX = 0; - private int displayY = 0; - private int width = 12; - private int height = 16; - private int pageSize = 1; - - private int maxScroll = 0; - private int minScroll = 0; - private int currentScroll = 0; - - public void draw(final GuiContainer g) { - if (g instanceof GuiWirelessCraftingTerminal) { - ((GuiWirelessCraftingTerminal) g).bindTexture("minecraft", "gui/container/creative_inventory/tabs.png"); - - } else if (g instanceof WCTBaseGui) { - ((WCTBaseGui) g).bindTexture("minecraft", "gui/container/creative_inventory/tabs.png"); - } - - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - if (this.getRange() == 0) { - g.drawTexturedModalRect(this.displayX, this.displayY, 232 + this.width, 0, this.width, 15); - } else { - final int offset = (this.currentScroll - this.minScroll) * (this.height - 15) / this.getRange(); - g.drawTexturedModalRect(this.displayX, offset + this.displayY, 232, 0, this.width, 15); - } - } - - private int getRange() { - return this.maxScroll - this.minScroll; - } - - public int getLeft() { - return this.displayX; - } - - public GuiScrollbar setLeft(final int v) { - this.displayX = v; - return this; - } - - public int getTop() { - return this.displayY; - } - - public GuiScrollbar setTop(final int v) { - this.displayY = v; - return this; - } - - public int getWidth() { - return this.width; - } - - public GuiScrollbar setWidth(final int v) { - this.width = v; - return this; - } - - public int getHeight() { - return this.height; - } - - public GuiScrollbar setHeight(final int v) { - this.height = v; - return this; - } - - public void setRange(final int min, final int max, final int pageSize) { - this.minScroll = min; - this.maxScroll = max; - this.pageSize = pageSize; - - if (this.minScroll > this.maxScroll) { - this.maxScroll = this.minScroll; - } - - this.applyRange(); - } - - private void applyRange() { - this.currentScroll = Math.max(Math.min(this.currentScroll, this.maxScroll), this.minScroll); - } - - @Override - public int getCurrentScroll() { - return this.currentScroll; - } - - public void click(final GuiContainer aeBaseGui, final int x, final int y) { - if (this.getRange() == 0) { - return; - } - - if (x > this.displayX && x <= this.displayX + this.width) { - if (y > this.displayY && y <= this.displayY + this.height) { - this.currentScroll = (y - this.displayY); - this.currentScroll = this.minScroll + ((this.currentScroll * 2 * this.getRange() / this.height)); - this.currentScroll = (this.currentScroll + 1) >> 1; - this.applyRange(); - } - } - } - - public void wheel(int delta) { - delta = Math.max(Math.min(-delta, 1), -1); - this.currentScroll += delta * this.pageSize; - this.applyRange(); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerOpenContext.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerOpenContext.java deleted file mode 100644 index 221c9a8..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerOpenContext.java +++ /dev/null @@ -1,68 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container; - -import appeng.api.parts.IPart; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - -public class ContainerOpenContext { - - private final boolean isItem; - private World w; - private int x; - private int y; - private int z; - private ForgeDirection side; - - public ContainerOpenContext(final Object myItem) { - final boolean isWorld = myItem instanceof IPart || myItem instanceof TileEntity; - this.isItem = !isWorld; - } - - public TileEntity getTile() { - if (this.isItem) { - return null; - } - return this.getWorld().getTileEntity(this.getX(), this.getY(), this.getZ()); - } - - public ForgeDirection getSide() { - return this.side; - } - - public void setSide(final ForgeDirection side) { - this.side = side; - } - - private int getZ() { - return this.z; - } - - public void setZ(final int z) { - this.z = z; - } - - private int getY() { - return this.y; - } - - public void setY(final int y) { - this.y = y; - } - - private int getX() { - return this.x; - } - - public void setX(final int x) { - this.x = x; - } - - private World getWorld() { - return this.w; - } - - public void setWorld(final World w) { - this.w = w; - } -} 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 8bc7da0..0fb14f5 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java @@ -14,11 +14,9 @@ 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.energy.IEnergySource; import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.ISecurityGrid; +import appeng.api.networking.security.IActionHost; import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEMonitor; import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.data.IAEItemStack; @@ -27,11 +25,12 @@ 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.AppEngSlot; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.IContainerCraftingPacket; -import appeng.helpers.ICustomNameObject; import appeng.helpers.InventoryAction; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.IAEAppEngInventory; @@ -41,22 +40,9 @@ import appeng.util.IConfigManagerHost; import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.AdaptorPlayerHand; -import appeng.util.item.AEItemStack; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.lang.reflect.Field; -import java.nio.BufferOverflowException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -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.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; @@ -66,7 +52,6 @@ import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ChatComponentText; @@ -74,12 +59,7 @@ 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.api.networking.security.WCTIActionHost; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.GuiSync; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.SyncData; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.NullSlot; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotArmor; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotBooster; @@ -101,9 +81,7 @@ import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryViewCe 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.PacketInventoryAction; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventoryUpdate; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; @@ -111,13 +89,20 @@ import net.p455w0rd.wirelesscraftingterminal.items.ItemInfinityBooster; import net.p455w0rd.wirelesscraftingterminal.items.ItemMagnet; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -public class ContainerWirelessCraftingTerminal extends Container - implements IConfigManagerHost, - IConfigurableObject, - IMEMonitorHandlerReceiver, - IAEAppEngInventory, - IContainerCraftingPacket, - IViewCellStorage { +import javax.annotation.Nonnull; +import java.io.IOException; +import java.nio.BufferOverflowException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class ContainerWirelessCraftingTerminal extends AEBaseContainer + implements IConfigManagerHost, + IConfigurableObject, + IMEMonitorHandlerReceiver, + IAEAppEngInventory, + IContainerCraftingPacket, + IViewCellStorage { private final ItemStack containerstack; public final WCTInventoryCrafting craftingGrid; @@ -127,37 +112,35 @@ public class ContainerWirelessCraftingTerminal extends Container public final WCTInventoryTrash trashInventory; public final InventoryPlayer inventoryPlayer; public ItemStack[] craftMatrixInventory; - public ItemStack craftItem; - private World worldObj; - private EntityPlayer player; + private final World worldObj; + private final EntityPlayer player; private static final int HOTBAR_START = 1, - 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, - CRAFT_GRID_START = ARMOR_END + 1, - CRAFT_GRID_END = CRAFT_GRID_START + 8, - CRAFT_RESULT = CRAFT_GRID_END + 1, - VIEW_CELL_START = CRAFT_RESULT + 1, - VIEW_CELL_END = VIEW_CELL_START + 4, - BOOSTER_INDEX = 0, - MAGNET_INDEX = VIEW_CELL_END + 1; + 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, + CRAFT_GRID_START = ARMOR_END + 1, + CRAFT_GRID_END = CRAFT_GRID_START + 8, + CRAFT_RESULT = CRAFT_GRID_END + 1, + VIEW_CELL_START = CRAFT_RESULT + 1, + VIEW_CELL_END = VIEW_CELL_START + 4, + BOOSTER_INDEX = 0, + MAGNET_INDEX = VIEW_CELL_END + 1; public static int CRAFTING_SLOT_X_POS = 80, CRAFTING_SLOT_Y_POS = 83; private SlotBooster boosterSlot; - private SlotMagnet magnetSlot; + private final SlotMagnet magnetSlot; private NullSlot nullSlot; - private Slot[] hotbarSlot; - private Slot[] inventorySlot; - private SlotArmor[] armorSlot; - private SlotCraftingMatrix[] craftMatrixSlot; - private SlotCraftingTerm craftingSlot; - private SlotViewCell[] viewCellSlot; + private final Slot[] hotbarSlot; + private final Slot[] inventorySlot; + private final SlotArmor[] armorSlot; + private final SlotCraftingMatrix[] craftMatrixSlot; + private final SlotCraftingTerm craftingSlot; + private final SlotViewCell[] viewCellSlot; public SlotTrash trashSlot; private int firstCraftingSlotNumber = -1, lastCraftingSlotNumber = -1; private final WirelessTerminalGuiObject obj; - private boolean isContainerValid = true; private double powerMultiplier = 0.5; private final IPortableCell civ; private int ticks = 0; @@ -165,25 +148,11 @@ public class ContainerWirelessCraftingTerminal extends Container private final IItemList items = AEApi.instance().storage().createItemList(); private final IConfigManager clientCM; private IConfigManager serverCM; - private IEnergySource powerSrc; - - @GuiSync(98) - public static boolean hasPower = false; private IConfigManagerHost gui; - private final BaseActionSource mySrc; - private final HashMap syncData = new HashMap(); - private final List dataChunks = new LinkedList(); - private IAEItemStack clientRequestedTargetItem = null; - private int ticksSinceCheck = 900; - private String customName; - private boolean sentCustomName; - private ContainerOpenContext openContext; private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1); - private final HashSet locked = new HashSet(); - private IWirelessCraftingTerminalItem thisItem; - private IGridNode networkNode; - private IMEInventoryHandler cellInv; + private final IWirelessCraftingTerminalItem thisItem; + private final IGridNode networkNode; private IRecipe currentRecipe; /** @@ -192,13 +161,12 @@ public class ContainerWirelessCraftingTerminal extends Container * @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); - this.mySrc = new WCTPlayerSource(inventoryPlayer.player, this.getActionHost()); - this.customName = "WCTContainer"; + this.setCustomName("WCTContainer"); this.boosterInventory = new WCTInventoryBooster(RandomUtils.getWirelessTerm(inventoryPlayer)); this.magnetInventory = new WCTInventoryMagnet(RandomUtils.getWirelessTerm(inventoryPlayer)); @@ -218,13 +186,11 @@ public class ContainerWirelessCraftingTerminal extends Container viewCellSlot = new SlotViewCell[5]; this.obj = - getGuiObject(containerstack, player, worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); - this.civ = (IPortableCell) 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; - this.prepareSync(); - if (Platform.isServer()) { this.serverCM = civ.getConfigManager(); this.monitor = civ.getItemInventory(); @@ -232,7 +198,7 @@ public class ContainerWirelessCraftingTerminal extends Container this.monitor.addListener(this, null); setCellInventory(this.monitor); if (civ instanceof IPortableCell) { - setPowerSource((IEnergySource) this.civ); + setPowerSource(this.civ); } } else { this.setValidContainer(false); @@ -260,7 +226,7 @@ public class ContainerWirelessCraftingTerminal extends Container // Add player inventory slots for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { - inventorySlot[k] = new SlotPlayerInv(this.inventoryPlayer, j + i * 9 + 9, j * 18 + 8, 0 + i * 18); + inventorySlot[k] = new SlotPlayerInv(this.inventoryPlayer, j + i * 9 + 9, j * 18 + 8, i * 18); this.addSlotToContainer(inventorySlot[k]); k++; } @@ -276,7 +242,7 @@ public class ContainerWirelessCraftingTerminal extends Container for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { craftMatrixSlot[k] = - new SlotCraftingMatrix(this, this.craftingGrid, j + i * 3, 80 + j * 18, (i * 18) - 76); + new SlotCraftingMatrix(this, this.craftingGrid, j + i * 3, 80 + j * 18, (i * 18) - 76); this.addSlotToContainer(craftMatrixSlot[k]); if (k == 0) { this.firstCraftingSlotNumber = craftMatrixSlot[k].slotNumber; @@ -287,16 +253,16 @@ public class ContainerWirelessCraftingTerminal extends Container this.lastCraftingSlotNumber = craftMatrixSlot[8].slotNumber; craftingSlot = new SlotCraftingTerm( - this.getPlayerInv().player, - this.mySrc, - this.getPowerSource(), - this.obj, - this.craftingGrid, - this.craftingGrid, - this.output, - 174, - -58, - this); + this.getPlayerInv().player, + this.getActionSource(), + this.getPowerSource(), + this.obj, + this.craftingGrid, + this.craftingGrid, + this.output, + 174, + -58, + this); // Add crafting result slot this.addSlotToContainer(craftingSlot); @@ -319,12 +285,6 @@ public class ContainerWirelessCraftingTerminal extends Container thisItem.checkForBooster(containerstack); } - public void setCellInventory(final IMEInventoryHandler cellInv) { - this.cellInv = cellInv; - } - - public void onSlotChange(final Slot s) {} - @Override protected Slot addSlotToContainer(final Slot newSlot) { if (newSlot instanceof AppEngSlot) { @@ -333,7 +293,7 @@ public class ContainerWirelessCraftingTerminal extends Container return super.addSlotToContainer(newSlot); } else { throw new IllegalArgumentException( - "Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot."); + "Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot."); } } @@ -453,7 +413,7 @@ public class ContainerWirelessCraftingTerminal extends Container } // get target item. - final IAEItemStack slotItem = this.clientRequestedTargetItem; + final IAEItemStack slotItem = getTargetStack(); switch (action) { case SHIFT_CLICK: @@ -476,7 +436,7 @@ public class ContainerWirelessCraftingTerminal extends Container } ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { adp.addItems(ais.getItemStack()); } @@ -496,14 +456,14 @@ public class ContainerWirelessCraftingTerminal extends Container final IAEItemStack extracted = ais.copy(); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + 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()); + .extractItems(extracted, Actionable.MODULATE, this.getActionSource()); } this.updateHeld(player); @@ -534,7 +494,7 @@ public class ContainerWirelessCraftingTerminal extends Container IAEItemStack ais = slotItem.copy(); ais.setStackSize(1); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { final InventoryAdaptor ia = new AdaptorPlayerHand(player); @@ -558,7 +518,7 @@ public class ContainerWirelessCraftingTerminal extends Container IAEItemStack ais = slotItem.copy(); ais.setStackSize(ais.getItemStack().getMaxStackSize()); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { player.inventory.setItemStack(ais.getItemStack()); } else { @@ -569,7 +529,7 @@ public class ContainerWirelessCraftingTerminal extends Container } else { IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { player.inventory.setItemStack(ais.getItemStack()); } else { @@ -595,7 +555,7 @@ public class ContainerWirelessCraftingTerminal extends Container final long stackSize = Math.min(maxSize, ais.getStackSize()); ais.setStackSize((stackSize + 1) >> 1); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); } if (ais != null) { @@ -609,7 +569,7 @@ public class ContainerWirelessCraftingTerminal extends Container IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); ais.setStackSize(1); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais == null) { final ItemStack is = player.inventory.getItemStack(); is.stackSize--; @@ -651,7 +611,7 @@ public class ContainerWirelessCraftingTerminal extends Container } ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { adp.addItems(ais.getItemStack()); } else { @@ -666,23 +626,6 @@ public class ContainerWirelessCraftingTerminal extends Container } } - public IMEInventoryHandler getCellInventory() { - return this.cellInv; - } - - protected void updateHeld(final EntityPlayerMP p) { - if (Platform.isServer()) { - try { - NetworkHandler.instance.sendTo( - new PacketInventoryAction( - InventoryAction.UPDATE_HAND, 0, AEItemStack.create(p.inventory.getItemStack())), - p); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - private void updateCraftingMatrix() { if (!this.containerstack.hasTagCompound()) { this.containerstack.setTagCompound(new NBTTagCompound()); @@ -701,11 +644,11 @@ public class ContainerWirelessCraftingTerminal extends Container @Override public void onChangeInventory( - final IInventory inv, - final int slot, - final InvOperation mc, - final ItemStack removedStack, - final ItemStack newStack) { + final IInventory inv, + final int slot, + final InvOperation mc, + final ItemStack removedStack, + final ItemStack newStack) { // <3 } @@ -750,11 +693,11 @@ public class ContainerWirelessCraftingTerminal extends Container return viewCellSlot[index]; } - private WirelessTerminalGuiObject getGuiObject( - final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { + public static WirelessTerminalGuiObject 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); + AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); if (wh != null) { return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z); } @@ -765,22 +708,12 @@ public class ContainerWirelessCraftingTerminal extends Container @Override public void detectAndSendChanges() { - - this.sendCustomName(); - - // if (Platform.isSameItem(this.civ.getItemStack(), this.getPlayerInv().getCurrentItem())) { - // this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); - // } - // else { - // this.setValidContainer(false); - // } - // 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); + this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); } else { this.civ.extractAEPower((int) (0.5 * this.ticks), Actionable.MODULATE, PowerMultiplier.CONFIG); } @@ -801,7 +734,7 @@ public class ContainerWirelessCraftingTerminal extends Container for (final Object crafter : this.crafters) { try { NetworkHandler.instance.sendTo( - new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); + new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); } catch (final IOException e) { WCTLog.debug(e.getMessage()); } @@ -838,18 +771,7 @@ public class ContainerWirelessCraftingTerminal extends Container WCTLog.debug(e.getMessage()); } } - - this.sendCustomName(); - if (Platform.isServer()) { - for (final Object crafter : this.crafters) { - final ICrafting icrafting = (ICrafting) crafter; - for (final SyncData sd : this.syncData.values()) { - sd.tick(icrafting); - } - } - } } - // if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { if (!isInRange()) { if (!isBoosterInstalled() || !Reference.WCT_BOOSTER_ENABLED) { if (this.isValidContainer()) { @@ -860,14 +782,14 @@ public class ContainerWirelessCraftingTerminal extends Container if (!networkIsPowered()) { if (this.isValidContainer()) { this.getPlayerInv() - .player - .addChatMessage(new ChatComponentText(LocaleHandler.NoNetworkPower.getLocal())); + .player + .addChatMessage(new ChatComponentText(LocaleHandler.NoNetworkPower.getLocal())); } this.setValidContainer(false); } } else if (!hasAccess(SecurityPermissions.CRAFT, true) - || !hasAccess(SecurityPermissions.EXTRACT, true) - || !hasAccess(SecurityPermissions.INJECT, true)) { + || !hasAccess(SecurityPermissions.EXTRACT, true) + || !hasAccess(SecurityPermissions.INJECT, true)) { if (this.isValidContainer()) { this.getPlayerInv().player.addChatMessage(PlayerMessages.CommunicationError.get()); } @@ -875,7 +797,7 @@ public class ContainerWirelessCraftingTerminal extends Container } else { this.setPowerMultiplier(AEConfig.instance.wireless_getDrainRate(this.obj.getRange())); } - // } + super.detectAndSendChanges(); } @@ -885,14 +807,12 @@ public class ContainerWirelessCraftingTerminal extends Container return false; } boolean hasStack = - getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX).getHasStack(); + getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX).getHasStack(); if (hasStack) { Item boosterSlotContents = getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX) - .getStack() - .getItem(); - if (boosterSlotContents instanceof ItemInfinityBooster) { - return true; - } + .getStack() + .getItem(); + return boosterSlotContents instanceof ItemInfinityBooster; } return false; } @@ -903,265 +823,32 @@ public class ContainerWirelessCraftingTerminal extends Container return false; } boolean hasStack = - getSlotFromInventory(this.magnetInventory, MAGNET_INDEX).getHasStack(); + getSlotFromInventory(this.magnetInventory, MAGNET_INDEX).getHasStack(); if (hasStack) { Item magnetSlotContents = getSlotFromInventory(this.magnetInventory, MAGNET_INDEX) - .getStack() - .getItem(); - if (magnetSlotContents instanceof ItemMagnet) { - return true; - } + .getStack() + .getItem(); + return magnetSlotContents instanceof ItemMagnet; } return false; } - public BaseActionSource getActionSource() { - return this.mySrc; - } - - @Override - public boolean canInteractWith(final EntityPlayer entityplayer) { - if (this.isValidContainer()) { - return true; - } - return false; - } - - private void sendCustomName() { - if (!this.sentCustomName) { - this.sentCustomName = true; - if (Platform.isServer()) { - ICustomNameObject name = null; - if (this.obj instanceof ICustomNameObject) { - name = (ICustomNameObject) this.obj; - } - - if (this instanceof ICustomNameObject) { - name = (ICustomNameObject) this; - } - - if (name != null) { - if (name.hasCustomName()) { - this.setCustomName(name.getCustomName()); - } - - if (this.getCustomName() != null) { - try { - NetworkHandler.instance.sendTo( - new PacketValueConfig("CustomName", this.getCustomName()), - (EntityPlayerMP) this.getInventoryPlayer().player); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - } - } - } - - public void setCustomName(final String customName) { - this.customName = customName; - } - - public String getCustomName() { - return this.customName; - } - - public void stringSync(final int idx, final String value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - } - } - - public void verifyPermissions(final SecurityPermissions security, final boolean requirePower) { - if (Platform.isClient()) { - return; - } - - this.ticksSinceCheck++; - if (this.ticksSinceCheck < 20) { - return; - } - - this.ticksSinceCheck = 0; - this.setValidContainer(this.isValidContainer() && this.hasAccess(security, requirePower)); - } - protected boolean isInRange() { return this.obj.rangeCheck(Reference.WCT_BOOSTER_ENABLED && this.isBoosterInstalled()); } protected boolean networkIsPowered() { - final WCTIActionHost host = this.getActionHost(); + final IActionHost host = this.getActionHost(); if (host != null) { final IGrid grid = this.obj.getTargetGrid(); if (grid != null) { final IEnergyGrid eg = grid.getCache(IEnergyGrid.class); - if (eg.isNetworkPowered()) { - return true; - } + return eg.isNetworkPowered(); } } return false; } - protected boolean hasAccess(final SecurityPermissions perm, final boolean requirePower) { - final IGrid grid = this.obj.getTargetGrid(); - if (grid != null) { - final IEnergyGrid eg = grid.getCache(IEnergyGrid.class); - if (!eg.isNetworkPowered()) { - return false; - } - } - final ISecurityGrid sg = grid.getCache(ISecurityGrid.class); - if (sg.hasPermission(this.getInventoryPlayer().player, perm)) { - return true; - } - return false; - } - - /* - protected boolean hasAccess(final SecurityPermissions perm, final boolean requirePower) { - final WCTIActionHost host = this.getActionHost(); - - if (host != null) { - final IGridNode gn = host.getActionableNode(); - if (gn != null) { - final IGrid g = gn.getGrid(); - if (g != null) { - if (requirePower) { - final IEnergyGrid eg = g.getCache(IEnergyGrid.class); - if (!eg.isNetworkPowered() && Platform.isServer()) { - return false; - } - } - - final ISecurityGrid sg = g.getCache(ISecurityGrid.class); - if (sg.hasPermission(this.player, perm) && Platform.isServer()) { - return true; - } - } - } - } - return false; - } - */ - public void lockPlayerInventorySlot(final int idx) { - this.locked.add(idx); - } - - public boolean isValidForSlot(final Slot s, final ItemStack i) { - return true; - } - - public void postPartial(final PacketPartialItem packetPartialItem) { - this.dataChunks.add(packetPartialItem); - if (packetPartialItem.getPageCount() == this.dataChunks.size()) { - this.parsePartials(); - } - } - - private void parsePartials() { - int total = 0; - for (final PacketPartialItem ppi : this.dataChunks) { - total += ppi.getSize(); - } - - final byte[] buffer = new byte[total]; - int cursor = 0; - - for (final PacketPartialItem ppi : this.dataChunks) { - cursor = ppi.write(buffer, cursor); - } - - try { - final NBTTagCompound data = CompressedStreamTools.readCompressed(new ByteArrayInputStream(buffer)); - if (data != null) { - this.setTargetStack(AEApi.instance().storage().createItemStack(ItemStack.loadItemStackFromNBT(data))); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - - this.dataChunks.clear(); - } - - public IAEItemStack getTargetStack() { - return this.clientRequestedTargetItem; - } - - public void setTargetStack(final IAEItemStack stack) { - // client doesn't need to re-send, makes for lower overhead rapid - // packets. - if (Platform.isClient()) { - final ItemStack a = stack == null ? null : stack.getItemStack(); - final ItemStack b = - this.clientRequestedTargetItem == null ? null : this.clientRequestedTargetItem.getItemStack(); - - if (Platform.isSameItemPrecise(a, b)) { - return; - } - - final ByteArrayOutputStream stream = new ByteArrayOutputStream(); - final NBTTagCompound item = new NBTTagCompound(); - - if (stack != null) { - stack.writeToNBT(item); - } - - try { - CompressedStreamTools.writeCompressed(item, stream); - - final int maxChunkSize = 30000; - final List miniPackets = new LinkedList(); - - final byte[] data = stream.toByteArray(); - - final ByteArrayInputStream bis = new ByteArrayInputStream(data, 0, stream.size()); - while (bis.available() > 0) { - final int nextBLock = bis.available() > maxChunkSize ? maxChunkSize : bis.available(); - final byte[] nextSegment = new byte[nextBLock]; - bis.read(nextSegment); - miniPackets.add(nextSegment); - } - bis.close(); - stream.close(); - - int page = 0; - for (final byte[] packet : miniPackets) { - final PacketPartialItem ppi = new PacketPartialItem(page, miniPackets.size(), packet); - page++; - NetworkHandler.instance.sendToServer(ppi); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - return; - } - } - - this.clientRequestedTargetItem = stack == null ? null : stack.copy(); - } - - private void prepareSync() { - for (final Field f : this.getClass().getFields()) { - if (f.isAnnotationPresent(GuiSync.class)) { - final GuiSync annotation = f.getAnnotation(GuiSync.class); - if (this.syncData.containsKey(annotation.value())) { - WCTLog.warning("Channel already in use: " + annotation.value() + " for " + f.getName()); - } else { - this.syncData.put(annotation.value(), new SyncData(this, f, annotation)); - } - } - } - } - - protected WCTIActionHost getActionHost() { - if (this.obj instanceof WCTIActionHost) { - return (WCTIActionHost) this.obj; - } - return null; - } - @Override public IConfigManager getConfigManager() { if (Platform.isServer()) { @@ -1198,9 +885,9 @@ public class ContainerWirelessCraftingTerminal extends Container @Override public void postChange( - final IBaseMonitor monitor, - final Iterable change, - final BaseActionSource source) { + final IBaseMonitor monitor, + final Iterable change, + final BaseActionSource source) { for (final IAEItemStack is : change) { this.items.add(is); } @@ -1258,23 +945,11 @@ public class ContainerWirelessCraftingTerminal extends Container } } - public void onUpdate(final String field, final Object oldValue, final Object newValue) { - // =] - } - - public IEnergySource getPowerSource() { - return this.powerSrc; - } - public boolean isPowered() { double pwr = this.thisItem.getAECurrentPower(this.containerstack); return (pwr > 0.0); } - public void setPowerSource(final IEnergySource powerSrc) { - this.powerSrc = powerSrc; - } - private double getPowerMultiplier() { return this.powerMultiplier; } @@ -1283,37 +958,6 @@ public class ContainerWirelessCraftingTerminal extends Container this.powerMultiplier = powerMultiplier; } - public InventoryPlayer getPlayerInv() { - return this.getInventoryPlayer(); - } - - public InventoryPlayer getInventoryPlayer() { - return this.inventoryPlayer; - } - - public boolean isValidContainer() { - return this.isContainerValid; - } - - public void setValidContainer(final boolean isContainerValid) { - this.isContainerValid = isContainerValid; - } - - public Object getTarget() { - if (this.obj != null) { - return this.obj; - } - return null; - } - - public ContainerOpenContext getOpenContext() { - return this.openContext; - } - - public void setOpenContext(final ContainerOpenContext openContext) { - this.openContext = openContext; - } - /** * Fetches crafting matrix ItemStacks * @@ -1325,7 +969,7 @@ public class ContainerWirelessCraftingTerminal extends Container NBTTagList tagList = nbtTagCompound.getTagList("CraftingMatrix", 10); craftMatrixInventory = new ItemStack[9]; for (int i = 0; i < tagList.tagCount(); ++i) { - NBTTagCompound tagCompound = (NBTTagCompound) tagList.getCompoundTagAt(i); + NBTTagCompound tagCompound = tagList.getCompoundTagAt(i); int slot = tagCompound.getByte("Slot"); if (slot >= 0 && slot < craftMatrixInventory.length) { craftMatrixInventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound); @@ -1342,27 +986,27 @@ public class ContainerWirelessCraftingTerminal extends Container } switch (which) { case "booster": - ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); + boosterInventory.writeNBT(this.containerstack.getTagCompound()); break; case "crafting": - ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); + craftingGrid.writeNBT(this.containerstack.getTagCompound()); break; case "viewCell": - ((WCTInventoryViewCell) viewCellInventory).writeNBT(this.containerstack.getTagCompound()); + viewCellInventory.writeNBT(this.containerstack.getTagCompound()); break; case "magnet": - ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); + magnetInventory.writeNBT(this.containerstack.getTagCompound()); break; case "trash": - ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); + trashInventory.writeNBT(this.containerstack.getTagCompound()); break; case "all": default: - ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryViewCell) viewCellInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); + boosterInventory.writeNBT(this.containerstack.getTagCompound()); + craftingGrid.writeNBT(this.containerstack.getTagCompound()); + viewCellInventory.writeNBT(this.containerstack.getTagCompound()); + magnetInventory.writeNBT(this.containerstack.getTagCompound()); + trashInventory.writeNBT(this.containerstack.getTagCompound()); break; } } @@ -1604,79 +1248,10 @@ public class ContainerWirelessCraftingTerminal extends Container return null; } - public void swapSlotContents(final int slotA, final int slotB) { - final Slot a = this.getSlot(slotA); - final Slot b = this.getSlot(slotB); - - // NPE protection... - if (a == null || b == null) { - return; - } - - final ItemStack isA = a.getStack(); - final ItemStack isB = b.getStack(); - - // something to do? - if (isA == null && isB == null) { - return; - } - - // can take? - - if (isA != null && !a.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - if (isB != null && !b.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - // swap valid? - - if (isB != null && !a.isItemValid(isB)) { - return; - } - - if (isA != null && !b.isItemValid(isA)) { - return; - } - - ItemStack testA = isB == null ? null : isB.copy(); - ItemStack testB = isA == null ? null : isA.copy(); - - // can put some back? - if (testA != null && testA.stackSize > a.getSlotStackLimit()) { - if (testB != null) { - return; - } - - final int totalA = testA.stackSize; - testA.stackSize = a.getSlotStackLimit(); - testB = testA.copy(); - - testB.stackSize = totalA - testA.stackSize; - } - - if (testB != null && testB.stackSize > b.getSlotStackLimit()) { - if (testA != null) { - return; - } - - final int totalB = testB.stackSize; - testB.stackSize = b.getSlotStackLimit(); - testA = testB.copy(); - - testA.stackSize = totalB - testA.stackSize; - } - - a.putStack(testA); - b.putStack(testB); - } - @SuppressWarnings("unused") private boolean isCraftMatrixSlot(AppEngSlot cs) { return (cs.getSlotIndex() >= this.firstCraftingSlotNumber) - && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); + && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); } private void updateSlot(final Slot clickSlot) { @@ -1688,10 +1263,10 @@ public class ContainerWirelessCraftingTerminal extends Container return input; } final IAEItemStack ais = Platform.poweredInsert( - this.getPowerSource(), - this.civ, - AEApi.instance().storage().createItemStack(input), - this.getActionSource()); + this.getPowerSource(), + this.civ, + AEApi.instance().storage().createItemStack(input), + this.getActionSource()); if (ais == null) { return null; } @@ -1728,19 +1303,15 @@ public class ContainerWirelessCraftingTerminal extends Container @SuppressWarnings("unused") private boolean notArmorOrBooster(ItemStack is) { - if ((is.getItem() instanceof ItemInfinityBooster) || (is.getItem() instanceof ItemArmor)) { - return false; - } else { - return true; - } + return (!(is.getItem() instanceof ItemInfinityBooster)) && (!(is.getItem() instanceof ItemArmor)); } @Override public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) { try { if (slot >= 0 - && getSlot(slot) != null - && getSlot(slot).getStack() == RandomUtils.getWirelessTerm(player.inventory)) { + && getSlot(slot) != null + && getSlot(slot).getStack() == RandomUtils.getWirelessTerm(player.inventory)) { return null; } return super.slotClick(slot, button, flag, player); @@ -1750,15 +1321,6 @@ public class ContainerWirelessCraftingTerminal extends Container return null; } - public final void updateFullProgressBar(final int idx, final long value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - return; - } - - this.updateProgressBar(idx, (int) value); - } - /** * Handles shift-clicking of items whose maxStackSize is 1 */ @@ -1780,9 +1342,9 @@ public class ContainerWirelessCraftingTerminal extends Container } if (itemstack1 != null - && itemstack1.getItem() == stack.getItem() - && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) - && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { + && itemstack1.getItem() == stack.getItem() + && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) + && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { int l = itemstack1.stackSize + stack.stackSize; if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) { @@ -1822,7 +1384,7 @@ public class ContainerWirelessCraftingTerminal extends Container break; } else { putStackInSlot( - k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); + k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); stack.stackSize -= slot.getSlotStackLimit(); boosterInventory.markDirty(); flag1 = true; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java deleted file mode 100644 index f039e7b..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java +++ /dev/null @@ -1,1098 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container; - -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.SecurityPermissions; -import appeng.api.implementations.guiobjects.IGuiItemObject; -import appeng.api.networking.IGrid; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.parts.IPart; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.me.InternalSlotME; -import appeng.client.me.SlotME; -import appeng.helpers.ICustomNameObject; -import appeng.helpers.InventoryAction; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.AdaptorPlayerHand; -import appeng.util.item.AEItemStack; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.GuiSync; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.SyncData; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerHotBar; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerInv; -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.PacketInventoryAction; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; - -public abstract class WCTBaseContainer extends Container { - - private final InventoryPlayer invPlayer; - private final BaseActionSource mySrc; - private final HashSet locked = new HashSet(); - private final TileEntity tileEntity; - private final IPart part; - public final IGuiItemObject obj; - public final WirelessTerminalGuiObject obj2; - private final List dataChunks = new LinkedList(); - private final HashMap syncData = new HashMap(); - private boolean isContainerValid = true; - private String customName; - private ContainerOpenContext openContext; - private IMEInventoryHandler cellInv; - private IEnergySource powerSrc; - private boolean sentCustomName; - private int ticksSinceCheck = 900; - private IAEItemStack clientRequestedTargetItem = null; - - public WCTBaseContainer(final InventoryPlayer ip, final TileEntity myTile, final IPart myPart) { - this(ip, myTile, myPart, null); - } - - public WCTBaseContainer( - final InventoryPlayer ip, final TileEntity myTile, final IPart myPart, final IGuiItemObject gio) { - this.invPlayer = ip; - this.tileEntity = myTile; - this.part = myPart; - this.obj = gio; - EntityPlayer player = ip.player; - this.obj2 = getGuiObject( - RandomUtils.getWirelessTerm(ip), player, player.worldObj, (int) player.posX, (int) player.posY, (int) - player.posZ); - this.mySrc = new WCTPlayerSource(ip.player, this.getActionHost()); - this.prepareSync(); - } - - protected WirelessTerminalGuiObject 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 null; - } - - protected WCTIActionHost getActionHost() { - if (this.obj instanceof WCTIActionHost) { - return (WCTIActionHost) this.obj; - } - - if (this.tileEntity instanceof WCTIActionHost) { - return (WCTIActionHost) this.tileEntity; - } - - if (this.part instanceof WCTIActionHost) { - return (WCTIActionHost) this.part; - } - - return null; - } - - private void prepareSync() { - for (final Field f : this.getClass().getFields()) { - if (f.isAnnotationPresent(GuiSync.class)) { - final GuiSync annotation = f.getAnnotation(GuiSync.class); - if (this.syncData.containsKey(annotation.value())) { - WCTLog.warning("Channel already in use: " + annotation.value() + " for " + f.getName()); - } else { - this.syncData.put(annotation.value(), new SyncData(this, f, annotation)); - } - } - } - } - - public WCTBaseContainer(final InventoryPlayer ip, final Object anchor) { - this.invPlayer = ip; - this.tileEntity = anchor instanceof TileEntity ? (TileEntity) anchor : null; - this.part = anchor instanceof IPart ? (IPart) anchor : null; - this.obj = anchor instanceof IGuiItemObject ? (IGuiItemObject) anchor : null; - - EntityPlayer player = ip.player; - this.obj2 = getGuiObject( - RandomUtils.getWirelessTerm(ip), player, player.worldObj, (int) player.posX, (int) player.posY, (int) - player.posZ); - - if (this.tileEntity == null && this.part == null && this.obj == null) { - throw new IllegalArgumentException("Must have a valid anchor, instead " + anchor + " in " + ip); - } - - this.mySrc = new WCTPlayerSource(ip.player, this.getActionHost()); - - this.prepareSync(); - } - - public void postPartial(final PacketPartialItem packetPartialItem) { - this.dataChunks.add(packetPartialItem); - if (packetPartialItem.getPageCount() == this.dataChunks.size()) { - this.parsePartials(); - } - } - - private void parsePartials() { - int total = 0; - for (final PacketPartialItem ppi : this.dataChunks) { - total += ppi.getSize(); - } - - final byte[] buffer = new byte[total]; - int cursor = 0; - - for (final PacketPartialItem ppi : this.dataChunks) { - cursor = ppi.write(buffer, cursor); - } - - try { - final NBTTagCompound data = CompressedStreamTools.readCompressed(new ByteArrayInputStream(buffer)); - if (data != null) { - this.setTargetStack(AEApi.instance().storage().createItemStack(ItemStack.loadItemStackFromNBT(data))); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - - this.dataChunks.clear(); - } - - public IAEItemStack getTargetStack() { - return this.clientRequestedTargetItem; - } - - public void setTargetStack(final IAEItemStack stack) { - // client doesn't need to re-send, makes for lower overhead rapid packets. - if (Platform.isClient()) { - final ItemStack a = stack == null ? null : stack.getItemStack(); - final ItemStack b = - this.clientRequestedTargetItem == null ? null : this.clientRequestedTargetItem.getItemStack(); - - if (Platform.isSameItemPrecise(a, b)) { - return; - } - - final ByteArrayOutputStream stream = new ByteArrayOutputStream(); - final NBTTagCompound item = new NBTTagCompound(); - - if (stack != null) { - stack.writeToNBT(item); - } - - try { - CompressedStreamTools.writeCompressed(item, stream); - - final int maxChunkSize = 30000; - final List miniPackets = new LinkedList(); - - final byte[] data = stream.toByteArray(); - - final ByteArrayInputStream bis = new ByteArrayInputStream(data, 0, stream.size()); - while (bis.available() > 0) { - final int nextBLock = bis.available() > maxChunkSize ? maxChunkSize : bis.available(); - final byte[] nextSegment = new byte[nextBLock]; - bis.read(nextSegment); - miniPackets.add(nextSegment); - } - bis.close(); - stream.close(); - - int page = 0; - for (final byte[] packet : miniPackets) { - final PacketPartialItem ppi = new PacketPartialItem(page, miniPackets.size(), packet); - page++; - NetworkHandler.instance.sendToServer(ppi); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - return; - } - } - - this.clientRequestedTargetItem = stack == null ? null : stack.copy(); - } - - public BaseActionSource getActionSource() { - return this.mySrc; - } - - public void verifyPermissions(final SecurityPermissions security, final boolean requirePower) { - if (Platform.isClient()) { - return; - } - - this.ticksSinceCheck++; - if (this.ticksSinceCheck < 20) { - return; - } - - this.ticksSinceCheck = 0; - this.setValidContainer(this.isValidContainer() && this.hasAccess(security, requirePower)); - } - - protected boolean hasAccess(final SecurityPermissions perm, final boolean requirePower) { - final IGrid grid = this.obj2.getTargetGrid(); - if (grid != null) { - final IEnergyGrid eg = grid.getCache(IEnergyGrid.class); - if (!eg.isNetworkPowered()) { - return false; - } - } - final ISecurityGrid sg = grid.getCache(ISecurityGrid.class); - if (sg.hasPermission(this.getInventoryPlayer().player, perm)) { - return true; - } - return false; - } - - public void lockPlayerInventorySlot(final int idx) { - this.locked.add(idx); - } - - public Object getTarget() { - if (this.tileEntity != null) { - return this.tileEntity; - } - if (this.part != null) { - return this.part; - } - if (this.obj2 != null) { - return this.obj2; - } - return null; - } - - public InventoryPlayer getPlayerInv() { - return this.getInventoryPlayer(); - } - - public TileEntity getTileEntity() { - return this.tileEntity; - } - - public final void updateFullProgressBar(final int idx, final long value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - return; - } - - this.updateProgressBar(idx, (int) value); - } - - public void stringSync(final int idx, final String value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - } - } - - protected void bindPlayerInventory(final InventoryPlayer inventoryPlayer, final int offsetX, final int offsetY) { - // bind player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - if (this.locked.contains(j + i * 9 + 9)) { - this.addSlotToContainer( - new SlotDisabled(inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18)); - } else { - this.addSlotToContainer( - new SlotPlayerInv(inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18)); - } - } - } - - // bind player hotbar - for (int i = 0; i < 9; i++) { - if (this.locked.contains(i)) { - this.addSlotToContainer(new SlotDisabled(inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY)); - } else { - this.addSlotToContainer(new SlotPlayerHotBar(inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY)); - } - } - } - - @Override - protected Slot addSlotToContainer(final Slot newSlot) { - if (newSlot instanceof AppEngSlot) { - final AppEngSlot s = (AppEngSlot) newSlot; - s.setContainer(this); - return super.addSlotToContainer(newSlot); - } else { - throw new IllegalArgumentException("Invalid Slot [" + newSlot + "]for AE Container instead of AppEngSlot."); - } - } - - @Override - public void detectAndSendChanges() { - this.sendCustomName(); - - if (Platform.isServer()) { - for (final Object crafter : this.crafters) { - final ICrafting icrafting = (ICrafting) crafter; - - for (final SyncData sd : this.syncData.values()) { - sd.tick(icrafting); - } - } - } - - super.detectAndSendChanges(); - } - - @Override - public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { - 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; - } - - final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots! - - if (clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible) { - return null; - } - if (clickSlot != null && clickSlot.getHasStack()) { - ItemStack tis = clickSlot.getStack(); - - if (tis == null) { - return null; - } - - 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 SlotCraftingMatrix)) { - 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 SlotCraftingMatrix)) { - 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; - } - - @Override - public final void updateProgressBar(final int idx, final int value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update((long) value); - } - } - - @Override - public boolean canInteractWith(final EntityPlayer entityplayer) { - if (this.isValidContainer()) { - if (this.tileEntity instanceof IInventory) { - return ((IInventory) this.tileEntity).isUseableByPlayer(entityplayer); - } - return true; - } - return false; - } - - @Override - public boolean canDragIntoSlot(final Slot s) { - return ((AppEngSlot) s).isDraggable(); - } - - 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); - default: - } - } - - 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 = this.clientRequestedTargetItem; - - 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 (this.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; - } - } - - protected void updateHeld(final EntityPlayerMP p) { - if (Platform.isServer()) { - try { - NetworkHandler.instance.sendTo( - new PacketInventoryAction( - InventoryAction.UPDATE_HAND, 0, AEItemStack.create(p.inventory.getItemStack())), - p); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - - private ItemStack shiftStoreItem(final ItemStack input) { - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return input; - } - final IAEItemStack ais = Platform.poweredInsert( - this.getPowerSource(), - this.getCellInventory(), - AEApi.instance().storage().createItemStack(input), - this.getActionSource()); - if (ais == null) { - return null; - } - return ais.getItemStack(); - } - - private void updateSlot(final Slot clickSlot) { - // ??? - this.detectAndSendChanges(); - } - - private void sendCustomName() { - if (!this.sentCustomName) { - this.sentCustomName = true; - if (Platform.isServer()) { - ICustomNameObject name = null; - - if (this.part instanceof ICustomNameObject) { - name = (ICustomNameObject) this.part; - } - - if (this.tileEntity instanceof ICustomNameObject) { - name = (ICustomNameObject) this.tileEntity; - } - - if (this.obj instanceof ICustomNameObject) { - name = (ICustomNameObject) this.obj; - } - - if (this instanceof ICustomNameObject) { - name = (ICustomNameObject) this; - } - - if (name != null) { - if (name.hasCustomName()) { - this.setCustomName(name.getCustomName()); - } - - if (this.getCustomName() != null) { - try { - NetworkHandler.instance.sendTo( - new PacketValueConfig("CustomName", this.getCustomName()), - (EntityPlayerMP) this.getInventoryPlayer().player); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - } - } - } - - public void swapSlotContents(final int slotA, final int slotB) { - final Slot a = this.getSlot(slotA); - final Slot b = this.getSlot(slotB); - - // NPE protection... - if (a == null || b == null) { - return; - } - - final ItemStack isA = a.getStack(); - final ItemStack isB = b.getStack(); - - // something to do? - if (isA == null && isB == null) { - return; - } - - // can take? - - if (isA != null && !a.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - if (isB != null && !b.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - // swap valid? - - if (isB != null && !a.isItemValid(isB)) { - return; - } - - if (isA != null && !b.isItemValid(isA)) { - return; - } - - ItemStack testA = isB == null ? null : isB.copy(); - ItemStack testB = isA == null ? null : isA.copy(); - - // can put some back? - if (testA != null && testA.stackSize > a.getSlotStackLimit()) { - if (testB != null) { - return; - } - - final int totalA = testA.stackSize; - testA.stackSize = a.getSlotStackLimit(); - testB = testA.copy(); - - testB.stackSize = totalA - testA.stackSize; - } - - if (testB != null && testB.stackSize > b.getSlotStackLimit()) { - if (testA != null) { - return; - } - - final int totalB = testB.stackSize; - testB.stackSize = b.getSlotStackLimit(); - testA = testB.copy(); - - testA.stackSize = totalB - testA.stackSize; - } - - a.putStack(testA); - b.putStack(testB); - } - - public void onUpdate(final String field, final Object oldValue, final Object newValue) {} - - public void onSlotChange(final Slot s) {} - - public boolean isValidForSlot(final Slot s, final ItemStack i) { - return true; - } - - public IMEInventoryHandler getCellInventory() { - return this.cellInv; - } - - public void setCellInventory(final IMEInventoryHandler cellInv) { - this.cellInv = cellInv; - } - - public String getCustomName() { - return this.customName; - } - - public void setCustomName(final String customName) { - this.customName = customName; - } - - public InventoryPlayer getInventoryPlayer() { - return this.invPlayer; - } - - public boolean isValidContainer() { - return this.isContainerValid; - } - - public void setValidContainer(final boolean isContainerValid) { - this.isContainerValid = isContainerValid; - } - - public ContainerOpenContext getOpenContext() { - return this.openContext; - } - - public void setOpenContext(final ContainerOpenContext openContext) { - this.openContext = openContext; - } - - public IEnergySource getPowerSource() { - return this.powerSrc; - } - - public void setPowerSource(final IEnergySource powerSrc) { - this.powerSrc = powerSrc; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/GuiSync.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/GuiSync.java deleted file mode 100644 index 8a4d922..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/GuiSync.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.guisync; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotates that this field should be synchronized between the server and client. - * Requires the field to be public. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface GuiSync { - - int value(); -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/SyncData.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/SyncData.java deleted file mode 100644 index af5f191..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/SyncData.java +++ /dev/null @@ -1,140 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.guisync; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.EnumSet; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; - -public class SyncData { - private final Container source; - private final Field field; - private final int channel; - private Object clientVersion; - - public SyncData(final Container container, final Field field, final GuiSync annotation) { - if (container instanceof ContainerWirelessCraftingTerminal) { - this.source = (ContainerWirelessCraftingTerminal) container; - } else if (container instanceof WCTBaseContainer) { - this.source = (WCTBaseContainer) container; - } else { - this.source = container; - } - this.clientVersion = null; - this.field = field; - this.channel = annotation.value(); - } - - public int getChannel() { - return this.channel; - } - - public void tick(final ICrafting c) { - try { - final Object val = this.field.get(this.source); - if (val != null && this.clientVersion == null) { - this.send(c, val); - } else if (!val.equals(this.clientVersion)) { - this.send(c, val); - } - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - - @SuppressWarnings("rawtypes") - private void send(final ICrafting o, final Object val) throws IOException { - if (val instanceof String) { - if (o instanceof EntityPlayerMP) { - NetworkHandler.instance.sendTo( - new PacketValueConfig("SyncDat." + this.channel, (String) val), (EntityPlayerMP) o); - } - } else if (this.field.getType().isEnum()) { - o.sendProgressBarUpdate(this.source, this.channel, ((Enum) val).ordinal()); - } else if (val instanceof Long || val.getClass() == long.class) { - // NetworkHandler.instance.sendTo( new PacketProgressBar( this.channel, (Long) val ), (EntityPlayerMP) o ); - } else if (val instanceof Boolean || val.getClass() == boolean.class) { - o.sendProgressBarUpdate(this.source, this.channel, ((Boolean) val) ? 1 : 0); - } else { - o.sendProgressBarUpdate(this.source, this.channel, (Integer) val); - } - - this.clientVersion = val; - } - - public void update(final Object val) { - try { - final Object oldValue = this.field.get(this.source); - if (val instanceof String) { - this.updateString(oldValue, (String) val); - } else { - this.updateValue(oldValue, (Long) val); - } - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } - } - - private void updateString(final Object oldValue, final String val) { - try { - this.field.set(this.source, val); - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private void updateValue(final Object oldValue, final long val) { - try { - if (this.field.getType().isEnum()) { - final EnumSet valList = EnumSet.allOf((Class) this.field.getType()); - for (final Enum e : valList) { - if (e.ordinal() == val) { - this.field.set(this.source, e); - break; - } - } - } else { - if (this.field.getType().equals(int.class)) { - this.field.set(this.source, (int) val); - } else if (this.field.getType().equals(long.class)) { - this.field.set(this.source, val); - } else if (this.field.getType().equals(boolean.class)) { - this.field.set(this.source, val == 1); - } else if (this.field.getType().equals(Integer.class)) { - this.field.set(this.source, (int) val); - } else if (this.field.getType().equals(Long.class)) { - this.field.set(this.source, val); - } else if (this.field.getType().equals(Boolean.class)) { - this.field.set(this.source, val == 1); - } - } - - if (this.source instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) this.source) - .onUpdate(this.field.getName(), oldValue, this.field.get(this.source)); - } - if (this.source instanceof WCTBaseContainer) { - ((WCTBaseContainer) this.source).onUpdate(this.field.getName(), oldValue, this.field.get(this.source)); - } - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java index 17516b6..0c0dccf 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java @@ -1,210 +1,10 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot; -import appeng.tile.inventory.AppEngInternalInventory; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -public class AppEngSlot extends Slot { - - private final int defX; - private final int defY; - private boolean isDraggable = true; - private boolean isPlayerSide = false; - private Container myContainer = null; - private int IIcon = -1; - private hasCalculatedValidness isValid; - private boolean isDisplay = false; +public class AppEngSlot extends appeng.container.slot.AppEngSlot { public AppEngSlot(final IInventory inv, final int idx, final int x, final int y) { super(inv, idx, x, y); - this.defX = x; - this.defY = y; - this.setIsValid(hasCalculatedValidness.NotAvailable); - } - - public Slot setNotDraggable() { - this.setDraggable(false); - return this; - } - - public Slot setPlayerSide() { - this.isPlayerSide = true; - return this; - } - - public String getTooltip() { - return null; - } - - public void clearStack() { - super.putStack(null); - } - - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - if (this.isEnabled()) { - return super.isItemValid(par1ItemStack); - } - return false; - } - - @Override - public ItemStack getStack() { - if (!this.isEnabled()) { - return null; - } - - if (this.inventory.getSizeInventory() <= this.getSlotIndex()) { - return null; - } - - if (this.isDisplay()) { - this.setDisplay(false); - return this.getDisplayStack(); - } - return super.getStack(); - } - - @Override - public void putStack(final ItemStack par1ItemStack) { - if (this.isEnabled()) { - super.putStack(par1ItemStack); - - if (this.getContainer() != null) { - if (this.getContainer() instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) this.getContainer()).onSlotChange(this); - } - if (this.getContainer() instanceof WCTBaseContainer) { - ((WCTBaseContainer) this.getContainer()).onSlotChange(this); - } - } - } - } - - @Override - public void onSlotChanged() { - if (this.inventory instanceof AppEngInternalInventory) { - ((AppEngInternalInventory) this.inventory).markDirty(this.getSlotIndex()); - } else { - super.onSlotChanged(); - } - - this.setIsValid(hasCalculatedValidness.NotAvailable); - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - if (this.isEnabled()) { - return super.canTakeStack(par1EntityPlayer); - } - return false; - } - - @Override - public boolean func_111238_b() { - return this.isEnabled(); - } - - public ItemStack getDisplayStack() { - return super.getStack(); - } - - public boolean isEnabled() { - return true; - } - - public float getOpacityOfIcon() { - return 0.4f; - } - - public boolean renderIconWithItem() { - return false; - } - - public int getIcon() { - return this.getIIcon(); - } - - public boolean isPlayerSide() { - return this.isPlayerSide; - } - - public boolean shouldDisplay() { - return this.isEnabled(); - } - - public int getX() { - return this.defX; - } - - public int getY() { - return this.defY; - } - - private int getIIcon() { - return this.IIcon; - } - - public void setIIcon(final int iIcon) { - this.IIcon = iIcon; - } - - private boolean isDisplay() { - return this.isDisplay; - } - - public void setDisplay(final boolean isDisplay) { - this.isDisplay = isDisplay; - } - - public boolean isDraggable() { - return this.isDraggable; - } - - private void setDraggable(final boolean isDraggable) { - this.isDraggable = isDraggable; - } - - void setPlayerSide(final boolean isPlayerSide) { - this.isPlayerSide = isPlayerSide; - } - - public hasCalculatedValidness getIsValid() { - return this.isValid; - } - - public void setIsValid(final hasCalculatedValidness isValid) { - this.isValid = isValid; - } - - Container getContainer() { - if (this.myContainer instanceof ContainerWirelessCraftingTerminal) { - return (ContainerWirelessCraftingTerminal) this.myContainer; - } - if (this.myContainer instanceof WCTBaseContainer) { - return (WCTBaseContainer) this.myContainer; - } - return this.myContainer; - } - - public void setContainer(final Container myContainer) { - if (this.myContainer instanceof ContainerWirelessCraftingTerminal) { - this.myContainer = (ContainerWirelessCraftingTerminal) myContainer; - } else if (this.myContainer instanceof WCTBaseContainer) { - this.myContainer = (WCTBaseContainer) myContainer; - } else { - this.myContainer = myContainer; - } - } - - public enum hasCalculatedValidness { - NotAvailable, - Valid, - Invalid } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java index 3ce44fc..81e7f56 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java @@ -2,10 +2,9 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot; import net.minecraft.inventory.IInventory; -public class SlotPlayerHotBar extends AppEngSlot { +public class SlotPlayerHotBar extends appeng.container.slot.SlotPlayerHotBar { public SlotPlayerHotBar(final IInventory par1iInventory, final int par2, final int par3, final int par4) { super(par1iInventory, par2, par3, par4); - this.setPlayerSide(true); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java index cfcfe20..9ed4abd 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java @@ -4,11 +4,9 @@ import net.minecraft.inventory.IInventory; // there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot. -public class SlotPlayerInv extends AppEngSlot { +public class SlotPlayerInv extends appeng.container.slot.SlotPlayerInv { public SlotPlayerInv(final IInventory par1iInventory, final int par2, final int par3, final int par4) { super(par1iInventory, par2, par3, par4); - - this.setPlayerSide(true); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java index adbf1bc..65dbada 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java @@ -14,9 +14,7 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventory import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMagnetFilter; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketOpenGui; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetMagnet; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; @@ -33,12 +31,8 @@ public class WCTPacketHandlerBase { PACKET_SWITCH_GUIS(PacketSwitchGuis.class), - PACKET_SWAP_SLOTS(PacketSwapSlots.class), - PACKET_RECIPE_NEI(PacketNEIRecipe.class), - PACKET_PARTIAL_ITEM(PacketPartialItem.class), - PACKET_CRAFTING_REQUEST(PacketCraftRequest.class), PACKET_MAGNETFILTER_MODE(PacketMagnetFilter.class), 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 ec013ff..c1b0ca0 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 @@ -2,6 +2,8 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; 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; @@ -13,9 +15,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerOpenContext; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; @@ -95,15 +95,10 @@ public class PacketInventoryAction extends WCTPacket { final EntityPlayerMP sender = (EntityPlayerMP) player; Container baseContainer = sender.openContainer; ContainerOpenContext context = null; - if (sender.openContainer instanceof ContainerWirelessCraftingTerminal) { - baseContainer = (ContainerWirelessCraftingTerminal) sender.openContainer; - context = ((ContainerWirelessCraftingTerminal) baseContainer).getOpenContext(); + if (baseContainer instanceof AEBaseContainer) { + context = ((AEBaseContainer) baseContainer).getOpenContext(); } - if (sender.openContainer instanceof WCTBaseContainer) { - baseContainer = (WCTBaseContainer) sender.openContainer; - context = ((WCTBaseContainer) baseContainer).getOpenContext(); - } if (this.action == InventoryAction.AUTO_CRAFT) { // if( context != null ) @@ -129,13 +124,13 @@ public class PacketInventoryAction extends WCTPacket { } } - if (baseContainer instanceof WCTBaseContainer) { - if (((WCTBaseContainer) baseContainer).getTargetStack() != null) { + if (baseContainer instanceof AEBaseContainer) { + if (((AEBaseContainer) baseContainer).getTargetStack() != null) { cca.getCraftingItem() - .putStack(((WCTBaseContainer) baseContainer) + .putStack(((AEBaseContainer) baseContainer) .getTargetStack() .getItemStack()); - cca.setItemToCraft(((WCTBaseContainer) baseContainer).getTargetStack()); + cca.setItemToCraft(((AEBaseContainer) baseContainer).getTargetStack()); } } @@ -150,8 +145,8 @@ public class PacketInventoryAction extends WCTPacket { ((ContainerWirelessCraftingTerminal) baseContainer) .doAction(sender, this.action, this.slot, this.id); } - if (baseContainer instanceof WCTBaseContainer) { - ((WCTBaseContainer) baseContainer).doAction(sender, this.action, this.slot, this.id); + if (baseContainer instanceof AEBaseContainer) { + ((AEBaseContainer) baseContainer).doAction(sender, this.action, this.slot, this.id); } } } 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 d542e08..3c27778 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 @@ -39,6 +39,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; +import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; @@ -82,19 +83,6 @@ public class PacketNEIRecipe extends WCTPacket { configureWrite(data); } - private WirelessTerminalGuiObject 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 null; - } - @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { @@ -106,7 +94,7 @@ public class PacketNEIRecipe extends WCTPacket { IGridNode node = cct.getNetworkNode(); if (node == null) { - WirelessTerminalGuiObject obj = getGuiObject( + WirelessTerminalGuiObject obj = ContainerWirelessCraftingTerminal.getGuiObject( RandomUtils.getWirelessTerm(player.inventory), player, player.worldObj, diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketPartialItem.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketPartialItem.java deleted file mode 100644 index e4d94fe..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketPartialItem.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import net.minecraft.entity.player.EntityPlayer; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketPartialItem extends WCTPacket { - - private final short pageNum; - private final byte[] data; - - // automatic. - public PacketPartialItem(final ByteBuf stream) { - this.pageNum = stream.readShort(); - stream.readBytes(this.data = new byte[stream.readableBytes()]); - } - - // api - public PacketPartialItem(final int page, final int maxPages, final byte[] buf) { - - final ByteBuf data = Unpooled.buffer(); - - this.pageNum = (short) (page | (maxPages << 8)); - this.data = buf; - data.writeInt(this.getPacketID()); - data.writeShort(this.pageNum); - data.writeBytes(buf); - - this.configureWrite(data); - } - - @Override - public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { - if (player.openContainer instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) player.openContainer).postPartial(this); - } - if (player.openContainer instanceof WCTBaseContainer) { - ((WCTBaseContainer) player.openContainer).postPartial(this); - } - } - - public int getPageCount() { - return this.pageNum >> 8; - } - - public int getSize() { - return this.data.length; - } - - public int write(final byte[] buffer, final int cursor) { - System.arraycopy(this.data, 0, buffer, cursor, this.data.length); - return cursor + this.data.length; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketProgressBar.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketProgressBar.java deleted file mode 100644 index fc489ad..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketProgressBar.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketProgressBar extends WCTPacket { - - private final short id; - private final long value; - - // automatic. - public PacketProgressBar(final ByteBuf stream) { - this.id = stream.readShort(); - this.value = stream.readLong(); - } - - // api - public PacketProgressBar(final int shortID, final long value) { - this.id = (short) shortID; - this.value = value; - - final ByteBuf data = Unpooled.buffer(); - - data.writeInt(this.getPacketID()); - data.writeShort(shortID); - data.writeLong(value); - - this.configureWrite(data); - } - - @Override - public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { - final Container c = player.openContainer; - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c).updateFullProgressBar(this.id, this.value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).updateFullProgressBar(this.id, this.value); - } - } - - @Override - public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) { - final Container c = player.openContainer; - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c).updateFullProgressBar(this.id, this.value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).updateFullProgressBar(this.id, this.value); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSwapSlots.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSwapSlots.java deleted file mode 100644 index 8f74f18..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSwapSlots.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import net.minecraft.entity.player.EntityPlayer; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketSwapSlots extends WCTPacket { - - private final int slotA; - private final int slotB; - - // automatic. - public PacketSwapSlots(final ByteBuf stream) { - this.slotA = stream.readInt(); - this.slotB = stream.readInt(); - } - - // api - public PacketSwapSlots(final int slotA, final int slotB) { - final ByteBuf data = Unpooled.buffer(); - - data.writeInt(this.getPacketID()); - data.writeInt(this.slotA = slotA); - data.writeInt(this.slotB = slotB); - - this.configureWrite(data); - } - - @Override - public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { - if (player != null) { - if (player.openContainer instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) player.openContainer).swapSlotContents(this.slotA, this.slotB); - } - if (player.openContainer instanceof WCTBaseContainer) { - ((WCTBaseContainer) player.openContainer).swapSlotContents(this.slotA, this.slotB); - } - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java index 6b6a9ae..e09728a 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java @@ -3,6 +3,7 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; import appeng.api.config.Settings; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigurableObject; +import appeng.container.AEBaseContainer; import appeng.helpers.IMouseWheelItem; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -15,7 +16,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; @@ -85,19 +85,12 @@ public class PacketValueConfig extends WCTPacket { final Container c = player.openContainer; if (this.Name.equals("CustomName")) { - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c).setCustomName(this.Value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).setCustomName(this.Value); + if (c instanceof AEBaseContainer) { + ((AEBaseContainer) c).setCustomName(this.Value); } } else if (this.Name.startsWith("SyncDat.")) { - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c) - .stringSync(Integer.parseInt(this.Name.substring(8)), this.Value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value); + if (c instanceof AEBaseContainer) { + ((AEBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value); } } else if (c instanceof IConfigurableObject) { final IConfigManager cm = ((IConfigurableObject) c).getConfigManager(); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java index 4a3d07d..9f7c68d 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java @@ -6,6 +6,7 @@ import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.features.ILocatable; import appeng.api.features.IWirelessTermHandler; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.tiles.IWirelessAccessPoint; import appeng.api.networking.IGrid; @@ -33,7 +34,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -public class WirelessTerminalGuiObject implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost { +public class WirelessTerminalGuiObject implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost, IGuiItemObject { private final ItemStack effectiveItem; private final IWirelessTermHandler wth; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java index 653108f..626c350 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java @@ -477,19 +477,6 @@ public class ItemMagnet extends Item { return true; } - public WirelessTerminalGuiObject 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 null; - } - public static List getEntitiesInRange( Class entityType, World world, int x, int y, int z, int distance) { return world.getEntitiesWithinAABB( diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java index df3d467..e8a2159 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java @@ -1,6 +1,7 @@ package net.p455w0rd.wirelesscraftingterminal.items; import appeng.api.config.*; +import appeng.api.features.IWirelessTermHandler; import appeng.api.util.IConfigManager; import appeng.items.tools.powered.powersink.AERootPoweredItem; import appeng.util.ConfigManager; @@ -32,7 +33,7 @@ import net.p455w0rd.wirelesscraftingterminal.integration.EnderIO; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.lwjgl.input.Keyboard; -public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTerminalItem, IBauble { +public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTerminalItem, IWirelessTermHandler, IBauble { public static final String LINK_KEY_STRING = "key"; public static double GLOBAL_POWER_MULTIPLIER = PowerMultiplier.CONFIG.multiplier; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java index 8f7eb5b..da1dcb7 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java @@ -31,6 +31,7 @@ import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; +import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; @@ -225,7 +226,7 @@ public class CommonProxy { if (magnetStack.getItem() instanceof ItemMagnet) { ItemMagnet magnet = (ItemMagnet) magnetStack.getItem(); - magnet.obj = magnet.getGuiObject( + magnet.obj = ContainerWirelessCraftingTerminal.getGuiObject( WCTStack, player, world, (int) player.posX, (int) player.posY, (int) player.posZ); magnet.civ = magnet.obj; magnet.powerSrc = magnet.civ;