Battery is mostly working!

This commit is contained in:
Aidan Brady 2013-08-04 23:44:58 -04:00
parent e3ab3e67ea
commit ae70542bbd
6 changed files with 52 additions and 25 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

@ -97,6 +97,11 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
}
}
if(!world.isRemote)
{
entityPlayer.openGui(ResonantInduction.INSTNACE, 0, world, x, y, z);
}
return true;
}

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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;
return max;
}
else {
return clientMaxEnergy;
}
}
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;
}