Fixed Battery NBT loading

This commit is contained in:
Aidan Brady 2013-08-05 02:38:04 -04:00
parent b44ea67b46
commit f5068bda2b
3 changed files with 52 additions and 53 deletions

View file

@ -260,12 +260,6 @@ public class BatteryUpdateProtocol
}
}
System.out.println("Bingo");
System.out.println("Height: " + structureFound.height);
System.out.println("Length: " + structureFound.length);
System.out.println("Width: " + structureFound.width);
System.out.println("Volume: " + structureFound.locations.size());
for(Vector3 obj : structureFound.locations)
{
TileEntityBattery tileEntity = (TileEntityBattery)obj.getTileEntity(pointer.worldObj);

View file

@ -58,7 +58,7 @@ public class ItemCapacitor extends ItemBase implements IBattery
@Override
public float getMaxEnergyStored()
{
return 100;
return 10;
}
@Override

View file

@ -46,18 +46,6 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray());
}
if(ListUtil.getTop(structure.inventory) != null)
{
System.out.println("-----");
for(ItemStack stack : structure.inventory)
{
System.out.println(((IBattery)stack.getItem()).getEnergyStored(stack));
}
System.out.println("----");
}
if(ticks == 5 && !structure.isMultiblock)
{
update();
@ -106,26 +94,32 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount);
System.out.println("Yup!");
structure.inventory.add(ItemStack.loadItemStackFromNBT(tagCompound));
int slotID = tagCompound.getInteger("Slot");
structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
}
}
//Visible inventory
if(nbtTags.hasKey("VisibleItems"))
{
NBTTagList tagList1 = nbtTags.getTagList("VisibleItems");
NBTTagList tagList = nbtTags.getTagList("VisibleItems");
structure.visibleInventory = new ItemStack[3];
for(int tagCount = 0; tagCount < tagList1.tagCount(); tagCount++)
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{
NBTTagCompound tagCompound = (NBTTagCompound)tagList1.tagAt(tagCount);
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount);
byte slotID = tagCompound.getByte("Slot");
if(slotID >= 0 && slotID < structure.visibleInventory.length)
{
if(slotID == 0)
{
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
}
else {
setInventorySlotContents(slotID+1, ItemStack.loadItemStackFromNBT(tagCompound));
}
}
}
}
}
@ -138,36 +132,47 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
if(!structure.wroteInventory)
{
//Inventory
if(structure.inventory != null)
{
NBTTagList tagList = new NBTTagList();
for(ItemStack itemStack : structure.inventory)
for(int slotCount = 0; slotCount < structure.inventory.size(); slotCount++)
{
if(itemStack != null)
if(structure.inventory.get(slotCount) != null)
{
System.out.println("YESTYSET");
NBTTagCompound tagCompound = new NBTTagCompound();
itemStack.writeToNBT(tagCompound);
tagCompound.setInteger("Slot", slotCount);
structure.inventory.get(slotCount).writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
nbtTags.setTag("Items", tagList);
}
//Visible inventory
NBTTagList tagList1 = new NBTTagList();
if(structure.visibleInventory != null)
{
NBTTagList tagList = new NBTTagList();
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
{
if(slotCount > 0)
{
slotCount++;
}
if(getStackInSlot(slotCount) != null)
{
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte)slotCount);
getStackInSlot(slotCount).writeToNBT(tagCompound);
tagList1.appendTag(tagCompound);
tagList.appendTag(tagCompound);
}
}
nbtTags.setTag("VisibleItems", tagList1);
nbtTags.setTag("VisibleItems", tagList);
}
structure.wroteInventory = true;
}