More inventory implementation
This commit is contained in:
parent
26393f8d72
commit
afb563898a
3 changed files with 90 additions and 21 deletions
|
@ -145,6 +145,16 @@ public class SetUtil
|
|||
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.
|
||||
* @param set - set to turn into a list
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package resonantinduction.battery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import resonantinduction.base.Vector3;
|
||||
import resonantinduction.api.IBattery;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
|
@ -41,4 +36,32 @@ public class BatteryManager implements ITickHandler
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
if(structure.inventory.size() < structure.getMaxCells())
|
||||
{
|
||||
structure.inventory.add(structure.visibleInventory[0]);
|
||||
structure.visibleInventory[0] = null;
|
||||
structure.sortInventory();
|
||||
}
|
||||
}
|
||||
|
@ -164,20 +165,26 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
|
||||
public float getEnergyStored()
|
||||
{
|
||||
float energy = 0;
|
||||
|
||||
for (ItemStack itemStack : structure.inventory)
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
if (itemStack != null)
|
||||
float energy = 0;
|
||||
|
||||
for (ItemStack itemStack : structure.inventory)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IBattery)
|
||||
if (itemStack != null)
|
||||
{
|
||||
energy += ((IBattery) itemStack.getItem()).getEnergyStored(itemStack);
|
||||
if (itemStack.getItem() instanceof IBattery)
|
||||
{
|
||||
energy += ((IBattery) itemStack.getItem()).getEnergyStored(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return energy;
|
||||
}
|
||||
else {
|
||||
return clientEnergy;
|
||||
}
|
||||
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -186,6 +193,9 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
try {
|
||||
structure.isMultiblock = input.readBoolean();
|
||||
|
||||
clientEnergy = input.readFloat();
|
||||
clientCells = input.readInt();
|
||||
|
||||
if(structure.isMultiblock)
|
||||
{
|
||||
structure.height = input.readInt();
|
||||
|
@ -198,9 +208,12 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
@Override
|
||||
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.length);
|
||||
|
@ -219,7 +232,17 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
@Override
|
||||
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
|
||||
|
@ -231,13 +254,26 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return null;
|
||||
return getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue