Untested work
This commit is contained in:
@@ -16,10 +16,6 @@ public class DiskStorage extends NBTStorage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPush(ItemStack stack) {
|
public boolean canPush(ItemStack stack) {
|
||||||
if (ModeConfigUtils.doesNotViolateMode(diskDrive.getInventory(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack)) {
|
return ModeConfigUtils.doesNotViolateMode(diskDrive.getInventory(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack) && super.canPush(stack);
|
||||||
return super.canPush(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,14 @@ public class ItemGroupMeta {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean compareNoQuantity(ItemGroupMeta other) {
|
||||||
|
return compare(other, RefinedStorageUtils.COMPARE_NBT | RefinedStorageUtils.COMPARE_DAMAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean compareNoQuantity(ItemStack stack) {
|
||||||
|
return compare(stack, RefinedStorageUtils.COMPARE_NBT | RefinedStorageUtils.COMPARE_DAMAGE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ 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 java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class NBTStorage implements IStorage {
|
public class NBTStorage implements IStorage {
|
||||||
public static final String NBT_ITEMS = "Items";
|
public static final String NBT_ITEMS = "Items";
|
||||||
@@ -16,98 +18,64 @@ public class NBTStorage implements IStorage {
|
|||||||
public static final String NBT_ITEM_DAMAGE = "Damage";
|
public static final String NBT_ITEM_DAMAGE = "Damage";
|
||||||
public static final String NBT_ITEM_NBT = "NBT";
|
public static final String NBT_ITEM_NBT = "NBT";
|
||||||
|
|
||||||
private NBTTagCompound nbt;
|
private NBTTagCompound tag;
|
||||||
private int capacity;
|
private int capacity;
|
||||||
private int priority;
|
private int priority;
|
||||||
|
|
||||||
public NBTStorage(NBTTagCompound nbt, int capacity, int priority) {
|
private Map<ItemGroupMeta, Integer> groups = new HashMap<ItemGroupMeta, Integer>();
|
||||||
this.nbt = nbt;
|
|
||||||
|
public NBTStorage(NBTTagCompound tag, int capacity, int priority) {
|
||||||
|
this.tag = tag;
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
|
|
||||||
|
readFromNBT();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromNBT() {
|
||||||
|
NBTTagList list = (NBTTagList) tag.getTag(NBT_ITEMS);
|
||||||
|
|
||||||
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
|
NBTTagCompound tag = list.getCompoundTagAt(i);
|
||||||
|
|
||||||
|
ItemGroupMeta meta = new ItemGroupMeta(
|
||||||
|
Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)),
|
||||||
|
tag.getInteger(NBT_ITEM_DAMAGE),
|
||||||
|
tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null
|
||||||
|
);
|
||||||
|
|
||||||
|
groups.put(meta, tag.getInteger(NBT_ITEM_QUANTITY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItems(List<ItemGroup> items) {
|
public void addItems(List<ItemGroup> items) {
|
||||||
NBTTagList list = (NBTTagList) nbt.getTag(NBT_ITEMS);
|
for (Map.Entry<ItemGroupMeta, Integer> entry : groups.entrySet()) {
|
||||||
|
items.add(new ItemGroup(entry.getKey(), entry.getValue()));
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
|
||||||
items.add(createItemGroupFromNBT(list.getCompoundTagAt(i)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(ItemStack stack) {
|
public void push(ItemStack stack) {
|
||||||
NBTTagList list = (NBTTagList) nbt.getTag(NBT_ITEMS);
|
for (Map.Entry<ItemGroupMeta, Integer> entry : groups.entrySet()) {
|
||||||
|
if (entry.getKey().compareNoQuantity(stack)) {
|
||||||
nbt.setInteger(NBT_STORED, getStored(nbt) + stack.stackSize);
|
groups.put(entry.getKey(), entry.getValue() + stack.stackSize);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
|
||||||
|
|
||||||
ItemGroup group = createItemGroupFromNBT(tag);
|
|
||||||
|
|
||||||
if (group.compareNoQuantity(stack)) {
|
|
||||||
tag.setInteger(NBT_ITEM_QUANTITY, group.getQuantity() + stack.stackSize);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
groups.put(new ItemGroupMeta(stack), stack.stackSize);
|
||||||
|
|
||||||
tag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(stack.getItem()));
|
|
||||||
tag.setInteger(NBT_ITEM_QUANTITY, stack.stackSize);
|
|
||||||
tag.setInteger(NBT_ITEM_DAMAGE, stack.getItemDamage());
|
|
||||||
|
|
||||||
if (stack.hasTagCompound()) {
|
|
||||||
tag.setTag(NBT_ITEM_NBT, stack.getTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
list.appendTag(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack take(ItemStack stack, int flags) {
|
public ItemStack take(ItemStack stack, int flags) {
|
||||||
int quantity = stack.stackSize;
|
|
||||||
|
|
||||||
NBTTagList list = (NBTTagList) nbt.getTag(NBT_ITEMS);
|
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
|
||||||
|
|
||||||
ItemGroup group = createItemGroupFromNBT(tag);
|
|
||||||
|
|
||||||
if (group.compare(stack, flags)) {
|
|
||||||
if (quantity > group.getQuantity()) {
|
|
||||||
quantity = group.getQuantity();
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.setInteger(NBT_ITEM_QUANTITY, group.getQuantity() - quantity);
|
|
||||||
|
|
||||||
if (group.getQuantity() - quantity == 0) {
|
|
||||||
list.removeTag(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
nbt.setInteger(NBT_STORED, getStored(nbt) - quantity);
|
|
||||||
|
|
||||||
ItemStack newItem = group.toStack();
|
|
||||||
|
|
||||||
newItem.stackSize = quantity;
|
|
||||||
|
|
||||||
return newItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPush(ItemStack stack) {
|
public boolean canPush(ItemStack stack) {
|
||||||
if (capacity == -1) {
|
return capacity == -1 || (getStored(tag) + stack.stackSize) <= capacity;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (getStored(nbt) + stack.stackSize) <= capacity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -115,14 +83,12 @@ public class NBTStorage implements IStorage {
|
|||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemGroup createItemGroupFromNBT(NBTTagCompound tag) {
|
public void setPriority(int priority) {
|
||||||
return new ItemGroup(
|
this.priority = priority;
|
||||||
new ItemGroupMeta(
|
}
|
||||||
Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)),
|
|
||||||
tag.getInteger(NBT_ITEM_DAMAGE),
|
public NBTTagCompound getTag() {
|
||||||
tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null
|
return tag;
|
||||||
), tag.getInteger(NBT_ITEM_QUANTITY)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStored(NBTTagCompound tag) {
|
public static int getStored(NBTTagCompound tag) {
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
|
|||||||
private InventorySimple inventory = new InventorySimple("disk_drive", 8, this);
|
private InventorySimple inventory = new InventorySimple("disk_drive", 8, this);
|
||||||
private InventorySimple filterInventory = new InventorySimple("filters", 9, this);
|
private InventorySimple filterInventory = new InventorySimple("filters", 9, this);
|
||||||
|
|
||||||
|
private NBTStorage storages[] = new NBTStorage[getSizeInventory()];
|
||||||
|
|
||||||
private int priority = 0;
|
private int priority = 0;
|
||||||
private int compare = 0;
|
private int compare = 0;
|
||||||
private int mode = 0;
|
private int mode = 0;
|
||||||
@@ -52,9 +54,9 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provide(List<IStorage> storages) {
|
public void provide(List<IStorage> storages) {
|
||||||
for (int i = 0; i < getSizeInventory(); ++i) {
|
for (NBTStorage storage : this.storages) {
|
||||||
if (getStackInSlot(i) != null) {
|
if (storage != null) {
|
||||||
storages.add(new DiskStorage(getStackInSlot(i), this));
|
storages.add(storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,6 +251,12 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||||
|
if (stack != null) {
|
||||||
|
storages[slot] = new DiskStorage(stack, this);
|
||||||
|
} else {
|
||||||
|
storages[slot] = null;
|
||||||
|
}
|
||||||
|
|
||||||
inventory.setInventorySlotContents(slot, stack);
|
inventory.setInventorySlotContents(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
|
|
||||||
private InventorySimple inventory = new InventorySimple("storage", 9, this);
|
private InventorySimple inventory = new InventorySimple("storage", 9, this);
|
||||||
|
|
||||||
private NBTTagCompound tag = NBTStorage.createNBT();
|
private NBTTagCompound storageTag = NBTStorage.createNBT();
|
||||||
|
|
||||||
|
private NBTStorage storage;
|
||||||
|
|
||||||
private int priority = 0;
|
private int priority = 0;
|
||||||
private int compare = 0;
|
private int compare = 0;
|
||||||
@@ -45,6 +47,14 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
public void updateMachine() {
|
public void updateMachine() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NBTStorage getStorage() {
|
||||||
|
if (storage == null) {
|
||||||
|
storage = new NBTStorage(storageTag, priority, getCapacity());
|
||||||
|
}
|
||||||
|
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provide(List<IStorage> storages) {
|
public void provide(List<IStorage> storages) {
|
||||||
storages.add(this);
|
storages.add(this);
|
||||||
@@ -56,14 +66,14 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
|
|
||||||
RefinedStorageUtils.restoreInventory(inventory, 0, nbt);
|
RefinedStorageUtils.restoreInventory(inventory, 0, nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_STORAGE)) {
|
|
||||||
tag = nbt.getCompoundTag(NBT_STORAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_PRIORITY)) {
|
if (nbt.hasKey(NBT_PRIORITY)) {
|
||||||
priority = nbt.getInteger(NBT_PRIORITY);
|
priority = nbt.getInteger(NBT_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nbt.hasKey(NBT_STORAGE)) {
|
||||||
|
storageTag = nbt.getCompoundTag(NBT_STORAGE);
|
||||||
|
}
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_COMPARE)) {
|
if (nbt.hasKey(NBT_COMPARE)) {
|
||||||
compare = nbt.getInteger(NBT_COMPARE);
|
compare = nbt.getInteger(NBT_COMPARE);
|
||||||
}
|
}
|
||||||
@@ -79,8 +89,8 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
|
|
||||||
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
|
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
|
||||||
|
|
||||||
nbt.setTag(NBT_STORAGE, tag);
|
|
||||||
nbt.setInteger(NBT_PRIORITY, priority);
|
nbt.setInteger(NBT_PRIORITY, priority);
|
||||||
|
nbt.setTag(NBT_STORAGE, getStorage().getTag());
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
nbt.setInteger(NBT_MODE, mode);
|
nbt.setInteger(NBT_MODE, mode);
|
||||||
}
|
}
|
||||||
@@ -97,7 +107,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
public void sendContainerData(ByteBuf buf) {
|
public void sendContainerData(ByteBuf buf) {
|
||||||
super.sendContainerData(buf);
|
super.sendContainerData(buf);
|
||||||
|
|
||||||
buf.writeInt(NBTStorage.getStored(tag));
|
buf.writeInt(NBTStorage.getStored(storageTag));
|
||||||
buf.writeInt(priority);
|
buf.writeInt(priority);
|
||||||
buf.writeInt(compare);
|
buf.writeInt(compare);
|
||||||
buf.writeInt(mode);
|
buf.writeInt(mode);
|
||||||
@@ -212,18 +222,14 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
RefinedStorage.NETWORK.sendToServer(new MessagePriorityUpdate(pos, priority));
|
RefinedStorage.NETWORK.sendToServer(new MessagePriorityUpdate(pos, priority));
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTStorage getStorage() {
|
|
||||||
return new NBTStorage(tag, getCapacity(), priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTTagCompound getStorageTag() {
|
public NBTTagCompound getStorageTag() {
|
||||||
return tag;
|
return storageTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStorageTag(NBTTagCompound tag) {
|
public void setStorageTag(NBTTagCompound tag) {
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
this.tag = tag;
|
this.storageTag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -234,6 +240,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
public void setPriority(int priority) {
|
public void setPriority(int priority) {
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
|
this.getStorage().setPriority(priority);
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user