216 lines
3.6 KiB
Java
216 lines
3.6 KiB
Java
package storagecraft.tile;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import java.util.List;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.inventory.IInventory;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.IChatComponent;
|
|
import storagecraft.inventory.InventorySimple;
|
|
import storagecraft.storage.CellStorage;
|
|
import storagecraft.storage.IStorage;
|
|
import storagecraft.storage.IStorageProvider;
|
|
import storagecraft.util.InventoryUtils;
|
|
|
|
public class TileDrive extends TileMachine implements IInventory, IStorageProvider
|
|
{
|
|
public static final String NBT_PRIORITY = "Priority";
|
|
|
|
private InventorySimple inventory = new InventorySimple("drive", 8);
|
|
|
|
private int priority = 0;
|
|
|
|
@Override
|
|
public int getEnergyUsage()
|
|
{
|
|
int base = 5;
|
|
|
|
for (int i = 0; i < getSizeInventory(); ++i)
|
|
{
|
|
if (getStackInSlot(i) != null)
|
|
{
|
|
base += 2;
|
|
}
|
|
}
|
|
|
|
return base;
|
|
}
|
|
|
|
@Override
|
|
public void updateMachine()
|
|
{
|
|
}
|
|
|
|
public int getPriority()
|
|
{
|
|
return priority;
|
|
}
|
|
|
|
public void setPriority(int priority)
|
|
{
|
|
markDirty();
|
|
|
|
this.priority = priority;
|
|
}
|
|
|
|
@Override
|
|
public void readFromNBT(NBTTagCompound nbt)
|
|
{
|
|
super.readFromNBT(nbt);
|
|
|
|
InventoryUtils.restoreInventory(this, nbt);
|
|
|
|
if (nbt.hasKey(NBT_PRIORITY))
|
|
{
|
|
priority = nbt.getInteger(NBT_PRIORITY);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void writeToNBT(NBTTagCompound nbt)
|
|
{
|
|
super.writeToNBT(nbt);
|
|
|
|
InventoryUtils.saveInventory(this, nbt);
|
|
|
|
nbt.setInteger(NBT_PRIORITY, priority);
|
|
}
|
|
|
|
@Override
|
|
public void toBytes(ByteBuf buf)
|
|
{
|
|
super.toBytes(buf);
|
|
|
|
buf.writeInt(priority);
|
|
}
|
|
|
|
@Override
|
|
public void fromBytes(ByteBuf buf)
|
|
{
|
|
super.fromBytes(buf);
|
|
|
|
priority = buf.readInt();
|
|
}
|
|
|
|
@Override
|
|
public void addStorages(List<IStorage> storages)
|
|
{
|
|
for (int i = 0; i < getSizeInventory(); ++i)
|
|
{
|
|
if (getStackInSlot(i) != null)
|
|
{
|
|
storages.add(new CellStorage(getStackInSlot(i), priority));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getSizeInventory()
|
|
{
|
|
return inventory.getSizeInventory();
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStackInSlot(int slot)
|
|
{
|
|
return inventory.getStackInSlot(slot);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack decrStackSize(int slot, int count)
|
|
{
|
|
return inventory.decrStackSize(slot, count);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack removeStackFromSlot(int slot)
|
|
{
|
|
return inventory.removeStackFromSlot(slot);
|
|
}
|
|
|
|
@Override
|
|
public void setInventorySlotContents(int slot, ItemStack stack)
|
|
{
|
|
inventory.setInventorySlotContents(slot, stack);
|
|
}
|
|
|
|
@Override
|
|
public int getInventoryStackLimit()
|
|
{
|
|
return inventory.getInventoryStackLimit();
|
|
}
|
|
|
|
@Override
|
|
public boolean isUseableByPlayer(EntityPlayer player)
|
|
{
|
|
return inventory.isUseableByPlayer(player);
|
|
}
|
|
|
|
@Override
|
|
public void openInventory(EntityPlayer player)
|
|
{
|
|
inventory.openInventory(player);
|
|
}
|
|
|
|
@Override
|
|
public void closeInventory(EntityPlayer player)
|
|
{
|
|
inventory.closeInventory(player);
|
|
}
|
|
|
|
@Override
|
|
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
|
{
|
|
return inventory.isItemValidForSlot(slot, stack);
|
|
}
|
|
|
|
@Override
|
|
public int getField(int id)
|
|
{
|
|
return inventory.getField(id);
|
|
}
|
|
|
|
@Override
|
|
public void setField(int id, int value)
|
|
{
|
|
inventory.setField(id, value);
|
|
}
|
|
|
|
@Override
|
|
public int getFieldCount()
|
|
{
|
|
return inventory.getFieldCount();
|
|
}
|
|
|
|
@Override
|
|
public void clear()
|
|
{
|
|
inventory.clear();
|
|
}
|
|
|
|
@Override
|
|
public String getName()
|
|
{
|
|
return inventory.getName();
|
|
}
|
|
|
|
@Override
|
|
public boolean hasCustomName()
|
|
{
|
|
return inventory.hasCustomName();
|
|
}
|
|
|
|
@Override
|
|
public IChatComponent getDisplayName()
|
|
{
|
|
return inventory.getDisplayName();
|
|
}
|
|
|
|
@Override
|
|
public IInventory getDroppedInventory()
|
|
{
|
|
return inventory;
|
|
}
|
|
}
|