Use better structure. End 0.6.8
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
### 0.6.8
|
### 0.6.8
|
||||||
**Bugfixes**
|
**Bugfixes**
|
||||||
|
- Performance improvements
|
||||||
- Fix CTRL + pick block on machines crashing game
|
- Fix CTRL + pick block on machines crashing game
|
||||||
|
|
||||||
### 0.6.7
|
### 0.6.7
|
||||||
|
@@ -1,13 +1,11 @@
|
|||||||
package refinedstorage.storage;
|
package refinedstorage.storage;
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
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 java.util.Collection;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class NBTStorage implements IStorage {
|
public abstract class NBTStorage implements IStorage {
|
||||||
@@ -24,7 +22,7 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
|
|
||||||
private boolean dirty;
|
private boolean dirty;
|
||||||
|
|
||||||
private Multimap<Item, ItemGroup> groups = ArrayListMultimap.create();
|
private List<ItemGroup> groups = new ArrayList<ItemGroup>();
|
||||||
|
|
||||||
public NBTStorage(NBTTagCompound tag, int capacity) {
|
public NBTStorage(NBTTagCompound tag, int capacity) {
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
@@ -46,14 +44,14 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null
|
tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null
|
||||||
);
|
);
|
||||||
|
|
||||||
groups.put(group.getType(), group);
|
groups.add(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound tag) {
|
public void writeToNBT(NBTTagCompound tag) {
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
|
||||||
for (ItemGroup group : groups.values()) {
|
for (ItemGroup group : groups) {
|
||||||
NBTTagCompound itemTag = new NBTTagCompound();
|
NBTTagCompound itemTag = new NBTTagCompound();
|
||||||
|
|
||||||
itemTag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(group.getType()));
|
itemTag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(group.getType()));
|
||||||
@@ -72,16 +70,14 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItems(List<ItemGroup> items) {
|
public void addItems(List<ItemGroup> items) {
|
||||||
items.addAll(groups.values());
|
items.addAll(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(ItemStack stack) {
|
public void push(ItemStack stack) {
|
||||||
tag.setInteger(NBT_STORED, getStored(tag) + stack.stackSize);
|
tag.setInteger(NBT_STORED, getStored(tag) + stack.stackSize);
|
||||||
|
|
||||||
Collection<ItemGroup> candidates = groups.get(stack.getItem());
|
for (ItemGroup group : groups) {
|
||||||
|
|
||||||
for (ItemGroup group : candidates) {
|
|
||||||
if (group.compareNoQuantity(stack)) {
|
if (group.compareNoQuantity(stack)) {
|
||||||
group.setQuantity(group.getQuantity() + stack.stackSize);
|
group.setQuantity(group.getQuantity() + stack.stackSize);
|
||||||
|
|
||||||
@@ -91,7 +87,7 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.put(stack.getItem(), new ItemGroup(stack));
|
groups.add(new ItemGroup(stack));
|
||||||
|
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
@@ -100,16 +96,14 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
public ItemStack take(ItemStack stack, int flags) {
|
public ItemStack take(ItemStack stack, int flags) {
|
||||||
int quantity = stack.stackSize;
|
int quantity = stack.stackSize;
|
||||||
|
|
||||||
Collection<ItemGroup> candidates = groups.get(stack.getItem());
|
for (ItemGroup group : groups) {
|
||||||
|
|
||||||
for (ItemGroup group : candidates) {
|
|
||||||
if (group.compare(stack, flags)) {
|
if (group.compare(stack, flags)) {
|
||||||
if (quantity > group.getQuantity()) {
|
if (quantity > group.getQuantity()) {
|
||||||
quantity = group.getQuantity();
|
quantity = group.getQuantity();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.getQuantity() - quantity == 0) {
|
if (group.getQuantity() - quantity == 0) {
|
||||||
groups.remove(group.getType(), group);
|
groups.remove(group);
|
||||||
} else {
|
} else {
|
||||||
group.setQuantity(group.getQuantity() - quantity);
|
group.setQuantity(group.getQuantity() - quantity);
|
||||||
}
|
}
|
||||||
|
@@ -53,11 +53,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
IDeepStorageUnit deep = (IDeepStorageUnit) connectedTile;
|
IDeepStorageUnit deep = (IDeepStorageUnit) connectedTile;
|
||||||
|
|
||||||
if (deep.getStoredItemType() != null) {
|
if (deep.getStoredItemType() != null) {
|
||||||
ItemStack stack = deep.getStoredItemType().copy();
|
items.add(new ItemGroup(deep.getStoredItemType().copy()));
|
||||||
|
|
||||||
while (stack.stackSize > 0) {
|
|
||||||
items.add(new ItemGroup(stack.splitStack(Math.min(stack.getMaxStackSize(), stack.stackSize))));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (connectedTile instanceof IInventory) {
|
} else if (connectedTile instanceof IInventory) {
|
||||||
IInventory inventory = (IInventory) connectedTile;
|
IInventory inventory = (IInventory) connectedTile;
|
||||||
|
Reference in New Issue
Block a user