From 116213d19714457c45876de9a79504fc43812bad Mon Sep 17 00:00:00 2001 From: thatsIch Date: Sat, 4 Oct 2014 10:50:53 +0200 Subject: [PATCH] Added typesafe method to obtain the inventory slots --- .../java/appeng/client/gui/AEBaseGui.java | 46 +++++++++++-------- .../resources/assets/appliedenergistics2/lang | 2 +- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/java/appeng/client/gui/AEBaseGui.java b/src/main/java/appeng/client/gui/AEBaseGui.java index 2a08aa7b..2daec12d 100644 --- a/src/main/java/appeng/client/gui/AEBaseGui.java +++ b/src/main/java/appeng/client/gui/AEBaseGui.java @@ -90,13 +90,20 @@ public abstract class AEBaseGui extends GuiContainer { super.initGui(); - Iterator i = inventorySlots.inventorySlots.iterator(); + final List slots = this.getInventorySlots(); + Iterator i = slots.iterator(); while (i.hasNext()) if ( i.next() instanceof SlotME ) i.remove(); for (InternalSlotME me : meSlots) - inventorySlots.inventorySlots.add( new SlotME( me ) ); + slots.add( new SlotME( me ) ); + } + + @SuppressWarnings( "unchecked" ) + private List getInventorySlots() + { + return this.inventorySlots.inventorySlots; } @Override @@ -126,9 +133,10 @@ public abstract class AEBaseGui extends GuiContainer ((AEBaseContainer) inventorySlots).setTargetStack( item ); InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP; int times = Math.abs( wheel ); + final int inventorySize = this.getInventorySlots().size(); for (int h = 0; h < times; h++) { - PacketInventoryAction p = new PacketInventoryAction( direction, inventorySlots.inventorySlots.size(), 0 ); + PacketInventoryAction p = new PacketInventoryAction( direction, inventorySize, 0 ); NetworkHandler.instance.sendToServer( p ); } } @@ -235,7 +243,7 @@ public abstract class AEBaseGui extends GuiContainer if ( slot instanceof SlotME ) stack = ((SlotME) slot).getAEStack(); - int slotNum = inventorySlots.inventorySlots.size(); + int slotNum = this.getInventorySlots().size(); if ( !(slot instanceof SlotME) && slot != null ) slotNum = slot.slotNumber; @@ -327,7 +335,7 @@ public abstract class AEBaseGui extends GuiContainer if ( action != null ) { ((AEBaseContainer) inventorySlots).setTargetStack( stack ); - PacketInventoryAction p = new PacketInventoryAction( action, inventorySlots.inventorySlots.size(), 0 ); + PacketInventoryAction p = new PacketInventoryAction( action, this.getInventorySlots().size(), 0 ); NetworkHandler.instance.sendToServer( p ); } @@ -352,14 +360,13 @@ public abstract class AEBaseGui extends GuiContainer { // a replica of the weird broken vanilla feature. - for (Object inventorySlot : this.inventorySlots.inventorySlots) + final List slots = this.getInventorySlots(); + for (Slot inventorySlot : slots) { - Slot targetSlot = (Slot) inventorySlot; - - if ( targetSlot != null && targetSlot.canTakeStack( this.mc.thePlayer ) && targetSlot.getHasStack() - && targetSlot.inventory == slot.inventory && Container.func_94527_a( targetSlot, dbl_whichItem, true ) ) + if ( inventorySlot != null && inventorySlot.canTakeStack( this.mc.thePlayer ) && inventorySlot.getHasStack() + && inventorySlot.inventory == slot.inventory && Container.func_94527_a( inventorySlot, dbl_whichItem, true ) ) { - this.handleMouseClick( targetSlot, targetSlot.slotNumber, ctrlDown, 1 ); + this.handleMouseClick( inventorySlot, inventorySlot.slotNumber, ctrlDown, 1 ); } } } @@ -418,7 +425,8 @@ public abstract class AEBaseGui extends GuiContainer { if ( p_146983_1_ == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode() ) { - for (Slot s : (List) inventorySlots.inventorySlots) + final List slots = this.getInventorySlots(); + for (Slot s : slots) { if ( s.getSlotIndex() == j && s.inventory == ((AEBaseContainer) inventorySlots).getPlayerInv() ) { @@ -436,7 +444,7 @@ public abstract class AEBaseGui extends GuiContainer } else { - for (Slot s : (List) inventorySlots.inventorySlots) + for (Slot s : slots) { if ( s.getSlotIndex() == j && s.inventory == ((AEBaseContainer) inventorySlots).getPlayerInv() ) { @@ -612,11 +620,12 @@ public abstract class AEBaseGui extends GuiContainer GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); drawBG( ox, oy, x, y ); - for (Object o : inventorySlots.inventorySlots) + final List slots = this.getInventorySlots(); + for (Slot slot : slots) { - if ( o instanceof OptionalSlotFake ) + if ( slot instanceof OptionalSlotFake ) { - OptionalSlotFake fs = (OptionalSlotFake) o; + OptionalSlotFake fs = (OptionalSlotFake) slot; if ( fs.renderDisabled() ) { if ( fs.isEnabled() ) @@ -669,10 +678,9 @@ public abstract class AEBaseGui extends GuiContainer protected Slot getSlot(int mouseX, int mouseY) { - for (int j1 = 0; j1 < this.inventorySlots.inventorySlots.size(); ++j1) + final List slots = this.getInventorySlots(); + for (Slot slot : slots) { - Slot slot = (Slot) this.inventorySlots.inventorySlots.get( j1 ); - // isPointInRegion if ( func_146978_c( slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY ) ) { diff --git a/src/main/resources/assets/appliedenergistics2/lang b/src/main/resources/assets/appliedenergistics2/lang index b0a451fe..38dd8952 160000 --- a/src/main/resources/assets/appliedenergistics2/lang +++ b/src/main/resources/assets/appliedenergistics2/lang @@ -1 +1 @@ -Subproject commit b0a451fecd97583367e12a98439dafac29e7ae97 +Subproject commit 38dd8952cea1985838347f741b895368d41948e3