added stuff
- storage proxy block: reads an another inventory into system - right clicking to push 1 item works - when take() returns 0, don't give any item stack to the player - tweaked energy usage
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package storagecraft.storage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,16 +26,12 @@ public class CellStorage implements IStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageItem> getAll() {
|
||||
List<StorageItem> items = new ArrayList<StorageItem>();
|
||||
|
||||
public void addItems(List<StorageItem> items) {
|
||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
items.add(createItemFromNBT(list.getCompoundTagAt(i)));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,11 +45,7 @@ public class CellStorage implements IStorage {
|
||||
|
||||
StorageItem item = createItemFromNBT(tag);
|
||||
|
||||
if (item.getType() == stack.getItem() && item.getMeta() == stack.getItemDamage()) {
|
||||
if (item.getTag() != null && !item.getTag().equals(stack.stackTagCompound)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.equalsIgnoreQuantity(stack)) {
|
||||
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
|
||||
|
||||
return;
|
||||
@@ -85,11 +76,7 @@ public class CellStorage implements IStorage {
|
||||
|
||||
StorageItem item = createItemFromNBT(tag);
|
||||
|
||||
if (item.getType() == stack.getItem() && item.getMeta() == stack.getItemDamage()) {
|
||||
if (item.getTag() != null && !item.getTag().equals(stack.stackTagCompound)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.equalsIgnoreQuantity(stack)) {
|
||||
if (quantity > item.getQuantity()) {
|
||||
quantity = item.getQuantity();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IStorage {
|
||||
public List<StorageItem> getAll();
|
||||
public void addItems(List<StorageItem> items);
|
||||
|
||||
public void push(ItemStack stack);
|
||||
|
||||
|
||||
@@ -17,10 +17,8 @@ public class StorageItem {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public StorageItem(Item type) {
|
||||
this.type = type;
|
||||
this.meta = 0;
|
||||
this.quantity = 1;
|
||||
public StorageItem(ItemStack stack) {
|
||||
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
|
||||
}
|
||||
|
||||
public Item getType() {
|
||||
@@ -70,4 +68,32 @@ public class StorageItem {
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public boolean equalsIgnoreQuantity(ItemStack other) {
|
||||
if (tag != null && !tag.equals(other.stackTagCompound)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return type == other.getItem() && meta == other.getItemDamage();
|
||||
}
|
||||
|
||||
public boolean equalsIgnoreQuantity(StorageItem other) {
|
||||
if (tag != null && !tag.equals(other.getTag())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return type == other.getType() && meta == other.getMeta();
|
||||
}
|
||||
|
||||
public static boolean equalsIgnoreQuantity(ItemStack first, ItemStack second) {
|
||||
if (first.stackTagCompound != null && !first.stackTagCompound.equals(second.stackTagCompound)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return first.getItem() == second.getItem() && first.getItemDamage() == second.getItemDamage();
|
||||
}
|
||||
|
||||
public boolean equals(StorageItem other) {
|
||||
return other.getQuantity() == quantity && equalsIgnoreQuantity(other);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user