From c920b7286242b9cab64b4660aaa97513b4a9fc25 Mon Sep 17 00:00:00 2001 From: p455w0rd Date: Wed, 27 Apr 2016 14:34:18 -0400 Subject: [PATCH] bit of code cleanup --- .../networking/security/WCTPlayerSource.java | 13 +- .../gui/GuiWirelessCraftingTerminal.java | 1283 +++++++---------- .../common/WirelessCraftingTerminal.java | 10 +- .../common/container/ContainerMagnet.java | 21 +- .../ContainerWirelessCraftingTerminal.java | 1104 ++++++-------- .../common/container/WCTBaseContainer.java | 1198 +++++++-------- .../common/container/slot/AppEngSlot.java | 151 +- .../common/container/slot/SlotMagnet.java | 30 +- .../core/sync/network/NetworkHandler.java | 75 +- .../core/sync/packets/PacketCraftRequest.java | 1 - .../sync/packets/PacketMagnetFilterMode.java | 19 +- .../sync/packets/PacketOpenWirelessTerm.java | 24 +- .../core/sync/packets/PacketValueConfig.java | 120 +- .../handlers/AchievementHandler.java | 1 - .../handlers/ConfigHandler.java | 7 + .../handlers/KeybindHandler.java | 13 +- .../handlers/RecipeHandler.java | 12 - .../helpers/WirelessTerminalGuiObject.java | 230 ++- .../implementation/WCTInteractionHelper.java | 37 +- .../implementation/WirelessAELink.java | 358 +---- .../items/ItemEnum.java | 47 +- .../items/ItemMagnet.java | 1 - .../items/ItemWirelessCraftingTerminal.java | 3 +- .../proxy/ClientProxy.java | 4 + .../proxy/CommonProxy.java | 30 +- 25 files changed, 1860 insertions(+), 2932 deletions(-) diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/api/networking/security/WCTPlayerSource.java b/src/java/net/p455w0rd/wirelesscraftingterminal/api/networking/security/WCTPlayerSource.java index 048a43f..3583b9e 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/api/networking/security/WCTPlayerSource.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/api/networking/security/WCTPlayerSource.java @@ -1,27 +1,22 @@ package net.p455w0rd.wirelesscraftingterminal.api.networking.security; - import appeng.api.networking.security.IActionHost; import appeng.api.networking.security.PlayerSource; import net.minecraft.entity.player.EntityPlayer; - -public class WCTPlayerSource extends PlayerSource -{ +public class WCTPlayerSource extends PlayerSource { public final EntityPlayer player; public final WCTIActionHost via; - public WCTPlayerSource( final EntityPlayer p, final WCTIActionHost v ) - { - super(p,(IActionHost) v); + public WCTPlayerSource(final EntityPlayer p, final WCTIActionHost v) { + super(p, (IActionHost) v); this.player = p; this.via = v; } @Override - public boolean isPlayer() - { + public boolean isPlayer() { return true; } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index 72677db..f3ace0b 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -73,31 +73,25 @@ import net.p455w0rd.wirelesscraftingterminal.integration.abstraction.INEI; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSource, IConfigManagerHost -{ +public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSource, IConfigManagerHost { - /* - * x and y size of the inventory window in pixels. Defined as float, passed as int - * These are used for drawing the player model. - */ private float xSize_lo; private float ySize_lo; - public static int tick = 0, GUI_HEIGHT = 240, GUI_WIDTH = 198, AE_ROW_HEIGHT = 18, AE_NUM_ROWS = 3, GUI_UPPER_HEIGHT = 35, GUI_SEARCH_ROW = 35, - SEARCH_X = 81, SEARCH_Y = 6, SEARCH_WIDTH = 88, SEARCH_HEIGHT = 10, 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; + public static int tick = 0, GUI_HEIGHT = 240, GUI_WIDTH = 198, AE_ROW_HEIGHT = 18, AE_NUM_ROWS = 3, + GUI_UPPER_HEIGHT = 35, GUI_SEARCH_ROW = 35, SEARCH_X = 81, SEARCH_Y = 6, SEARCH_WIDTH = 88, + SEARCH_HEIGHT = 10, 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, previousMouseX = 0, previousMouseY = 0; private static final String bgTexturePath = "gui/crafting.png"; - /** The inventory to render on screen */ private final WCTInventoryBooster inventory; private final ContainerWirelessCraftingTerminal containerWCT; private boolean isFullScreen, init = true, reInit, wasResized = false; public static GuiWirelessCraftingTerminal INSTANCE; - 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; @@ -106,10 +100,8 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo private ItemStack dbl_whichItem; private Slot bl_clicked; private boolean subGui; - public static int craftingGridOffsetX = 80; public static int craftingGridOffsetY; - private static String memoryText = ""; private static String memoryText2 = ""; private final ItemRepo repo; @@ -131,10 +123,9 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo public boolean devicePowered = false; private boolean isNEIEnabled; private boolean wasTextboxFocused = false; - private int screenResTicks=0; + private int screenResTicks = 0; - public GuiWirelessCraftingTerminal(Container container) - { + public GuiWirelessCraftingTerminal(Container container) { super(container); this.INSTANCE = this; this.containerWCT = (ContainerWirelessCraftingTerminal) container; @@ -142,111 +133,86 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.scrollBar = new GuiScrollbar(); this.subGui = switchingGuis; switchingGuis = false; - this.setScrollBar( scrollBar ); - this.repo = new ItemRepo( scrollBar, this ); - this.configSrc = ( (IConfigurableObject) this.inventorySlots ).getConfigManager(); + this.setScrollBar(scrollBar); + this.repo = new ItemRepo(scrollBar, this); + this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager(); this.devicePowered = containerWCT.isPowered(); - ((ContainerWirelessCraftingTerminal) this.inventorySlots).setGui( this ); - this.isNEIEnabled = IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.NEI ); + ((ContainerWirelessCraftingTerminal) this.inventorySlots).setGui(this); + this.isNEIEnabled = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI); } - - public void onReceiveFullList( final IItemList itemList ) - { - // - } - - public void postUpdate( final List list ) - { - for( final IAEItemStack is : list ) - { - this.repo.postUpdate( is ); + + public void postUpdate(final List list) { + for (final IAEItemStack is : list) { + this.repo.postUpdate(is); } this.repo.updateView(); this.setScrollBar(); } - - private void setScrollBar() - { - this.getScrollBar().setTop( 18 ).setLeft( 174 ).setHeight( (AE_NUM_ROWS + 3) * 18 - 2 ); - this.getScrollBar().setRange( 0, ( this.repo.size() + this.perRow - 1 ) / this.perRow - (AE_NUM_ROWS + 3), Math.max( 1, (AE_NUM_ROWS + 3)/ 6 ) ); + + private void setScrollBar() { + this.getScrollBar().setTop(18).setLeft(174).setHeight((AE_NUM_ROWS + 3) * 18 - 2); + this.getScrollBar().setRange(0, (this.repo.size() + this.perRow - 1) / this.perRow - (AE_NUM_ROWS + 3), Math.max(1, (AE_NUM_ROWS + 3) / 6)); } - + @Override - protected void actionPerformed( final GuiButton btn ) - { - if( btn == this.craftingStatusBtn ) - { - NetworkHandler.instance.sendToServer( new PacketSwitchGuis( Reference.GUI_CRAFTING_STATUS ) ); + protected void actionPerformed(final GuiButton btn) { + if (btn == this.craftingStatusBtn) { + NetworkHandler.instance.sendToServer(new PacketSwitchGuis(Reference.GUI_CRAFTING_STATUS)); } - if( btn instanceof GuiImgButton ) - { - final boolean backwards = Mouse.isButtonDown( 1 ); + if (btn instanceof GuiImgButton) { + final boolean backwards = Mouse.isButtonDown(1); final GuiImgButton iBtn = (GuiImgButton) btn; - if( iBtn.getSetting() != Settings.ACTIONS ) - { + if (iBtn.getSetting() != Settings.ACTIONS) { final Enum cv = iBtn.getCurrentValue(); - final Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() ); + final Enum next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); - if( btn == this.searchBoxSettings ) - { - AEConfig.instance.settings.putSetting( iBtn.getSetting(), next ); + if (btn == this.searchBoxSettings) { + AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); } - else - { - try - { - NetworkHandler.instance.sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) ); + else { + try { + NetworkHandler.instance.sendToServer(new PacketValueConfig(iBtn.getSetting().name(), next.name())); } - catch( final IOException e ) - { - WCTLog.debug( e.getMessage() ); + catch (final IOException e) { + WCTLog.debug(e.getMessage()); } } - iBtn.set( next ); + iBtn.set(next); - if( next.getClass() == SearchBoxMode.class ) - { + if (next.getClass() == SearchBoxMode.class) { this.reinitalize(); } } - if( this.clearBtn == btn ) - { + if (this.clearBtn == btn) { Slot s = null; final Container c = this.inventorySlots; - for( final Object j : c.inventorySlots ) - { - if( j instanceof SlotCraftingMatrix ) - { + for (final Object j : c.inventorySlots) { + if (j instanceof SlotCraftingMatrix) { s = (Slot) j; } } - if( s != null ) - { - final PacketInventoryAction p = new PacketInventoryAction( InventoryAction.MOVE_REGION, s.slotNumber, 0 ); - NetworkHandler.instance.sendToServer( p ); + if (s != null) { + final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); + NetworkHandler.instance.sendToServer(p); } } } if (btn instanceof GuiTrashButton) { - if( this.trashBtn == btn ) - { + if (this.trashBtn == btn) { Slot s = null; final Container c = this.inventorySlots; - for( final Object j : c.inventorySlots ) - { - if( j instanceof SlotTrash ) - { + for (final Object j : c.inventorySlots) { + if (j instanceof SlotTrash) { s = (Slot) j; } } - if( s != null ) - { + if (s != null) { if (s.getHasStack()) { containerWCT.emptyTrash(); } @@ -254,147 +220,127 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } } } - - private void reinitalize() - { + + private void reinitalize() { this.buttonList.clear(); this.initGui(); } - - - - protected static String join( final Collection toolTip, final String delimiter ) - { - final Joiner joiner = Joiner.on( delimiter ); - return joiner.join( toolTip ); + 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(); + + protected int getQty(final GuiButton btn) { + try { + final DecimalFormat df = new DecimalFormat("+#;-#"); + return df.parse(btn.displayString).intValue(); } - catch( final ParseException e ) - { + catch (final ParseException e) { return 0; } } - public boolean isSubGui() - { + public boolean isSubGui() { return this.subGui; } - + /** * Initializes the GUI */ @Override - public void initGui() - { - Keyboard.enableRepeatEvents( true ); + public void initGui() { + Keyboard.enableRepeatEvents(true); this.getMeSlots().clear(); - for( int y = 0; y < AE_NUM_ROWS+3; 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 ) ); + for (int y = 0; y < AE_NUM_ROWS + 3; 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)); } } super.initGui(); final List slots = this.getInventorySlots(); final Iterator i = slots.iterator(); - while( i.hasNext() ) - { - if( i.next() instanceof SlotME ) - { + while (i.hasNext()) { + if (i.next() instanceof SlotME) { i.remove(); } } - for( final InternalSlotME me : this.meSlots ) - { - slots.add( new SlotME( me ) ); + for (final InternalSlotME me : this.meSlots) { + slots.add(new SlotME(me)); } int offset = this.guiTop + 8; this.buttonList.clear(); - this.buttonList.add( this.clearBtn = new GuiImgButton( this.guiLeft + 134, this.GUI_HEIGHT - this.GUI_LOWER_HEIGHT + 46, Settings.ACTIONS, ActionItems.STASH ) ); - this.buttonList.add( this.trashBtn = new GuiTrashButton( this.guiLeft + 98, this.GUI_HEIGHT - this.GUI_LOWER_HEIGHT + 103 ) ); - 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.buttonList.add(this.clearBtn = new GuiImgButton(this.guiLeft + 134, this.GUI_HEIGHT - this.GUI_LOWER_HEIGHT + 46, Settings.ACTIONS, ActionItems.STASH)); + this.buttonList.add(this.trashBtn = new GuiTrashButton(this.guiLeft + 98, this.GUI_HEIGHT - this.GUI_LOWER_HEIGHT + 103)); + this.clearBtn.setHalfSize(true); + if (this.customSortOrder) { + this.buttonList.add(this.SortByBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY))); offset += 20; } - this.buttonList.add( this.ViewBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting( Settings.VIEW_MODE ) ) ); - offset += 20; - - this.buttonList.add( this.SortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc.getSetting( Settings.SORT_DIRECTION ) ) ); + this.buttonList.add(this.ViewBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting(Settings.VIEW_MODE))); offset += 20; - this.buttonList.add( this.searchBoxSettings = new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ) ) ); + this.buttonList.add(this.SortDirBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc.getSetting(Settings.SORT_DIRECTION))); offset += 20; - - this.searchField = new MEGuiTextField( this.fontRendererObj, SEARCH_X, SEARCH_Y, SEARCH_WIDTH, SEARCH_HEIGHT ); - - this.searchField.setEnableBackgroundDrawing( false ); - this.searchField.setMaxStringLength( 25 ); - this.searchField.setTextColor( 0xFFFFFF ); - this.searchField.setVisible( true ); + + this.buttonList.add(this.searchBoxSettings = new GuiImgButton(this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE))); + offset += 20; + + this.searchField = new MEGuiTextField(this.fontRendererObj, SEARCH_X, SEARCH_Y, SEARCH_WIDTH, SEARCH_HEIGHT); + + this.searchField.setEnableBackgroundDrawing(false); + this.searchField.setMaxStringLength(25); + this.searchField.setTextColor(0xFFFFFF); + this.searchField.setVisible(true); 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.setHideEdge( 13 ); - - final Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); - this.searchField.setFocused( SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting ); - - - if( this.isSubGui() || this.init ) - { + + this.buttonList.add(this.craftingStatusBtn = new GuiTabButton(this.guiLeft + 169, this.guiTop - 4, 2 + 11 * 16, GuiText.CraftingStatus.getLocal(), itemRender)); + this.craftingStatusBtn.setHideEdge(13); + + final Enum setting = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); + this.searchField.setFocused(SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting); + + if (this.isSubGui() || this.init) { if (this.isSubGui()) { - this.searchField.setText( memoryText ); - this.repo.setSearchString( memoryText ); + this.searchField.setText(memoryText); + this.repo.setSearchString(memoryText); } this.repo.updateView(); this.setScrollBar(); } } - - @SuppressWarnings( "unchecked" ) - private List getInventorySlots() - { + + @SuppressWarnings("unchecked") + private List getInventorySlots() { return this.inventorySlots.inventorySlots; } - + /** - * Called every tick. It is used in this instance - * to detect screen size changes to automatically - * update the gui height. + * 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. + * reInit variable is used to call initGui() on the next tick. It has to be + * called this way to update correctly. * * @author p455w0rd */ @Override public void updateScreen() { this.devicePowered = containerWCT.isPowered(); - this.repo.setPower( devicePowered ); + this.repo.setPower(devicePowered); //this.repo.setPower( true ); - + super.updateScreen(); if (this.init) { this.currScreenWidth = this.mc.displayWidth; this.currScreenHeight = this.mc.displayHeight; this.isFullScreen = this.mc.isFullScreen(); - this.reInit=true; - this.init=false; + this.reInit = true; + this.init = false; } ++screenResTicks; if (screenResTicks == 20) { @@ -412,51 +358,50 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.searchField.setFocused(this.wasTextboxFocused); this.searchField.setText(this.repo.getSearchString()); this.wasTextboxFocused = false; - this.wasResized=false; + this.wasResized = false; } containerWCT.updateSlots(slotYOffset); - this.reInit=false; + this.reInit = false; tick = 0; } } - if (hasScreenResChanged()) { - this.reInit = true; - this.wasResized=true; - } - //if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) { - // this.mc.thePlayer.closeScreen(); - //} - //else { - // this block of variables is used to automatically - // reposition the slots in the container - GUI_HEIGHT = this.mc.displayHeight / 2; - AE_NUM_ROWS = Math.max(0, ((GUI_HEIGHT) - 240) / AE_ROW_HEIGHT); - if (isNEIEnabled && AE_NUM_ROWS >= 2) { - AE_NUM_ROWS -= 2; - GUI_HEIGHT -= AE_ROW_HEIGHT * 2 + 5; - this.clearBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 32; - this.trashBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 89; - } - else { - this.clearBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 13; - this.trashBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 68; - } - AE_TOTAL_ROWS_HEIGHT = AE_NUM_ROWS * AE_ROW_HEIGHT; - GUI_LOWER_HEIGHT = GUI_HEIGHT - AE_TOTAL_ROWS_HEIGHT - GUI_UPPER_HEIGHT; - slotYOffset = AE_TOTAL_ROWS_HEIGHT; - craftingGridOffsetY = slotYOffset + 83; - //} + if (hasScreenResChanged()) { + this.reInit = true; + this.wasResized = true; + } + if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) { + this.mc.thePlayer.closeScreen(); + } + else { + // this block of variables is used to automatically + // reposition the slots in the container + GUI_HEIGHT = this.mc.displayHeight / 2; + AE_NUM_ROWS = Math.max(0, ((GUI_HEIGHT) - 240) / AE_ROW_HEIGHT); + if (isNEIEnabled && AE_NUM_ROWS >= 2) { + AE_NUM_ROWS -= 2; + GUI_HEIGHT -= AE_ROW_HEIGHT * 2 + 5; + this.clearBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 32; + this.trashBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 89; + } + else { + this.clearBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 13; + this.trashBtn.yPosition = AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 68; + } + AE_TOTAL_ROWS_HEIGHT = AE_NUM_ROWS * AE_ROW_HEIGHT; + GUI_LOWER_HEIGHT = GUI_HEIGHT - AE_TOTAL_ROWS_HEIGHT - GUI_UPPER_HEIGHT; + slotYOffset = AE_TOTAL_ROWS_HEIGHT; + craftingGridOffsetY = slotYOffset + 83; + } } - + /** * Detects if the window has been resized + * * @return True if window has been resized * @author p455w0rd */ private boolean hasScreenResChanged() { - if ((this.currScreenWidth != this.mc.displayWidth) || - (this.currScreenHeight != this.mc.displayHeight) || - (this.isFullScreen != this.mc.isFullScreen())) { + if ((this.currScreenWidth != this.mc.displayWidth) || (this.currScreenHeight != this.mc.displayHeight) || (this.isFullScreen != this.mc.isFullScreen())) { this.currScreenWidth = this.mc.displayWidth; this.currScreenHeight = this.mc.displayHeight; this.isFullScreen = this.mc.isFullScreen(); @@ -468,69 +413,57 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo /** * Draws the screen and tooltips. */ - public void drawScreen(int mouseX, int mouseY, float btn) - { + public void drawScreen(int mouseX, int mouseY, float btn) { super.drawScreen(mouseX, mouseY, btn); - this.xSize_lo = (float)mouseX; - this.ySize_lo = (float)mouseY; + this.xSize_lo = (float) mouseX; + this.ySize_lo = (float) mouseY; this.xSize = GUI_WIDTH; this.ySize = GUI_HEIGHT; - - final boolean hasClicked = Mouse.isButtonDown( 0 ); - if( hasClicked && this.scrollBar != null ) - { - this.scrollBar.click( this, mouseX - this.guiLeft, mouseY - this.guiTop ); + + 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 ) - { + 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; + 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 ) - { + 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 ); + 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 ) - { + 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] ); + for (var6 = 0; var6 < var4.length; ++var6) { + var7 = this.fontRendererObj.getStringWidth(var4[var6]); - if( var7 > var5 ) - { + if (var7 > var5) { var5 = var7; } } @@ -539,53 +472,46 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo var7 = par3 - 12; int var9 = 8; - if( var4.length > 1 ) - { - var9 += 2 + ( var4.length - 1 ) * 10; + if (var4.length > 1) { + var9 += 2 + (var4.length - 1) * 10; } - if( this.guiTop + var7 + var9 + 6 > this.height ) - { + if (this.guiTop + var7 + var9 + 6 > this.height) { var7 = this.height - var9 - this.guiTop - 6; } - if( forceWidth > 0 ) - { + 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 ); + 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 ); + 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 ) - { + for (int var13 = 0; var13 < var4.length; ++var13) { String var14 = var4[var13]; - if( var13 == 0 ) - { - var14 = '\u00a7' + Integer.toHexString( 15 ) + var14; + if (var13 == 0) { + var14 = '\u00a7' + Integer.toHexString(15) + var14; } - else - { + else { var14 = "\u00a77" + var14; } - this.fontRendererObj.drawStringWithShadow( var14, var6, var7, -1 ); + this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); - if( var13 == 0 ) - { + if (var13 == 0) { var7 += 2; } @@ -597,35 +523,31 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } GL11.glPopAttrib(); } - - public void bindTexture( final String base, final String file ) - { - final ResourceLocation loc = new ResourceLocation( base, "textures/" + file ); - this.mc.getTextureManager().bindTexture( loc ); + + 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 */ - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) - { + 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 ); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - if( this.scrollBar != null ) - { - this.scrollBar.draw( this ); - } - this.drawFG( ox, oy, mouseX, mouseY ); + 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 ) { + + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { String s = LocaleHandler.WirelessTermLabel.getLocal(); this.mc.fontRenderer.drawString(s, 7, 5, 4210752); this.mc.fontRenderer.drawString(I18n.format("container.inventory"), 7, AE_TOTAL_ROWS_HEIGHT + GUI_SEARCH_ROW + GUI_UPPER_HEIGHT + 3, 4210752); - if( this.searchField != null ) - { + if (this.searchField != null) { this.searchField.drawTextBox(); } } @@ -633,304 +555,257 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo /** * Draw and piece together the background texture */ - protected void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) - { + 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 ); - + this.drawBG(ox, oy, x, y); + final List slots = this.getInventorySlots(); - for( final Slot slot : slots ) - { - if( slot instanceof OptionalSlotFake ) - { + 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 ); + 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 ); + 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(int ox, int oy, int x, int y) { this.bindTexture(bgTexturePath); - + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, GUI_WIDTH, GUI_UPPER_HEIGHT); - - for ( int i = 0; i <= AE_NUM_ROWS; ++i) { + + for (int i = 0; i <= AE_NUM_ROWS; ++i) { int yPos = this.guiTop + GUI_UPPER_HEIGHT + (i * AE_ROW_HEIGHT); // Draw the texture this.drawTexturedModalRect(this.guiLeft, yPos, 0, GUI_SEARCH_ROW, GUI_WIDTH, AE_ROW_HEIGHT); } - + this.drawTexturedModalRect(this.guiLeft, this.guiTop + GUI_UPPER_HEIGHT + AE_TOTAL_ROWS_HEIGHT, 0, AE_ROW_HEIGHT + 17, GUI_WIDTH, GUI_LOWER_HEIGHT); if (Reference.WCT_BOOSTER_ENABLED) { this.drawTexturedModalRect(this.guiLeft + 132, this.guiTop + GUI_UPPER_HEIGHT + AE_TOTAL_ROWS_HEIGHT + 102, 237, 237, 19, 19); } - GuiInventory.func_147046_a(this.guiLeft + 51, this.guiTop + GUI_UPPER_HEIGHT + AE_TOTAL_ROWS_HEIGHT + 112, 32, (float)(this.guiLeft + 51) - this.xSize_lo, (float)(this.guiTop + 95 + (AE_NUM_ROWS * AE_ROW_HEIGHT)) - this.ySize_lo, this.mc.thePlayer); + GuiInventory.func_147046_a(this.guiLeft + 51, this.guiTop + GUI_UPPER_HEIGHT + AE_TOTAL_ROWS_HEIGHT + 112, 32, (float) (this.guiLeft + 51) - this.xSize_lo, (float) (this.guiTop + 95 + (AE_NUM_ROWS * AE_ROW_HEIGHT)) - this.ySize_lo, this.mc.thePlayer); } - - @Override - protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) - { - - final Enum searchMode = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); - if( searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH ) - { - this.searchField.mouseClicked( xCoord - this.guiLeft, yCoord - this.guiTop, btn ); + @Override + protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { + + final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); + + if (searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH) { + this.searchField.mouseClicked(xCoord - this.guiLeft, yCoord - this.guiTop, btn); } - //if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) ) - if( btn == 1 && this.searchField.isMouseIn( xCoord - this.guiLeft, yCoord - this.guiTop ) ) - { - this.searchField.setText( "" ); - this.repo.setSearchString( "" ); + if (btn == 1 && this.searchField.isMouseIn(xCoord - this.guiLeft, yCoord - this.guiTop)) { + this.searchField.setText(""); + this.repo.setSearchString(""); this.repo.updateView(); this.setScrollBar(); } - + this.drag_click.clear(); - if( btn == 1 ) - { - for( final Object o : this.buttonList ) - { + 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 ); + if (guibutton.mousePressed(this.mc, xCoord, yCoord)) { + super.mouseClicked(xCoord, yCoord, 0); return; } } } - super.mouseClicked( xCoord, yCoord, btn ); + 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 ); + 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 ); + 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 ); + else { + super.mouseClickMove(x, y, c, d); } } - + @Override - protected void handleMouseClick( final Slot slot, final int slotIdx, final int ctrlDown, final int key ) - { + 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 ) - { + 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 ) - { + if (this.drag_click.size() > 1) { return; } - final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 ); - NetworkHandler.instance.sendToServer( p ); + final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); + NetworkHandler.instance.sendToServer(p); return; } - else if( slot instanceof SlotCraftingTerm ) - { - if( key == 6 ) - { + else if (slot instanceof SlotCraftingTerm) { + if (key == 6) { return; // prevent weird double clicks.. } InventoryAction action = null; - if( key == 1 ) - { + if (key == 1) { action = InventoryAction.CRAFT_SHIFT; } - else - { + else { action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM; } - final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 ); - NetworkHandler.instance.sendToServer( p ); + final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); + NetworkHandler.instance.sendToServer(p); return; } - if( Keyboard.isKeyDown( Keyboard.KEY_SPACE ) ) - { - if( this.enableSpaceClicking() ) - { + if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { + if (this.enableSpaceClicking()) { IAEItemStack stack = null; - if( slot instanceof SlotME ) - { - stack = ( (SlotME) slot ).getAEStack(); + if (slot instanceof SlotME) { + stack = ((SlotME) slot).getAEStack(); } int slotNum = this.getInventorySlots().size(); - if( !( slot instanceof SlotME ) && slot != null ) - { + 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 ); + ((ContainerWirelessCraftingTerminal) this.inventorySlots).setTargetStack(stack); + final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0); + NetworkHandler.instance.sendToServer(p); return; } } - if( slot instanceof SlotDisconnected ) - { + 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; + 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: + case 3: // creative dupe: - if( player.capabilities.isCreativeMode ) - { - action = InventoryAction.CREATIVE_DUPLICATE; - } + if (player.capabilities.isCreativeMode) { + action = InventoryAction.CREATIVE_DUPLICATE; + } - break; + break; - default: - case 4: // drop item: - case 6: + 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 ); + if (action != null) { + final PacketInventoryAction p = new PacketInventoryAction(action, slot.getSlotIndex(), ((SlotDisconnected) slot).getSlot().getId()); + NetworkHandler.instance.sendToServer(p); } return; } - if( slot instanceof SlotME ) - { + 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(); + 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; + 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; - 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: + 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 ); + 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() ) - { + if (!this.disableShiftClick && isShiftKeyDown()) { this.disableShiftClick = true; - if( this.dbl_whichItem == null || this.bl_clicked != slot || this.dbl_clickTimer.elapsed( TimeUnit.MILLISECONDS ) > 150 ) - { + 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 ) - { + if (slot != null) { this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null; } - else - { + else { this.dbl_whichItem = null; } } - else if( 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 ); + 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); } } } @@ -938,53 +813,40 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.disableShiftClick = false; } - super.handleMouseClick( slot, slotIdx, ctrlDown, key ); + super.handleMouseClick(slot, slotIdx, ctrlDown, key); } - + @Override - protected boolean checkHotbarKeys( final int keyCode ) - { + protected boolean checkHotbarKeys(final int keyCode) { final Slot theSlot; - try - { - theSlot = ObfuscationReflectionHelper.getPrivateValue( GuiContainer.class, this, "theSlot", "field_147006_u", "f" ); + try { + theSlot = ObfuscationReflectionHelper.getPrivateValue(GuiContainer.class, this, "theSlot", "field_147006_u", "f"); } - catch( final Throwable t ) - { + 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() ) - { + 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.canTakeStack( ( (ContainerWirelessCraftingTerminal) this.inventorySlots ).getPlayerInv().player ) ) - { + for (final Slot s : slots) { + if (s.getSlotIndex() == j && s.inventory == ((ContainerWirelessCraftingTerminal) this.inventorySlots).getPlayerInv()) { + if (!s.canTakeStack(((ContainerWirelessCraftingTerminal) this.inventorySlots).getPlayerInv().player)) { return false; } } } - if( theSlot.getSlotStackLimit() == 64 ) - { - this.handleMouseClick( theSlot, theSlot.slotNumber, j, 2 ); + 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 ) ); + 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; } } @@ -995,486 +857,401 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo return false; } - + @Override - public void onGuiClosed() - { + public void onGuiClosed() { super.onGuiClosed(); this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI ) - Keyboard.enableRepeatEvents( false ); + Keyboard.enableRepeatEvents(false); memoryText = this.searchField.getText(); } - - protected Slot getSlot( final int mouseX, final int mouseY ) - { + + protected Slot getSlot(final int mouseX, final int mouseY) { final List slots = this.getInventorySlots(); - for( final Slot slot : slots ) - { + for (final Slot slot : slots) { // isPointInRegion - if( this.func_146978_c( slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY ) ) - { + if (this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) { return slot; } } return null; } - + @Override - public void handleMouseInput() - { + public void handleMouseInput() { super.handleMouseInput(); final int i = Mouse.getEventDWheel(); - if( i != 0 && isShiftKeyDown() ) - { + 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 ) ); + this.mouseWheelEvent(x, y, i / Math.abs(i)); } - else if( i != 0 && this.scrollBar != null ) - { - this.scrollBar.wheel( 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 ); + + 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 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 ); + for (int h = 0; h < times; h++) { + final PacketInventoryAction p = new PacketInventoryAction(direction, inventorySize, 0); + NetworkHandler.instance.sendToServer(p); } } } } - protected boolean enableSpaceClicking() - { + protected boolean enableSpaceClicking() { return true; } - - protected void drawItem( final int x, final int y, final ItemStack is ) - { + + 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 ); + 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 ); + 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 ) - { + 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; + 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 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 - { + + 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 ); + 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.aeRenderItem.setAeStack(((SlotME) s).getAEStack()); - this.safeDrawSlot( s ); + this.safeDrawSlot(s); } - catch( final Exception err ) - { - WCTLog.warning( "WCT prevented crash while drawing slot: " + err.toString() ); + catch (final Exception err) { + WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); } - this.setItemRender( pIR ); + this.setItemRender(pIR); return; } - else - { + else { this.itemRender = new RenderItem(); - try - { + try { final ItemStack is = s.getStack(); - if( s instanceof AppEngSlot && ( ( (AppEngSlot) s ).renderIconWithItem() || is == null ) && ( ( (AppEngSlot) s ).shouldDisplay() ) ) - { + 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" ); + if (aes.getIcon() >= 0) { + this.bindTexture("appliedenergistics2", "guis/states.png"); - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); final Tessellator tessellator = Tessellator.instance; - try - { - final int uv_y = (int) Math.floor( aes.getIcon() / 16 ); + 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 ); + 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() ); + 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 ); + 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.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 ) - { + 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 ); + 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() ); + catch (final Exception err) { + WCTLog.debug(err.getMessage()); } } - ( (AppEngSlot) s ).setIsValid( isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid ); + ((AppEngSlot) s).setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid); } - if( ( (AppEngSlot) s ).getIsValid() == 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 ); + 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 ); + if (s instanceof AppEngSlot) { + ((AppEngSlot) s).setDisplay(true); + this.safeDrawSlot(s); } - else - { - this.safeDrawSlot( s ); + else { + this.safeDrawSlot(s); } return; } - catch( final Exception err ) - { - WCTLog.warning( "WCT prevented crash while drawing slot: " + err.toString() ); + catch (final Exception err) { + WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); } } // do the usual for non-ME Slots. - this.safeDrawSlot( s ); + this.safeDrawSlot(s); } - - private RenderItem setItemRender( final RenderItem item ) - { - if( isNEIEnabled ) - { - return ( (INEI) IntegrationRegistry.INSTANCE.getInstance( IntegrationType.NEI ) ).setItemRender( item ); + + private RenderItem setItemRender(final RenderItem item) { + if (isNEIEnabled) { + return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item); } - else - { + else { final RenderItem ri = itemRender; itemRender = item; return ri; } } - + @Override - protected void keyTyped( final char character, final int key ) - { - if( !this.checkHotbarKeys( key ) ) - { - if( character == ' ' && this.searchField.getText().isEmpty() ) - { + protected void keyTyped(final char character, final int key) { + if (!this.checkHotbarKeys(key)) { + if (character == ' ' && this.searchField.getText().isEmpty()) { return; } - if( this.searchField.textboxKeyTyped( character, key ) ) - { - this.repo.setSearchString( this.searchField.getText() ); + if (this.searchField.textboxKeyTyped(character, key)) { + this.repo.setSearchString(this.searchField.getText()); this.repo.updateView(); this.setScrollBar(); } - else - { - super.keyTyped( character, key ); + else { + super.keyTyped(character, key); } } } - protected boolean isPowered() - { + protected boolean isPowered() { return this.repo.hasPower(); } - private void safeDrawSlot( final Slot s ) - { - try - { - GuiContainer.class.getDeclaredMethod( "func_146977_a_original", Slot.class ).invoke( this, s ); + private void safeDrawSlot(final Slot s) { + try { + GuiContainer.class.getDeclaredMethod("func_146977_a_original", Slot.class).invoke(this, s); } - catch( final Exception err ) - { + 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 ); + public void bindTexture(final String file) { + final ResourceLocation loc = new ResourceLocation(Reference.MODID, "textures/" + file); + this.mc.getTextureManager().bindTexture(loc); } - protected GuiScrollbar getScrollBar() - { + public void func_146977_a(final Slot s) { + this.drawSlot(s); + } + + protected GuiScrollbar getScrollBar() { return this.scrollBar; } - protected void setScrollBar( final GuiScrollbar myScrollBar ) - { + protected void setScrollBar(final GuiScrollbar myScrollBar) { this.scrollBar = myScrollBar; } - protected List getMeSlots() - { + protected List getMeSlots() { return this.meSlots; } - public static final synchronized boolean isSwitchingGuis() - { + public static final synchronized boolean isSwitchingGuis() { return switchingGuis; } - public static final synchronized void setSwitchingGuis( final boolean 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 ) - { - if( stack != null ) - { - final Slot s = this.getSlot( mouseX, mouseY ); - if( s instanceof SlotME ) - { + + public List handleItemTooltip(final ItemStack stack, final int mouseX, final int mouseY, final List currentToolTip) { + if (stack != null) { + final Slot s = this.getSlot(mouseX, mouseY); + if (s instanceof SlotME) { final int BigNumber = AEConfig.instance.useTerminalUseLargeFont() ? 999 : 9999; IAEItemStack myStack = null; - try - { + try { final SlotME theSlotField = (SlotME) s; myStack = theSlotField.getAEStack(); } - catch( final Throwable ignore ) - { + catch (final Throwable ignore) { } - if( myStack != null ) - { - if( myStack.getStackSize() > BigNumber || ( myStack.getStackSize() > 1 && stack.isItemDamaged() ) ) - { + if (myStack != null) { + if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { final String local = ButtonToolTips.ItemsStored.getLocal(); - final String formattedAmount = NumberFormat.getNumberInstance( Locale.US ).format( myStack.getStackSize() ); - final String format = String.format( local, formattedAmount ); + final String formattedAmount = NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize()); + final String format = String.format(local, formattedAmount); - currentToolTip.add( "\u00a77" + format ); + currentToolTip.add("\u00a77" + format); } - if( myStack.getCountRequestable() > 0 ) - { + if (myStack.getCountRequestable() > 0) { final String local = ButtonToolTips.ItemsRequestable.getLocal(); - final String formattedAmount = NumberFormat.getNumberInstance( Locale.US ).format( myStack.getCountRequestable() ); - final String format = String.format( local, formattedAmount ); + final String formattedAmount = NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable()); + final String format = String.format(local, formattedAmount); - currentToolTip.add( "\u00a77" + format ); + currentToolTip.add("\u00a77" + format); } } - else if( stack.stackSize > BigNumber || ( stack.stackSize > 1 && stack.isItemDamaged() ) ) - { + else if (stack.stackSize > BigNumber || (stack.stackSize > 1 && stack.isItemDamaged())) { final String local = ButtonToolTips.ItemsStored.getLocal(); - final String formattedAmount = NumberFormat.getNumberInstance( Locale.US ).format( stack.stackSize ); - final String format = String.format( local, formattedAmount ); + final String formattedAmount = NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize); + final String format = String.format(local, formattedAmount); - currentToolTip.add( "\u00a77" + format ); + currentToolTip.add("\u00a77" + format); } } } return currentToolTip; } - + @Override - protected void renderToolTip( final ItemStack stack, final int x, final int y ) - { - final Slot s = this.getSlot( x, y ); - if( s instanceof SlotME && stack != null ) - { + protected void renderToolTip(final ItemStack stack, final int x, final int y) { + final Slot s = this.getSlot(x, y); + if (s instanceof SlotME && stack != null) { final int BigNumber = AEConfig.instance.useTerminalUseLargeFont() ? 999 : 9999; IAEItemStack myStack = null; - try - { + try { final SlotME theSlotField = (SlotME) s; myStack = theSlotField.getAEStack(); } - catch( final Throwable ignore ) - { + catch (final Throwable ignore) { } - if( myStack != null ) - { - @SuppressWarnings( "unchecked" ) - final List currentToolTip = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); + if (myStack != null) { + @SuppressWarnings("unchecked") + final List currentToolTip = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); - if( myStack.getStackSize() > BigNumber || ( myStack.getStackSize() > 1 && stack.isItemDamaged() ) ) - { - currentToolTip.add( "Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getStackSize() ) ); + if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { + currentToolTip.add("Items Stored: " + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize())); } - if( myStack.getCountRequestable() > 0 ) - { - currentToolTip.add( "Items Requestable: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getCountRequestable() ) ); + if (myStack.getCountRequestable() > 0) { + currentToolTip.add("Items Requestable: " + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable())); } - this.drawTooltip( x, y, 0, join( currentToolTip, "\n" ) ); + this.drawTooltip(x, y, 0, join(currentToolTip, "\n")); } - else if( stack.stackSize > BigNumber ) - { - final List var4 = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); - var4.add( "Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( stack.stackSize ) ); - this.drawTooltip( x, y, 0, join( var4, "\n" ) ); + else if (stack.stackSize > BigNumber) { + final List var4 = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); + var4.add("Items Stored: " + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize)); + this.drawTooltip(x, y, 0, join(var4, "\n")); return; } } - super.renderToolTip( stack, x, y ); + super.renderToolTip(stack, x, y); // super.drawItemStackTooltip( stack, x, y ); } - + @Override - public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue ) - { - if( this.SortByBox != null ) - { - this.SortByBox.set( this.configSrc.getSetting( Settings.SORT_BY ) ); + public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) { + if (this.SortByBox != null) { + this.SortByBox.set(this.configSrc.getSetting(Settings.SORT_BY)); } - if( this.SortDirBox != null ) - { - this.SortDirBox.set( this.configSrc.getSetting( Settings.SORT_DIRECTION ) ); + if (this.SortDirBox != null) { + this.SortDirBox.set(this.configSrc.getSetting(Settings.SORT_DIRECTION)); } - if( this.ViewBox != null ) - { - this.ViewBox.set( this.configSrc.getSetting( Settings.VIEW_MODE ) ); + if (this.ViewBox != null) { + this.ViewBox.set(this.configSrc.getSetting(Settings.VIEW_MODE)); } this.repo.updateView(); } - - public boolean isCustomSortOrder() - { + + public boolean isCustomSortOrder() { return this.customSortOrder; } - void setCustomSortOrder( final boolean customSortOrder ) - { + void setCustomSortOrder(final boolean customSortOrder) { this.customSortOrder = customSortOrder; } - + @Override - public Enum getSortBy() - { - return this.configSrc.getSetting( Settings.SORT_BY ); + public Enum getSortBy() { + return this.configSrc.getSetting(Settings.SORT_BY); } @Override - public Enum getSortDir() - { - return this.configSrc.getSetting( Settings.SORT_DIRECTION ); + public Enum getSortDir() { + return this.configSrc.getSetting(Settings.SORT_DIRECTION); } @Override - public Enum getSortDisplay() - { - return this.configSrc.getSetting( Settings.VIEW_MODE ); + public Enum getSortDisplay() { + return this.configSrc.getSetting(Settings.VIEW_MODE); } - - - + } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java b/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java index 67afde1..2498fc9 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java @@ -25,12 +25,12 @@ import net.p455w0rd.wirelesscraftingterminal.proxy.CommonProxy; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; -@Mod(modid = Reference.MODID, acceptedMinecraftVersions = "[1.7.10]", name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY, dependencies = "required-after:Forge@[" // require - // forge. +@Mod(modid = Reference.MODID, acceptedMinecraftVersions = "[1.7.10]", name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY, dependencies = "required-after:Forge@[" + net.minecraftforge.common.ForgeVersion.majorVersion + '.' // majorVersion + net.minecraftforge.common.ForgeVersion.minorVersion + '.' // minorVersion + net.minecraftforge.common.ForgeVersion.revisionVersion + '.' // revisionVersion - + net.minecraftforge.common.ForgeVersion.buildVersion + ",);required-after:appliedenergistics2@[rv3-beta-1,);") + + net.minecraftforge.common.ForgeVersion.buildVersion + ",);" + + "required-after:appliedenergistics2@[rv3-beta-1,);") public class WirelessCraftingTerminal { @@ -52,7 +52,7 @@ public class WirelessCraftingTerminal { WirelessCraftingTerminal.WCTState = LoaderState.PREINITIALIZATION; WirelessCraftingTerminal.INSTANCE = this; creativeTab = new CreativeTabWCT(CreativeTabs.getNextID(), Reference.MODID).setNoScrollbar(); - WirelessCraftingTerminal.proxy.registerItems(); + proxy.registerItems(); ConfigHandler.init(new File(event.getModConfigurationDirectory(), Reference.CONFIG_FILE)); FMLCommonHandler.instance().bus().register(proxy); AEApi.instance().registries().wireless().registerWirelessHandler((IWirelessTermHandler) ItemEnum.WIRELESS_CRAFTING_TERMINAL.getItem()); @@ -76,7 +76,7 @@ public class WirelessCraftingTerminal { FMLCommonHandler.instance().registerCrashCallable(new IntegrationCrashEnhancement()); NetworkRegistry.INSTANCE.registerGuiHandler(this.INSTANCE, new WCTGuiHandler()); NetworkHandler.instance = new NetworkHandler("WCT"); - WirelessCraftingTerminal.proxy.removeItemsFromNEI(); + proxy.removeItemsFromNEI(); WCTLog.endSection("PostInit", stopwatch); } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerMagnet.java b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerMagnet.java index 093ee61..47de7c5 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerMagnet.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerMagnet.java @@ -51,7 +51,7 @@ public class ContainerMagnet extends Container { } } } - + private boolean isInHotbar(int slotNum) { return (slotNum >= HOTBAR_START) && (slotNum <= HOTBAR_END); } @@ -68,6 +68,7 @@ public class ContainerMagnet extends Container { public boolean canInteractWith(EntityPlayer p) { return true; } + private boolean alreadyFiltered(ItemStack item) { for (int i = 0; i < magnetInventory.getSizeInventory(); i++) { if (isIdenticalItem(item, magnetInventory.getStackInSlot(i))) { @@ -92,7 +93,7 @@ public class ContainerMagnet extends Container { // return null; //} if (getSlot(slotNum) instanceof SlotMagnetFilter) { - + SlotMagnetFilter slot = (SlotMagnetFilter) getSlot(slotNum); ItemStack stack = null; @@ -158,7 +159,7 @@ public class ContainerMagnet extends Container { } } } - + private void fillPhantomSlot(SlotMagnetFilter slot, ItemStack stackHeld, int mouseButton) { if (!slot.canAdjustPhantom()) { return; @@ -237,20 +238,6 @@ public class ContainerMagnet extends Container { } slot.onPickupFromSlot(p, stack); return stack; - /* - * - * int numSlots = inventorySlots.size(); ItemStack stackInSlot = - * slot.getStack(); ItemStack originalStack = stackInSlot.copy(); - * - * slot.onSlotChange(stackInSlot, originalStack); if - * (stackInSlot.stackSize <= 0) { slot.putStack(null); } else { - * slot.onSlotChanged(); } - * - * if (stackInSlot.stackSize == originalStack.stackSize) { return null; - * } - * - * slot.onPickupFromSlot(player, stackInSlot); return originalStack; - */ } public boolean isIdenticalItem(ItemStack lhs, ItemStack rhs) { diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java index af2a0fe..3a46660 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java @@ -117,8 +117,7 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; -public class ContainerWirelessCraftingTerminal extends Container - implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IAEAppEngInventory, IContainerCraftingPacket { +public class ContainerWirelessCraftingTerminal extends Container implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IAEAppEngInventory, IContainerCraftingPacket { private final ItemStack containerstack; public WCTInventoryCrafting craftingGrid; @@ -135,7 +134,8 @@ public class ContainerWirelessCraftingTerminal extends Container CRAFT_GRID_START = ARMOR_END + 1, CRAFT_GRID_END = CRAFT_GRID_START + 8, CRAFT_RESULT = CRAFT_GRID_END + 1, BOOSTER_INDEX = 0, MAGNET_INDEX = CRAFT_RESULT + 1, TRASH_INDEX = MAGNET_INDEX + 1; private int BOOSTER_Y_OFFSET = 139, HOTBAR_Y_OFFSET = 217, INV_Y_OFFSET = 159, ARMOR_Y_OFFSET = 83, - CRAFTMATRIX_Y_OFFSET = 83, CRAFTING_Y_OFFSET = 100, MAGNET_Y_OFFSET = BOOSTER_Y_OFFSET, TRASH_Y_OFFSET = MAGNET_Y_OFFSET; + CRAFTMATRIX_Y_OFFSET = 83, CRAFTING_Y_OFFSET = 100, MAGNET_Y_OFFSET = BOOSTER_Y_OFFSET, + TRASH_Y_OFFSET = MAGNET_Y_OFFSET; public static int CRAFTING_SLOT_X_POS = 80, CRAFTING_SLOT_Y_POS = 83; private SlotBooster boosterSlot; private SlotMagnet magnetSlot; @@ -169,7 +169,7 @@ public class ContainerWirelessCraftingTerminal extends Container private String customName; private boolean sentCustomName; private ContainerOpenContext openContext; - private final AppEngInternalInventory output = new AppEngInternalInventory( this, 1 ); + private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1); private final HashSet locked = new HashSet(); private ItemWirelessCraftingTerminal thisItem; private IGridNode networkNode; @@ -181,7 +181,7 @@ public class ContainerWirelessCraftingTerminal extends Container * @author p455w0rd */ public ContainerWirelessCraftingTerminal(EntityPlayer player, InventoryPlayer inventoryPlayer) { - + this.clientCM = new ConfigManager(this); this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME); this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); @@ -203,12 +203,10 @@ public class ContainerWirelessCraftingTerminal extends Container inventorySlot = new Slot[27]; armorSlot = new SlotArmor[4]; craftMatrixSlot = new SlotCraftingMatrix[9]; - - this.obj = getGuiObject(containerstack, player, worldObj, (int)player.posX, (int)player.posY, (int)player.posZ); + + this.obj = getGuiObject(containerstack, player, worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); this.civ = (IPortableCell) this.obj; - // this.monitor = (IMEMonitor) this.civ; - //this.host = (ITerminalHost)civ; - final IGridNode node = ( (IGridHost) this.obj ).getGridNode( ForgeDirection.UNKNOWN ); + final IGridNode node = ((IGridHost) this.obj).getGridNode(ForgeDirection.UNKNOWN); this.networkNode = node; this.prepareSync(); @@ -218,14 +216,16 @@ public class ContainerWirelessCraftingTerminal extends Container this.monitor = civ.getItemInventory(); if (this.monitor != null) { this.monitor.addListener(this, null); - setCellInventory( this.monitor ); + setCellInventory(this.monitor); if (civ instanceof IPortableCell) { setPowerSource((IEnergySource) this.civ); } - } else { + } + else { this.setValidContainer(false); } - } else { + } + else { this.monitor = null; } @@ -244,8 +244,8 @@ public class ContainerWirelessCraftingTerminal extends Container this.addSlotToContainer(hotbarSlot[i]); } - int k=0; - + int k = 0; + // Add player inventory slots for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { @@ -260,7 +260,7 @@ public class ContainerWirelessCraftingTerminal extends Container armorSlot[i] = new SlotArmor(this.player, this.inventoryPlayer, 39 - i, (int) 8.5, ARMOR_Y_OFFSET + i * 18, i); this.addSlotToContainer(armorSlot[i]); } - k=0; + k = 0; // Add crafting grid slots for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { @@ -274,14 +274,14 @@ 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, CRAFTING_Y_OFFSET, this ); + craftingSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.mySrc, this.getPowerSource(), this.obj, this.craftingGrid, this.craftingGrid, this.output, 174, CRAFTING_Y_OFFSET, this); this.craftingSlotNumber = this.lastCraftingSlotNumber + 1; // Add crafting result slot this.addSlotToContainer(craftingSlot); - + magnetSlot = new SlotMagnet(this.magnetInventory, 152, MAGNET_Y_OFFSET); this.addSlotToContainer(magnetSlot); - + trashSlot = new SlotTrash(trashInventory, 80, TRASH_Y_OFFSET, player); trashSlot.setContainer(this); this.addSlotToContainer(trashSlot); @@ -290,159 +290,133 @@ public class ContainerWirelessCraftingTerminal extends Container this.onCraftMatrixChanged(this.craftingGrid); thisItem.checkForBooster(containerstack); - //FMLCommonHandler.instance().bus().register(magnetSlot); } - + public void emptyTrash() { this.trashSlot.clearStack(); } - public void setCellInventory( final IMEInventoryHandler cellInv ) - { + public void setCellInventory(final IMEInventoryHandler cellInv) { this.cellInv = cellInv; } - - public void onSlotChange( final Slot s ) - { + + public void onSlotChange(final Slot s) { } - + @Override - protected Slot addSlotToContainer( final Slot newSlot ) - { - if( newSlot instanceof AppEngSlot ) - { + protected Slot addSlotToContainer(final Slot newSlot) { + if (newSlot instanceof AppEngSlot) { final AppEngSlot s = (AppEngSlot) newSlot; - s.setContainer( this ); - return super.addSlotToContainer( newSlot ); + s.setContainer(this); + return super.addSlotToContainer(newSlot); } - else - { - throw new IllegalArgumentException( "Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot." ); + else { + throw new IllegalArgumentException("Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot."); } } - + @Override - public boolean canDragIntoSlot( final Slot s ) - { - return ( (AppEngSlot) s ).isDraggable(); + public boolean canDragIntoSlot(final Slot s) { + return ((AppEngSlot) s).isDraggable(); } @Override public void onCraftMatrixChanged(final IInventory iinv) { - - final ContainerNull cn = new ContainerNull(); - final InventoryCrafting ic = new InventoryCrafting( cn, 3, 3 ); - for( int x = 0; x < 9; x++ ) - { - ic.setInventorySlotContents( x, this.craftMatrixSlot[x].getStack() ); + final ContainerNull cn = new ContainerNull(); + final InventoryCrafting ic = new InventoryCrafting(cn, 3, 3); + + for (int x = 0; x < 9; x++) { + ic.setInventorySlotContents(x, this.craftMatrixSlot[x].getStack()); } - + //this.output.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(ic, worldObj)); - this.craftingSlot.putStack(CraftingManager.getInstance().findMatchingRecipe( ic, this.worldObj )); + this.craftingSlot.putStack(CraftingManager.getInstance().findMatchingRecipe(ic, this.worldObj)); writeToNBT("crafting"); } - - 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: + 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 ) - { + if (s instanceof SlotFake) { final ItemStack hand = player.inventory.getItemStack(); - switch( action ) - { - case PICKUP_OR_SET_DOWN: + switch (action) { + case PICKUP_OR_SET_DOWN: - if( hand == null ) - { - s.putStack( null ); + 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 - { - s.putStack( hand.copy() ); + else if (hand.isItemEqual(is)) { + is.stackSize = Math.min(is.getMaxStackSize(), is.stackSize + 1); } - - 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 ) - { + else { is = hand.copy(); is.stackSize = 1; - s.putStack( is ); } - break; - case CREATIVE_DUPLICATE: - case MOVE_REGION: - case SHIFT_CLICK: - default: - break; + 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 ) - { + 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 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 ); + for (final Slot fr : from) { + this.transferStackInSlot(player, fr.slotNumber); } } @@ -452,271 +426,226 @@ public class ContainerWirelessCraftingTerminal extends Container // get target item. final IAEItemStack slotItem = this.clientRequestedTargetItem; - switch( action ) - { - case SHIFT_CLICK: - if( this.getPowerSource() == null || this.getCellInventory() == null ) - { - return; + 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); } - if( slotItem != null ) - { + ais = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais != null) { + adp.addItems(ais.getItemStack()); + } + } + break; + case ROLL_DOWN: + if (this.getPowerSource() == null || this.getCellInventory() == null) { + return; + } + + final int releaseQty = 1; + final ItemStack isg = player.inventory.getItemStack(); + + if (isg != null && releaseQty > 0) { + IAEItemStack ais = AEApi.instance().storage().createItemStack(isg); + ais.setStackSize(1); + final IAEItemStack extracted = ais.copy(); + + ais = Platform.poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais == null) { + final InventoryAdaptor ia = new AdaptorPlayerHand(player); + + final ItemStack fail = ia.removeItems(1, extracted.getItemStack(), null); + if (fail == null) { + this.getCellInventory().extractItems(extracted, Actionable.MODULATE, this.getActionSource()); + } + + this.updateHeld(player); + } + } + + break; + case ROLL_UP: + case PICKUP_SINGLE: + if (this.getPowerSource() == null || this.getCellInventory() == null) { + return; + } + + if (slotItem != null) { + int liftQty = 1; + final ItemStack item = player.inventory.getItemStack(); + + if (item != null) { + if (item.stackSize >= item.getMaxStackSize()) { + liftQty = 0; + } + if (!Platform.isSameItemPrecise(slotItem.getItemStack(), item)) { + liftQty = 0; + } + } + + if (liftQty > 0) { + IAEItemStack ais = slotItem.copy(); + ais.setStackSize(1); + ais = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais != null) { + final InventoryAdaptor ia = new AdaptorPlayerHand(player); + + final ItemStack fail = ia.addItems(ais.getItemStack()); + if (fail != null) { + this.getCellInventory().injectItems(ais, Actionable.MODULATE, this.getActionSource()); + } + + this.updateHeld(player); + } + } + } + break; + case PICKUP_OR_SET_DOWN: + if (getPowerSource() == null || this.getCellInventory() == null) { + return; + } + + if (player.inventory.getItemStack() == null) { + if (slotItem != null) { + IAEItemStack ais = slotItem.copy(); + ais.setStackSize(ais.getItemStack().getMaxStackSize()); + ais = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais != null) { + player.inventory.setItemStack(ais.getItemStack()); + } + else { + player.inventory.setItemStack(null); + } + this.updateHeld(player); + } + } + else { + IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); + ais = Platform.poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais != null) { + player.inventory.setItemStack(ais.getItemStack()); + } + else { + player.inventory.setItemStack(null); + } + this.updateHeld(player); + } + + break; + case SPLIT_OR_PLACE_SINGLE: + if (this.getPowerSource() == null || this.getCellInventory() == null) { + return; + } + + if (player.inventory.getItemStack() == null) { + if (slotItem != null) { + IAEItemStack ais = slotItem.copy(); + final long maxSize = ais.getItemStack().getMaxStackSize(); + ais.setStackSize(maxSize); + ais = this.getCellInventory().extractItems(ais, Actionable.SIMULATE, this.getActionSource()); + + if (ais != null) { + final long stackSize = Math.min(maxSize, ais.getStackSize()); + ais.setStackSize((stackSize + 1) >> 1); + ais = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + } + + if (ais != null) { + player.inventory.setItemStack(ais.getItemStack()); + } + else { + player.inventory.setItemStack(null); + } + this.updateHeld(player); + } + } + else { + IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); + ais.setStackSize(1); + ais = Platform.poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais == null) { + final ItemStack is = player.inventory.getItemStack(); + is.stackSize--; + if (is.stackSize <= 0) { + player.inventory.setItemStack(null); + } + this.updateHeld(player); + } + } + + break; + case CREATIVE_DUPLICATE: + if (player.capabilities.isCreativeMode && slotItem != null) { + final ItemStack is = slotItem.getItemStack(); + is.stackSize = is.getMaxStackSize(); + player.inventory.setItemStack(is); + this.updateHeld(player); + } + break; + case MOVE_REGION: + + if (this.getPowerSource() == null || this.getCellInventory() == null) { + return; + } + + if (slotItem != null) { + final int playerInv = 9 * 4; + for (int slotNum = 0; slotNum < playerInv; slotNum++) { IAEItemStack ais = slotItem.copy(); ItemStack myItem = ais.getItemStack(); - ais.setStackSize( myItem.getMaxStackSize() ); + ais.setStackSize(myItem.getMaxStackSize()); - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); + final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN); myItem.stackSize = (int) ais.getStackSize(); - myItem = adp.simulateAdd( myItem ); + myItem = adp.simulateAdd(myItem); - if( myItem != null ) - { - ais.setStackSize( ais.getStackSize() - myItem.stackSize ); + 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() ); + ais = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais != null) { + adp.addItems(ais.getItemStack()); + } + else { + return; } } - break; - case ROLL_DOWN: - if( this.getPowerSource() == null || this.getCellInventory() == null ) - { - return; - } + } - final int releaseQty = 1; - final ItemStack isg = player.inventory.getItemStack(); - - if( isg != null && releaseQty > 0 ) - { - IAEItemStack ais = AEApi.instance().storage().createItemStack( isg ); - ais.setStackSize( 1 ); - final IAEItemStack extracted = ais.copy(); - - ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); - if( ais == null ) - { - final InventoryAdaptor ia = new AdaptorPlayerHand( player ); - - final ItemStack fail = ia.removeItems( 1, extracted.getItemStack(), null ); - if( fail == null ) - { - this.getCellInventory().extractItems( extracted, Actionable.MODULATE, this.getActionSource() ); - } - - this.updateHeld( player ); - } - } - - break; - case ROLL_UP: - case PICKUP_SINGLE: - if( this.getPowerSource() == null || this.getCellInventory() == null ) - { - return; - } - - if( slotItem != null ) - { - int liftQty = 1; - final ItemStack item = player.inventory.getItemStack(); - - if( item != null ) - { - if( item.stackSize >= item.getMaxStackSize() ) - { - liftQty = 0; - } - if( !Platform.isSameItemPrecise( slotItem.getItemStack(), item ) ) - { - liftQty = 0; - } - } - - if( liftQty > 0 ) - { - IAEItemStack ais = slotItem.copy(); - ais.setStackSize( 1 ); - ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); - if( ais != null ) - { - final InventoryAdaptor ia = new AdaptorPlayerHand( player ); - - final ItemStack fail = ia.addItems( ais.getItemStack() ); - if( fail != null ) - { - this.getCellInventory().injectItems( ais, Actionable.MODULATE, this.getActionSource() ); - } - - this.updateHeld( player ); - } - } - } - break; - case PICKUP_OR_SET_DOWN: - if( getPowerSource() == null || this.getCellInventory() == null ) - { - return; - } - - if( player.inventory.getItemStack() == null ) - { - if( slotItem != null ) - { - IAEItemStack ais = slotItem.copy(); - ais.setStackSize( ais.getItemStack().getMaxStackSize() ); - ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); - if( ais != null ) - { - player.inventory.setItemStack( ais.getItemStack() ); - } - else - { - player.inventory.setItemStack( null ); - } - this.updateHeld( player ); - } - } - else - { - IAEItemStack ais = AEApi.instance().storage().createItemStack( player.inventory.getItemStack() ); - ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); - if( ais != null ) - { - player.inventory.setItemStack( ais.getItemStack() ); - } - else - { - player.inventory.setItemStack( null ); - } - this.updateHeld( player ); - } - - break; - case SPLIT_OR_PLACE_SINGLE: - if( this.getPowerSource() == null || this.getCellInventory() == null ) - { - return; - } - - if( player.inventory.getItemStack() == null ) - { - if( slotItem != null ) - { - IAEItemStack ais = slotItem.copy(); - final long maxSize = ais.getItemStack().getMaxStackSize(); - ais.setStackSize( maxSize ); - ais = this.getCellInventory().extractItems( ais, Actionable.SIMULATE, this.getActionSource() ); - - if( ais != null ) - { - final long stackSize = Math.min( maxSize, ais.getStackSize() ); - ais.setStackSize( ( stackSize + 1 ) >> 1 ); - ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); - } - - if( ais != null ) - { - player.inventory.setItemStack( ais.getItemStack() ); - } - else - { - player.inventory.setItemStack( null ); - } - this.updateHeld( player ); - } - } - else - { - IAEItemStack ais = AEApi.instance().storage().createItemStack( player.inventory.getItemStack() ); - ais.setStackSize( 1 ); - ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); - if( ais == null ) - { - final ItemStack is = player.inventory.getItemStack(); - is.stackSize--; - if( is.stackSize <= 0 ) - { - player.inventory.setItemStack( null ); - } - this.updateHeld( player ); - } - } - - break; - case CREATIVE_DUPLICATE: - if( player.capabilities.isCreativeMode && slotItem != null ) - { - final ItemStack is = slotItem.getItemStack(); - is.stackSize = is.getMaxStackSize(); - player.inventory.setItemStack( is ); - this.updateHeld( player ); - } - break; - case MOVE_REGION: - - if( this.getPowerSource() == null || this.getCellInventory() == null ) - { - return; - } - - if( slotItem != null ) - { - final int playerInv = 9 * 4; - for( int slotNum = 0; slotNum < playerInv; slotNum++ ) - { - IAEItemStack ais = slotItem.copy(); - ItemStack myItem = ais.getItemStack(); - - ais.setStackSize( myItem.getMaxStackSize() ); - - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); - myItem.stackSize = (int) ais.getStackSize(); - myItem = adp.simulateAdd( myItem ); - - if( myItem != null ) - { - ais.setStackSize( ais.getStackSize() - myItem.stackSize ); - } - - ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); - if( ais != null ) - { - adp.addItems( ais.getItemStack() ); - } - else - { - return; - } - } - } - - break; - default: - break; + break; + default: + break; } } 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 ); + + 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() ); + catch (final IOException e) { + WCTLog.debug(e.getMessage()); } } } @@ -731,49 +660,43 @@ public class ContainerWirelessCraftingTerminal extends Container this.craftingGrid.setInventorySlotContents(i, craftMatrixInventory[i]); } } - + @Override - public void saveChanges() - { + public void saveChanges() { // :P } - + @Override - public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack ) - { + public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) { // <3 } - + @Override public IGridNode getNetworkNode() { return this.networkNode; } - + @Override public boolean useRealItems() { return true; } - + @Override - public IInventory getInventoryByName( final String name ) - { - if( name.equals( "player" ) || name.equals("container.inventory")) - { + public IInventory getInventoryByName(final String name) { + if (name.equals("player") || name.equals("container.inventory")) { return this.getInventoryPlayer(); } - if( name.equals( "crafting" ) ) - { + if (name.equals("crafting")) { return this.craftingGrid; } return null; } - + @Override - public ItemStack[] getViewCells() - { + public ItemStack[] getViewCells() { return null; } - + public void updateSlots(int yOffset) { int i, j, index = 0; @@ -795,7 +718,7 @@ public class ContainerWirelessCraftingTerminal extends Container index++; this.getSlot(index).yDisplayPosition = ARMOR_Y_OFFSET + yOffset + (18 * i); } - + Reference.WCT_CRAFTMATRIX_Y_OFFSET = CRAFTMATRIX_Y_OFFSET + yOffset; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { @@ -810,15 +733,12 @@ public class ContainerWirelessCraftingTerminal extends Container index++; this.getSlot(index).yDisplayPosition = TRASH_Y_OFFSET + yOffset; } - - 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 ); + + 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); } } @@ -827,20 +747,20 @@ 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 { + } + else { this.setValidContainer(false); } // drain 1 ae t this.ticks++; if (this.ticks > 10) { - this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, - PowerMultiplier.CONFIG); + this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); this.ticks = 0; } @@ -857,9 +777,9 @@ public class ContainerWirelessCraftingTerminal extends Container this.clientCM.putSetting(set, sideLocal); for (final Object crafter : this.crafters) { try { - NetworkHandler.instance.sendTo(new PacketValueConfig(set.name(), sideLocal.name()), - (EntityPlayerMP) crafter); - } catch (final IOException e) { + NetworkHandler.instance.sendTo(new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); + } + catch (final IOException e) { WCTLog.debug(e.getMessage()); } } @@ -877,7 +797,8 @@ public class ContainerWirelessCraftingTerminal extends Container if (send == null) { is.setStackSize(0); piu.appendItem(is); - } else { + } + else { piu.appendItem(send); } } @@ -891,11 +812,12 @@ public class ContainerWirelessCraftingTerminal extends Container } } } - } catch (final IOException e) { + } + catch (final IOException e) { WCTLog.debug(e.getMessage()); } } - + this.sendCustomName(); if (Platform.isServer()) { for (final Object crafter : this.crafters) { @@ -932,7 +854,7 @@ public class ContainerWirelessCraftingTerminal extends Container } super.detectAndSendChanges(); } - + public boolean isBoosterInstalled() { Slot slot = getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX); if (slot == null) { @@ -947,7 +869,7 @@ public class ContainerWirelessCraftingTerminal extends Container } return false; } - + public boolean isMagnetInstalled() { Slot slot = getSlotFromInventory(this.magnetInventory, MAGNET_INDEX); if (slot == null) { @@ -995,9 +917,9 @@ public class ContainerWirelessCraftingTerminal extends Container if (this.getCustomName() != null) { try { - NetworkHandler.instance.sendTo(new PacketValueConfig("CustomName", this.getCustomName()), - (EntityPlayerMP) this.getInventoryPlayer().player); - } catch (final IOException e) { + NetworkHandler.instance.sendTo(new PacketValueConfig("CustomName", this.getCustomName()), (EntityPlayerMP) this.getInventoryPlayer().player); + } + catch (final IOException e) { WCTLog.debug(e.getMessage()); } } @@ -1033,11 +955,11 @@ public class ContainerWirelessCraftingTerminal extends Container 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(); boolean test2 = false; @@ -1081,10 +1003,9 @@ public class ContainerWirelessCraftingTerminal extends Container return false; } - - public void lockPlayerInventorySlot( final int idx ) - { - this.locked.add( idx ); + + public void lockPlayerInventorySlot(final int idx) { + this.locked.add(idx); } public boolean isValidForSlot(final Slot s, final ItemStack i) { @@ -1116,7 +1037,8 @@ public class ContainerWirelessCraftingTerminal extends Container if (data != null) { this.setTargetStack(AEApi.instance().storage().createItemStack(ItemStack.loadItemStackFromNBT(data))); } - } catch (final IOException e) { + } + catch (final IOException e) { WCTLog.debug(e.getMessage()); } @@ -1132,8 +1054,7 @@ public class ContainerWirelessCraftingTerminal extends Container // packets. if (Platform.isClient()) { final ItemStack a = stack == null ? null : stack.getItemStack(); - final ItemStack b = this.clientRequestedTargetItem == null ? null - : this.clientRequestedTargetItem.getItemStack(); + final ItemStack b = this.clientRequestedTargetItem == null ? null : this.clientRequestedTargetItem.getItemStack(); if (Platform.isSameItemPrecise(a, b)) { return; @@ -1170,7 +1091,8 @@ public class ContainerWirelessCraftingTerminal extends Container page++; NetworkHandler.instance.sendToServer(ppi); } - } catch (final IOException e) { + } + catch (final IOException e) { WCTLog.debug(e.getMessage()); return; } @@ -1185,7 +1107,8 @@ public class ContainerWirelessCraftingTerminal extends Container 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 { + } + else { this.syncData.put(annotation.value(), new SyncData(this, f, annotation)); } } @@ -1233,8 +1156,7 @@ public class ContainerWirelessCraftingTerminal extends Container } @Override - public void postChange(final IBaseMonitor monitor, final Iterable change, - final BaseActionSource source) { + public void postChange(final IBaseMonitor monitor, final Iterable change, final BaseActionSource source) { for (final IAEItemStack is : change) { this.items.add(is); } @@ -1277,7 +1199,8 @@ public class ContainerWirelessCraftingTerminal extends Container for (final IAEItemStack send : monitorCache) { try { piu.appendItem(send); - } catch (final BufferOverflowException boe) { + } + catch (final BufferOverflowException boe) { NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c); piu = new PacketMEInventoryUpdate(); @@ -1286,12 +1209,13 @@ public class ContainerWirelessCraftingTerminal extends Container } NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c); - } catch (final IOException e) { + } + catch (final IOException e) { WCTLog.debug(e.getMessage()); } } } - + public void onUpdate(final String field, final Object oldValue, final Object newValue) { // =] } @@ -1349,7 +1273,6 @@ public class ContainerWirelessCraftingTerminal extends Container this.openContext = openContext; } - /** * Fetches crafting matrix ItemStacks * @@ -1377,31 +1300,31 @@ public class ContainerWirelessCraftingTerminal extends Container this.containerstack.setTagCompound(new NBTTagCompound()); } switch (which) { - case "booster": - ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); - break; - case "crafting": - ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); - break; - case "magnet": - ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); - break; - case "trash": - ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); - break; - case "all": - default: - ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); - break; + case "booster": + ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); + break; + case "crafting": + ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); + break; + case "magnet": + ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); + break; + case "trash": + ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); + break; + case "all": + default: + ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); + ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); + ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); + ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); + break; } } - + @Override - public ItemStack transferStackInSlot( final EntityPlayer p, final int idx ) { - final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots! + public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { + final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots! ItemStack tis = clickSlot.getStack(); if (tis == null) { return null; @@ -1430,57 +1353,55 @@ public class ContainerWirelessCraftingTerminal extends Container } } } - - if( Platform.isClient() ) { + + if (Platform.isClient()) { return null; } boolean hasMETiles = false; - for( final Object is : this.inventorySlots ) { - if( is instanceof InternalSlotME ) { + for (final Object is : this.inventorySlots) { + if (is instanceof InternalSlotME) { hasMETiles = true; break; } } - if( hasMETiles && Platform.isClient() ) { + if (hasMETiles && Platform.isClient()) { return null; } - - - if( clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible ) { + if (clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible) { return null; } - if( clickSlot != null && clickSlot.getHasStack() ) { + if (clickSlot != null && clickSlot.getHasStack()) { final List selectedSlots = new ArrayList(); /** * Gather a list of valid destinations. */ - if( clickSlot.isPlayerSide() ) { - tis = this.shiftStoreItem( tis ); + if (clickSlot.isPlayerSide()) { + tis = this.shiftStoreItem(tis); // target slots in the container... - for( final Object inventorySlot : this.inventorySlots ) { + for (final Object inventorySlot : this.inventorySlots) { final AppEngSlot cs = (AppEngSlot) inventorySlot; - if( !( cs.isPlayerSide() ) && !( cs instanceof SlotFake ) && !(cs instanceof AppEngCraftingSlot) ) { - if( cs.isItemValid( tis ) ) { - selectedSlots.add( cs ); + if (!(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof AppEngCraftingSlot)) { + if (cs.isItemValid(tis)) { + selectedSlots.add(cs); } } } } else { // target slots in the container... - for( final Object inventorySlot : this.inventorySlots ) { + for (final Object inventorySlot : this.inventorySlots) { final AppEngSlot cs = (AppEngSlot) inventorySlot; - if( ( cs.isPlayerSide() ) && !( cs instanceof SlotFake ) && !(cs instanceof AppEngCraftingSlot) ) { - if( cs.isItemValid( tis ) ) { - selectedSlots.add( cs ); + if ((cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof AppEngCraftingSlot)) { + if (cs.isItemValid(tis)) { + selectedSlots.add(cs); } } } @@ -1489,21 +1410,21 @@ public class ContainerWirelessCraftingTerminal extends Container /** * Handle Fake Slot Shift clicking. */ - if( selectedSlots.isEmpty() && clickSlot.isPlayerSide() ) { - if( tis != null ) { + if (selectedSlots.isEmpty() && clickSlot.isPlayerSide()) { + if (tis != null) { // target slots in the container... - for( final Object inventorySlot : this.inventorySlots ) { + 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 ) ) { + if (!(cs.isPlayerSide()) && cs instanceof SlotFake) { + if (Platform.isSameItemPrecise(destination, tis)) { return null; } - else if( destination == null ) { - cs.putStack( tis.copy() ); + else if (destination == null) { + cs.putStack(tis.copy()); cs.onSlotChanged(); - this.updateSlot( cs ); + this.updateSlot(cs); return null; } } @@ -1511,45 +1432,45 @@ public class ContainerWirelessCraftingTerminal extends Container } } - if( tis != null ) { + if (tis != null) { // find partials.. - for( final Slot d : selectedSlots ) { - if( d instanceof SlotDisabled || d instanceof SlotME ) { + for (final Slot d : selectedSlots) { + if (d instanceof SlotDisabled || d instanceof SlotME) { continue; } - if( d.isItemValid( tis ) ) { - if( d.getHasStack() ) { + if (d.isItemValid(tis)) { + if (d.getHasStack()) { final ItemStack t = d.getStack(); - if( Platform.isSameItemPrecise( tis, t ) ) // t.isItemEqual(tis)) + if (Platform.isSameItemPrecise(tis, t)) // t.isItemEqual(tis)) { int maxSize = t.getMaxStackSize(); - if( maxSize > d.getSlotStackLimit() ) { + if (maxSize > d.getSlotStackLimit()) { maxSize = d.getSlotStackLimit(); } int placeAble = maxSize - t.stackSize; - if( tis.stackSize < placeAble ) { + if (tis.stackSize < placeAble) { placeAble = tis.stackSize; } t.stackSize += placeAble; tis.stackSize -= placeAble; - if( tis.stackSize <= 0 ) { - clickSlot.putStack( null ); + if (tis.stackSize <= 0) { + clickSlot.putStack(null); d.onSlotChanged(); // if ( hasMETiles ) updateClient(); - this.updateSlot( clickSlot ); - this.updateSlot( d ); + this.updateSlot(clickSlot); + this.updateSlot(d); return null; } else { - this.updateSlot( d ); + this.updateSlot(d); } } } @@ -1557,96 +1478,94 @@ public class ContainerWirelessCraftingTerminal extends Container } // any match.. - for( final Slot d : selectedSlots ) { - if( d instanceof SlotDisabled || d instanceof SlotME ) { + for (final Slot d : selectedSlots) { + if (d instanceof SlotDisabled || d instanceof SlotME) { continue; } - if( d.isItemValid( tis ) ) { - if( d.getHasStack() ) { + if (d.isItemValid(tis)) { + if (d.getHasStack()) { final ItemStack t = d.getStack(); - if( Platform.isSameItemPrecise( t, tis ) ) { + if (Platform.isSameItemPrecise(t, tis)) { int maxSize = t.getMaxStackSize(); - if( d.getSlotStackLimit() < maxSize ) { + if (d.getSlotStackLimit() < maxSize) { maxSize = d.getSlotStackLimit(); } int placeAble = maxSize - t.stackSize; - if( tis.stackSize < placeAble ) { + if (tis.stackSize < placeAble) { placeAble = tis.stackSize; } t.stackSize += placeAble; tis.stackSize -= placeAble; - if( tis.stackSize <= 0 ) { - clickSlot.putStack( null ); + if (tis.stackSize <= 0) { + clickSlot.putStack(null); d.onSlotChanged(); // if ( worldEntity != null ) // worldEntity.markDirty(); // if ( hasMETiles ) updateClient(); - this.updateSlot( clickSlot ); - this.updateSlot( d ); + this.updateSlot(clickSlot); + this.updateSlot(d); return null; } else { - this.updateSlot( d ); + this.updateSlot(d); } } } else { int maxSize = tis.getMaxStackSize(); - if( maxSize > d.getSlotStackLimit() ) { + if (maxSize > d.getSlotStackLimit()) { maxSize = d.getSlotStackLimit(); } final ItemStack tmp = tis.copy(); - if( tmp.stackSize > maxSize ) { + if (tmp.stackSize > maxSize) { tmp.stackSize = maxSize; } tis.stackSize -= tmp.stackSize; - d.putStack( tmp ); + d.putStack(tmp); - if( tis.stackSize <= 0 ) { - clickSlot.putStack( null ); + if (tis.stackSize <= 0) { + clickSlot.putStack(null); d.onSlotChanged(); // if ( worldEntity != null ) // worldEntity.markDirty(); // if ( hasMETiles ) updateClient(); - this.updateSlot( clickSlot ); - this.updateSlot( d ); + this.updateSlot(clickSlot); + this.updateSlot(d); return null; } else { - this.updateSlot( d ); + this.updateSlot(d); } } } } } - clickSlot.putStack( tis != null ? tis.copy() : null ); + clickSlot.putStack(tis != null ? tis.copy() : null); } - this.updateSlot( clickSlot ); + this.updateSlot(clickSlot); return null; } - - public void swapSlotContents( final int slotA, final int slotB ) - { - final Slot a = this.getSlot( slotA ); - final Slot b = this.getSlot( slotB ); + + 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 ) - { + if (a == null || b == null) { return; } @@ -1654,32 +1573,27 @@ public class ContainerWirelessCraftingTerminal extends Container final ItemStack isB = b.getStack(); // something to do? - if( isA == null && isB == null ) - { + if (isA == null && isB == null) { return; } // can take? - if( isA != null && !a.canTakeStack( this.getInventoryPlayer().player ) ) - { + if (isA != null && !a.canTakeStack(this.getInventoryPlayer().player)) { return; } - if( isB != null && !b.canTakeStack( this.getInventoryPlayer().player ) ) - { + if (isB != null && !b.canTakeStack(this.getInventoryPlayer().player)) { return; } // swap valid? - if( isB != null && !a.isItemValid( isB ) ) - { + if (isB != null && !a.isItemValid(isB)) { return; } - if( isA != null && !b.isItemValid( isA ) ) - { + if (isA != null && !b.isItemValid(isA)) { return; } @@ -1687,10 +1601,8 @@ public class ContainerWirelessCraftingTerminal extends Container ItemStack testB = isA == null ? null : isA.copy(); // can put some back? - if( testA != null && testA.stackSize > a.getSlotStackLimit() ) - { - if( testB != null ) - { + if (testA != null && testA.stackSize > a.getSlotStackLimit()) { + if (testB != null) { return; } @@ -1701,10 +1613,8 @@ public class ContainerWirelessCraftingTerminal extends Container testB.stackSize = totalA - testA.stackSize; } - if( testB != null && testB.stackSize > b.getSlotStackLimit() ) - { - if( testA != null ) - { + if (testB != null && testB.stackSize > b.getSlotStackLimit()) { + if (testA != null) { return; } @@ -1715,121 +1625,62 @@ public class ContainerWirelessCraftingTerminal extends Container testA.stackSize = totalB - testA.stackSize; } - a.putStack( testA ); - b.putStack( testB ); + a.putStack(testA); + b.putStack(testB); } - + private boolean isCraftMatrixSlot(AppEngSlot cs) { - return ( cs.getSlotIndex() >= this.firstCraftingSlotNumber ) && !( cs.getSlotIndex() <= this.lastCraftingSlotNumber ); + return (cs.getSlotIndex() >= this.firstCraftingSlotNumber) && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); } - - private void updateSlot( final Slot clickSlot ) { - // ??? + + private void updateSlot(final Slot clickSlot) { this.detectAndSendChanges(); } - - private ItemStack shiftStoreItem( final ItemStack input ) { - if( this.getPowerSource() == null || this.civ == null) { + + private ItemStack shiftStoreItem(final ItemStack input) { + if (this.getPowerSource() == null || this.civ == null) { return input; } - final IAEItemStack ais = Platform.poweredInsert( this.getPowerSource(), this.civ, AEApi.instance().storage().createItemStack( input ), this.getActionSource() ); - if( ais == null ) { + final IAEItemStack ais = Platform.poweredInsert(this.getPowerSource(), this.civ, AEApi.instance().storage().createItemStack(input), this.getActionSource()); + if (ais == null) { return null; } return ais.getItemStack(); } - /** - * Checks to see if the given integer is within the range of hotbar slot - * index values - * - * @param index - * @return true/false - * @author p455w0rd - */ private boolean isInHotbar(@Nonnull int index) { return (index >= HOTBAR_START && index <= HOTBAR_END); } - /** - * Checks to see if the given integer is within the range of player - * inventory slot index values - * - * @param index - * @return true/false - * @author p455w0rd - */ private boolean isInInventory(@Nonnull int index) { return (index >= INV_START && index <= INV_END); } - /** - * Checks to see if the given integer is within the range of armor slot - * index values - * - * @param index - * @return true/false - * @author p455w0rd - */ private boolean isInArmorSlot(@Nonnull int index) { return (index >= ARMOR_START && index <= ARMOR_END); } - /** - * Checks to see if the given integer is equal to the infinity booster card - * slot index value - * - * @param index - * @return true/false - * @author p455w0rd - */ private boolean isInBoosterSlot(@Nonnull int index) { return (index == BOOSTER_INDEX); } - /** - * Checks to see if the given integer is equal to the crafting result slot - * index value - * - * @param index - * @return true/false - * @author p455w0rd - */ private boolean isCraftResult(@Nonnull int index) { return (index == CRAFT_RESULT); } - /** - * Checks to see if the given integer is within the range of crafting matrix - * slot index values - * - * @param index - * @return true/false - * @author p455w0rd - */ private boolean isInCraftMatrix(@Nonnull int index) { return (index >= CRAFT_GRID_START && index <= CRAFT_GRID_END); } - /** - * Checks if the ItemStack is an armor item or an Infinity Booster Card - * - * @param is - * @return - * @author p455w0rd - */ private boolean notArmorOrBooster(ItemStack is) { if ((is.getItem() instanceof ItemInfinityBooster) || (is.getItem() instanceof ItemArmor)) { return false; - } else { + } + else { return true; } } - /** - * Prevents player from moving item used to open the container - */ - @Override public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) { if (slot >= 0 && getSlot(slot) != null && getSlot(slot).getStack() == RandomUtils.getWirelessTerm(player.inventory)) { @@ -1837,16 +1688,14 @@ public class ContainerWirelessCraftingTerminal extends Container } return super.slotClick(slot, button, flag, player); } - - public final void updateFullProgressBar( final int idx, final long value ) - { - if( this.syncData.containsKey( idx ) ) - { - this.syncData.get( idx ).update( value ); + + 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 ); + this.updateProgressBar(idx, (int) value); } /** @@ -1870,9 +1719,7 @@ public class ContainerWirelessCraftingTerminal extends Container continue; } - if (itemstack1 != null && itemstack1.getItem() == stack.getItem() - && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) - && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { + if (itemstack1 != null && 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()) { @@ -1880,7 +1727,8 @@ public class ContainerWirelessCraftingTerminal extends Container itemstack1.stackSize = l; boosterInventory.markDirty(); flag1 = true; - } else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) { + } + else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) { stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = stack.getMaxStackSize(); boosterInventory.markDirty(); @@ -1910,9 +1758,9 @@ public class ContainerWirelessCraftingTerminal extends Container boosterInventory.markDirty(); flag1 = true; break; - } else { - putStackInSlot(k, - new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); + } + else { + putStackInSlot(k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); stack.stackSize -= slot.getSlotStackLimit(); boosterInventory.markDirty(); flag1 = true; diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java index dedfb16..164561d 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java @@ -61,9 +61,7 @@ import appeng.util.Platform; import appeng.util.inv.AdaptorPlayerHand; import appeng.util.item.AEItemStack; - -public abstract class WCTBaseContainer extends Container -{ +public abstract class WCTBaseContainer extends Container { private final InventoryPlayer invPlayer; private final BaseActionSource mySrc; @@ -82,175 +80,145 @@ public abstract class WCTBaseContainer extends Container 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) { + this(ip, myTile, myPart, null); } - public WCTBaseContainer( final InventoryPlayer ip, final TileEntity myTile, final IPart myPart, final IGuiItemObject gio ) - { + 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; - this.mySrc = new WCTPlayerSource( ip.player, this.getActionHost() ); + this.mySrc = new WCTPlayerSource(ip.player, this.getActionHost()); this.prepareSync(); } - protected WCTIActionHost getActionHost() - { - if( this.obj instanceof WCTIActionHost ) - { + protected WCTIActionHost getActionHost() { + if (this.obj instanceof WCTIActionHost) { return (WCTIActionHost) this.obj; } - if( this.tileEntity instanceof WCTIActionHost ) - { + if (this.tileEntity instanceof WCTIActionHost) { return (WCTIActionHost) this.tileEntity; } - if( this.part instanceof WCTIActionHost ) - { + 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() ); + 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 ) ); + else { + this.syncData.put(annotation.value(), new SyncData(this, f, annotation)); } } } } - public WCTBaseContainer( final InventoryPlayer ip, final Object anchor ) - { + 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; - if( this.tileEntity == null && this.part == null && this.obj == null ) - { - throw new IllegalArgumentException( "Must have a valid anchor, instead " + anchor + " in " + ip ); + 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.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() ) - { + public void postPartial(final PacketPartialItem packetPartialItem) { + this.dataChunks.add(packetPartialItem); + if (packetPartialItem.getPageCount() == this.dataChunks.size()) { this.parsePartials(); } } - private void parsePartials() - { + private void parsePartials() { int total = 0; - for( final PacketPartialItem ppi : this.dataChunks ) - { + 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 ); + 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 ) ) ); + 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() ); + catch (final IOException e) { + WCTLog.debug(e.getMessage()); } this.dataChunks.clear(); } - public IAEItemStack getTargetStack() - { + public IAEItemStack getTargetStack() { return this.clientRequestedTargetItem; } - public void setTargetStack( final IAEItemStack stack ) - { + public void setTargetStack(final IAEItemStack stack) { // client doesn't need to re-send, makes for lower overhead rapid packets. - if( Platform.isClient() ) - { + 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 ) ) - { + if (Platform.isSameItemPrecise(a, b)) { return; } final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final NBTTagCompound item = new NBTTagCompound(); - if( stack != null ) - { - stack.writeToNBT( item ); + if (stack != null) { + stack.writeToNBT(item); } - try - { - CompressedStreamTools.writeCompressed( item, stream ); + 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 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.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 ); + for (final byte[] packet : miniPackets) { + final PacketPartialItem ppi = new PacketPartialItem(page, miniPackets.size(), packet); page++; - NetworkHandler.instance.sendToServer( ppi ); + NetworkHandler.instance.sendToServer(ppi); } } - catch( final IOException e ) - { - WCTLog.debug( e.getMessage() ); + catch (final IOException e) { + WCTLog.debug(e.getMessage()); return; } } @@ -258,52 +226,41 @@ public abstract class WCTBaseContainer extends Container this.clientRequestedTargetItem = stack == null ? null : stack.copy(); } - public BaseActionSource getActionSource() - { + public BaseActionSource getActionSource() { return this.mySrc; } - public void verifyPermissions( final SecurityPermissions security, final boolean requirePower ) - { - if( Platform.isClient() ) - { + public void verifyPermissions(final SecurityPermissions security, final boolean requirePower) { + if (Platform.isClient()) { return; } this.ticksSinceCheck++; - if( this.ticksSinceCheck < 20 ) - { + if (this.ticksSinceCheck < 20) { return; } this.ticksSinceCheck = 0; - this.setValidContainer( this.isValidContainer() && this.hasAccess( security, requirePower ) ); + this.setValidContainer(this.isValidContainer() && this.hasAccess(security, requirePower)); } - protected boolean hasAccess( final SecurityPermissions perm, final boolean requirePower ) - { + protected boolean hasAccess(final SecurityPermissions perm, final boolean requirePower) { final WCTIActionHost host = this.getActionHost(); - if( host != null ) - { + if (host != null) { final IGridNode gn = host.getActionableNode(); - if( gn != null ) - { + if (gn != null) { final IGrid g = gn.getGrid(); - if( g != null ) - { - if( requirePower ) - { - final IEnergyGrid eg = g.getCache( IEnergyGrid.class ); - if( !eg.isNetworkPowered() ) - { + if (g != null) { + if (requirePower) { + final IEnergyGrid eg = g.getCache(IEnergyGrid.class); + if (!eg.isNetworkPowered()) { return false; } } - final ISecurityGrid sg = g.getCache( ISecurityGrid.class ); - if( sg.hasPermission( this.getInventoryPlayer().player, perm ) ) - { + final ISecurityGrid sg = g.getCache(ISecurityGrid.class); + if (sg.hasPermission(this.getInventoryPlayer().player, perm)) { return true; } } @@ -313,118 +270,92 @@ public abstract class WCTBaseContainer extends Container return false; } - public void lockPlayerInventorySlot( final int idx ) - { - this.locked.add( idx ); + public void lockPlayerInventorySlot(final int idx) { + this.locked.add(idx); } - public Object getTarget() - { - if( this.tileEntity != null ) - { + public Object getTarget() { + if (this.tileEntity != null) { return this.tileEntity; } - if( this.part != null ) - { + if (this.part != null) { return this.part; } - if( this.obj != null ) - { + if (this.obj != null) { return this.obj; } return null; } - public InventoryPlayer getPlayerInv() - { + public InventoryPlayer getPlayerInv() { return this.getInventoryPlayer(); } - public TileEntity getTileEntity() - { + 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 ); + 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 ); + 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 ); + 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 ) - { + 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 ) ); + 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 ) ); + 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 ) ); + 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 ) ); + else { + this.addSlotToContainer(new SlotPlayerHotBar(inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY)); } } } @Override - protected Slot addSlotToContainer( final Slot newSlot ) - { - if( newSlot instanceof AppEngSlot ) - { + protected Slot addSlotToContainer(final Slot newSlot) { + if (newSlot instanceof AppEngSlot) { final AppEngSlot s = (AppEngSlot) newSlot; - s.setContainer( this ); - return super.addSlotToContainer( newSlot ); + s.setContainer(this); + return super.addSlotToContainer(newSlot); } - else - { - throw new IllegalArgumentException( "Invalid Slot [" + newSlot + "]for AE Container instead of AppEngSlot." ); + else { + throw new IllegalArgumentException("Invalid Slot [" + newSlot + "]for AE Container instead of AppEngSlot."); } } @Override - public void detectAndSendChanges() - { + public void detectAndSendChanges() { this.sendCustomName(); - if( Platform.isServer() ) - { - for( final Object crafter : this.crafters ) - { + if (Platform.isServer()) { + for (final Object crafter : this.crafters) { final ICrafting icrafting = (ICrafting) crafter; - for( final SyncData sd : this.syncData.values() ) - { - sd.tick( icrafting ); + for (final SyncData sd : this.syncData.values()) { + sd.tick(icrafting); } } } @@ -433,40 +364,32 @@ public abstract class WCTBaseContainer extends Container } @Override - public ItemStack transferStackInSlot( final EntityPlayer p, final int idx ) - { - if( Platform.isClient() ) - { + 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 ) - { + for (final Object is : this.inventorySlots) { + if (is instanceof InternalSlotME) { hasMETiles = true; break; } } - if( hasMETiles && Platform.isClient() ) - { + if (hasMETiles && Platform.isClient()) { return null; } - final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots! + final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots! - if( clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible ) - { + if (clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible) { return null; } - if( clickSlot != null && clickSlot.getHasStack() ) - { + if (clickSlot != null && clickSlot.getHasStack()) { ItemStack tis = clickSlot.getStack(); - if( tis == null ) - { + if (tis == null) { return null; } @@ -475,36 +398,28 @@ public abstract class WCTBaseContainer extends Container /** * Gather a list of valid destinations. */ - if( clickSlot.isPlayerSide() ) - { - tis = this.shiftStoreItem( tis ); + if (clickSlot.isPlayerSide()) { + tis = this.shiftStoreItem(tis); // target slots in the container... - for( final Object inventorySlot : this.inventorySlots ) - { + 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 ); + if (!(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix)) { + if (cs.isItemValid(tis)) { + selectedSlots.add(cs); } } } } - else - { + else { // target slots in the container... - for( final Object inventorySlot : this.inventorySlots ) - { + 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 ); + if ((cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix)) { + if (cs.isItemValid(tis)) { + selectedSlots.add(cs); } } } @@ -513,27 +428,21 @@ public abstract class WCTBaseContainer extends Container /** * Handle Fake Slot Shift clicking. */ - if( selectedSlots.isEmpty() && clickSlot.isPlayerSide() ) - { - if( tis != null ) - { + if (selectedSlots.isEmpty() && clickSlot.isPlayerSide()) { + if (tis != null) { // target slots in the container... - for( final Object inventorySlot : this.inventorySlots ) - { + 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 ) ) - { + if (!(cs.isPlayerSide()) && cs instanceof SlotFake) { + if (Platform.isSameItemPrecise(destination, tis)) { return null; } - else if( destination == null ) - { - cs.putStack( tis.copy() ); + else if (destination == null) { + cs.putStack(tis.copy()); cs.onSlotChanged(); - this.updateSlot( cs ); + this.updateSlot(cs); return null; } } @@ -541,54 +450,45 @@ public abstract class WCTBaseContainer extends Container } } - if( tis != null ) - { + if (tis != null) { // find partials.. - for( final Slot d : selectedSlots ) - { - if( d instanceof SlotDisabled || d instanceof SlotME ) - { + for (final Slot d : selectedSlots) { + if (d instanceof SlotDisabled || d instanceof SlotME) { continue; } - if( d.isItemValid( tis ) ) - { - if( d.getHasStack() ) - { + if (d.isItemValid(tis)) { + if (d.getHasStack()) { final ItemStack t = d.getStack(); - if( Platform.isSameItemPrecise( tis, t ) ) // t.isItemEqual(tis)) + if (Platform.isSameItemPrecise(tis, t)) // t.isItemEqual(tis)) { int maxSize = t.getMaxStackSize(); - if( maxSize > d.getSlotStackLimit() ) - { + if (maxSize > d.getSlotStackLimit()) { maxSize = d.getSlotStackLimit(); } int placeAble = maxSize - t.stackSize; - if( tis.stackSize < placeAble ) - { + if (tis.stackSize < placeAble) { placeAble = tis.stackSize; } t.stackSize += placeAble; tis.stackSize -= placeAble; - if( tis.stackSize <= 0 ) - { - clickSlot.putStack( null ); + if (tis.stackSize <= 0) { + clickSlot.putStack(null); d.onSlotChanged(); // if ( hasMETiles ) updateClient(); - this.updateSlot( clickSlot ); - this.updateSlot( d ); + this.updateSlot(clickSlot); + this.updateSlot(d); return null; } - else - { - this.updateSlot( d ); + else { + this.updateSlot(d); } } } @@ -596,119 +496,100 @@ public abstract class WCTBaseContainer extends Container } // any match.. - for( final Slot d : selectedSlots ) - { - if( d instanceof SlotDisabled || d instanceof SlotME ) - { + for (final Slot d : selectedSlots) { + if (d instanceof SlotDisabled || d instanceof SlotME) { continue; } - if( d.isItemValid( tis ) ) - { - if( d.getHasStack() ) - { + if (d.isItemValid(tis)) { + if (d.getHasStack()) { final ItemStack t = d.getStack(); - if( Platform.isSameItemPrecise( t, tis ) ) - { + if (Platform.isSameItemPrecise(t, tis)) { int maxSize = t.getMaxStackSize(); - if( d.getSlotStackLimit() < maxSize ) - { + if (d.getSlotStackLimit() < maxSize) { maxSize = d.getSlotStackLimit(); } int placeAble = maxSize - t.stackSize; - if( tis.stackSize < placeAble ) - { + if (tis.stackSize < placeAble) { placeAble = tis.stackSize; } t.stackSize += placeAble; tis.stackSize -= placeAble; - if( tis.stackSize <= 0 ) - { - clickSlot.putStack( null ); + if (tis.stackSize <= 0) { + clickSlot.putStack(null); d.onSlotChanged(); // if ( worldEntity != null ) // worldEntity.markDirty(); // if ( hasMETiles ) updateClient(); - this.updateSlot( clickSlot ); - this.updateSlot( d ); + this.updateSlot(clickSlot); + this.updateSlot(d); return null; } - else - { - this.updateSlot( d ); + else { + this.updateSlot(d); } } } - else - { + else { int maxSize = tis.getMaxStackSize(); - if( maxSize > d.getSlotStackLimit() ) - { + if (maxSize > d.getSlotStackLimit()) { maxSize = d.getSlotStackLimit(); } final ItemStack tmp = tis.copy(); - if( tmp.stackSize > maxSize ) - { + if (tmp.stackSize > maxSize) { tmp.stackSize = maxSize; } tis.stackSize -= tmp.stackSize; - d.putStack( tmp ); + d.putStack(tmp); - if( tis.stackSize <= 0 ) - { - clickSlot.putStack( null ); + if (tis.stackSize <= 0) { + clickSlot.putStack(null); d.onSlotChanged(); // if ( worldEntity != null ) // worldEntity.markDirty(); // if ( hasMETiles ) updateClient(); - this.updateSlot( clickSlot ); - this.updateSlot( d ); + this.updateSlot(clickSlot); + this.updateSlot(d); return null; } - else - { - this.updateSlot( d ); + else { + this.updateSlot(d); } } } } } - clickSlot.putStack( tis != null ? tis.copy() : null ); + clickSlot.putStack(tis != null ? tis.copy() : null); } - this.updateSlot( clickSlot ); + 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 ); + 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 ); + public boolean canInteractWith(final EntityPlayer entityplayer) { + if (this.isValidContainer()) { + if (this.tileEntity instanceof IInventory) { + return ((IInventory) this.tileEntity).isUseableByPlayer(entityplayer); } return true; } @@ -716,110 +597,91 @@ public abstract class WCTBaseContainer extends Container } @Override - public boolean canDragIntoSlot( final Slot s ) - { - return ( (AppEngSlot) s ).isDraggable(); + 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 ); + 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 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 ) - { + if (s instanceof SlotFake) { final ItemStack hand = player.inventory.getItemStack(); - switch( action ) - { - case PICKUP_OR_SET_DOWN: + switch (action) { + case PICKUP_OR_SET_DOWN: - if( hand == null ) - { - s.putStack( null ); + 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 - { - s.putStack( hand.copy() ); + else if (hand.isItemEqual(is)) { + is.stackSize = Math.min(is.getMaxStackSize(), is.stackSize + 1); } - - 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 ) - { + else { is = hand.copy(); is.stackSize = 1; - s.putStack( is ); } - break; - case CREATIVE_DUPLICATE: - case MOVE_REGION: - case SHIFT_CLICK: - default: - break; + 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 ) - { + 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 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 ); + for (final Slot fr : from) { + this.transferStackInSlot(player, fr.slotNumber); } } @@ -829,336 +691,275 @@ public abstract class WCTBaseContainer extends Container // get target item. final IAEItemStack slotItem = this.clientRequestedTargetItem; - switch( action ) - { - case SHIFT_CLICK: - if( this.getPowerSource() == null || this.getCellInventory() == null ) - { - return; + 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); } - if( slotItem != null ) - { + 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() ); + ais.setStackSize(myItem.getMaxStackSize()); - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); + final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN); myItem.stackSize = (int) ais.getStackSize(); - myItem = adp.simulateAdd( myItem ); + myItem = adp.simulateAdd(myItem); - if( myItem != null ) - { - ais.setStackSize( ais.getStackSize() - myItem.stackSize ); + 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() ); + ais = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + if (ais != null) { + adp.addItems(ais.getItemStack()); + } + else { + return; } } - 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; + 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 ); + 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() ); + catch (final IOException e) { + WCTLog.debug(e.getMessage()); } } } - private ItemStack shiftStoreItem( final ItemStack input ) - { - if( this.getPowerSource() == null || this.getCellInventory() == null ) - { + 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 ) - { + 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 ) - { + private void updateSlot(final Slot clickSlot) { // ??? this.detectAndSendChanges(); } - private void sendCustomName() - { - if( !this.sentCustomName ) - { + private void sendCustomName() { + if (!this.sentCustomName) { this.sentCustomName = true; - if( Platform.isServer() ) - { + if (Platform.isServer()) { ICustomNameObject name = null; - if( this.part instanceof ICustomNameObject ) - { + if (this.part instanceof ICustomNameObject) { name = (ICustomNameObject) this.part; } - if( this.tileEntity instanceof ICustomNameObject ) - { + if (this.tileEntity instanceof ICustomNameObject) { name = (ICustomNameObject) this.tileEntity; } - if( this.obj instanceof ICustomNameObject ) - { + if (this.obj instanceof ICustomNameObject) { name = (ICustomNameObject) this.obj; } - if( this instanceof ICustomNameObject ) - { + if (this instanceof ICustomNameObject) { name = (ICustomNameObject) this; } - if( name != null ) - { - if( name.hasCustomName() ) - { - this.setCustomName( name.getCustomName() ); + 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 ); + 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() ); + catch (final IOException e) { + WCTLog.debug(e.getMessage()); } } } @@ -1166,14 +967,12 @@ public abstract class WCTBaseContainer extends Container } } - public void swapSlotContents( final int slotA, final int slotB ) - { - final Slot a = this.getSlot( slotA ); - final Slot b = this.getSlot( slotB ); + 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 ) - { + if (a == null || b == null) { return; } @@ -1181,32 +980,27 @@ public abstract class WCTBaseContainer extends Container final ItemStack isB = b.getStack(); // something to do? - if( isA == null && isB == null ) - { + if (isA == null && isB == null) { return; } // can take? - if( isA != null && !a.canTakeStack( this.getInventoryPlayer().player ) ) - { + if (isA != null && !a.canTakeStack(this.getInventoryPlayer().player)) { return; } - if( isB != null && !b.canTakeStack( this.getInventoryPlayer().player ) ) - { + if (isB != null && !b.canTakeStack(this.getInventoryPlayer().player)) { return; } // swap valid? - if( isB != null && !a.isItemValid( isB ) ) - { + if (isB != null && !a.isItemValid(isB)) { return; } - if( isA != null && !b.isItemValid( isA ) ) - { + if (isA != null && !b.isItemValid(isA)) { return; } @@ -1214,10 +1008,8 @@ public abstract class WCTBaseContainer extends Container ItemStack testB = isA == null ? null : isA.copy(); // can put some back? - if( testA != null && testA.stackSize > a.getSlotStackLimit() ) - { - if( testB != null ) - { + if (testA != null && testA.stackSize > a.getSlotStackLimit()) { + if (testB != null) { return; } @@ -1228,10 +1020,8 @@ public abstract class WCTBaseContainer extends Container testB.stackSize = totalA - testA.stackSize; } - if( testB != null && testB.stackSize > b.getSlotStackLimit() ) - { - if( testA != null ) - { + if (testB != null && testB.stackSize > b.getSlotStackLimit()) { + if (testA != null) { return; } @@ -1242,77 +1032,63 @@ public abstract class WCTBaseContainer extends Container testA.stackSize = totalB - testA.stackSize; } - a.putStack( testA ); - b.putStack( testB ); + a.putStack(testA); + b.putStack(testB); } - public void onUpdate( final String field, final Object oldValue, final Object newValue ) - { + public void onUpdate(final String field, final Object oldValue, final Object newValue) { } - public void onSlotChange( final Slot s ) - { + public void onSlotChange(final Slot s) { } - public boolean isValidForSlot( final Slot s, final ItemStack i ) - { + public boolean isValidForSlot(final Slot s, final ItemStack i) { return true; } - public IMEInventoryHandler getCellInventory() - { + public IMEInventoryHandler getCellInventory() { return this.cellInv; } - public void setCellInventory( final IMEInventoryHandler cellInv ) - { + public void setCellInventory(final IMEInventoryHandler cellInv) { this.cellInv = cellInv; } - public String getCustomName() - { + public String getCustomName() { return this.customName; } - public void setCustomName( final String customName ) - { + public void setCustomName(final String customName) { this.customName = customName; } - public InventoryPlayer getInventoryPlayer() - { + public InventoryPlayer getInventoryPlayer() { return this.invPlayer; } - public boolean isValidContainer() - { + public boolean isValidContainer() { return this.isContainerValid; } - public void setValidContainer( final boolean isContainerValid ) - { + public void setValidContainer(final boolean isContainerValid) { this.isContainerValid = isContainerValid; } - public ContainerOpenContext getOpenContext() - { + public ContainerOpenContext getOpenContext() { return this.openContext; } - public void setOpenContext( final ContainerOpenContext openContext ) - { + public void setOpenContext(final ContainerOpenContext openContext) { this.openContext = openContext; } - public IEnergySource getPowerSource() - { + public IEnergySource getPowerSource() { return this.powerSrc; } - public void setPowerSource( final IEnergySource powerSrc ) - { + public void setPowerSource(final IEnergySource powerSrc) { this.powerSrc = powerSrc; } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java index 6362220..b77d207 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java @@ -9,9 +9,7 @@ import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import appeng.tile.inventory.AppEngInternalInventory; - -public class AppEngSlot extends Slot -{ +public class AppEngSlot extends Slot { private final int defX; private final int defY; @@ -22,209 +20,170 @@ public class AppEngSlot extends Slot private hasCalculatedValidness isValid; private boolean isDisplay = false; - public AppEngSlot( final IInventory inv, final int idx, final int x, final int y ) - { - super( inv, idx, x, y ); + 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 ); + this.setIsValid(hasCalculatedValidness.NotAvailable); } - public Slot setNotDraggable() - { - this.setDraggable( false ); + public Slot setNotDraggable() { + this.setDraggable(false); return this; } - public Slot setPlayerSide() - { + public Slot setPlayerSide() { this.isPlayerSide = true; return this; } - public String getTooltip() - { + public String getTooltip() { return null; } - public void clearStack() - { - super.putStack( null ); + public void clearStack() { + super.putStack(null); } @Override - public boolean isItemValid( final ItemStack par1ItemStack ) - { - if( this.isEnabled() ) - { - return super.isItemValid( par1ItemStack ); + public boolean isItemValid(final ItemStack par1ItemStack) { + if (this.isEnabled()) { + return super.isItemValid(par1ItemStack); } return false; } @Override - public ItemStack getStack() - { - if( !this.isEnabled() ) - { + public ItemStack getStack() { + if (!this.isEnabled()) { return null; } - if( this.inventory.getSizeInventory() <= this.getSlotIndex() ) - { + if (this.inventory.getSizeInventory() <= this.getSlotIndex()) { return null; } - if( this.isDisplay() ) - { - this.setDisplay( false ); + 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 ); + public void putStack(final ItemStack par1ItemStack) { + if (this.isEnabled()) { + super.putStack(par1ItemStack); - if( this.getContainer() != null ) - { + if (this.getContainer() != null) { if (this.getContainer() instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) this.getContainer()).onSlotChange( this ); + ((ContainerWirelessCraftingTerminal) this.getContainer()).onSlotChange(this); } if (this.getContainer() instanceof WCTBaseContainer) { - ((WCTBaseContainer) this.getContainer()).onSlotChange( this ); + ((WCTBaseContainer) this.getContainer()).onSlotChange(this); } } } } @Override - public void onSlotChanged() - { - if( this.inventory instanceof AppEngInternalInventory ) - { - ( (AppEngInternalInventory) this.inventory ).markDirty( this.getSlotIndex() ); + public void onSlotChanged() { + if (this.inventory instanceof AppEngInternalInventory) { + ((AppEngInternalInventory) this.inventory).markDirty(this.getSlotIndex()); } - else - { + else { super.onSlotChanged(); } - this.setIsValid( hasCalculatedValidness.NotAvailable ); + this.setIsValid(hasCalculatedValidness.NotAvailable); } @Override - public boolean canTakeStack( final EntityPlayer par1EntityPlayer ) - { - if( this.isEnabled() ) - { - return super.canTakeStack( par1EntityPlayer ); + public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { + if (this.isEnabled()) { + return super.canTakeStack(par1EntityPlayer); } return false; } @Override - public boolean func_111238_b() - { + public boolean func_111238_b() { return this.isEnabled(); } - public ItemStack getDisplayStack() - { + public ItemStack getDisplayStack() { return super.getStack(); } - public boolean isEnabled() - { + public boolean isEnabled() { return true; } - public float getOpacityOfIcon() - { + public float getOpacityOfIcon() { return 0.4f; } - public boolean renderIconWithItem() - { + public boolean renderIconWithItem() { return false; } - public int getIcon() - { + public int getIcon() { return this.getIIcon(); } - public boolean isPlayerSide() - { + public boolean isPlayerSide() { return this.isPlayerSide; } - public boolean shouldDisplay() - { + public boolean shouldDisplay() { return this.isEnabled(); } - public int getX() - { + public int getX() { return this.defX; } - public int getY() - { + public int getY() { return this.defY; } - private int getIIcon() - { + private int getIIcon() { return this.IIcon; } - public void setIIcon( final int iIcon ) - { + public void setIIcon(final int iIcon) { this.IIcon = iIcon; } - private boolean isDisplay() - { + private boolean isDisplay() { return this.isDisplay; } - public void setDisplay( final boolean isDisplay ) - { + public void setDisplay(final boolean isDisplay) { this.isDisplay = isDisplay; } - public boolean isDraggable() - { + public boolean isDraggable() { return this.isDraggable; } - private void setDraggable( final boolean isDraggable ) - { + private void setDraggable(final boolean isDraggable) { this.isDraggable = isDraggable; } - void setPlayerSide( final boolean isPlayerSide ) - { + void setPlayerSide(final boolean isPlayerSide) { this.isPlayerSide = isPlayerSide; } - public hasCalculatedValidness getIsValid() - { + public hasCalculatedValidness getIsValid() { return this.isValid; } - public void setIsValid( final hasCalculatedValidness isValid ) - { + public void setIsValid(final hasCalculatedValidness isValid) { this.isValid = isValid; } - Container getContainer() - { + Container getContainer() { if (this.myContainer instanceof ContainerWirelessCraftingTerminal) { return (ContainerWirelessCraftingTerminal) this.myContainer; } @@ -234,8 +193,7 @@ public class AppEngSlot extends Slot return this.myContainer; } - public void setContainer( final Container myContainer ) - { + public void setContainer(final Container myContainer) { if (this.myContainer instanceof ContainerWirelessCraftingTerminal) { this.myContainer = (ContainerWirelessCraftingTerminal) myContainer; } @@ -247,8 +205,7 @@ public class AppEngSlot extends Slot } } - public enum hasCalculatedValidness - { + public enum hasCalculatedValidness { NotAvailable, Valid, Invalid } } \ No newline at end of file diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java index e5e86f4..6a691d8 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java @@ -1,39 +1,17 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.TickEvent; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.entity.Entity; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.items.ItemMagnet; -public class SlotMagnet extends AppEngSlot -{ +public class SlotMagnet extends AppEngSlot { - /** - * Custom slot for magnet card - * - * @param inv - * @param index - * @param xPos - * @param yPos - */ - public SlotMagnet(IInventory inv, int xPos, int yPos) - { + public SlotMagnet(IInventory inv, int xPos, int yPos) { super(inv, 0, xPos, yPos); } - - /** - * Ensures only the infinity booster card can be placed in the custom slot - * - * @param is - */ + @Override - public boolean isItemValid(ItemStack is) - { - // Everything returns false except an instance of our Item + public boolean isItemValid(ItemStack is) { return ((is != null) && (is.getItem() instanceof ItemMagnet)); } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/network/NetworkHandler.java b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/network/NetworkHandler.java index ec79abf..220b60f 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/network/NetworkHandler.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/network/NetworkHandler.java @@ -14,9 +14,7 @@ import cpw.mods.fml.common.network.FMLNetworkEvent.ServerConnectionFromClientEve import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import cpw.mods.fml.common.network.NetworkRegistry; - -public class NetworkHandler -{ +public class NetworkHandler { public static NetworkHandler instance; @@ -26,86 +24,69 @@ public class NetworkHandler private final IPacketHandler clientHandler; private final IPacketHandler serveHandler; - public NetworkHandler( final String channelName ) - { - FMLCommonHandler.instance().bus().register( this ); - this.ec = NetworkRegistry.INSTANCE.newEventDrivenChannel( this.myChannelName = channelName ); - this.ec.register( this ); + public NetworkHandler(final String channelName) { + FMLCommonHandler.instance().bus().register(this); + this.ec = NetworkRegistry.INSTANCE.newEventDrivenChannel(this.myChannelName = channelName); + this.ec.register(this); this.clientHandler = this.createClientSide(); this.serveHandler = this.createServerSide(); } - private IPacketHandler createClientSide() - { - try - { + private IPacketHandler createClientSide() { + try { return new WCTClientPacketHandler(); } - catch( final Throwable t ) - { + catch (final Throwable t) { return null; } } - private IPacketHandler createServerSide() - { - try - { + private IPacketHandler createServerSide() { + try { return new WCTServerPacketHandler(); } - catch( final Throwable t ) - { + catch (final Throwable t) { return null; } } @SubscribeEvent - public void serverPacket( final ServerCustomPacketEvent ev ) - { + public void serverPacket(final ServerCustomPacketEvent ev) { final NetHandlerPlayServer srv = (NetHandlerPlayServer) ev.packet.handler(); - if( this.serveHandler != null ) - { - this.serveHandler.onPacketData( null, ev.packet, srv.playerEntity ); + if (this.serveHandler != null) { + this.serveHandler.onPacketData(null, ev.packet, srv.playerEntity); } } @SubscribeEvent - public void clientPacket( final ClientCustomPacketEvent ev ) - { - if( this.clientHandler != null ) - { - this.clientHandler.onPacketData( null, ev.packet, null ); + public void clientPacket(final ClientCustomPacketEvent ev) { + if (this.clientHandler != null) { + this.clientHandler.onPacketData(null, ev.packet, null); } } - public String getChannel() - { + public String getChannel() { return this.myChannelName; } - public void sendToAll( final WCTPacket message ) - { - this.ec.sendToAll( message.getProxy() ); + public void sendToAll(final WCTPacket message) { + this.ec.sendToAll(message.getProxy()); } - public void sendTo( final WCTPacket message, final EntityPlayerMP player ) - { - this.ec.sendTo( message.getProxy(), player ); + public void sendTo(final WCTPacket message, final EntityPlayerMP player) { + this.ec.sendTo(message.getProxy(), player); } - public void sendToAllAround( final WCTPacket message, final NetworkRegistry.TargetPoint point ) - { - this.ec.sendToAllAround( message.getProxy(), point ); + public void sendToAllAround(final WCTPacket message, final NetworkRegistry.TargetPoint point) { + this.ec.sendToAllAround(message.getProxy(), point); } - public void sendToDimension( final WCTPacket message, final int dimensionId ) - { - this.ec.sendToDimension( message.getProxy(), dimensionId ); + public void sendToDimension(final WCTPacket message, final int dimensionId) { + this.ec.sendToDimension(message.getProxy(), dimensionId); } - public void sendToServer( final WCTPacket message ) - { - this.ec.sendToServer( message.getProxy() ); + public void sendToServer(final WCTPacket message) { + this.ec.sendToServer(message.getProxy()); } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java index d2c1ffc..ee2e324 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java @@ -28,7 +28,6 @@ public class PacketCraftRequest extends WCTPacket { private final long amount; private final boolean heldShift; - // automatic. public PacketCraftRequest(final ByteBuf stream) { this.heldShift = stream.readBoolean(); this.amount = stream.readLong(); diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketMagnetFilterMode.java b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketMagnetFilterMode.java index 96f0190..0ba618a 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketMagnetFilterMode.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketMagnetFilterMode.java @@ -18,12 +18,11 @@ import net.p455w0rd.wirelesscraftingterminal.items.ItemWirelessCraftingTerminal; public class PacketMagnetFilterMode extends WCTPacket { boolean isWhitelisting; - - public PacketMagnetFilterMode( final ByteBuf stream ) - { + + public PacketMagnetFilterMode(final ByteBuf stream) { this.isWhitelisting = stream.readBoolean(); } - + public PacketMagnetFilterMode(final boolean isWhitelisting) { this.isWhitelisting = isWhitelisting; if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { @@ -32,12 +31,11 @@ public class PacketMagnetFilterMode extends WCTPacket { final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeBoolean(this.isWhitelisting); - this.configureWrite( data ); + this.configureWrite(data); } - + @Override - public void serverPacketData( final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player ) - { + public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { ItemStack magnetItem = RandomUtils.getMagnet(player.inventory); if (!(magnetItem.getItem() instanceof ItemMagnet)) { return; @@ -49,10 +47,9 @@ public class PacketMagnetFilterMode extends WCTPacket { magnetItem.getTagCompound().setBoolean("Whitelisting", this.isWhitelisting); } } - + @Override - public void clientPacketData( final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player ) - { + public void clientPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { GuiMagnet.mode = this.isWhitelisting; } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketOpenWirelessTerm.java b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketOpenWirelessTerm.java index 8049cd8..d56c15d 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketOpenWirelessTerm.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketOpenWirelessTerm.java @@ -20,38 +20,22 @@ public class PacketOpenWirelessTerm extends WCTPacket { public PacketOpenWirelessTerm(final ByteBuf stream) { } - + public PacketOpenWirelessTerm() { - if( Platform.isClient() ) { - EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; - //WCTApi.instance().interact().openWirelessCraftingTerminalGui(player); - } final ByteBuf data = Unpooled.buffer(); - data.writeInt( this.getPacketID() ); - this.configureWrite( data ); + data.writeInt(this.getPacketID()); + this.configureWrite(data); } @Override public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { - World world = player.worldObj; - int x = (int) player.posX; - int y = (int) player.posY; - int z = (int) player.posZ; - //WCTGuiHandler.launchGui(WirelessCraftingTerminal.GUI_WCT, player, world, x, y, z); if (player.openContainer instanceof ContainerPlayer) { - //WCTApi.instance().interact().openWirelessCraftingTerminalGui(player); - player.openGui(WirelessCraftingTerminal.INSTANCE, Reference.GUI_WCT, world, x, y, z); + WCTApi.instance().interact().openWirelessCraftingTerminalGui(player); } } @Override public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) { - World world = player.worldObj; - int x = (int) player.posX; - int y = (int) player.posY; - int z = (int) player.posZ; - //WCTGuiHandler.launchGui(WirelessCraftingTerminal.GUI_WCT, player, world, x, y, z); //WCTApi.instance().interact().openWirelessCraftingTerminalGui(player); - player.openGui(WirelessCraftingTerminal.INSTANCE, Reference.GUI_WCT, world, x, y, z); } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java index e01c513..aab1155 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java @@ -28,89 +28,70 @@ import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; -public class PacketValueConfig extends WCTPacket -{ +public class PacketValueConfig extends WCTPacket { private final String Name; private final String Value; // automatic. - public PacketValueConfig( final ByteBuf stream ) throws IOException - { - final DataInputStream dis = new DataInputStream( new ByteArrayInputStream( stream.array(), stream.readerIndex(), stream.readableBytes() ) ); + public PacketValueConfig(final ByteBuf stream) throws IOException { + final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(stream.array(), stream.readerIndex(), stream.readableBytes())); this.Name = dis.readUTF(); this.Value = dis.readUTF(); - // dis.close(); } // api - public PacketValueConfig( final String name, final String value ) throws IOException - { + public PacketValueConfig(final String name, final String value) throws IOException { this.Name = name; this.Value = value; final ByteBuf data = Unpooled.buffer(); - data.writeInt( this.getPacketID() ); - + data.writeInt(this.getPacketID()); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); - final DataOutputStream dos = new DataOutputStream( bos ); - dos.writeUTF( name ); - dos.writeUTF( value ); - // dos.close(); - - data.writeBytes( bos.toByteArray() ); - - this.configureWrite( data ); + final DataOutputStream dos = new DataOutputStream(bos); + dos.writeUTF(name); + dos.writeUTF(value); + data.writeBytes(bos.toByteArray()); + this.configureWrite(data); } @Override - public void serverPacketData( final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player ) - { + public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { final Container c = player.openContainer; - if( this.Name.equals( "Item" ) && RandomUtils.getWirelessTerm(player.inventory) != null && RandomUtils.getWirelessTerm(player.inventory).getItem() instanceof IMouseWheelItem ) - { + if (this.Name.equals("Item") && RandomUtils.getWirelessTerm(player.inventory) != null && RandomUtils.getWirelessTerm(player.inventory).getItem() instanceof IMouseWheelItem) { final ItemStack is = RandomUtils.getWirelessTerm(player.inventory); final IMouseWheelItem si = (IMouseWheelItem) is.getItem(); - si.onWheel( is, this.Value.equals( "WheelUp" ) ); + si.onWheel(is, this.Value.equals("WheelUp")); } - else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus ) - { + else if (this.Name.equals("Terminal.Cpu") && c instanceof ContainerCraftingStatus) { final ContainerCraftingStatus qk = (ContainerCraftingStatus) c; - qk.cycleCpu( this.Value.equals( "Next" ) ); + qk.cycleCpu(this.Value.equals("Next")); } - else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm ) - { + else if (this.Name.equals("Terminal.Cpu") && c instanceof ContainerCraftConfirm) { final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; - qk.cycleCpu( this.Value.equals( "Next" ) ); + qk.cycleCpu(this.Value.equals("Next")); } - else if( this.Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm ) - { + else if (this.Name.equals("Terminal.Start") && c instanceof ContainerCraftConfirm) { final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; qk.startJob(); } - else if( this.Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU ) - { + else if (this.Name.equals("TileCrafting.Cancel") && c instanceof ContainerCraftingCPU) { final ContainerCraftingCPU qk = (ContainerCraftingCPU) c; qk.cancelCrafting(); } - else if( c instanceof IConfigurableObject ) - { - final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager(); + else if (c instanceof IConfigurableObject) { + final IConfigManager cm = ((IConfigurableObject) c).getConfigManager(); - for( final Settings e : cm.getSettings() ) - { - if( e.name().equals( this.Name ) ) - { - final Enum def = cm.getSetting( e ); + for (final Settings e : cm.getSettings()) { + if (e.name().equals(this.Name)) { + final Enum def = cm.getSetting(e); - try - { - cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) ); + try { + cm.putSetting(e, Enum.valueOf(def.getClass(), this.Value)); } - catch( final IllegalArgumentException err ) - { + catch (final IllegalArgumentException err) { // :P } @@ -121,55 +102,44 @@ public class PacketValueConfig extends WCTPacket } @Override - public void clientPacketData( final INetworkInfo network, final WCTPacket packet, final EntityPlayer player ) - { + public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) { final Container c = player.openContainer; - if( this.Name.equals( "CustomName" )) - { + if (this.Name.equals("CustomName")) { if (c instanceof ContainerWirelessCraftingTerminal) { - ( (ContainerWirelessCraftingTerminal) c ).setCustomName( this.Value ); + ((ContainerWirelessCraftingTerminal) c).setCustomName(this.Value); } if (c instanceof WCTBaseContainer) { - ( (WCTBaseContainer) c ).setCustomName( this.Value ); + ((WCTBaseContainer) c).setCustomName(this.Value); } } - else if( this.Name.startsWith( "SyncDat." ) ) - { + else if (this.Name.startsWith("SyncDat.")) { if (c instanceof ContainerWirelessCraftingTerminal) { - ( (ContainerWirelessCraftingTerminal) c ).stringSync( Integer.parseInt( this.Name.substring( 8 ) ), this.Value ); + ((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 ); + ((WCTBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value); } } - else if( this.Name.equals( "CraftingStatus" ) && this.Value.equals( "Clear" ) ) - { + else if (this.Name.equals("CraftingStatus") && this.Value.equals("Clear")) { final GuiScreen gs = Minecraft.getMinecraft().currentScreen; - if( gs instanceof GuiCraftingCPU ) - { - ( (GuiCraftingCPU) gs ).clearItems(); + if (gs instanceof GuiCraftingCPU) { + ((GuiCraftingCPU) gs).clearItems(); } } - else if( c instanceof IConfigurableObject ) - { - final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager(); + else if (c instanceof IConfigurableObject) { + final IConfigManager cm = ((IConfigurableObject) c).getConfigManager(); - for( final Settings e : cm.getSettings() ) - { - if( e.name().equals( this.Name ) ) - { - final Enum def = cm.getSetting( e ); + for (final Settings e : cm.getSettings()) { + if (e.name().equals(this.Name)) { + final Enum def = cm.getSetting(e); - try - { - cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) ); + try { + cm.putSetting(e, Enum.valueOf(def.getClass(), this.Value)); } - catch( final IllegalArgumentException err ) - { + catch (final IllegalArgumentException err) { // :P } - break; } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/AchievementHandler.java b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/AchievementHandler.java index cf878a9..087494a 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/AchievementHandler.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/AchievementHandler.java @@ -36,7 +36,6 @@ public class AchievementHandler { public static void init() { registerAchievements(); registerPage(); - //addAchievementToPage(wctAch); } public static void registerAchievements() { diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java index f994cb7..ae03d3e 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java @@ -14,6 +14,11 @@ import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; public class ConfigHandler { + /* + * A big part of what goes on here is reloading the cfg on-the-fly + * since Ender-Core adds the abilitty to modify config stuff while in game, + * I figured I'd add support for such possibilities + */ public static Configuration config; public static boolean enableInfinityBooster; public static boolean enableEasyMode; @@ -106,6 +111,8 @@ public class ConfigHandler { } ItemEnum.BOOSTER_CARD.getItem().setCreativeTab(null); } + //Added here because the only item being added to creative was the Booster Card + //even when I set the Creative Tabs in the individual item classes ItemEnum.WIRELESS_CRAFTING_TERMINAL.getItem().setCreativeTab(WirelessCraftingTerminal.creativeTab); ItemEnum.MAGNET_CARD.getItem().setCreativeTab(WirelessCraftingTerminal.creativeTab); } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/KeybindHandler.java b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/KeybindHandler.java index 31f6b40..e3a04f1 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/KeybindHandler.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/KeybindHandler.java @@ -38,17 +38,14 @@ public class KeybindHandler { @SubscribeEvent public void onKeyInput(KeyInputEvent event) { - //if (event.phase == Phase.END) { - EntityClientPlayerMP p = (EntityClientPlayerMP) Minecraft.getMinecraft().thePlayer; - if (openTerminal.isPressed()) { - //if (p.openContainer != null && p.openContainer instanceof ContainerPlayer) { - //WCTApi.instance().interact().openWirelessCraftingTerminalGui(p); + EntityClientPlayerMP p = (EntityClientPlayerMP) Minecraft.getMinecraft().thePlayer; + if (openTerminal.isPressed()) { + if (p.openContainer != null && p.openContainer instanceof ContainerPlayer) { if (!FMLClientHandler.instance().isGUIOpen(GuiWirelessCraftingTerminal.class)) { - NetworkHandler.instance.sendToServer( new PacketOpenWirelessTerm() ); + NetworkHandler.instance.sendToServer(new PacketOpenWirelessTerm()); } - //} } - //} + } } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/RecipeHandler.java b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/RecipeHandler.java index ab7274d..84c79ec 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/RecipeHandler.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/RecipeHandler.java @@ -100,17 +100,5 @@ public class RecipeHandler { } recipeList.clear(); init(); - /* - * ItemStack recipeRegistryItem = null; ArrayList recipeRegistry = - * (ArrayList) CraftingManager.getInstance().getRecipeList(); for (int i - * = 0; i < recipeRegistry.size(); i++) { IRecipe tmpRecipe = (IRecipe) - * recipeRegistry.get(i); if (tmpRecipe instanceof ShapedOreRecipe) { - * ShapedOreRecipe recipeRegistryRecipe = (ShapedOreRecipe)tmpRecipe; - * recipeRegistryItem = recipeRegistryRecipe.getRecipeOutput(); } else { - * continue; } for (IRecipe recipe : recipeList) { ItemStack - * recipeOutput = recipe.getRecipeOutput(); if - * (ItemStack.areItemStacksEqual(recipeOutput, recipeRegistryItem)) { - * recipeRegistry.remove(i); } } } - */ } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java b/src/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java index 62a325a..2ccba1c 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java @@ -32,9 +32,7 @@ import appeng.api.util.IConfigManager; import appeng.container.interfaces.IInventorySlotAware; import appeng.tile.networking.TileWireless; - -public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware, WCTIActionHost -{ +public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware, WCTIActionHost { private final ItemStack effectiveItem; private final IWirelessTermHandler wth; @@ -48,37 +46,28 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II private double myRange = Double.MAX_VALUE; private final int inventorySlot; - public WirelessTerminalGuiObject( final IWirelessTermHandler wh, final ItemStack is, final EntityPlayer ep, final World w, final int x, final int y, final int z ) - { - this.encryptionKey = wh.getEncryptionKey( is ); + public WirelessTerminalGuiObject(final IWirelessTermHandler wh, final ItemStack is, final EntityPlayer ep, final World w, final int x, final int y, final int z) { + this.encryptionKey = wh.getEncryptionKey(is); this.effectiveItem = is; this.myPlayer = ep; this.wth = wh; this.inventorySlot = x; - ILocatable obj = null; - - try - { - final long encKey = Long.parseLong( this.encryptionKey ); - obj = AEApi.instance().registries().locatable().getLocatableBy( encKey ); + try { + final long encKey = Long.parseLong(this.encryptionKey); + obj = AEApi.instance().registries().locatable().getLocatableBy(encKey); } - catch( final NumberFormatException err ) - { + catch (final NumberFormatException err) { // :P } - if( obj instanceof IGridHost ) - { - final IGridNode n = ((IGridHost) obj).getGridNode( ForgeDirection.UNKNOWN ); - if( n != null ) - { + if (obj instanceof IGridHost) { + final IGridNode n = ((IGridHost) obj).getGridNode(ForgeDirection.UNKNOWN); + if (n != null) { this.targetGrid = n.getGrid(); - if( this.targetGrid != null ) - { - this.sg = this.targetGrid.getCache( IStorageGrid.class ); - if( this.sg != null ) - { + if (this.targetGrid != null) { + this.sg = this.targetGrid.getCache(IStorageGrid.class); + if (this.sg != null) { this.itemStorage = this.sg.getItemInventory(); } } @@ -86,196 +75,158 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } } - public double getRange() - { + public double getRange() { return this.myRange; } @Override - public IMEMonitor getItemInventory() - { - if( this.sg == null ) - { + public IMEMonitor getItemInventory() { + if (this.sg == null) { return null; } return this.sg.getItemInventory(); } @Override - public IMEMonitor getFluidInventory() - { - if( this.sg == null ) - { + public IMEMonitor getFluidInventory() { + if (this.sg == null) { return null; } return this.sg.getFluidInventory(); } @Override - public void addListener( final IMEMonitorHandlerReceiver l, final Object verificationToken ) - { - if( this.itemStorage != null ) - { - this.itemStorage.addListener( l, verificationToken ); + public void addListener(final IMEMonitorHandlerReceiver l, final Object verificationToken) { + if (this.itemStorage != null) { + this.itemStorage.addListener(l, verificationToken); } } @Override - public void removeListener( final IMEMonitorHandlerReceiver l ) - { - if( this.itemStorage != null ) - { - this.itemStorage.removeListener( l ); + public void removeListener(final IMEMonitorHandlerReceiver l) { + if (this.itemStorage != null) { + this.itemStorage.removeListener(l); } } @Override - public IItemList getAvailableItems( final IItemList out ) - { - if( this.itemStorage != null ) - { - return this.itemStorage.getAvailableItems( out ); + public IItemList getAvailableItems(final IItemList out) { + if (this.itemStorage != null) { + return this.itemStorage.getAvailableItems(out); } return out; } @Override - public IItemList getStorageList() - { - if( this.itemStorage != null ) - { + public IItemList getStorageList() { + if (this.itemStorage != null) { return this.itemStorage.getStorageList(); } return null; } @Override - public AccessRestriction getAccess() - { - if( this.itemStorage != null ) - { + public AccessRestriction getAccess() { + if (this.itemStorage != null) { return this.itemStorage.getAccess(); } return AccessRestriction.NO_ACCESS; } @Override - public boolean isPrioritized( final IAEItemStack input ) - { - if( this.itemStorage != null ) - { - return this.itemStorage.isPrioritized( input ); + public boolean isPrioritized(final IAEItemStack input) { + if (this.itemStorage != null) { + return this.itemStorage.isPrioritized(input); } return false; } @Override - public boolean canAccept( final IAEItemStack input ) - { - if( this.itemStorage != null ) - { - return this.itemStorage.canAccept( input ); + public boolean canAccept(final IAEItemStack input) { + if (this.itemStorage != null) { + return this.itemStorage.canAccept(input); } return false; } @Override - public int getPriority() - { - if( this.itemStorage != null ) - { + public int getPriority() { + if (this.itemStorage != null) { return this.itemStorage.getPriority(); } return 0; } @Override - public int getSlot() - { - if( this.itemStorage != null ) - { + public int getSlot() { + if (this.itemStorage != null) { return this.itemStorage.getSlot(); } return 0; } @Override - public boolean validForPass( final int i ) - { - return this.itemStorage.validForPass( i ); + public boolean validForPass(final int i) { + return this.itemStorage.validForPass(i); } @Override - public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final BaseActionSource src ) - { - if( this.itemStorage != null ) - { - return this.itemStorage.injectItems( input, type, src ); + public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, final BaseActionSource src) { + if (this.itemStorage != null) { + return this.itemStorage.injectItems(input, type, src); } return input; } @Override - public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src ) - { - if( this.itemStorage != null ) - { - return this.itemStorage.extractItems( request, mode, src ); + public IAEItemStack extractItems(final IAEItemStack request, final Actionable mode, final BaseActionSource src) { + if (this.itemStorage != null) { + return this.itemStorage.extractItems(request, mode, src); } return null; } @Override - public StorageChannel getChannel() - { - if( this.itemStorage != null ) - { + public StorageChannel getChannel() { + if (this.itemStorage != null) { return this.itemStorage.getChannel(); } return StorageChannel.ITEMS; } @Override - public double extractAEPower( final double amt, final Actionable mode, final PowerMultiplier usePowerMultiplier ) - { - if( this.wth != null && this.effectiveItem != null ) - { - if( mode == Actionable.SIMULATE ) - { - return this.wth.hasPower( this.myPlayer, amt, this.effectiveItem ) ? amt : 0; + public double extractAEPower(final double amt, final Actionable mode, final PowerMultiplier usePowerMultiplier) { + if (this.wth != null && this.effectiveItem != null) { + if (mode == Actionable.SIMULATE) { + return this.wth.hasPower(this.myPlayer, amt, this.effectiveItem) ? amt : 0; } - return this.wth.usePower( this.myPlayer, amt, this.effectiveItem ) ? amt : 0; + return this.wth.usePower(this.myPlayer, amt, this.effectiveItem) ? amt : 0; } return 0.0; } @Override - public ItemStack getItemStack() - { + public ItemStack getItemStack() { return this.effectiveItem; } @Override - public IConfigManager getConfigManager() - { - return this.wth.getConfigManager( this.effectiveItem ); + public IConfigManager getConfigManager() { + return this.wth.getConfigManager(this.effectiveItem); } @Override - public IGridNode getGridNode( final ForgeDirection dir ) - { + public IGridNode getGridNode(final ForgeDirection dir) { return this.getActionableNode(); } @Override - public AECableType getCableConnectionType( final ForgeDirection dir ) - { + public AECableType getCableConnectionType(final ForgeDirection dir) { return AECableType.NONE; } @Override - public void securityBreak() - { + public void securityBreak() { } @@ -283,48 +234,39 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II public IGridNode getActionableNode() { return getActionableNode(false); } - - public IGridNode getActionableNode(boolean ignoreRange) - { + + public IGridNode getActionableNode(boolean ignoreRange) { this.rangeCheck(ignoreRange); - if( this.myWap != null ) - { + if (this.myWap != null) { return this.myWap.getActionableNode(); } return null; } - + public boolean rangeCheck() { return rangeCheck(false); } - public boolean rangeCheck(boolean ignoreRange) - { + public boolean rangeCheck(boolean ignoreRange) { this.sqRange = this.myRange = Double.MAX_VALUE; - if( this.targetGrid != null && this.itemStorage != null ) - { - if( this.myWap != null ) - { - if( this.myWap.getGrid() == this.targetGrid ) - { - if( this.testWap( this.myWap ) ) - { + if (this.targetGrid != null && this.itemStorage != null) { + if (this.myWap != null) { + if (this.myWap.getGrid() == this.targetGrid) { + if (this.testWap(this.myWap)) { return true; } } return false; } - final IMachineSet tw = this.targetGrid.getMachines( TileWireless.class ); + final IMachineSet tw = this.targetGrid.getMachines(TileWireless.class); this.myWap = null; - for( final IGridNode n : tw ) - { + for (final IGridNode n : tw) { final IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine(); - if( this.testWap( wap, ignoreRange ) ) - { + if (this.testWap(wap, ignoreRange)) { this.myWap = wap; } } @@ -337,35 +279,30 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II private boolean testWap(final IWirelessAccessPoint wap) { return testWap(wap, false); } - - private boolean testWap( final IWirelessAccessPoint wap, boolean ignoreRange ) - { + + private boolean testWap(final IWirelessAccessPoint wap, boolean ignoreRange) { double rangeLimit = wap.getRange(); rangeLimit *= rangeLimit; final DimensionalCoord dc = wap.getLocation(); - if( dc.getWorld() == this.myPlayer.worldObj ) - { + if (dc.getWorld() == this.myPlayer.worldObj) { final double offX = dc.x - this.myPlayer.posX; final double offY = dc.y - this.myPlayer.posY; final double offZ = dc.z - this.myPlayer.posZ; final double r = offX * offX + offY * offY + offZ * offZ; - if( r < rangeLimit && this.sqRange > r && !ignoreRange) - { - if( wap.isActive() ) - { + if (r < rangeLimit && this.sqRange > r && !ignoreRange) { + if (wap.isActive()) { this.sqRange = r; - this.myRange = Math.sqrt( r ); + this.myRange = Math.sqrt(r); return true; } } else { - if( wap.isActive() ) - { + if (wap.isActive()) { this.sqRange = r; - this.myRange = Math.sqrt( r ); + this.myRange = Math.sqrt(r); return true; } } @@ -374,8 +311,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } @Override - public int getInventorySlot() - { + public int getInventorySlot() { return this.inventorySlot; } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WCTInteractionHelper.java b/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WCTInteractionHelper.java index 89b469e..4db69f7 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WCTInteractionHelper.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WCTInteractionHelper.java @@ -18,12 +18,7 @@ public class WCTInteractionHelper implements IWCTInteractionHelper { @Override public void openWirelessCraftingTerminalGui(final EntityPlayer player) { - // Valid player? - if ((player == null) || (player instanceof FakePlayer)) { - return; - } - - if (player.worldObj.isRemote) { + if ((player == null) || (player instanceof FakePlayer) || player.worldObj.isRemote) { return; } @@ -33,7 +28,8 @@ public class WCTInteractionHelper implements IWCTInteractionHelper { return; } - // Get the item the first wireless terminal + // Get the first wireless terminal + // If one is held, it takes precidence ItemStack wirelessTerminal = null; for (int i = 0; i < invSize; ++i) { @@ -46,51 +42,26 @@ public class WCTInteractionHelper implements IWCTInteractionHelper { break; } } - // Ensure the stack is valid if ((wirelessTerminal == null)) { - // Invalid terminal return; } - - // Get the interface IWirelessCraftingTermHandler terminalInterface = (IWirelessCraftingTermHandler) wirelessTerminal.getItem(); - - // Ensure the terminal has power - if (terminalInterface.getAECurrentPower(wirelessTerminal) == 0) { - // Terminal is dead + if (terminalInterface.getAECurrentPower(wirelessTerminal) <= 0) { player.addChatMessage(PlayerMessages.DeviceNotPowered.get()); return; } - - // Ensure the terminal is linked if (!isTerminalLinked(terminalInterface, wirelessTerminal)) { - // Unlinked terminal player.addChatMessage(PlayerMessages.DeviceNotLinked.get()); return; } - - // Get the encryption key String encKey = terminalInterface.getEncryptionKey(wirelessTerminal); - - // Are any AP's in range? ArrayList accessPoints = WirelessAELink.locateAPsInRangeOfPlayer(player, encKey); - - // Error occured if (accessPoints == null) { player.addChatMessage(PlayerMessages.StationCanNotBeLocated.get()); } - // None in range - /* - * else if( accessPoints.isEmpty() ) { player.addChatMessage( - * PlayerMessages.OutOfRange.get() ); player.addChatMessage(new - * ChatComponentText("XX")); } - */ - // Attempt to launch the gui - // NOTE: Range check done in here else { WCTGuiHandler.launchGui(Reference.GUI_WCT, player, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); } - } public static boolean isTerminalLinked(final IWirelessCraftingTermHandler wirelessTerminal, final ItemStack wirelessTerminalItemstack) { diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java b/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java index dfb22b4..3a6e9d1 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java @@ -34,104 +34,42 @@ import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionH * */ public abstract class WirelessAELink implements IStorageMonitorable { - /** - * The player who owns this link. - */ + protected final EntityPlayer player; - /** - * Encryption key used to access the network. - */ protected final String encryptionKey; - /** - * Access point used to communicate with the AE network. - */ protected IWirelessAccessPoint accessPoint; - /** - * Where in the world is the access point. - */ protected DimensionalCoord apLocation = null; - /** - * Network source representing the player - */ protected BaseActionSource actionSource; - public WirelessAELink( final @Nullable EntityPlayer player, @Nonnull final String encryptionKey ) - { - // Set the player + public WirelessAELink(final @Nullable EntityPlayer player, @Nonnull final String encryptionKey) { this.player = player; - - // Set the enc key this.encryptionKey = encryptionKey; - - // Link with the AP this.linkWithNewAP(); } - /** - * Checks if the AP at the specified location and has the specified range, - * is close enough to communicate with. - * - * @param APLocation - * @param APRange - * @param world - * @param x - * @param y - * @param z - * @return - */ - private static boolean isAPInRange( final DimensionalCoord APLocation, final double APRange, final World world, final int x, final int y, - final int z ) - { - // Is the AP in the same world? - if( !APLocation.isInWorld( world ) ) - { + private static boolean isAPInRange(final DimensionalCoord APLocation, final double APRange, final World world, final int x, final int y, final int z) { + if (!APLocation.isInWorld(world)) { return false; } - - // Calculate the square distance - double squareDistance = getSquaredDistanceFromAP( APLocation, x, y, z ); - - // Return if close enough to use AP - return squareDistance <= ( APRange * APRange ); + double squareDistance = getSquaredDistanceFromAP(APLocation, x, y, z); + return squareDistance <= (APRange * APRange); } - /** - * @param world - * @param x - * @param y - * @param z - * @param grid - * @return - */ - private static ArrayList locateAPsInRange( final World world, final int x, final int y, final int z, final IGrid grid ) - { - // Get all AP's on the grid - IMachineSet accessPoints = grid.getMachines( TileWireless.class ); - if( accessPoints.isEmpty() ) - { + private static ArrayList locateAPsInRange(final World world, final int x, final int y, final int z, final IGrid grid) { + IMachineSet accessPoints = grid.getMachines(TileWireless.class); + if (accessPoints.isEmpty()) { return null; } - - // Create the list ArrayList aps = new ArrayList(); - - // Loop over AP's and see if any are close enough to communicate with - for( IGridNode APNode : accessPoints ) - { - // Get the AP - IWirelessAccessPoint AP = (IWirelessAccessPoint)APNode.getMachine(); - - // Is the AP active? - if( AP.isActive() ) - { - // Close enough to the AP? - if( isAPInRange( AP.getLocation(), AP.getRange(), world, x, y, z ) ) - { - aps.add( AP ); + for (IGridNode APNode : accessPoints) { + IWirelessAccessPoint AP = (IWirelessAccessPoint) APNode.getMachine(); + if (AP.isActive()) { + if (isAPInRange(AP.getLocation(), AP.getRange(), world, x, y, z)) { + aps.add(AP); } } } @@ -139,253 +77,125 @@ public abstract class WirelessAELink implements IStorageMonitorable { return aps; } - /** - * Returns the squared distance the specified coords are from the Access Point. - * - * @param locationAP - * @param x - * @param y - * @param z - * @return - */ - protected static double getSquaredDistanceFromAP( final DimensionalCoord locationAP, final int x, final int y, final int z ) - { - if( locationAP == null ) - { + protected static double getSquaredDistanceFromAP(final DimensionalCoord locationAP, final int x, final int y, final int z) { + if (locationAP == null) { return Double.MAX_VALUE; } - - // Calculate the distance from the AP int dX = locationAP.x - x, dY = locationAP.y - y, dZ = locationAP.z - z; - - // Calculate the square distance - return( ( dX * dX ) + ( dY * dY ) + ( dZ * dZ ) ); + return ((dX * dX) + (dY * dY) + (dZ * dZ)); } - /** - * Returns an unsorted list of AP's in range. - * - * @param world - * @param x - * @param y - * @param z - * @param encryptionKey - * @return Null on error, list of AP's in range otherwise. - */ - public static ArrayList locateAPsInRange( final World world, final int x, final int y, final int z, - final String encryptionKey ) - { - // Get the encryption key + public static ArrayList locateAPsInRange(final World world, final int x, final int y, final int z, final String encryptionKey) { long encryptionValue; - try - { - encryptionValue = Long.parseLong( encryptionKey ); + try { + encryptionValue = Long.parseLong(encryptionKey); } - catch( NumberFormatException e ) - { - // Invalid security key + catch (NumberFormatException e) { return null; } - // Get the linked source - Object source = AEApi.instance().registries().locatable().getLocatableBy( encryptionValue ); + Object source = AEApi.instance().registries().locatable().getLocatableBy(encryptionValue); - // Ensure it is a security terminal - if( !( source instanceof TileSecurity ) ) - { - // Invalid security terminal + if (!(source instanceof TileSecurity)) { return null; } - - // Get the terminal - TileSecurity securityHost = (TileSecurity)source; - - // Get the grid + TileSecurity securityHost = (TileSecurity) source; IGrid grid; - try - { - grid = securityHost.getGridNode( ForgeDirection.UNKNOWN ).getGrid(); + try { + grid = securityHost.getGridNode(ForgeDirection.UNKNOWN).getGrid(); } - catch( Exception e ) - { - // Can not find the grid + catch (Exception e) { return null; } - return locateAPsInRange( world, x, y, z, grid ); + return locateAPsInRange(world, x, y, z, grid); } - /** - * Returns an unsorted list of AP's in range. - * - * @param player - * @param encryptionKey - * @return Null on error, list of AP's in range otherwise. - */ - public static ArrayList locateAPsInRangeOfPlayer( final EntityPlayer player, final String encryptionKey ) - { - return locateAPsInRange( player.worldObj, - (int)Math.floor( player.posX ), - (int)Math.floor( player.posY ), - (int)Math.floor( player.posZ ), encryptionKey ); + public static ArrayList locateAPsInRangeOfPlayer(final EntityPlayer player, final String encryptionKey) { + return locateAPsInRange(player.worldObj, (int) Math.floor(player.posX), (int) Math.floor(player.posY), (int) Math.floor(player.posZ), encryptionKey); } - /** - * Checks if the AP is still active and in range. - * - * @return - */ - private boolean isAPInRangeAndActive() - { - // Has AP? - if( this.accessPoint != null ) - { - // Is active? - if( this.accessPoint.isActive() ) - { - // In range? - return isAPInRange( this.apLocation, this.accessPoint.getRange(), this.getUserWorld(), - this.getUserPositionX(), this.getUserPositionY(), this.getUserPositionZ() ); + private boolean isAPInRangeAndActive() { + if (this.accessPoint != null) { + if (this.accessPoint.isActive()) { + return isAPInRange(this.apLocation, this.accessPoint.getRange(), this.getUserWorld(), this.getUserPositionX(), this.getUserPositionY(), this.getUserPositionZ()); } } return false; } - /** - * Locates the closest AP in range and links with it. - * - * @return True if AP linked with. - */ - private boolean linkWithNewAP() - { + private boolean linkWithNewAP() { World w = this.getUserWorld(); int x = this.getUserPositionX(); int y = this.getUserPositionY(); int z = this.getUserPositionZ(); IGrid grid = null; - if( this.accessPoint != null ) - { - try - { + if (this.accessPoint != null) { + try { grid = this.accessPoint.getGrid(); } - catch( Exception e ) - { + catch (Exception e) { } } - // Get a list of AP's in range ArrayList apList; - if( grid != null ) - { - apList = locateAPsInRange( w, x, y, z, grid ); + if (grid != null) { + apList = locateAPsInRange(w, x, y, z, grid); } - else - { - apList = locateAPsInRange( w, x, y, z, this.encryptionKey ); + else { + apList = locateAPsInRange(w, x, y, z, this.encryptionKey); } - if( ( apList == null ) || ( apList.isEmpty() ) ) - { - // No valid AP's found + if ((apList == null) || (apList.isEmpty())) { this.accessPoint = null; return false; } - // Get the closest IWirelessAccessPoint closest = null; double closestDistance = Double.MAX_VALUE; - for( IWirelessAccessPoint ap : apList ) - { - double dist = getSquaredDistanceFromAP( ap.getLocation(), x, y, z ); - if( dist < closestDistance ) - { + for (IWirelessAccessPoint ap : apList) { + double dist = getSquaredDistanceFromAP(ap.getLocation(), x, y, z); + if (dist < closestDistance) { closestDistance = dist; closest = ap; } } - - // Set the closest as the AP to use - this.setAP( closest ); + this.setAP(closest); return true; } - /** - * Set's the access point used for communication. - * - * @param accessPoint - */ - private void setAP( final IWirelessAccessPoint accessPoint ) - { - // Set the access point + private void setAP(final IWirelessAccessPoint accessPoint) { this.accessPoint = accessPoint; - - // Get the location of the access point this.apLocation = this.accessPoint.getLocation(); - - // Create the action source - if( this.player != null ) - { - this.actionSource = new WCTPlayerSource( this.player, (WCTIActionHost) this.accessPoint ); + if (this.player != null) { + this.actionSource = new WCTPlayerSource(this.player, (WCTIActionHost) this.accessPoint); } - else - { - this.actionSource = new MachineSource( (WCTIActionHost) this.accessPoint ); + else { + this.actionSource = new MachineSource((WCTIActionHost) this.accessPoint); } } - /** - * Return the x position of the user. - * - * @return - */ protected abstract int getUserPositionX(); - /** - * Return the y position of the user. - * - * @return - */ protected abstract int getUserPositionY(); - /** - * Return the z position of the user. - * - * @return - */ protected abstract int getUserPositionZ(); - /** - * Return the world the user is in. - * - * @return - */ protected abstract World getUserWorld(); - /** - * Is there enough local power to communicate with the AP? - * - * @return - */ protected abstract boolean hasPowerToCommunicate(); - public IEnergyGrid getEnergyGrid() - { - // Check AP - if( this.accessPoint == null ) - { + public IEnergyGrid getEnergyGrid() { + if (this.accessPoint == null) { return null; } - try - { - // Get the energy grid - return this.accessPoint.getActionableNode().getGrid().getCache( IEnergyGrid.class ); + try { + return this.accessPoint.getActionableNode().getGrid().getCache(IEnergyGrid.class); } - catch( Exception e ) - { + catch (Exception e) { // Ignored } @@ -393,24 +203,16 @@ public abstract class WirelessAELink implements IStorageMonitorable { } @Override - public IMEMonitor getFluidInventory() - { - // Check connectivity - if( ( this.accessPoint == null ) || !this.isConnected() ) - { + public IMEMonitor getFluidInventory() { + if ((this.accessPoint == null) || !this.isConnected()) { return null; } - try - { - // Get the storage grid - IStorageGrid storageGrid = this.accessPoint.getActionableNode().getGrid().getCache( IStorageGrid.class ); - - // Return the monitor + try { + IStorageGrid storageGrid = this.accessPoint.getActionableNode().getGrid().getCache(IStorageGrid.class); return storageGrid.getFluidInventory(); } - catch( Exception e ) - { + catch (Exception e) { // Ignored } @@ -418,51 +220,31 @@ public abstract class WirelessAELink implements IStorageMonitorable { } @Override - public IMEMonitor getItemInventory() - { - // Check connectivity - if( ( this.accessPoint == null ) || !this.isConnected() ) - { + public IMEMonitor getItemInventory() { + if ((this.accessPoint == null) || !this.isConnected()) { return null; } - try - { - // Get the storage grid - IStorageGrid storageGrid = this.accessPoint.getActionableNode().getGrid().getCache( IStorageGrid.class ); - - // Return the monitor + try { + IStorageGrid storageGrid = this.accessPoint.getActionableNode().getGrid().getCache(IStorageGrid.class); return storageGrid.getItemInventory(); } - catch( Exception e ) - { + catch (Exception e) { // Ignored } return null; } - /** - * Checks if the AP is still connected. - * - * @return - */ - public boolean isConnected() - { - // Is there power? - if( !this.hasPowerToCommunicate() ) - { + public boolean isConnected() { + if (!this.hasPowerToCommunicate()) { return false; } - // Is the current AP still good? - if( this.isAPInRangeAndActive() ) - { - // Current AP is still connected. + if (this.isAPInRangeAndActive()) { return true; } - // Attempt to link with a new AP return this.linkWithNewAP(); } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemEnum.java b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemEnum.java index 120c48b..1f2b7a5 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemEnum.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemEnum.java @@ -4,51 +4,44 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public enum ItemEnum { - BOOSTER_CARD ("infinityBoosterCard", new ItemInfinityBooster().setUnlocalizedName("infinityBoosterCard")), - BOOSTER_ICON ("infinityBoosterIcon", new ItemInfinityBooster().setUnlocalizedName("infinityBoosterIcon")), - WIRELESS_CRAFTING_TERMINAL ("wirelessCraftingTerminal", new ItemWirelessCraftingTerminal()), - WCT_DUMMY_ICON ("ae2wctDummyIcon", new ItemAE2WCTDummyIcon()), - MAGNET_CARD ("magnetCard", new ItemMagnet().setUnlocalizedName("magnetCard")), - WCT_BOOSTER_BG_ICON ("boosterBG", new ItemBoosterBGIcon()); - + BOOSTER_CARD("infinityBoosterCard", new ItemInfinityBooster().setUnlocalizedName("infinityBoosterCard")), + BOOSTER_ICON("infinityBoosterIcon", new ItemInfinityBooster().setUnlocalizedName("infinityBoosterIcon")), + WIRELESS_CRAFTING_TERMINAL("wirelessCraftingTerminal", new ItemWirelessCraftingTerminal()), + WCT_DUMMY_ICON("ae2wctDummyIcon", new ItemAE2WCTDummyIcon()), + MAGNET_CARD("magnetCard", new ItemMagnet().setUnlocalizedName("magnetCard")), + WCT_BOOSTER_BG_ICON("boosterBG", new ItemBoosterBGIcon()); + private final String internalName; private Item item; public static final ItemEnum[] VALUES = ItemEnum.values(); - - private ItemEnum( final String internalName, final Item item ) - { + + private ItemEnum(final String internalName, final Item item) { this.internalName = internalName; this.item = item; } - - public ItemStack getDMGStack( final int damageValue ) - { - return this.getDMGStack( damageValue, 1 ); + + public ItemStack getDMGStack(final int damageValue) { + return this.getDMGStack(damageValue, 1); } - public ItemStack getDMGStack( final int damageValue, final int size ) - { - return new ItemStack( this.item, size, damageValue ); + public ItemStack getDMGStack(final int damageValue, final int size) { + return new ItemStack(this.item, size, damageValue); } - public String getInternalName() - { + public String getInternalName() { return this.internalName; } - public Item getItem() - { + public Item getItem() { return this.item; } - public ItemStack getStack() - { - return this.getStack( 1 ); + public ItemStack getStack() { + return this.getStack(1); } - public ItemStack getStack( final int size ) - { - return new ItemStack( this.item, size ); + public ItemStack getStack(final int size) { + return new ItemStack(this.item, size); } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java index 9cd1747..e5c22b0 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java @@ -156,7 +156,6 @@ public class ItemMagnet extends Item { } @SuppressWarnings("rawtypes") - // @Override public void doMagnet(ItemStack item, World world, EntityPlayer player, ItemStack wirelessTerm) { if (world.isRemote || getItemStack() == null) return; diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java index 3ab49c5..a896798 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java @@ -1,5 +1,6 @@ package net.p455w0rd.wirelesscraftingterminal.items; +import java.util.EnumSet; import java.util.List; import org.lwjgl.input.Keyboard; @@ -14,6 +15,7 @@ import appeng.api.config.SortDir; import appeng.api.config.SortOrder; import appeng.api.config.ViewItems; import appeng.api.util.IConfigManager; +import appeng.core.features.AEFeature; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; @@ -51,7 +53,6 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I public ItemWirelessCraftingTerminal() { super(Reference.WCT_MAX_POWER, Optional. absent()); - //this.setFeature(EnumSet.of(AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools)); this.setUnlocalizedName("wirelessCraftingTerminal"); this.setTextureName(Reference.MODID + ":wirelessCraftingTerminal"); this.setMaxStackSize(1); diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java index 9164fa7..db3feca 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java @@ -27,6 +27,10 @@ public class ClientProxy extends CommonProxy { return; } } + + public void registerItems() { + // =] + } public void registerRenderers() { // No renderers...yet =] diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java index c861913..6265fdb 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java @@ -44,6 +44,7 @@ public class CommonProxy { MinecraftForge.EVENT_BUS.register( this ); FMLCommonHandler.instance().bus().register(new ConfigHandler()); } + public void registerItems() { for (ItemEnum item : ItemEnum.VALUES) { GameRegistry.registerItem(item.getItem(), item.getInternalName()); @@ -51,10 +52,11 @@ public class CommonProxy { } public void removeItemsFromNEI() { + // XD } public void registerRenderers() { - // Ignored server side. + // =P } public void missingCoreMod() { @@ -125,7 +127,7 @@ public class CommonProxy { ConfigHandler.reloadRecipes(); } // Was using this for hidden booster achievement - // it was giving me too much of a headache..mayeb + // it was giving me too much of a headache..maybe // i'll implement in the future /* AchievementPage achPg = AchievementPage.getAchievementPage("Wireless Crafting Term"); @@ -154,6 +156,17 @@ public class CommonProxy { } } + @SubscribeEvent + public void pickupEvent(PlayerEvent.ItemPickupEvent e) { + if (Reference.WCT_BOOSTER_ENABLED && !Reference.WCT_EASYMODE_ENABLED) { + if (e.pickedUp.getEntityItem().getItem() == ItemEnum.BOOSTER_CARD.getItem()) { + if (AchievementHandler.isAchievementUnlocked(e.player, wctAch)) { + AchievementHandler.triggerAch(boosterAch, e.player); + } + } + } + } + @SubscribeEvent public void onPlayerCraftingEvent(final PlayerEvent.ItemCraftedEvent event) { boolean hasWCTAch = ((EntityPlayerMP) event.player).func_147099_x().hasAchievementUnlocked(AchievementHandler.wctAch); @@ -180,7 +193,7 @@ public class CommonProxy { } } } - + /* @SubscribeEvent public void achievementGetEvent(AchievementEvent event) { @@ -194,15 +207,4 @@ public class CommonProxy { } } */ - - @SubscribeEvent - public void pickupEvent(PlayerEvent.ItemPickupEvent e) { - if (Reference.WCT_BOOSTER_ENABLED && !Reference.WCT_EASYMODE_ENABLED) { - if (e.pickedUp.getEntityItem().getItem() == ItemEnum.BOOSTER_CARD.getItem()) { - if (AchievementHandler.isAchievementUnlocked(e.player, wctAch)) { - AchievementHandler.triggerAch(boosterAch, e.player); - } - } - } - } } \ No newline at end of file