mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 15:03:07 +00:00
refactored server/client classes into their own package
This commit is contained in:
1 parent
d65a517c1b
commit
81784b82e9
28 files changed
+664
-602
No files matched your search
@@ -9,6 +9,10 @@ import crazypants.enderio.gui.TextFieldEIO;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.gui.VScrollbarEIO;
|
||||
import crazypants.enderio.machine.gui.GuiMachineBase;
|
||||
import crazypants.enderio.machine.invpanel.client.ICraftingHelper;
|
||||
import crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient;
|
||||
import crazypants.enderio.machine.invpanel.client.ItemEntry;
|
||||
import crazypants.enderio.machine.invpanel.client.SortOrder;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GhostSlot;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
@@ -338,7 +342,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
}
|
||||
|
||||
class InvSlot extends GhostSlot {
|
||||
InventoryDatabaseClient.ItemEntry entry;
|
||||
ItemEntry entry;
|
||||
|
||||
InvSlot(int x, int y) {
|
||||
this.x = x;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
public interface ICraftingHelper {
|
||||
|
||||
void refill(GuiInventoryPanel gui, int amount);
|
||||
|
||||
}
|
||||
@@ -1,456 +0,0 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.CompressedDataInput;
|
||||
import crazypants.enderio.network.CompressedDataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
|
||||
public class InventoryDatabaseServer extends InventoryDatabase<InventoryDatabaseServer.ItemEntry> {
|
||||
|
||||
private AbstractInventoryKey[] inventories;
|
||||
private int currentInventory;
|
||||
private ChangeLog changeLog;
|
||||
|
||||
public InventoryDatabaseServer() {
|
||||
}
|
||||
|
||||
public void addChangeLog(ChangeLog cl) {
|
||||
if(changeLog == null) {
|
||||
changeLog = cl;
|
||||
} else if(changeLog instanceof ChangeLogList) {
|
||||
((ChangeLogList)changeLog).add(cl);
|
||||
} else if(changeLog != cl) {
|
||||
changeLog = new ChangeLogList(changeLog, cl);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeChangeLog(ChangeLog cl) {
|
||||
if(changeLog == cl) {
|
||||
changeLog = null;
|
||||
} else if(changeLog instanceof ChangeLogList) {
|
||||
changeLog = ((ChangeLogList)changeLog).remove(cl);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemEntry> decompressMissingItems(byte[] compressed) throws IOException {
|
||||
CompressedDataInput cdi = new CompressedDataInput(compressed);
|
||||
try {
|
||||
int numIDs = cdi.readVariable();
|
||||
ArrayList<InventoryDatabaseServer.ItemEntry> items = new ArrayList<InventoryDatabaseServer.ItemEntry>(numIDs);
|
||||
for(int i = 0; i < numIDs; i++) {
|
||||
int dbIndex = cdi.readVariable();
|
||||
if(dbIndex < complexItems.size()) {
|
||||
InventoryDatabaseServer.ItemEntry entry = complexItems.get(dbIndex);
|
||||
items.add(entry);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
} finally {
|
||||
cdi.close();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] compressItemInfo(List<ItemEntry> items) throws IOException{
|
||||
CompressedDataOutput cdo = new CompressedDataOutput();
|
||||
try {
|
||||
int count = items.size();
|
||||
cdo.writeVariable(generation);
|
||||
cdo.writeVariable(count);
|
||||
for(ItemEntry entry : items) {
|
||||
assert entry.dbID >= COMPLEX_DBINDEX_START;
|
||||
int code = (entry.dbID - COMPLEX_DBINDEX_START) << 1;
|
||||
if(entry.nbt != null) {
|
||||
code |= 1;
|
||||
}
|
||||
cdo.writeVariable(code);
|
||||
cdo.writeVariable(entry.itemID);
|
||||
cdo.writeVariable(entry.meta);
|
||||
if(entry.nbt != null) {
|
||||
CompressedStreamTools.write(entry.nbt, cdo);
|
||||
}
|
||||
cdo.writeVariable(entry.countItems(this));
|
||||
}
|
||||
return cdo.getCompressed();
|
||||
} finally {
|
||||
cdo.close();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] compressItemList() throws IOException {
|
||||
CompressedDataOutput cdo = new CompressedDataOutput();
|
||||
try {
|
||||
cdo.writeVariable(generation);
|
||||
cdo.writeByte(0);
|
||||
for(Map.Entry<Integer, ItemEntry> entry : simpleRegsitry.entrySet()) {
|
||||
int count = entry.getValue().countItems(this);
|
||||
if(count > 0) {
|
||||
cdo.writeVariable(count);
|
||||
cdo.writeShort(entry.getKey());
|
||||
}
|
||||
}
|
||||
cdo.writeByte(0);
|
||||
int prevID = COMPLEX_DBINDEX_START;
|
||||
for(ItemEntry entry : complexItems) {
|
||||
if(entry != null) {
|
||||
int count = entry.countItems(this);
|
||||
if(count > 0) {
|
||||
cdo.writeVariable(count);
|
||||
cdo.writeVariable(entry.dbID - prevID);
|
||||
prevID = entry.dbID;
|
||||
}
|
||||
}
|
||||
}
|
||||
cdo.writeByte(0);
|
||||
return cdo.getCompressed();
|
||||
} finally {
|
||||
cdo.close();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] compressChangedItems(Collection<ItemEntry> items) throws IOException {
|
||||
CompressedDataOutput cdo = new CompressedDataOutput();
|
||||
try {
|
||||
cdo.writeVariable(generation);
|
||||
cdo.writeVariable(items.size());
|
||||
for(ItemEntry entry : items) {
|
||||
cdo.writeVariable(entry.dbID);
|
||||
cdo.writeVariable(entry.countItems(this));
|
||||
}
|
||||
return cdo.getCompressed();
|
||||
} finally {
|
||||
cdo.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setNetworkSources(List<NetworkedInventory> sources) {
|
||||
simpleRegsitry.clear();
|
||||
complexRegistry.clear();
|
||||
complexItems.clear();
|
||||
generation++;
|
||||
currentInventory = 0;
|
||||
|
||||
if(sources == null || sources.isEmpty()) {
|
||||
this.inventories = null;
|
||||
} else {
|
||||
this.inventories = new AbstractInventoryKey[sources.size()];
|
||||
for(int i=0; i<sources.size(); i++) {
|
||||
NetworkedInventory ni = sources.get(i);
|
||||
if(ni.getInventory() instanceof IDeepStorageUnit) {
|
||||
inventories[i] = new DSUKey((IDeepStorageUnit) ni.getInventory());
|
||||
} else {
|
||||
inventories[i] = new InventoryKey(ni);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(changeLog != null) {
|
||||
changeLog.databaseReset();
|
||||
}
|
||||
}
|
||||
|
||||
public void scanNextInventory() {
|
||||
if(inventories == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractInventoryKey inv = inventories[currentInventory];
|
||||
inv.scanInventory(this, currentInventory);
|
||||
|
||||
currentInventory = (currentInventory+1) % inventories.length;
|
||||
}
|
||||
|
||||
void entryChanged(ItemEntry entry) {
|
||||
if(changeLog != null) {
|
||||
changeLog.entryChanged(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendChangeLogs() {
|
||||
if(changeLog != null) {
|
||||
changeLog.sendChangeLog();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemEntry createItemEntry(int dbId, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
return new ItemEntry(dbId, hash, itemID, meta, nbt);
|
||||
}
|
||||
|
||||
public static class ItemEntry extends ItemEntryBase {
|
||||
private final HashSet<Integer> slots = new HashSet<Integer>();
|
||||
|
||||
public ItemEntry(int dbID, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
super(dbID, hash, itemID, meta, nbt);
|
||||
}
|
||||
|
||||
static int encodeNISlot(int niIndex, int slot) {
|
||||
return (niIndex << 12) | slot;
|
||||
}
|
||||
|
||||
void addSlot(int niIndex, int slot) {
|
||||
slots.add(encodeNISlot(niIndex, slot));
|
||||
}
|
||||
|
||||
void removeSlot(int niIndex, int slot) {
|
||||
slots.remove(encodeNISlot(niIndex, slot));
|
||||
}
|
||||
|
||||
int countItems(InventoryDatabaseServer db) {
|
||||
int count = 0;
|
||||
for(Integer idx : slots) {
|
||||
AbstractInventoryKey key = db.inventories[idx >> 12];
|
||||
count += key.itemCounts[idx & 4095];
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int extractItems(InventoryDatabaseServer db, int count) {
|
||||
int extracted = 0;
|
||||
Integer[] copy = slots.toArray(new Integer[slots.size()]);
|
||||
for(Integer idx : copy) {
|
||||
int niIndex = idx >> 12;
|
||||
int slotIndex = idx & 4095;
|
||||
AbstractInventoryKey key = db.inventories[niIndex];
|
||||
int amount = key.extractItem(db, this, slotIndex, niIndex, count);
|
||||
count -= amount;
|
||||
extracted += amount;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
|
||||
static abstract class AbstractInventoryKey {
|
||||
static final ItemEntry[] NO_SLOTS = new ItemEntry[0];
|
||||
|
||||
ItemEntry[] slotItems = NO_SLOTS;
|
||||
int[] itemCounts;
|
||||
|
||||
protected void setEmpty(InventoryDatabaseServer db, int niIndex) {
|
||||
if(slotItems.length != 0) {
|
||||
reset(db, 0, niIndex);
|
||||
}
|
||||
}
|
||||
|
||||
protected void reset(InventoryDatabaseServer db, int count, int niIndex) {
|
||||
for(int slot=0; slot<slotItems.length; slot++) {
|
||||
ItemEntry key = slotItems[slot];
|
||||
if(key != null) {
|
||||
key.removeSlot(niIndex, slot);
|
||||
db.entryChanged(key);
|
||||
}
|
||||
}
|
||||
|
||||
slotItems = new ItemEntry[count];
|
||||
itemCounts = new int[count];
|
||||
}
|
||||
|
||||
protected void updateSlot(InventoryDatabaseServer db, int slot, int niIndex, ItemStack stack) {
|
||||
ItemEntry current = slotItems[slot];
|
||||
if(stack == null || stack.stackSize <= 0) {
|
||||
if(current != null) {
|
||||
slotItems[slot] = null;
|
||||
itemCounts[slot] = 0;
|
||||
current.removeSlot(niIndex, slot);
|
||||
db.entryChanged(current);
|
||||
}
|
||||
} else {
|
||||
ItemEntry key = db.lookupItem(stack, current, true);
|
||||
if(key != current) {
|
||||
slotItems[slot] = key;
|
||||
itemCounts[slot] = stack.stackSize;
|
||||
key.addSlot(niIndex, slot);
|
||||
db.entryChanged(key);
|
||||
if(current != null) {
|
||||
current.removeSlot(niIndex, slot);
|
||||
db.entryChanged(current);
|
||||
}
|
||||
} else if(itemCounts[slot] != stack.stackSize) {
|
||||
itemCounts[slot] = stack.stackSize;
|
||||
db.entryChanged(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateCount(InventoryDatabaseServer db, int slot, int niIndex, ItemEntry entry, int count) {
|
||||
if(itemCounts[slot] != count) {
|
||||
itemCounts[slot] = count;
|
||||
if(count == 0) {
|
||||
slotItems[slot] = null;
|
||||
entry.removeSlot(niIndex, slot);
|
||||
}
|
||||
db.entryChanged(entry);
|
||||
}
|
||||
}
|
||||
|
||||
abstract void scanInventory(InventoryDatabaseServer db, int niIndex);
|
||||
abstract int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int niIndex, int count);
|
||||
}
|
||||
|
||||
static class InventoryKey extends AbstractInventoryKey {
|
||||
|
||||
final NetworkedInventory ni;
|
||||
|
||||
InventoryKey(NetworkedInventory ni) {
|
||||
this.ni = ni;
|
||||
}
|
||||
|
||||
@Override
|
||||
void scanInventory(InventoryDatabaseServer db, int niIndex) {
|
||||
ISidedInventory inv = ni.getInventoryRecheck();
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if(slotIndices == null || slotIndices.length == 0) {
|
||||
setEmpty(db, niIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = slotIndices.length;
|
||||
if(count != slotItems.length) {
|
||||
reset(db, count, niIndex);
|
||||
}
|
||||
|
||||
for(int slot=0; slot<count; slot++) {
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if(stack != null && !inv.canExtractItem(invSlot, stack, side)) {
|
||||
stack = null;
|
||||
}
|
||||
updateSlot(db, slot, niIndex, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int niIndex, int count) {
|
||||
ISidedInventory inv = ni.getInventoryRecheck();
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if(slotIndices == null || slot >= slotIndices.length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if(stack == null || !inv.canExtractItem(invSlot, stack, side)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(db.lookupItem(stack, entry, false) != entry) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remaining = stack.stackSize;
|
||||
if(count > remaining) {
|
||||
count = remaining;
|
||||
}
|
||||
|
||||
ni.itemExtracted(invSlot, count);
|
||||
remaining -= count;
|
||||
|
||||
updateCount(db, slot, niIndex, entry, remaining);
|
||||
|
||||
System.out.println("result " + count);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
static class DSUKey extends AbstractInventoryKey {
|
||||
private final IDeepStorageUnit dsu;
|
||||
|
||||
DSUKey(IDeepStorageUnit dsu) {
|
||||
this.dsu = dsu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanInventory(InventoryDatabaseServer db, int niIndex) {
|
||||
if(slotItems.length != 1) {
|
||||
reset(db, 1, niIndex);
|
||||
}
|
||||
ItemStack stack = dsu.getStoredItemType();
|
||||
updateSlot(db, 0, niIndex, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int niIndex, int count) {
|
||||
if(slotItems.length != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ItemStack stack = dsu.getStoredItemType();
|
||||
if(db.lookupItem(stack, entry, false) != entry) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remaining = stack.stackSize;
|
||||
if(count > remaining) {
|
||||
count = remaining;
|
||||
}
|
||||
|
||||
remaining -= count;
|
||||
dsu.setStoredItemCount(remaining);
|
||||
|
||||
updateCount(db, slot, niIndex, entry, remaining);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ChangeLog {
|
||||
void entryChanged(ItemEntry entry);
|
||||
void databaseReset();
|
||||
void sendChangeLog();
|
||||
}
|
||||
|
||||
static final class ChangeLogList implements ChangeLog {
|
||||
final ArrayList<ChangeLog> clList;
|
||||
|
||||
public ChangeLogList(ChangeLog cl0, ChangeLog cl1) {
|
||||
clList = new ArrayList<InventoryDatabaseServer.ChangeLog>(2);
|
||||
clList.add(cl0);
|
||||
clList.add(cl1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entryChanged(ItemEntry entry) {
|
||||
for(ChangeLog cl : clList) {
|
||||
cl.entryChanged(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void databaseReset() {
|
||||
for(ChangeLog cl : clList) {
|
||||
cl.databaseReset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChangeLog() {
|
||||
for(ChangeLog cl : clList) {
|
||||
cl.sendChangeLog();
|
||||
}
|
||||
}
|
||||
|
||||
ChangeLog remove(ChangeLog cl) {
|
||||
clList.remove(cl);
|
||||
if(clList.size() == 1) {
|
||||
return clList.get(0);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void add(ChangeLog cl) {
|
||||
if(!clList.contains(cl)) {
|
||||
clList.add(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import crazypants.enderio.machine.invpanel.server.InventoryDatabaseServer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.machine.gui.AbstractMachineContainer;
|
||||
import crazypants.enderio.machine.invpanel.server.ChangeLog;
|
||||
import crazypants.enderio.machine.invpanel.server.ItemEntry;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.util.ItemUtil;
|
||||
import java.awt.Point;
|
||||
@@ -27,7 +29,7 @@ import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
|
||||
public class InventoryPanelContainer extends AbstractMachineContainer implements InventoryDatabaseServer.ChangeLog {
|
||||
public class InventoryPanelContainer extends AbstractMachineContainer implements ChangeLog {
|
||||
|
||||
public static final int CRAFTING_GRID_X = 7;
|
||||
public static final int CRAFTING_GRID_Y = 16;
|
||||
@@ -38,7 +40,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
public static final int FILTER_SLOT_X = 233;
|
||||
public static final int FILTER_SLOT_Y = 7;
|
||||
|
||||
private final HashSet<InventoryDatabaseServer.ItemEntry> changedItems;
|
||||
private final HashSet<ItemEntry> changedItems;
|
||||
|
||||
private Slot slotFilter;
|
||||
|
||||
@@ -57,7 +59,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
if(te.getWorldObj().isRemote) {
|
||||
changedItems = null;
|
||||
} else {
|
||||
changedItems = new HashSet<InventoryDatabaseServer.ItemEntry>();
|
||||
changedItems = new HashSet<ItemEntry>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +245,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entryChanged(InventoryDatabaseServer.ItemEntry entry) {
|
||||
public void entryChanged(ItemEntry entry) {
|
||||
changedItems.add(entry);
|
||||
}
|
||||
|
||||
@@ -284,7 +286,7 @@ public class InventoryPanelContainer extends AbstractMachineContainer implements
|
||||
|
||||
public void executeFetchItems(EntityPlayerMP player, int dbID, int targetSlot, int count) {
|
||||
InventoryDatabaseServer db = getInventoryPanel().getDatabaseServer();
|
||||
InventoryDatabaseServer.ItemEntry entry = db.getExistingItem(dbID);
|
||||
ItemEntry entry = db.getExistingItem(dbID);
|
||||
if(entry != null) {
|
||||
ItemStack targetStack;
|
||||
Slot slot;
|
||||
|
||||
@@ -11,7 +11,7 @@ public class ItemEntryBase {
|
||||
public final int meta;
|
||||
public final NBTTagCompound nbt;
|
||||
|
||||
ItemEntryBase(int dbID, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
protected ItemEntryBase(int dbID, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
this.dbID = dbID;
|
||||
this.hash = hash;
|
||||
this.itemID = itemID;
|
||||
|
||||
@@ -3,6 +3,7 @@ package crazypants.enderio.machine.invpanel;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.invpanel.client.ItemEntry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
@@ -15,7 +16,7 @@ public class PacketFetchItem implements IMessage, IMessageHandler<PacketFetchIte
|
||||
public PacketFetchItem() {
|
||||
}
|
||||
|
||||
public PacketFetchItem(InventoryDatabaseClient.ItemEntry entry, int targetSlot, int count) {
|
||||
public PacketFetchItem(ItemEntry entry, int targetSlot, int count) {
|
||||
this.dbID = entry.dbID;
|
||||
this.targetSlot = targetSlot;
|
||||
this.count = count;
|
||||
|
||||
@@ -4,6 +4,8 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient;
|
||||
import crazypants.enderio.machine.invpanel.server.ItemEntry;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -21,7 +23,7 @@ public class PacketItemInfo extends MessageTileEntity<TileInventoryPanel> implem
|
||||
public PacketItemInfo() {
|
||||
}
|
||||
|
||||
public PacketItemInfo(TileInventoryPanel tile, List<InventoryDatabaseServer.ItemEntry> items) {
|
||||
public PacketItemInfo(TileInventoryPanel tile, List<ItemEntry> items) {
|
||||
super(tile);
|
||||
try {
|
||||
compressed = tile.getDatabaseServer().compressItemInfo(items);
|
||||
|
||||
@@ -4,6 +4,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import crazypants.enderio.machine.invpanel.server.InventoryDatabaseServer;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.invpanel.server.ItemEntry;
|
||||
import crazypants.enderio.network.CompressedDataOutput;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
@@ -60,7 +62,7 @@ public class PacketRequestMissingItems extends MessageTileEntity<TileInventoryPa
|
||||
TileInventoryPanel teInvPanel = (TileInventoryPanel) te;
|
||||
InventoryDatabaseServer db = teInvPanel.getDatabaseServer();
|
||||
try {
|
||||
List<InventoryDatabaseServer.ItemEntry> items = db.decompressMissingItems(message.compressed);
|
||||
List<ItemEntry> items = db.decompressMissingItems(message.compressed);
|
||||
if(!items.isEmpty()) {
|
||||
PacketHandler.sendTo(new PacketItemInfo(teInvPanel, items), player);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
public enum SortOrder {
|
||||
NAME,
|
||||
MOD,
|
||||
COUNT
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient;
|
||||
import crazypants.enderio.machine.invpanel.server.InventoryDatabaseServer;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.TileConduitBundle;
|
||||
import crazypants.enderio.conduit.item.FilterRegister;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
class CountComparator implements Comparator<ItemEntry> {
|
||||
public static final CountComparator INSTANCE = new CountComparator();
|
||||
|
||||
@Override
|
||||
public int compare(ItemEntry a, ItemEntry b) {
|
||||
return b.count - a.count;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import crazypants.enderio.machine.invpanel.GuiInventoryPanel;
|
||||
|
||||
public interface ICraftingHelper {
|
||||
|
||||
void refill(GuiInventoryPanel gui, int amount);
|
||||
|
||||
}
|
||||
+5
-112
@@ -1,7 +1,9 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilter;
|
||||
import crazypants.enderio.machine.invpanel.InventoryDatabase;
|
||||
import crazypants.enderio.machine.invpanel.PacketRequestMissingItems;
|
||||
import crazypants.enderio.machine.invpanel.TileInventoryPanel;
|
||||
import crazypants.enderio.network.CompressedDataInput;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import java.io.IOException;
|
||||
@@ -14,13 +16,10 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class InventoryDatabaseClient extends InventoryDatabase<InventoryDatabaseClient.ItemEntry> {
|
||||
public class InventoryDatabaseClient extends InventoryDatabase<ItemEntry> {
|
||||
|
||||
private final TileInventoryPanel te;
|
||||
private final ArrayList<ItemEntry> clientItems;
|
||||
@@ -290,110 +289,4 @@ public class InventoryDatabaseClient extends InventoryDatabase<InventoryDatabase
|
||||
return new ItemEntry(dbId, hash, itemID, meta, nbt);
|
||||
}
|
||||
|
||||
public static class ItemEntry extends ItemEntryBase {
|
||||
String name;
|
||||
String modId;
|
||||
String lowerCaseLocName;
|
||||
int count;
|
||||
|
||||
public ItemEntry(int dbID, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
super(dbID, hash, itemID, meta, nbt);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public ItemStack makeItemStack() {
|
||||
ItemStack stack = new ItemStack(getItem(), count, meta);
|
||||
stack.stackTagCompound = nbt;
|
||||
return stack;
|
||||
}
|
||||
|
||||
public String getUnlocName() {
|
||||
if(name == null) {
|
||||
findUnlocName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getLowercaseUnlocName(Locale locale) {
|
||||
if(lowerCaseLocName == null) {
|
||||
lowerCaseLocName = StatCollector.translateToLocal(getUnlocName()).toLowerCase(locale);
|
||||
}
|
||||
return lowerCaseLocName;
|
||||
}
|
||||
|
||||
private void findUnlocName() {
|
||||
ItemStack stack = makeItemStack();
|
||||
try {
|
||||
name = stack.getDisplayName();
|
||||
if(name == null || name.isEmpty()) {
|
||||
name = stack.getItem().getUnlocalizedName();
|
||||
if(name == null || name.isEmpty()) {
|
||||
name = stack.getItem().getClass().getName();
|
||||
}
|
||||
}
|
||||
} catch(Throwable ex) {
|
||||
name = "Exception: " + ex.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public String getModId() {
|
||||
if(modId == null) {
|
||||
findModId();
|
||||
}
|
||||
return modId;
|
||||
}
|
||||
|
||||
private void findModId() {
|
||||
Item item = getItem();
|
||||
GameRegistry.UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(item);
|
||||
if(id != null && id.modId != null) {
|
||||
modId = id.modId;
|
||||
} else {
|
||||
modId = "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class NameComparator implements Comparator<ItemEntry> {
|
||||
protected final Collator collator;
|
||||
|
||||
NameComparator(Collator collator) {
|
||||
this.collator = collator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ItemEntry a, ItemEntry b) {
|
||||
String nameA = a.getUnlocName();
|
||||
String nameB = b.getUnlocName();
|
||||
return collator.compare(nameA, nameB);
|
||||
}
|
||||
}
|
||||
|
||||
static class ModComparator extends NameComparator {
|
||||
ModComparator(Collator collator) {
|
||||
super(collator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ItemEntry a, ItemEntry b) {
|
||||
String modIdA = a.getModId();
|
||||
String modIdB = b.getModId();
|
||||
int res = collator.compare(modIdA, modIdB);
|
||||
if(res == 0) {
|
||||
res = super.compare(a, b);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
static class CountComparator implements Comparator<ItemEntry> {
|
||||
public static final CountComparator INSTANCE = new CountComparator();
|
||||
@Override
|
||||
public int compare(ItemEntry a, ItemEntry b) {
|
||||
return b.count - a.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -1,4 +1,4 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import codechicken.lib.inventory.InventoryUtils;
|
||||
import codechicken.nei.LayoutManager;
|
||||
@@ -8,6 +8,9 @@ import codechicken.nei.api.DefaultOverlayRenderer;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IStackPositioner;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import crazypants.enderio.machine.invpanel.GuiInventoryPanel;
|
||||
import crazypants.enderio.machine.invpanel.InventoryPanelContainer;
|
||||
import crazypants.enderio.machine.invpanel.PacketFetchItem;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -243,7 +246,7 @@ public class InventoryPanelNEIOverlayHandler implements IOverlayHandler {
|
||||
static class Candidate {
|
||||
final ItemStack stack;
|
||||
final ArrayList<Slot> sourceSlots = new ArrayList<Slot>();
|
||||
InventoryDatabaseClient.ItemEntry entry;
|
||||
ItemEntry entry;
|
||||
int available;
|
||||
int used;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.machine.invpanel.ItemEntryBase;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class ItemEntry extends ItemEntryBase {
|
||||
String name;
|
||||
String modId;
|
||||
String lowerCaseLocName;
|
||||
int count;
|
||||
|
||||
public ItemEntry(int dbID, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
super(dbID, hash, itemID, meta, nbt);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public ItemStack makeItemStack() {
|
||||
ItemStack stack = new ItemStack(getItem(), count, meta);
|
||||
stack.stackTagCompound = nbt;
|
||||
return stack;
|
||||
}
|
||||
|
||||
public String getUnlocName() {
|
||||
if (name == null) {
|
||||
findUnlocName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getLowercaseUnlocName(Locale locale) {
|
||||
if (lowerCaseLocName == null) {
|
||||
lowerCaseLocName = StatCollector.translateToLocal(getUnlocName()).toLowerCase(locale);
|
||||
}
|
||||
return lowerCaseLocName;
|
||||
}
|
||||
|
||||
private void findUnlocName() {
|
||||
ItemStack stack = makeItemStack();
|
||||
try {
|
||||
name = stack.getDisplayName();
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = stack.getItem().getUnlocalizedName();
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = stack.getItem().getClass().getName();
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
name = "Exception: " + ex.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public String getModId() {
|
||||
if (modId == null) {
|
||||
findModId();
|
||||
}
|
||||
return modId;
|
||||
}
|
||||
|
||||
private void findModId() {
|
||||
Item item = getItem();
|
||||
GameRegistry.UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(item);
|
||||
if (id != null && id.modId != null) {
|
||||
modId = id.modId;
|
||||
} else {
|
||||
modId = "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilter;
|
||||
import java.util.ArrayList;
|
||||
@@ -10,7 +10,7 @@ public abstract class ItemFilter {
|
||||
|
||||
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\s+");
|
||||
|
||||
public abstract boolean matches(InventoryDatabaseClient.ItemEntry entry);
|
||||
public abstract boolean matches(ItemEntry entry);
|
||||
|
||||
public static ItemFilter parse(String filter, Locale locale, IItemFilter filterCard) {
|
||||
ArrayList<ItemFilter> list = new ArrayList<ItemFilter>();
|
||||
@@ -47,7 +47,7 @@ public abstract class ItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryDatabaseClient.ItemEntry entry) {
|
||||
public boolean matches(ItemEntry entry) {
|
||||
for(ItemFilter f : list) {
|
||||
if(!f.matches(entry)) {
|
||||
return false;
|
||||
@@ -72,7 +72,7 @@ public abstract class ItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryDatabaseClient.ItemEntry entry) {
|
||||
public boolean matches(ItemEntry entry) {
|
||||
return entry.getModId().toLowerCase(locale).contains(text);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public abstract class ItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryDatabaseClient.ItemEntry entry) {
|
||||
public boolean matches(ItemEntry entry) {
|
||||
return entry.getLowercaseUnlocName(locale).contains(text);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public abstract class ItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryDatabaseClient.ItemEntry entry) {
|
||||
public boolean matches(ItemEntry entry) {
|
||||
return filter.doesItemPassFilter(null, entry.makeItemStack());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import java.text.Collator;
|
||||
|
||||
class ModComparator extends NameComparator {
|
||||
|
||||
ModComparator(Collator collator) {
|
||||
super(collator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ItemEntry a, ItemEntry b) {
|
||||
String modIdA = a.getModId();
|
||||
String modIdB = b.getModId();
|
||||
int res = collator.compare(modIdA, modIdB);
|
||||
if (res == 0) {
|
||||
res = super.compare(a, b);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
|
||||
class NameComparator implements Comparator<ItemEntry> {
|
||||
protected final Collator collator;
|
||||
|
||||
NameComparator(Collator collator) {
|
||||
this.collator = collator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ItemEntry a, ItemEntry b) {
|
||||
String nameA = a.getUnlocName();
|
||||
String nameB = b.getUnlocName();
|
||||
return collator.compare(nameA, nameB);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package crazypants.enderio.machine.invpanel.client;
|
||||
|
||||
public enum SortOrder {
|
||||
NAME,
|
||||
MOD,
|
||||
COUNT
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package crazypants.enderio.machine.invpanel.server;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
abstract class AbstractInventory {
|
||||
static final ItemEntry[] NO_SLOTS = new ItemEntry[0];
|
||||
ItemEntry[] slotItems = NO_SLOTS;
|
||||
int[] itemCounts;
|
||||
|
||||
protected void setEmpty(InventoryDatabaseServer db, int aiIndex) {
|
||||
if (slotItems.length != 0) {
|
||||
reset(db, 0, aiIndex);
|
||||
}
|
||||
}
|
||||
|
||||
protected void reset(InventoryDatabaseServer db, int count, int aiIndex) {
|
||||
for (int slot = 0; slot < slotItems.length; slot++) {
|
||||
ItemEntry key = slotItems[slot];
|
||||
if (key != null) {
|
||||
key.removeSlot(aiIndex, slot);
|
||||
db.entryChanged(key);
|
||||
}
|
||||
}
|
||||
slotItems = new ItemEntry[count];
|
||||
itemCounts = new int[count];
|
||||
}
|
||||
|
||||
protected void updateSlot(InventoryDatabaseServer db, int slot, int aiIndex, ItemStack stack) {
|
||||
ItemEntry current = slotItems[slot];
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
if (current != null) {
|
||||
slotItems[slot] = null;
|
||||
itemCounts[slot] = 0;
|
||||
current.removeSlot(aiIndex, slot);
|
||||
db.entryChanged(current);
|
||||
}
|
||||
} else {
|
||||
ItemEntry key = db.lookupItem(stack, current, true);
|
||||
if (key != current) {
|
||||
slotItems[slot] = key;
|
||||
itemCounts[slot] = stack.stackSize;
|
||||
key.addSlot(aiIndex, slot);
|
||||
db.entryChanged(key);
|
||||
if (current != null) {
|
||||
current.removeSlot(aiIndex, slot);
|
||||
db.entryChanged(current);
|
||||
}
|
||||
} else if (itemCounts[slot] != stack.stackSize) {
|
||||
itemCounts[slot] = stack.stackSize;
|
||||
db.entryChanged(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateCount(InventoryDatabaseServer db, int slot, int aiIndex, ItemEntry entry, int count) {
|
||||
if (itemCounts[slot] != count) {
|
||||
itemCounts[slot] = count;
|
||||
if (count == 0) {
|
||||
slotItems[slot] = null;
|
||||
entry.removeSlot(aiIndex, slot);
|
||||
}
|
||||
db.entryChanged(entry);
|
||||
}
|
||||
}
|
||||
|
||||
abstract void scanInventory(InventoryDatabaseServer db, int aiIndex);
|
||||
|
||||
abstract int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int aiIndex, int count);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package crazypants.enderio.machine.invpanel.server;
|
||||
|
||||
public interface ChangeLog {
|
||||
|
||||
void entryChanged(ItemEntry entry);
|
||||
|
||||
void databaseReset();
|
||||
|
||||
void sendChangeLog();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package crazypants.enderio.machine.invpanel.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
final class ChangeLogList implements ChangeLog {
|
||||
final ArrayList<ChangeLog> clList;
|
||||
|
||||
public ChangeLogList(ChangeLog cl0, ChangeLog cl1) {
|
||||
clList = new ArrayList<ChangeLog>(2);
|
||||
clList.add(cl0);
|
||||
clList.add(cl1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entryChanged(ItemEntry entry) {
|
||||
for (ChangeLog cl : clList) {
|
||||
cl.entryChanged(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void databaseReset() {
|
||||
for (ChangeLog cl : clList) {
|
||||
cl.databaseReset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChangeLog() {
|
||||
for (ChangeLog cl : clList) {
|
||||
cl.sendChangeLog();
|
||||
}
|
||||
}
|
||||
|
||||
ChangeLog remove(ChangeLog cl) {
|
||||
clList.remove(cl);
|
||||
if (clList.size() == 1) {
|
||||
return clList.get(0);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void add(ChangeLog cl) {
|
||||
if (!clList.contains(cl)) {
|
||||
clList.add(cl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package crazypants.enderio.machine.invpanel.server;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
|
||||
class DSUInventory extends AbstractInventory {
|
||||
final IDeepStorageUnit dsu;
|
||||
|
||||
DSUInventory(IDeepStorageUnit dsu) {
|
||||
this.dsu = dsu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanInventory(InventoryDatabaseServer db, int aiIndex) {
|
||||
if (slotItems.length != 1) {
|
||||
reset(db, 1, aiIndex);
|
||||
}
|
||||
ItemStack stack = dsu.getStoredItemType();
|
||||
updateSlot(db, 0, aiIndex, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int aiIndex, int count) {
|
||||
if (slotItems.length != 1) {
|
||||
return 0;
|
||||
}
|
||||
ItemStack stack = dsu.getStoredItemType();
|
||||
if (db.lookupItem(stack, entry, false) != entry) {
|
||||
return 0;
|
||||
}
|
||||
int remaining = stack.stackSize;
|
||||
if (count > remaining) {
|
||||
count = remaining;
|
||||
}
|
||||
remaining -= count;
|
||||
dsu.setStoredItemCount(remaining);
|
||||
updateCount(db, slot, aiIndex, entry, remaining);
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
package crazypants.enderio.machine.invpanel.server;
|
||||
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.machine.invpanel.InventoryDatabase;
|
||||
import crazypants.enderio.network.CompressedDataInput;
|
||||
import crazypants.enderio.network.CompressedDataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
|
||||
public class InventoryDatabaseServer extends InventoryDatabase<ItemEntry> {
|
||||
|
||||
private AbstractInventory[] inventories;
|
||||
private int currentInventory;
|
||||
private ChangeLog changeLog;
|
||||
|
||||
public InventoryDatabaseServer() {
|
||||
}
|
||||
|
||||
public void addChangeLog(ChangeLog cl) {
|
||||
if(changeLog == null) {
|
||||
changeLog = cl;
|
||||
} else if(changeLog instanceof ChangeLogList) {
|
||||
((ChangeLogList)changeLog).add(cl);
|
||||
} else if(changeLog != cl) {
|
||||
changeLog = new ChangeLogList(changeLog, cl);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeChangeLog(ChangeLog cl) {
|
||||
if(changeLog == cl) {
|
||||
changeLog = null;
|
||||
} else if(changeLog instanceof ChangeLogList) {
|
||||
changeLog = ((ChangeLogList)changeLog).remove(cl);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemEntry> decompressMissingItems(byte[] compressed) throws IOException {
|
||||
CompressedDataInput cdi = new CompressedDataInput(compressed);
|
||||
try {
|
||||
int numIDs = cdi.readVariable();
|
||||
ArrayList<ItemEntry> items = new ArrayList<ItemEntry>(numIDs);
|
||||
for(int i = 0; i < numIDs; i++) {
|
||||
int dbIndex = cdi.readVariable();
|
||||
if(dbIndex < complexItems.size()) {
|
||||
ItemEntry entry = complexItems.get(dbIndex);
|
||||
items.add(entry);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
} finally {
|
||||
cdi.close();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] compressItemInfo(List<ItemEntry> items) throws IOException{
|
||||
CompressedDataOutput cdo = new CompressedDataOutput();
|
||||
try {
|
||||
int count = items.size();
|
||||
cdo.writeVariable(generation);
|
||||
cdo.writeVariable(count);
|
||||
for(ItemEntry entry : items) {
|
||||
assert entry.dbID >= COMPLEX_DBINDEX_START;
|
||||
int code = (entry.dbID - COMPLEX_DBINDEX_START) << 1;
|
||||
if(entry.nbt != null) {
|
||||
code |= 1;
|
||||
}
|
||||
cdo.writeVariable(code);
|
||||
cdo.writeVariable(entry.itemID);
|
||||
cdo.writeVariable(entry.meta);
|
||||
if(entry.nbt != null) {
|
||||
CompressedStreamTools.write(entry.nbt, cdo);
|
||||
}
|
||||
cdo.writeVariable(entry.countItems(this));
|
||||
}
|
||||
return cdo.getCompressed();
|
||||
} finally {
|
||||
cdo.close();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] compressItemList() throws IOException {
|
||||
CompressedDataOutput cdo = new CompressedDataOutput();
|
||||
try {
|
||||
cdo.writeVariable(generation);
|
||||
cdo.writeByte(0);
|
||||
for(Map.Entry<Integer, ItemEntry> entry : simpleRegsitry.entrySet()) {
|
||||
int count = entry.getValue().countItems(this);
|
||||
if(count > 0) {
|
||||
cdo.writeVariable(count);
|
||||
cdo.writeShort(entry.getKey());
|
||||
}
|
||||
}
|
||||
cdo.writeByte(0);
|
||||
int prevID = COMPLEX_DBINDEX_START;
|
||||
for(ItemEntry entry : complexItems) {
|
||||
if(entry != null) {
|
||||
int count = entry.countItems(this);
|
||||
if(count > 0) {
|
||||
cdo.writeVariable(count);
|
||||
cdo.writeVariable(entry.dbID - prevID);
|
||||
prevID = entry.dbID;
|
||||
}
|
||||
}
|
||||
}
|
||||
cdo.writeByte(0);
|
||||
return cdo.getCompressed();
|
||||
} finally {
|
||||
cdo.close();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] compressChangedItems(Collection<ItemEntry> items) throws IOException {
|
||||
CompressedDataOutput cdo = new CompressedDataOutput();
|
||||
try {
|
||||
cdo.writeVariable(generation);
|
||||
cdo.writeVariable(items.size());
|
||||
for(ItemEntry entry : items) {
|
||||
cdo.writeVariable(entry.dbID);
|
||||
cdo.writeVariable(entry.countItems(this));
|
||||
}
|
||||
return cdo.getCompressed();
|
||||
} finally {
|
||||
cdo.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setNetworkSources(List<NetworkedInventory> sources) {
|
||||
simpleRegsitry.clear();
|
||||
complexRegistry.clear();
|
||||
complexItems.clear();
|
||||
generation++;
|
||||
currentInventory = 0;
|
||||
|
||||
if(sources == null || sources.isEmpty()) {
|
||||
this.inventories = null;
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(changeLog != null) {
|
||||
changeLog.databaseReset();
|
||||
}
|
||||
}
|
||||
|
||||
public void scanNextInventory() {
|
||||
if(inventories == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractInventory inv = inventories[currentInventory];
|
||||
inv.scanInventory(this, currentInventory);
|
||||
|
||||
currentInventory = (currentInventory+1) % inventories.length;
|
||||
}
|
||||
|
||||
void entryChanged(ItemEntry entry) {
|
||||
if(changeLog != null) {
|
||||
changeLog.entryChanged(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendChangeLogs() {
|
||||
if(changeLog != null) {
|
||||
changeLog.sendChangeLog();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemEntry createItemEntry(int dbId, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
return new ItemEntry(dbId, hash, itemID, meta, nbt);
|
||||
}
|
||||
|
||||
AbstractInventory getInventory(int aiIndex) {
|
||||
return inventories[aiIndex];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package crazypants.enderio.machine.invpanel.server;
|
||||
|
||||
import crazypants.enderio.machine.invpanel.ItemEntryBase;
|
||||
import java.util.HashSet;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemEntry extends ItemEntryBase {
|
||||
private final HashSet<Integer> slots = new HashSet<Integer>();
|
||||
|
||||
public ItemEntry(int dbID, int hash, int itemID, int meta, NBTTagCompound nbt) {
|
||||
super(dbID, hash, itemID, meta, nbt);
|
||||
}
|
||||
|
||||
static int encodeAISlot(int aiIndex, int slot) {
|
||||
return (aiIndex << 12) | slot;
|
||||
}
|
||||
|
||||
void addSlot(int aiIndex, int slot) {
|
||||
slots.add(encodeAISlot(aiIndex, slot));
|
||||
}
|
||||
|
||||
void removeSlot(int aiIndex, int slot) {
|
||||
slots.remove(encodeAISlot(aiIndex, slot));
|
||||
}
|
||||
|
||||
int countItems(InventoryDatabaseServer db) {
|
||||
int count = 0;
|
||||
for (Integer idx : slots) {
|
||||
AbstractInventory key = db.getInventory(idx >> 12);
|
||||
count += key.itemCounts[idx & 4095];
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public int extractItems(InventoryDatabaseServer db, int count) {
|
||||
int extracted = 0;
|
||||
Integer[] copy = slots.toArray(new Integer[slots.size()]);
|
||||
for (Integer idx : copy) {
|
||||
int aiIndex = idx >> 12;
|
||||
int slotIndex = idx & 4095;
|
||||
AbstractInventory key = db.getInventory(aiIndex);
|
||||
int amount = key.extractItem(db, this, slotIndex, aiIndex, count);
|
||||
count -= amount;
|
||||
extracted += amount;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package crazypants.enderio.machine.invpanel.server;
|
||||
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
class NormalInventory extends AbstractInventory {
|
||||
final NetworkedInventory ni;
|
||||
|
||||
NormalInventory(NetworkedInventory ni) {
|
||||
this.ni = ni;
|
||||
}
|
||||
|
||||
@Override
|
||||
void scanInventory(InventoryDatabaseServer db, int aiIndex) {
|
||||
ISidedInventory inv = ni.getInventoryRecheck();
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if (slotIndices == null || slotIndices.length == 0) {
|
||||
setEmpty(db, aiIndex);
|
||||
return;
|
||||
}
|
||||
int count = slotIndices.length;
|
||||
if (count != slotItems.length) {
|
||||
reset(db, count, aiIndex);
|
||||
}
|
||||
for (int slot = 0; slot < count; slot++) {
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if (stack != null && !inv.canExtractItem(invSlot, stack, side)) {
|
||||
stack = null;
|
||||
}
|
||||
updateSlot(db, slot, aiIndex, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int aiIndex, int count) {
|
||||
ISidedInventory inv = ni.getInventoryRecheck();
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if (slotIndices == null || slot >= slotIndices.length) {
|
||||
return 0;
|
||||
}
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if (stack == null || !inv.canExtractItem(invSlot, stack, side)) {
|
||||
return 0;
|
||||
}
|
||||
if (db.lookupItem(stack, entry, false) != entry) {
|
||||
return 0;
|
||||
}
|
||||
int remaining = stack.stackSize;
|
||||
if (count > remaining) {
|
||||
count = remaining;
|
||||
}
|
||||
ni.itemExtracted(invSlot, count);
|
||||
remaining -= count;
|
||||
updateCount(db, slot, aiIndex, entry, remaining);
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.conduit.gas.GasUtil;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.invpanel.GuiInventoryPanel;
|
||||
import crazypants.enderio.machine.invpanel.InventoryPanelNEIOverlayHandler;
|
||||
import crazypants.enderio.machine.invpanel.client.InventoryPanelNEIOverlayHandler;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
|
||||
public class NEIEnderIOConfig implements IConfigureNEI {
|
||||
|
||||
Reference in new issue
Block a user