This commit is contained in:
tterrag1098 committed 2015-06-12 19:06:10 -04:00
commit dedd877af7
32 files changed
+845 -11

No files matched your search

@@ -22,24 +22,40 @@ abstract class AbstractInventory {
}
protected void updateSlot(InventoryDatabaseServer db, int slot, ItemStack stack) {
if (stack == null) {
emptySlot(db, slot);
} else {
updateSlot(db, slot, stack, stack.stackSize);
}
}
protected void updateSlot(InventoryDatabaseServer db, int slot, ItemStack stack, int count) {
SlotKey slotKey = slotKeys[slot];
ItemEntry current = slotKey != null ? slotKey.item : null;
ItemEntry key = db.lookupItem(stack, current, true);
if (key != current) {
updateSlotKey(db, slot, slotKey, key, stack);
} else if (slotKey != null && slotKey.count != stack.stackSize) {
slotKey.count = stack.stackSize;
updateSlotKey(db, slot, slotKey, key, count);
} else if (slotKey != null && slotKey.count != count) {
slotKey.count = count;
db.entryChanged(current);
}
}
private void updateSlotKey(InventoryDatabaseServer db, int slot, SlotKey slotKey, ItemEntry key, ItemStack stack) {
protected void emptySlot(InventoryDatabaseServer db, int slot) {
SlotKey slotKey = slotKeys[slot];
if (slotKey != null) {
slotKey.remove(db);
slotKeys[slot] = null;
}
}
private void updateSlotKey(InventoryDatabaseServer db, int slot, SlotKey slotKey, ItemEntry key, int count) {
if (slotKey != null) {
slotKey.remove(db);
slotKey = null;
}
if (key != null) {
slotKey = new SlotKey(this, slot, key, stack.stackSize);
slotKey = new SlotKey(this, slot, key, count);
key.addSlot(slotKey);
db.entryChanged(key);
}
@@ -0,0 +1,66 @@
package crazypants.enderio.machine.invpanel.server;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
import net.minecraft.item.ItemStack;
public class DrawerGroupInventory extends AbstractInventory {
final IDrawerGroup dg;
public DrawerGroupInventory(IDrawerGroup dg) {
this.dg = dg;
}
@Override
int scanInventory(InventoryDatabaseServer db) {
int count = dg.getDrawerCount();
if (count == 0) {
setEmpty(db);
return 0;
}
if (count != slotKeys.length) {
reset(db, count);
}
for (int i = 0; i < count; i++) {
IDrawer drawer = dg.getDrawer(i);
ItemStack stack;
int quantity;
if (drawer != null &&
(quantity = drawer.getStoredItemCount()) > 0 &&
(stack = drawer.getStoredItemPrototype()) != null &&
drawer.canItemBeExtracted(stack)) {
updateSlot(db, i, stack, quantity);
} else {
emptySlot(db, i);
}
}
return count;
}
@Override
int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int count) {
if (slot >= dg.getDrawerCount()) {
return 0;
}
IDrawer drawer = dg.getDrawer(slot);
if (drawer == null) {
return 0;
}
int remaining = drawer.getStoredItemCount();
if (remaining <= 0) {
return 0;
}
ItemStack stack = drawer.getStoredItemPrototype();
if (db.lookupItem(stack, entry, false) != entry) {
return 0;
}
if (count > remaining) {
count = remaining;
}
remaining -= count;
drawer.setStoredItemCount(remaining);
updateCount(db, slot, entry, remaining);
return count;
}
}
@@ -18,7 +18,6 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
public class InventoryDatabaseServer extends InventoryDatabase<ItemEntry> {
@@ -179,11 +178,7 @@ public class InventoryDatabaseServer extends InventoryDatabase<ItemEntry> {
this.inventories = new AbstractInventory[sources.size()];
for(int i=0; i<sources.size(); i++) {
NetworkedInventory ni = sources.get(i);
if(ni.getInventory() instanceof IDeepStorageUnit) {
inventories[i] = new DSUInventory((IDeepStorageUnit) ni.getInventory());
} else {
inventories[i] = new NormalInventory(ni);
}
inventories[i] = InventoryFactory.createInventory(ni);
}
}
@@ -0,0 +1,55 @@
package crazypants.enderio.machine.invpanel.server;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
import cpw.mods.fml.common.Loader;
import crazypants.enderio.conduit.item.NetworkedInventory;
import java.util.ArrayList;
import net.minecraft.inventory.ISidedInventory;
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
public abstract class InventoryFactory {
private static final ArrayList<InventoryFactory> factories;
static {
factories = new ArrayList<InventoryFactory>();
factories.add(new DSUFactory());
if (Loader.isModLoaded("StorageDrawers")) {
factories.add(new DrawerFactory());
}
}
static AbstractInventory createInventory(NetworkedInventory ni) {
for(InventoryFactory f : factories) {
AbstractInventory ai = f.create(ni);
if (ai != null) {
return ai;
}
}
return new NormalInventory(ni);
}
abstract AbstractInventory create(NetworkedInventory ni);
static class DSUFactory extends InventoryFactory {
@Override
AbstractInventory create(NetworkedInventory ni) {
ISidedInventory inv = ni.getInventory();
if (inv instanceof IDeepStorageUnit) {
return new DSUInventory((IDeepStorageUnit) inv);
}
return null;
}
}
static class DrawerFactory extends InventoryFactory {
@Override
AbstractInventory create(NetworkedInventory ni) {
ISidedInventory inv = ni.getInventory();
if (inv instanceof IDrawerGroup) {
return new DrawerGroupInventory((IDrawerGroup) inv);
}
return null;
}
}
}