fix some todos
This commit is contained in:
@@ -2,8 +2,8 @@ package storagecraft.inventory;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import storagecraft.SCItems;
|
import storagecraft.SCItems;
|
||||||
|
import storagecraft.inventory.slot.SlotDrive;
|
||||||
import storagecraft.tile.TileDrive;
|
import storagecraft.tile.TileDrive;
|
||||||
import storagecraft.inventory.slot.SlotItemFilter;
|
|
||||||
|
|
||||||
public class ContainerDrive extends ContainerSC {
|
public class ContainerDrive extends ContainerSC {
|
||||||
public ContainerDrive(EntityPlayer player, TileDrive drive) {
|
public ContainerDrive(EntityPlayer player, TileDrive drive) {
|
||||||
@@ -15,7 +15,7 @@ public class ContainerDrive extends ContainerSC {
|
|||||||
int y = 20;
|
int y = 20;
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
addSlotToContainer(new SlotItemFilter(drive, i, x, y, SCItems.STORAGE_CELL, drive));
|
addSlotToContainer(new SlotDrive(drive, i, x, y, SCItems.STORAGE_CELL, drive));
|
||||||
|
|
||||||
if ((i + 1) % 2 == 0) {
|
if ((i + 1) % 2 == 0) {
|
||||||
x = 71;
|
x = 71;
|
||||||
|
28
src/main/java/storagecraft/inventory/slot/SlotDrive.java
Normal file
28
src/main/java/storagecraft/inventory/slot/SlotDrive.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package storagecraft.inventory.slot;
|
||||||
|
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import storagecraft.tile.TileDrive;
|
||||||
|
|
||||||
|
public class SlotDrive extends SlotItemFilter {
|
||||||
|
private TileDrive drive;
|
||||||
|
|
||||||
|
public SlotDrive(IInventory inventory, int id, int x, int y, Item item, TileDrive drive) {
|
||||||
|
super(inventory, id, x, y, item);
|
||||||
|
|
||||||
|
this.drive = drive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValid(ItemStack item) {
|
||||||
|
return drive.isConnected() && super.isItemValid(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSlotChanged() {
|
||||||
|
super.onSlotChanged();
|
||||||
|
|
||||||
|
drive.getController().getStorage().sync();
|
||||||
|
}
|
||||||
|
}
|
@@ -4,30 +4,18 @@ import net.minecraft.inventory.IInventory;
|
|||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import storagecraft.tile.TileDrive;
|
|
||||||
|
|
||||||
// @TODO: make special SlotDrive
|
|
||||||
public class SlotItemFilter extends Slot {
|
public class SlotItemFilter extends Slot {
|
||||||
private Item item;
|
private Item item;
|
||||||
|
|
||||||
private TileDrive dr;
|
public SlotItemFilter(IInventory inventory, int id, int x, int y, Item item) {
|
||||||
|
|
||||||
public SlotItemFilter(IInventory inventory, int id, int x, int y, Item item, TileDrive dr) {
|
|
||||||
super(inventory, id, x, y);
|
super(inventory, id, x, y);
|
||||||
|
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.dr = dr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack item) {
|
public boolean isItemValid(ItemStack item) {
|
||||||
return dr.isConnected() && item.getItem() == this.item;
|
return item.getItem() == this.item;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSlotChanged() {
|
|
||||||
super.onSlotChanged();
|
|
||||||
|
|
||||||
dr.getController().getStorage().sync();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,10 @@ public class ItemSC extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName(ItemStack stack) {
|
public String getUnlocalizedName(ItemStack stack) {
|
||||||
|
if (getHasSubtypes()) {
|
||||||
|
return getUnlocalizedName() + "." + stack.getItemDamage();
|
||||||
|
}
|
||||||
|
|
||||||
return getUnlocalizedName();
|
return getUnlocalizedName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,74 +2,89 @@ package storagecraft.item;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.util.StatCollector;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import storagecraft.storage.StorageItem;
|
import storagecraft.storage.StorageItem;
|
||||||
|
|
||||||
public class ItemStorageCell extends ItemSC {
|
public class ItemStorageCell extends ItemSC {
|
||||||
// @TODO: Different types of storage cells
|
public static final String NBT_ITEMS = "Items";
|
||||||
public static final int MAX_STORED = 64;
|
public static final String NBT_STORED = "Stored";
|
||||||
|
|
||||||
|
public static final String NBT_ITEM_TYPE = "Type";
|
||||||
|
public static final String NBT_ITEM_QUANTITY = "Quantity";
|
||||||
|
public static final String NBT_ITEM_META = "Meta";
|
||||||
|
|
||||||
public ItemStorageCell() {
|
public ItemStorageCell() {
|
||||||
super("storageCell");
|
super("storageCell");
|
||||||
|
|
||||||
setMaxStackSize(1);
|
setMaxStackSize(1);
|
||||||
|
setHasSubtypes(true);
|
||||||
|
setMaxDamage(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getSubItems(Item item, CreativeTabs tab, List list) {
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
ItemStack cell = new ItemStack(item, 1, i);
|
||||||
|
|
||||||
|
init(cell);
|
||||||
|
|
||||||
|
list.add(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInformation(ItemStack cell, EntityPlayer player, List list, boolean b) {
|
||||||
|
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStored"), getStored(cell), getCapacity(cell)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO: clean everythin up
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
||||||
super.onCreated(stack, world, player);
|
super.onCreated(stack, world, player);
|
||||||
|
|
||||||
stack.stackTagCompound = new NBTTagCompound();
|
init(stack);
|
||||||
stack.stackTagCompound.setTag("Items", new NBTTagList());
|
}
|
||||||
|
|
||||||
|
private static StorageItem createItemFromNBT(NBTTagCompound tag) {
|
||||||
|
return new StorageItem(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_META));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<StorageItem> getStoredItems(ItemStack cell) {
|
public static List<StorageItem> getStoredItems(ItemStack cell) {
|
||||||
List<StorageItem> items = new ArrayList<StorageItem>();
|
List<StorageItem> items = new ArrayList<StorageItem>();
|
||||||
|
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag("Items");
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
items.add(createItemFromNBT(list.getCompoundTagAt(i)));
|
||||||
|
|
||||||
Item type = Item.getItemById(tag.getInteger("Type"));
|
|
||||||
int quantity = tag.getInteger("Quantity");
|
|
||||||
int meta = tag.getInteger("Meta");
|
|
||||||
|
|
||||||
items.add(new StorageItem(type, quantity, meta));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getQuantityStored(ItemStack cell) {
|
public static void init(ItemStack cell) {
|
||||||
int quantity = 0;
|
cell.stackTagCompound = new NBTTagCompound();
|
||||||
|
cell.stackTagCompound.setTag(NBT_ITEMS, new NBTTagList());
|
||||||
for (StorageItem item : getStoredItems(cell)) {
|
cell.stackTagCompound.setInteger(NBT_STORED, 0);
|
||||||
quantity += item.getQuantity();
|
|
||||||
}
|
|
||||||
|
|
||||||
return quantity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO: store quantity of items on itemStack itself (for speed, and displaying)
|
public static void push(ItemStack cell, ItemStack stack) {
|
||||||
public static void store(ItemStack cell, ItemStack stack) {
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag("Items");
|
|
||||||
|
cell.stackTagCompound.setInteger(NBT_STORED, getStored(cell) + stack.stackSize);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
NBTTagCompound tag = list.getCompoundTagAt(i);
|
||||||
|
|
||||||
Item type = Item.getItemById(tag.getInteger("Type"));
|
StorageItem item = createItemFromNBT(tag);
|
||||||
int quantity = tag.getInteger("Quantity");
|
|
||||||
int meta = tag.getInteger("Meta");
|
|
||||||
|
|
||||||
if (type == stack.getItem() && meta == stack.getItemDamage()) {
|
if (item.getType() == stack.getItem() && item.getMeta() == stack.getItemDamage()) {
|
||||||
tag.setInteger("Quantity", quantity + stack.stackSize);
|
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -77,34 +92,34 @@ public class ItemStorageCell extends ItemSC {
|
|||||||
|
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
|
||||||
tag.setInteger("Type", Item.getIdFromItem(stack.getItem()));
|
tag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(stack.getItem()));
|
||||||
tag.setInteger("Quantity", stack.stackSize);
|
tag.setInteger(NBT_ITEM_QUANTITY, stack.stackSize);
|
||||||
tag.setInteger("Meta", stack.getItemDamage());
|
tag.setInteger(NBT_ITEM_META, stack.getItemDamage());
|
||||||
|
|
||||||
list.appendTag(tag);
|
list.appendTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int take(ItemStack cell, Item type, int quantity, int meta) {
|
public static int take(ItemStack cell, Item type, int quantity, int meta) {
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag("Items");
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
NBTTagCompound tag = list.getCompoundTagAt(i);
|
||||||
|
|
||||||
Item typeInCell = Item.getItemById(tag.getInteger("Type"));
|
StorageItem item = createItemFromNBT(tag);
|
||||||
int quantityInCell = tag.getInteger("Quantity");
|
|
||||||
int metaInCell = tag.getInteger("Meta");
|
|
||||||
|
|
||||||
if (typeInCell == type && metaInCell == meta) {
|
if (item.getType() == type && item.getMeta() == meta) {
|
||||||
if (quantity > quantityInCell) {
|
if (quantity > item.getQuantity()) {
|
||||||
quantity = quantityInCell;
|
quantity = item.getQuantity();
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setInteger("Quantity", quantityInCell - quantity);
|
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() - quantity);
|
||||||
|
|
||||||
if (quantityInCell - quantity == 0) {
|
if (item.getQuantity() - quantity == 0) {
|
||||||
list.removeTag(i);
|
list.removeTag(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cell.stackTagCompound.setInteger(NBT_STORED, getStored(cell) - quantity);
|
||||||
|
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,6 +128,25 @@ public class ItemStorageCell extends ItemSC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasSpace(ItemStack cell, ItemStack stack) {
|
public static boolean hasSpace(ItemStack cell, ItemStack stack) {
|
||||||
return (getQuantityStored(cell) + stack.stackSize) <= MAX_STORED;
|
return (getStored(cell) + stack.stackSize) <= getCapacity(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getStored(ItemStack cell) {
|
||||||
|
return cell.stackTagCompound.getInteger(NBT_STORED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCapacity(ItemStack cell) {
|
||||||
|
switch (cell.getItemDamage()) {
|
||||||
|
case 0:
|
||||||
|
return 1000;
|
||||||
|
case 1:
|
||||||
|
return 4000;
|
||||||
|
case 2:
|
||||||
|
return 16000;
|
||||||
|
case 3:
|
||||||
|
return 64000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,7 @@ public class Storage {
|
|||||||
public void sync() {
|
public void sync() {
|
||||||
items.clear();
|
items.clear();
|
||||||
|
|
||||||
|
// @TODO: merge stored items with others..
|
||||||
for (ItemStack cell : provider.getStorageCells()) {
|
for (ItemStack cell : provider.getStorageCells()) {
|
||||||
items.addAll(ItemStorageCell.getStoredItems(cell));
|
items.addAll(ItemStorageCell.getStoredItems(cell));
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,7 @@ public class Storage {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStorageCell.store(cellWithSpace, stack);
|
ItemStorageCell.push(cellWithSpace, stack);
|
||||||
|
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
|
@@ -10,7 +10,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import storagecraft.SCItems;
|
import storagecraft.SCItems;
|
||||||
import storagecraft.item.ItemStorageCell;
|
|
||||||
import storagecraft.storage.IStorageCellProvider;
|
import storagecraft.storage.IStorageCellProvider;
|
||||||
import storagecraft.storage.Storage;
|
import storagecraft.storage.Storage;
|
||||||
|
|
||||||
@@ -108,14 +107,7 @@ public class TileController extends TileSC implements IEnergyReceiver, INetworkT
|
|||||||
|
|
||||||
for (int i = 0; i < drive.getSizeInventory(); ++i) {
|
for (int i = 0; i < drive.getSizeInventory(); ++i) {
|
||||||
if (drive.getStackInSlot(i) != null && drive.getStackInSlot(i).getItem() == SCItems.STORAGE_CELL) {
|
if (drive.getStackInSlot(i) != null && drive.getStackInSlot(i).getItem() == SCItems.STORAGE_CELL) {
|
||||||
ItemStack cell = drive.getStackInSlot(i);
|
stacks.add(drive.getStackInSlot(i));
|
||||||
|
|
||||||
// @TODO: find out why this isn't working
|
|
||||||
if (cell.stackTagCompound == null) {
|
|
||||||
((ItemStorageCell) cell.getItem()).onCreated(cell, worldObj, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
stacks.add(cell);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,10 +6,15 @@ gui.storagecraft:drive=Drive
|
|||||||
|
|
||||||
misc.storagecraft:energyStored=%d / %d RF
|
misc.storagecraft:energyStored=%d / %d RF
|
||||||
misc.storagecraft:energyUsage=Energy Usage: %d RF/t
|
misc.storagecraft:energyUsage=Energy Usage: %d RF/t
|
||||||
|
misc.storagecraft:storageCellStored=Stored: %d / %d
|
||||||
|
|
||||||
block.storagecraft:controller.name=Controller
|
block.storagecraft:controller.name=Controller
|
||||||
block.storagecraft:cable.name=Cable
|
block.storagecraft:cable.name=Cable
|
||||||
block.storagecraft:grid.name=Grid
|
block.storagecraft:grid.name=Grid
|
||||||
block.storagecraft:drive.name=Drive
|
block.storagecraft:drive.name=Drive
|
||||||
|
|
||||||
item.storagecraft:storageCell.name=Storage Cell
|
item.storagecraft:storageCell.name=Storage Cell
|
||||||
|
item.storagecraft:storageCell.0.name=1k Storage Cell
|
||||||
|
item.storagecraft:storageCell.1.name=4k Storage Cell
|
||||||
|
item.storagecraft:storageCell.2.name=16k Storage Cell
|
||||||
|
item.storagecraft:storageCell.3.name=64k Storage Cell
|
||||||
|
Reference in New Issue
Block a user