More inventory implementation

This commit is contained in:
Aidan Brady 2013-08-04 20:39:25 -04:00
parent 26393f8d72
commit afb563898a
3 changed files with 90 additions and 21 deletions

View file

@ -145,6 +145,16 @@ public class SetUtil
return toReturn; return toReturn;
} }
public static <V> V getTop(Set<V> set)
{
for(V obj : set)
{
return obj;
}
return null;
}
/** /**
* Returns a List of a Set, while maintaining all it's objects. * Returns a List of a Set, while maintaining all it's objects.
* @param set - set to turn into a list * @param set - set to turn into a list

View file

@ -1,16 +1,11 @@
package resonantinduction.battery; package resonantinduction.battery;
import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import resonantinduction.api.IBattery;
import net.minecraftforge.fluids.FluidStack;
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;
@ -41,4 +36,32 @@ public class BatteryManager implements ITickHandler
{ {
return "BatteryMultiblockManager"; return "BatteryMultiblockManager";
} }
public static class SlotOut extends Slot
{
public SlotOut(IInventory inventory, int index, int x, int y)
{
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack itemstack)
{
return false;
}
}
public static class SlotBattery extends Slot
{
public SlotBattery(IInventory inventory, int index, int x, int y)
{
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack itemstack)
{
return itemstack.getItem() instanceof IBattery;
}
}
} }

View file

@ -53,6 +53,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
if(structure.inventory.size() < structure.getMaxCells()) if(structure.inventory.size() < structure.getMaxCells())
{ {
structure.inventory.add(structure.visibleInventory[0]); structure.inventory.add(structure.visibleInventory[0]);
structure.visibleInventory[0] = null;
structure.sortInventory(); structure.sortInventory();
} }
} }
@ -163,6 +164,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
} }
public float getEnergyStored() public float getEnergyStored()
{
if(!worldObj.isRemote)
{ {
float energy = 0; float energy = 0;
@ -179,6 +182,10 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
return energy; return energy;
} }
else {
return clientEnergy;
}
}
@Override @Override
public void handle(ByteArrayDataInput input) public void handle(ByteArrayDataInput input)
@ -186,6 +193,9 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
try { try {
structure.isMultiblock = input.readBoolean(); structure.isMultiblock = input.readBoolean();
clientEnergy = input.readFloat();
clientCells = input.readInt();
if(structure.isMultiblock) if(structure.isMultiblock)
{ {
structure.height = input.readInt(); structure.height = input.readInt();
@ -198,9 +208,12 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
@Override @Override
public ArrayList getNetworkedData(ArrayList data) public ArrayList getNetworkedData(ArrayList data)
{ {
data.add(structure != null); data.add(structure.isMultiblock);
if(structure != null) data.add(getEnergyStored());
data.add(structure.inventory.size());
if(structure.isMultiblock)
{ {
data.add(structure.height); data.add(structure.height);
data.add(structure.length); data.add(structure.length);
@ -219,7 +232,17 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
@Override @Override
public ItemStack getStackInSlot(int i) public ItemStack getStackInSlot(int i)
{ {
return null; if(i == 0)
{
return structure.visibleInventory[0];
}
else if(i == 1)
{
return SetUtil.getTop(structure.inventory);
}
else {
return structure.visibleInventory[i-1];
}
} }
@Override @Override
@ -231,13 +254,26 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
@Override @Override
public ItemStack getStackInSlotOnClosing(int i) public ItemStack getStackInSlotOnClosing(int i)
{ {
return null; return getStackInSlot(i);
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack itemstack) public void setInventorySlotContents(int i, ItemStack itemstack)
{ {
if(i == 0)
{
structure.visibleInventory[0] = itemstack;
}
else if(i == 1)
{
if(itemstack == null)
{
structure.inventory.remove(SetUtil.getTop(structure.inventory));
}
}
else {
structure.visibleInventory[i-1] = itemstack;
}
} }
@Override @Override