diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 84549981..d0df10a8 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -9,7 +9,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.Configuration; import net.minecraftforge.oredict.ShapedOreRecipe; -import resonantinduction.battery.BatteryMultiblockManager; +import resonantinduction.battery.BatteryManager; import resonantinduction.battery.BlockBattery; import resonantinduction.battery.ItemCapacitor; import resonantinduction.battery.TileEntityBattery; @@ -164,7 +164,7 @@ public class ResonantInduction GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName()); - TickRegistry.registerTickHandler(new BatteryMultiblockManager(), Side.SERVER); + TickRegistry.registerTickHandler(new BatteryManager(), Side.SERVER); ResonantInduction.proxy.registerRenderers(); diff --git a/src/resonantinduction/battery/BatteryMultiblockManager.java b/src/resonantinduction/battery/BatteryManager.java similarity index 92% rename from src/resonantinduction/battery/BatteryMultiblockManager.java rename to src/resonantinduction/battery/BatteryManager.java index b5b5a31a..4d6903b0 100644 --- a/src/resonantinduction/battery/BatteryMultiblockManager.java +++ b/src/resonantinduction/battery/BatteryManager.java @@ -14,7 +14,7 @@ import resonantinduction.base.Vector3; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; -public class BatteryMultiblockManager implements ITickHandler +public class BatteryManager implements ITickHandler { public static final int WILDCARD = -1; @@ -37,7 +37,7 @@ public class BatteryMultiblockManager implements ITickHandler if(tileEntity != null) { tileEntity.inventory = new HashSet(); - tileEntity.inventoryID = -1; + tileEntity.inventoryID = WILDCARD; } } @@ -51,7 +51,7 @@ public class BatteryMultiblockManager implements ITickHandler * @param inventoryID - inventory ID of the battery * @param fluid - cached fluid of the battery * @param inventory - inventory of the battery - * @param tileEntity - dynamic tank TileEntity + * @param tileEntity - battery TileEntity */ public static void updateCache(int inventoryID, HashSet inventory, TileEntityBattery tileEntity) { @@ -153,12 +153,12 @@ public class BatteryMultiblockManager implements ITickHandler { for(Vector3 obj : dynamicInventories.get(inventoryID).locations) { - TileEntityBattery dynamicTank = (TileEntityBattery)obj.getTileEntity(world); + TileEntityBattery battery = (TileEntityBattery)obj.getTileEntity(world); - if(dynamicTank != null) + if(battery != null) { - dynamicTank.inventory = new HashSet(); - dynamicTank.inventoryID = -1; + battery.inventory = new HashSet(); + battery.inventoryID = WILDCARD; } } diff --git a/src/resonantinduction/battery/BatteryUpdateProtocol.java b/src/resonantinduction/battery/BatteryUpdateProtocol.java index d3015d20..eb81fc54 100644 --- a/src/resonantinduction/battery/BatteryUpdateProtocol.java +++ b/src/resonantinduction/battery/BatteryUpdateProtocol.java @@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.base.Vector3; -import resonantinduction.battery.BatteryMultiblockManager.BatteryCache; +import resonantinduction.battery.BatteryManager.BatteryCache; public class BatteryUpdateProtocol { @@ -193,7 +193,7 @@ public class BatteryUpdateProtocol } /** - * Whether or not the block at the specified location is a viable node for a dynamic tank. + * Whether or not the block at the specified location is a battery. * @param x - x coordinate * @param y - y coordinate * @param z - z coordinate @@ -210,9 +210,9 @@ public class BatteryUpdateProtocol } /** - * Runs the protocol and updates all tanks that make a part of the dynamic tank. + * Runs the protocol and updates all batteries that make a part of the multiblock battery. */ - public void updateTanks() + public void updateBatteries() { loopThrough(pointer); @@ -231,13 +231,13 @@ public class BatteryUpdateProtocol } } - int idFound = -1; + int idFound = BatteryManager.WILDCARD; for(Vector3 obj : structureFound.locations) { TileEntityBattery tileEntity = (TileEntityBattery)obj.getTileEntity(pointer.worldObj); - if(tileEntity.inventoryID != -1) + if(tileEntity.inventoryID != BatteryManager.WILDCARD) { idFound = tileEntity.inventoryID; break; @@ -246,15 +246,15 @@ public class BatteryUpdateProtocol BatteryCache cache = new BatteryCache(); - if(idFound != -1) + if(idFound != BatteryManager.WILDCARD) { - if(BatteryMultiblockManager.dynamicInventories.get(idFound) != null) + if(BatteryManager.dynamicInventories.get(idFound) != null) { - cache = BatteryMultiblockManager.pullInventory(pointer.worldObj, idFound); + cache = BatteryManager.pullInventory(pointer.worldObj, idFound); } } else { - idFound = BatteryMultiblockManager.getUniqueInventoryID(); + idFound = BatteryManager.getUniqueInventoryID(); } structureFound.inventory = cache.inventory; diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index 9586e0d0..dc3665ae 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -6,11 +6,9 @@ package resonantinduction.battery; import java.util.HashSet; import java.util.Set; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.FluidStack; +import net.minecraft.nbt.NBTTagList; import resonantinduction.api.IBattery; import resonantinduction.base.TileEntityBase; @@ -49,9 +47,17 @@ public class TileEntityBattery extends TileEntityBase { inventoryID = nbtTags.getInteger("inventoryID"); - if(inventoryID != -1) + if(inventoryID != BatteryManager.WILDCARD) { - //inventory + NBTTagList tagList = nbtTags.getTagList("Items"); + inventory = new HashSet(); + + for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++) + { + NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount); + + inventory.add(ItemStack.loadItemStackFromNBT(tagCompound)); + } } } } @@ -63,12 +69,32 @@ public class TileEntityBattery extends TileEntityBase nbtTags.setInteger("inventoryID", inventoryID); - //inventory + NBTTagList tagList = new NBTTagList(); + + for(ItemStack itemStack : inventory) + { + if(itemStack != null) + { + NBTTagCompound tagCompound = new NBTTagCompound(); + itemStack.writeToNBT(tagCompound); + tagList.appendTag(tagCompound); + } + } + + nbtTags.setTag("Items", tagList); } public void update() { - + if(!worldObj.isRemote && (structure == null || !structure.didTick)) + { + new BatteryUpdateProtocol(this).updateBatteries(); + + if(structure != null) + { + structure.didTick = true; + } + } } public float getMaxEnergyStored()