And yet more work.

This commit is contained in:
Aidan Brady 2013-08-04 02:37:49 -04:00
parent c6eb7eba25
commit bea61449b4
4 changed files with 52 additions and 26 deletions

View file

@ -9,7 +9,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration; import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import resonantinduction.battery.BatteryMultiblockManager; import resonantinduction.battery.BatteryManager;
import resonantinduction.battery.BlockBattery; import resonantinduction.battery.BlockBattery;
import resonantinduction.battery.ItemCapacitor; import resonantinduction.battery.ItemCapacitor;
import resonantinduction.battery.TileEntityBattery; import resonantinduction.battery.TileEntityBattery;
@ -164,7 +164,7 @@ public class ResonantInduction
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
TickRegistry.registerTickHandler(new BatteryMultiblockManager(), Side.SERVER); TickRegistry.registerTickHandler(new BatteryManager(), Side.SERVER);
ResonantInduction.proxy.registerRenderers(); ResonantInduction.proxy.registerRenderers();

View file

@ -14,7 +14,7 @@ import resonantinduction.base.Vector3;
import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType; import cpw.mods.fml.common.TickType;
public class BatteryMultiblockManager implements ITickHandler public class BatteryManager implements ITickHandler
{ {
public static final int WILDCARD = -1; public static final int WILDCARD = -1;
@ -37,7 +37,7 @@ public class BatteryMultiblockManager implements ITickHandler
if(tileEntity != null) if(tileEntity != null)
{ {
tileEntity.inventory = new HashSet<ItemStack>(); tileEntity.inventory = new HashSet<ItemStack>();
tileEntity.inventoryID = -1; tileEntity.inventoryID = WILDCARD;
} }
} }
@ -51,7 +51,7 @@ public class BatteryMultiblockManager implements ITickHandler
* @param inventoryID - inventory ID of the battery * @param inventoryID - inventory ID of the battery
* @param fluid - cached fluid of the battery * @param fluid - cached fluid of the battery
* @param inventory - inventory 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<ItemStack> inventory, TileEntityBattery tileEntity) public static void updateCache(int inventoryID, HashSet<ItemStack> inventory, TileEntityBattery tileEntity)
{ {
@ -153,12 +153,12 @@ public class BatteryMultiblockManager implements ITickHandler
{ {
for(Vector3 obj : dynamicInventories.get(inventoryID).locations) 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<ItemStack>(); battery.inventory = new HashSet<ItemStack>();
dynamicTank.inventoryID = -1; battery.inventoryID = WILDCARD;
} }
} }

View file

@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.base.Vector3; import resonantinduction.base.Vector3;
import resonantinduction.battery.BatteryMultiblockManager.BatteryCache; import resonantinduction.battery.BatteryManager.BatteryCache;
public class BatteryUpdateProtocol 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 x - x coordinate
* @param y - y coordinate * @param y - y coordinate
* @param z - z 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); loopThrough(pointer);
@ -231,13 +231,13 @@ public class BatteryUpdateProtocol
} }
} }
int idFound = -1; int idFound = BatteryManager.WILDCARD;
for(Vector3 obj : structureFound.locations) for(Vector3 obj : structureFound.locations)
{ {
TileEntityBattery tileEntity = (TileEntityBattery)obj.getTileEntity(pointer.worldObj); TileEntityBattery tileEntity = (TileEntityBattery)obj.getTileEntity(pointer.worldObj);
if(tileEntity.inventoryID != -1) if(tileEntity.inventoryID != BatteryManager.WILDCARD)
{ {
idFound = tileEntity.inventoryID; idFound = tileEntity.inventoryID;
break; break;
@ -246,15 +246,15 @@ public class BatteryUpdateProtocol
BatteryCache cache = new BatteryCache(); 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 { else {
idFound = BatteryMultiblockManager.getUniqueInventoryID(); idFound = BatteryManager.getUniqueInventoryID();
} }
structureFound.inventory = cache.inventory; structureFound.inventory = cache.inventory;

View file

@ -6,11 +6,9 @@ package resonantinduction.battery;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack; import net.minecraft.nbt.NBTTagList;
import resonantinduction.api.IBattery; import resonantinduction.api.IBattery;
import resonantinduction.base.TileEntityBase; import resonantinduction.base.TileEntityBase;
@ -49,9 +47,17 @@ public class TileEntityBattery extends TileEntityBase
{ {
inventoryID = nbtTags.getInteger("inventoryID"); inventoryID = nbtTags.getInteger("inventoryID");
if(inventoryID != -1) if(inventoryID != BatteryManager.WILDCARD)
{ {
//inventory NBTTagList tagList = nbtTags.getTagList("Items");
inventory = new HashSet<ItemStack>();
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); 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() public void update()
{ {
if(!worldObj.isRemote && (structure == null || !structure.didTick))
{
new BatteryUpdateProtocol(this).updateBatteries();
if(structure != null)
{
structure.didTick = true;
}
}
} }
public float getMaxEnergyStored() public float getMaxEnergyStored()