mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 05:02:25 +00:00
#517 Item conduit filters fail when more than one conduit ends at one chest
This commit is contained in:
1 parent
7e958a1a3b
commit
cb2cd58040
2 files changed
+80
-38
No files matched your search
@@ -32,7 +32,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
private long timeAtLastApply;
|
||||
|
||||
private final List<NetworkedInventory> inventories = new ArrayList<ItemConduitNetwork.NetworkedInventory>();
|
||||
private final Map<BlockCoord, NetworkedInventory> invMap = new HashMap<BlockCoord, ItemConduitNetwork.NetworkedInventory>();
|
||||
private final Map<BlockCoord, List<NetworkedInventory>> invMap = new HashMap<BlockCoord, List<ItemConduitNetwork.NetworkedInventory>>();
|
||||
|
||||
private final Map<BlockCoord, IItemConduit> conMap = new HashMap<BlockCoord, IItemConduit>();
|
||||
|
||||
@@ -69,17 +69,35 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
BlockCoord bc = new BlockCoord(x, y, z);
|
||||
NetworkedInventory inv = new NetworkedInventory(externalInventory, itemConduit, direction, bc);
|
||||
inventories.add(inv);
|
||||
invMap.put(bc, inv);
|
||||
getOrCreate(bc).add(inv);
|
||||
requiresSort = true;
|
||||
}
|
||||
|
||||
private List<NetworkedInventory> getOrCreate(BlockCoord bc) {
|
||||
List<NetworkedInventory> res = invMap.get(bc);
|
||||
if(res == null) {
|
||||
res = new ArrayList<ItemConduitNetwork.NetworkedInventory>();
|
||||
invMap.put(bc, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public void inventoryRemoved(ItemConduit itemConduit, int x, int y, int z) {
|
||||
BlockCoord bc = new BlockCoord(x, y, z);
|
||||
NetworkedInventory inv = invMap.remove(bc);
|
||||
if(inv != null) {
|
||||
inventories.remove(inv);
|
||||
List<NetworkedInventory> invs = getOrCreate(bc);
|
||||
NetworkedInventory remove = null;
|
||||
for (NetworkedInventory ni : invs) {
|
||||
if(ni.con.getLocation().equals(itemConduit.getLocation())) {
|
||||
remove = ni;
|
||||
break;
|
||||
}
|
||||
}
|
||||
requiresSort = true;
|
||||
if(remove != null) {
|
||||
invs.remove(remove);
|
||||
inventories.remove(remove);
|
||||
requiresSort = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void routesChanged() {
|
||||
@@ -87,43 +105,56 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
}
|
||||
|
||||
public ItemStack sendItems(ItemConduit itemConduit, ItemStack item, ForgeDirection side) {
|
||||
BlockCoord loc = itemConduit.getLocation().getLocation(side);
|
||||
NetworkedInventory inv = invMap.get(loc);
|
||||
if(inv == null || item == null) {
|
||||
if(item == null) {
|
||||
return item;
|
||||
}
|
||||
|
||||
int numInserted = inv.insertIntoTargets(item.copy());
|
||||
if(numInserted >= item.stackSize) {
|
||||
//TODO: I was returning null here as per the API but quarries plus
|
||||
//was interpreting this as nothing being taken
|
||||
ItemStack result = item.copy();
|
||||
result.stackSize = 0;
|
||||
return result;
|
||||
BlockCoord loc = itemConduit.getLocation().getLocation(side);
|
||||
|
||||
ItemStack result = null;
|
||||
List<NetworkedInventory> invs = getOrCreate(loc);
|
||||
for (NetworkedInventory inv : invs) {
|
||||
|
||||
if(inv.con.getLocation().equals(loc)) {
|
||||
|
||||
int numInserted = inv.insertIntoTargets(item.copy());
|
||||
if(numInserted >= item.stackSize) {
|
||||
//TODO: I was returning null here as per the API but quarries plus
|
||||
//was interpreting this as nothing being taken
|
||||
result = item.copy();
|
||||
result.stackSize = 0;
|
||||
return result;
|
||||
}
|
||||
if(result == null) {
|
||||
result = item.copy();
|
||||
}
|
||||
result.stackSize -= numInserted;
|
||||
}
|
||||
}
|
||||
ItemStack result = item.copy();
|
||||
result.stackSize -= numInserted;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> getTargetsForExtraction(BlockCoord extractFrom, ItemStack input) {
|
||||
public List<String> getTargetsForExtraction(BlockCoord extractFrom, IItemConduit con, ItemStack input) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
NetworkedInventory source = invMap.get(extractFrom);
|
||||
if(source == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if(source.sendPriority == null) {
|
||||
return result;
|
||||
}
|
||||
List<NetworkedInventory> invs = getOrCreate(extractFrom);
|
||||
for (NetworkedInventory source : invs) {
|
||||
|
||||
for (Target t : source.sendPriority) {
|
||||
ItemFilter f = t.inv.con.getOutputFilter(t.inv.conDir);
|
||||
if(input == null || f == null || f.doesItemPassFilter(input)) {
|
||||
String s = "[" + t.distance + "] " + Lang.localize(t.inv.inv.getInvName(), false);
|
||||
result.add(s);
|
||||
if(source.con.getLocation().equals(con.getLocation())) {
|
||||
if(source != null && source.sendPriority != null) {
|
||||
|
||||
for (Target t : source.sendPriority) {
|
||||
ItemFilter f = t.inv.con.getOutputFilter(t.inv.conDir);
|
||||
if(input == null || f == null || f.doesItemPassFilter(input)) {
|
||||
String s = Lang.localize(t.inv.inv.getInvName(), false) + " " + t.inv.location + " Distance [" + t.distance + "] ";
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -411,7 +442,8 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
return;
|
||||
}
|
||||
|
||||
Map<BlockCoord, Target> result = new HashMap<BlockCoord, Target>();
|
||||
//Map<BlockCoord, Target> result = new HashMap<BlockCoord, Target>();
|
||||
List<Target> result = new ArrayList<ItemConduitNetwork.NetworkedInventory.Target>();
|
||||
|
||||
for (NetworkedInventory other : inventories) {
|
||||
if((con.isSelfFeedEnabled(conDir) || (other != this))
|
||||
@@ -421,7 +453,8 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
if(Config.itemConduitUsePhyscialDistance) {
|
||||
sendPriority.add(new Target(other, distanceTo(other), other.isSticky()));
|
||||
} else {
|
||||
result.put(other.location, new Target(other, 9999999, other.isSticky()));
|
||||
//result.put(other.location, new Target(other, 9999999, other.isSticky()));
|
||||
result.add(new Target(other, 9999999, other.isSticky()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,7 +468,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
steps.add(con.getLocation());
|
||||
calculateDistances(result, visited, steps, 0);
|
||||
|
||||
sendPriority.addAll(result.values());
|
||||
sendPriority.addAll(result);
|
||||
|
||||
Collections.sort(sendPriority);
|
||||
}
|
||||
@@ -443,7 +476,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
|
||||
}
|
||||
|
||||
private void calculateDistances(Map<BlockCoord, Target> result, Map<BlockCoord, Integer> visited, List<BlockCoord> steps, int distance) {
|
||||
private void calculateDistances(List<Target> targets, Map<BlockCoord, Integer> visited, List<BlockCoord> steps, int distance) {
|
||||
if(steps == null || steps.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -453,7 +486,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
IItemConduit con = conMap.get(bc);
|
||||
if(con != null) {
|
||||
for (ForgeDirection dir : con.getExternalConnections()) {
|
||||
Target target = result.get(bc.getLocation(dir));
|
||||
Target target = getTarget(targets, con, dir);
|
||||
if(target != null && target.distance > distance) {
|
||||
target.distance = distance;
|
||||
}
|
||||
@@ -474,7 +507,16 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
}
|
||||
}
|
||||
}
|
||||
calculateDistances(result, visited, nextSteps, distance + 1);
|
||||
calculateDistances(targets, visited, nextSteps, distance + 1);
|
||||
}
|
||||
|
||||
private Target getTarget(List<Target> targets, IItemConduit con, ForgeDirection dir) {
|
||||
for (Target target : targets) {
|
||||
if(target.inv.conDir == dir && target.inv.con.getLocation().equals(con.getLocation())) {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int distanceTo(NetworkedInventory other) {
|
||||
|
||||
@@ -230,7 +230,7 @@ public class MJReaderPacketHandler implements IPacketProcessor {
|
||||
sb.append(input.getDisplayName());
|
||||
}
|
||||
sb.append(" ");
|
||||
List<String> targets = icn.getTargetsForExtraction(conduit.getLocation().getLocation(dir), input);
|
||||
List<String> targets = icn.getTargetsForExtraction(conduit.getLocation().getLocation(dir), conduit, input);
|
||||
if(targets.isEmpty()) {
|
||||
sb.append(" ");
|
||||
sb.append(Lang.localize("gui.mjReader.noOutputs"));
|
||||
|
||||
Reference in new issue
Block a user