Revert "WIP stuff"

This reverts commit 959072422c.
This commit is contained in:
Raoul Van den Berge
2016-05-18 17:24:02 +02:00
parent 959072422c
commit 819e624b62
4 changed files with 64 additions and 94 deletions

View File

@@ -5,7 +5,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.ArrayList;
import java.util.List;
public class NBTStorage implements IStorage {
@@ -17,93 +16,81 @@ public class NBTStorage implements IStorage {
public static final String NBT_ITEM_DAMAGE = "Damage";
public static final String NBT_ITEM_NBT = "NBT";
private NBTTagCompound nbt;
private NBTTagCompound nbtTag;
private int capacity;
private int priority;
private List<ItemGroup> items = new ArrayList<ItemGroup>();
public NBTStorage(NBTTagCompound nbt, int capacity, int priority) {
this.nbt = nbt;
public NBTStorage(NBTTagCompound tag, int capacity, int priority) {
this.nbtTag = tag;
this.capacity = capacity;
this.priority = priority;
readFromNBT();
}
public void readFromNBT() {
NBTTagList list = (NBTTagList) nbt.getTag(NBT_ITEMS);
for (int i = 0; i < list.tagCount(); ++i) {
NBTTagCompound tag = list.getCompoundTagAt(i);
items.add(new ItemGroup(
Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)),
tag.getInteger(NBT_ITEM_QUANTITY),
tag.getInteger(NBT_ITEM_DAMAGE),
tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null)
);
}
}
public void writeToNBT(NBTTagCompound nbt) {
NBTTagList list = new NBTTagList();
for (ItemGroup item : items) {
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(item.getType()));
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity());
tag.setInteger(NBT_ITEM_DAMAGE, item.getDamage());
if (item.getTag() != null) {
tag.setTag(NBT_ITEM_NBT, item.getTag());
}
list.appendTag(tag);
}
nbt.setTag(NBT_ITEMS, list);
}
@Override
public void addItems(List<ItemGroup> items) {
items.addAll(this.items);
NBTTagList list = (NBTTagList) nbtTag.getTag(NBT_ITEMS);
for (int i = 0; i < list.tagCount(); ++i) {
items.add(createItemGroupFromNBT(list.getCompoundTagAt(i)));
}
}
@Override
public void push(ItemStack stack) {
nbt.setInteger(NBT_STORED, getStored(nbt) + stack.stackSize);
NBTTagList list = (NBTTagList) nbtTag.getTag(NBT_ITEMS);
for (ItemGroup item : items) {
if (item.compareNoQuantity(stack)) {
item.setQuantity(item.getQuantity() + stack.stackSize);
nbtTag.setInteger(NBT_STORED, getStored(nbtTag) + 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;
}
}
items.add(new ItemGroup(stack));
NBTTagCompound tag = new NBTTagCompound();
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
public ItemStack take(ItemStack stack, int flags) {
int quantity = stack.stackSize;
for (ItemGroup item : items) {
if (item.compare(stack, flags)) {
if (quantity > item.getQuantity()) {
quantity = item.getQuantity();
NBTTagList list = (NBTTagList) nbtTag.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();
}
item.setQuantity(item.getQuantity() - quantity);
tag.setInteger(NBT_ITEM_QUANTITY, group.getQuantity() - quantity);
if (item.getQuantity() == 0) {
items.remove(item);
if (group.getQuantity() - quantity == 0) {
list.removeTag(i);
}
nbt.setInteger(NBT_STORED, getStored(nbt) - quantity);
nbtTag.setInteger(NBT_STORED, getStored(nbtTag) - quantity);
ItemStack newItem = item.toItemStack();
ItemStack newItem = group.toItemStack();
newItem.stackSize = quantity;
@@ -120,7 +107,7 @@ public class NBTStorage implements IStorage {
return true;
}
return (getStored(nbt) + stack.stackSize) <= capacity;
return (getStored(nbtTag) + stack.stackSize) <= capacity;
}
@Override
@@ -128,8 +115,8 @@ public class NBTStorage implements IStorage {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
private ItemGroup createItemGroupFromNBT(NBTTagCompound tag) {
return new ItemGroup(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_DAMAGE), tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null);
}
public static int getStored(NBTTagCompound tag) {

View File

@@ -192,7 +192,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
}
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageControllerEnergyUpdate(this));
if (lastEnergy != energy.getEnergyStored()) {
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
}
@@ -377,6 +377,8 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
}
}
markDirty();
return true;
}
}
@@ -385,10 +387,14 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
}
public ItemStack take(ItemStack stack) {
markDirty();
return take(stack, RefinedStorageUtils.COMPARE_DAMAGE | RefinedStorageUtils.COMPARE_NBT);
}
public ItemStack take(ItemStack stack, int flags) {
markDirty();
int requested = stack.stackSize;
int receiving = 0;

View File

@@ -27,7 +27,6 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
private InventorySimple inventory = new InventorySimple("disk_drive", 8, this);
private InventorySimple filterInventory = new InventorySimple("filters", 9, this);
private DiskStorage[] storages = new DiskStorage[getSizeInventory()];
private int priority = 0;
private int compare = 0;
@@ -53,8 +52,8 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
@Override
public void provide(List<IStorage> storages) {
for (int i = 0; i < getSizeInventory(); ++i) {
if (this.storages[i] != null) {
storages.add(this.storages[i]);
if (getStackInSlot(i) != null) {
storages.add(new DiskStorage(getStackInSlot(i), this));
}
}
}
@@ -83,12 +82,6 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
for (int i = 0; i < getSizeInventory(); ++i) {
if (storages[i] != null) {
storages[i].writeToNBT(getStackInSlot(i).getTagCompound());
}
}
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
RefinedStorageUtils.saveInventory(filterInventory, 1, nbt);
@@ -255,12 +248,6 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
if (stack == null) {
storages[slot] = null;
} else {
storages[slot] = new DiskStorage(stack, this);
}
inventory.setInventorySlotContents(slot, stack);
}

View File

@@ -30,7 +30,6 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
private InventorySimple inventory = new InventorySimple("storage", 9, this);
private NBTTagCompound tag = NBTStorage.getBaseNBT();
private NBTStorage storage;
private int priority = 0;
private int compare = 0;
@@ -57,14 +56,14 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
RefinedStorageUtils.restoreInventory(inventory, 0, nbt);
if (nbt.hasKey(NBT_PRIORITY)) {
priority = nbt.getInteger(NBT_PRIORITY);
}
if (nbt.hasKey(NBT_STORAGE)) {
tag = nbt.getCompoundTag(NBT_STORAGE);
}
if (nbt.hasKey(NBT_PRIORITY)) {
priority = nbt.getInteger(NBT_PRIORITY);
}
if (nbt.hasKey(NBT_COMPARE)) {
compare = nbt.getInteger(NBT_COMPARE);
}
@@ -80,8 +79,8 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
nbt.setInteger(NBT_PRIORITY, priority);
nbt.setTag(NBT_STORAGE, tag);
nbt.setInteger(NBT_PRIORITY, priority);
nbt.setInteger(NBT_COMPARE, compare);
nbt.setInteger(NBT_MODE, mode);
}
@@ -98,7 +97,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
public void sendContainerData(ByteBuf buf) {
super.sendContainerData(buf);
buf.writeInt(stored);
buf.writeInt(NBTStorage.getStored(tag));
buf.writeInt(priority);
buf.writeInt(compare);
buf.writeInt(mode);
@@ -214,11 +213,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
}
public NBTStorage getStorage() {
if (storage == null) {
storage = new NBTStorage(tag, getCapacity(), priority);
}
return storage;
return new NBTStorage(tag, getCapacity(), priority);
}
public NBTTagCompound getStorageTag() {
@@ -239,17 +234,12 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
public void setPriority(int priority) {
markDirty();
this.storage.setPriority(priority);
this.priority = priority;
}
@Override
public int getStored() {
if (worldObj.isRemote) {
return stored;
} else {
return NBTStorage.getStored(tag);
}
return stored;
}
@Override