From ae70542bbdddc823b869358f083c5a30476478aa Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Sun, 4 Aug 2013 23:44:58 -0400 Subject: [PATCH] Battery is mostly working! --- .../textures/gui/batterybox_gui.png | Bin 5781 -> 5742 bytes .../battery/BlockBattery.java | 5 ++ .../battery/ContainerBattery.java | 4 +- src/resonantinduction/battery/GuiBattery.java | 9 +++- .../battery/SynchronizedBatteryData.java | 9 +++- .../battery/TileEntityBattery.java | 50 ++++++++++-------- 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/resources/assets/resonantinduction/textures/gui/batterybox_gui.png b/resources/assets/resonantinduction/textures/gui/batterybox_gui.png index 9d845a2cb21d71a3ccd65dd5a417180bb4de770f..a44d57d5fd4eb82f482972ec09db179b38118e81 100644 GIT binary patch delta 4678 zcmbVPdo+}5+n;$F+YCuY*^W_W9Llkr$xIFzgE2Z$*o2~XL~2mXGh;h!hsZgF8NEb0 zkwTHC(@Y}dup1=jB;%a(>AP!v>s#wv@80X(?|%Mz*8N=TcmICZ@4Bz+elj%2HA)Ym zU?E$peTPDkW4R7VgItOI)q|PapJ#5AHcyc{cKY_+RnpDArv&-PjjuW=`D{Ybp3y0D zDzIo5Qx_@ZY5y_;BS>UGrR5A$cT6Hi4dE?2Zs+NX+QP^c`Zz-Nv?n5^TLV2{$W)n) z5NPyLoFQ*Wg!2Pl1_1aXL!MxzC8-Fm-p4FXBU%k%Dq7W=!MVzSbZ++5qG;{F3ksyIauQT9gW}hKWKC4?SA#-R@Y2L&5Q*5Zs^Ee zloXzg(1<_ijrB`lK+Q*Lz8!%QuvCQ9>sz{*ht@=-->zRS?qXU4r3w9QS5cii*ocQ) zwV!5iZUBDPL8t8@e~_Wh_^eN4PbZ-ChLOGsvjPUf{9oIh#h0o9(M~zCX+&2LU(sJ! ziFHW_`BS4@wqgGqvC?e@H+kGhf9U?g!=LP#fKm}+7%sY9%I3LA zqT!qDV#L9QM?(I#U#-GJ()~2;aRJ78cg+JKS<{!r8>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{QRIc{JD4#t|lw&<7nk;-<>59_Qr|_ovE2(N8%g{^M>;0+`X1* zK4UxS63U=K+&*umB3DPKYq^hCv}MM&uP!v;DUQy8J;%o7QQZmY7&Y`dE=HVh^`WnU z%G@VZ>adu8!f<+mhTW~5_5mEN#NmbK!}rsJ)1JQyyegFF?z|!T`nsl+qy9WMbt=;K z3(1;FbiPFU%k$-{RC-!Eqyr(!%6xPG=qTg`h_c!>irQF0XKR3d7{m-om7-!Iq z&uf!pL?2Gvn?<9d(5&{tBmRrAGSW&`Yg%^%9QJ%U{4hnzK8kmsq-7zHlO4EL+S0ZQ z_CIuAb3(#++t7&G*-Hflt}*FmlvYyiwVgkoiCjISu?_p!%H`DZ88@9ynGeZ!0$*BB zJw7u_i)u^Ml9tI{I#v19TCwn_azh^{C3IqK!qS`>7q(=AMh{V&+m>nb7MuBsn@rOu zDqn{v1{~r}?x8~?_x7E*)4004y(D_JnWz54<;$_0Ei~4ZW>iru+$-m_&(0gZ2NB93nEAe}v~ zE6y38Q9oU#GCQw=Xq4h@H*DOT4J?9fn72m`*emM}&hh{} zOJWlNo)o?RA^k3i;Gv{B%@HVH$QjDw`KHNkD>EyWM!&v2mm|$lyqfGlwNtPR9*KAK z6L|X|f1!qol}o)}fGHjqG&q#_1$Uk6V(4BRM+D7PVd4 zJtuG3Jj`{ipRdvh%~&s@ZLZ|ls2+==UF{nfK2?QtNM%(v)JG?u?oBi+%a86mFSOn7 zs@Z(5uMav_M|et6`uv-slUK4Si!!`cKgL}kO8b7yS)2Vf8Z+JSL^gf?xYu;?=J}?kZ<^1u&IWN; z_Mmb_nTcKx`1!&8dG-kEHb2^!Y`AjGwoH{5gH=aK^rcaj~5fydm8YFcXS^80@QaoOkW diff --git a/src/resonantinduction/battery/BlockBattery.java b/src/resonantinduction/battery/BlockBattery.java index 023c3c932..df07d2782 100644 --- a/src/resonantinduction/battery/BlockBattery.java +++ b/src/resonantinduction/battery/BlockBattery.java @@ -96,6 +96,11 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider } } } + + if(!world.isRemote) + { + entityPlayer.openGui(ResonantInduction.INSTNACE, 0, world, x, y, z); + } return true; } diff --git a/src/resonantinduction/battery/ContainerBattery.java b/src/resonantinduction/battery/ContainerBattery.java index de7d54ae3..1b9df9653 100644 --- a/src/resonantinduction/battery/ContainerBattery.java +++ b/src/resonantinduction/battery/ContainerBattery.java @@ -25,13 +25,13 @@ public class ContainerBattery extends Container { for(int slotY = 0; slotY < 9; ++slotY) { - addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18)); + addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 125 + slotX * 18)); } } for(slotX = 0; slotX < 9; ++slotX) { - addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); + addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 183)); } tileEntity.openChest(); diff --git a/src/resonantinduction/battery/GuiBattery.java b/src/resonantinduction/battery/GuiBattery.java index bab1ec8ed..d5a00c6cb 100644 --- a/src/resonantinduction/battery/GuiBattery.java +++ b/src/resonantinduction/battery/GuiBattery.java @@ -18,6 +18,7 @@ public class GuiBattery extends GuiContainer { super(new ContainerBattery(inventory, tentity)); tileEntity = tentity; + ySize+=41; } @Override @@ -27,7 +28,10 @@ public class GuiBattery extends GuiContainer int yAxis = (mouseY - (height - ySize) / 2); fontRenderer.drawString("Battery", 43, 6, 0x404040); - fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 0x00CD00); + fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 0x404040); + fontRenderer.drawString("Cells: " + tileEntity.clientCells + " / " + tileEntity.structure.getMaxCells(), 62, 23, 0x404040); + fontRenderer.drawString("Energy: " + tileEntity.getEnergyStored() + " / " + tileEntity.getMaxEnergyStored(), 62, 32, 0x404040); + fontRenderer.drawString("Volume: " + tileEntity.structure.getVolume(), 62, 41, 0x404040); } @Override @@ -41,5 +45,8 @@ public class GuiBattery extends GuiContainer int xAxis = (mouseX - (width - xSize) / 2); int yAxis = (mouseY - (height - ySize) / 2); + + int scale = (int)((tileEntity.getEnergyStored() / tileEntity.getMaxEnergyStored()) * 105); + drawTexturedModalRect(guiWidth + 61, guiHeight + 102, 0, 207, scale, 12); } } diff --git a/src/resonantinduction/battery/SynchronizedBatteryData.java b/src/resonantinduction/battery/SynchronizedBatteryData.java index c0ca748ce..9a613f9dc 100644 --- a/src/resonantinduction/battery/SynchronizedBatteryData.java +++ b/src/resonantinduction/battery/SynchronizedBatteryData.java @@ -45,7 +45,14 @@ public class SynchronizedBatteryData public void sortInventory() { - ItemStack[] toSort = (ItemStack[])SetUtil.copy(inventory).toArray(); + Object[] array = SetUtil.copy(inventory).toArray(); + + ItemStack[] toSort = new ItemStack[array.length]; + + for(int i = 0; i < array.length-1; i++) + { + toSort[i] = (ItemStack)array[i]; + } boolean cont = true; ItemStack temp; diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index e6d06fcf1..b4fb2e126 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -33,6 +33,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver public float clientEnergy; public int clientCells; + public float clientMaxEnergy; @Override public void updateEntity() @@ -43,6 +44,11 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver if(!worldObj.isRemote) { + if(playersUsing.size() > 0) + { + PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray()); + } + if(ticks == 5 && !structure.isMultiblock) { update(); @@ -65,7 +71,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver player.closeScreen(); } - PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList())); + PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray()); } prevStructure = structure; @@ -187,20 +193,26 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver public float getMaxEnergyStored() { - float max = 0; - - for (ItemStack itemStack : structure.inventory) + if(!worldObj.isRemote) { - if (itemStack != null) + float max = 0; + + for (ItemStack itemStack : structure.inventory) { - if (itemStack.getItem() instanceof IBattery) + if (itemStack != null) { - max += ((IBattery) itemStack.getItem()).getMaxEnergyStored(); + if (itemStack.getItem() instanceof IBattery) + { + max += ((IBattery) itemStack.getItem()).getMaxEnergyStored(); + } } } + + return max; + } + else { + return clientMaxEnergy; } - - return max; } public float getEnergyStored() @@ -235,13 +247,11 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver clientEnergy = input.readFloat(); clientCells = input.readInt(); + clientMaxEnergy = input.readFloat(); - if(structure.isMultiblock) - { - structure.height = input.readInt(); - structure.length = input.readInt(); - structure.width = input.readInt(); - } + structure.height = input.readInt(); + structure.length = input.readInt(); + structure.width = input.readInt(); } catch(Exception e) {} } @@ -252,13 +262,11 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver data.add(getEnergyStored()); data.add(structure.inventory.size()); + data.add(getMaxEnergyStored()); - if(structure.isMultiblock) - { - data.add(structure.height); - data.add(structure.length); - data.add(structure.width); - } + data.add(structure.height); + data.add(structure.length); + data.add(structure.width); return data; }