mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
some more fixes and cleanup
This commit is contained in:
parent
87d983611e
commit
27954a9765
4 changed files with 25 additions and 23 deletions
|
@ -213,15 +213,27 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
|
||||||
public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe, BlockPos destInventory, ItemStack stack, ItemEqualityType... equalityTypes) {
|
public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe, BlockPos destInventory, ItemStack stack, ItemEqualityType... equalityTypes) {
|
||||||
if (location.getPos().equals(destInventory))
|
if (location.getPos().equals(destInventory))
|
||||||
return stack;
|
return stack;
|
||||||
|
// make sure we don't pull any locked items
|
||||||
|
int amount = location.getItemAmount(this.world, stack, equalityTypes);
|
||||||
|
if (amount <= 0)
|
||||||
|
return stack;
|
||||||
|
// we ignore locks on the destination inventory, since we're probably the ones trying to solve those locks
|
||||||
|
amount -= this.getLockedAmount(location.getPos(), stack, destInventory, equalityTypes);
|
||||||
|
if (amount <= 0)
|
||||||
|
return stack;
|
||||||
ItemStack remain = stack.copy();
|
ItemStack remain = stack.copy();
|
||||||
|
// make sure we only extract less than or equal to the requested amount
|
||||||
|
if (remain.getCount() < amount)
|
||||||
|
amount = remain.getCount();
|
||||||
|
remain.shrink(amount);
|
||||||
for (int slot : location.getStackSlots(this.world, stack, equalityTypes)) {
|
for (int slot : location.getStackSlots(this.world, stack, equalityTypes)) {
|
||||||
// try to extract from that location's inventory and send the item
|
// try to extract from that location's inventory and send the item
|
||||||
IItemHandler handler = location.getItemHandler(this.world);
|
IItemHandler handler = location.getItemHandler(this.world);
|
||||||
ItemStack extracted = handler.extractItem(slot, remain.getCount(), true);
|
ItemStack extracted = handler.extractItem(slot, amount, true);
|
||||||
if (this.routeItemToLocation(location.pipePos, location.getPos(), destPipe, destInventory, extracted, speed -> new PipeItem(extracted, speed))) {
|
if (this.routeItemToLocation(location.pipePos, location.getPos(), destPipe, destInventory, extracted, speed -> new PipeItem(extracted, speed))) {
|
||||||
handler.extractItem(slot, extracted.getCount(), false);
|
handler.extractItem(slot, extracted.getCount(), false);
|
||||||
remain.shrink(extracted.getCount());
|
amount -= extracted.getCount();
|
||||||
if (remain.isEmpty())
|
if (amount <= 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,9 +307,9 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
|
||||||
return this.networkLocks.get(pos);
|
return this.networkLocks.get(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLockedAmount(BlockPos pos, ItemStack stack, ItemEqualityType... equalityTypes) {
|
public int getLockedAmount(BlockPos pos, ItemStack stack, BlockPos ignoredLock, ItemEqualityType... equalityTypes) {
|
||||||
return this.getNetworkLocks(pos).stream()
|
return this.getNetworkLocks(pos).stream()
|
||||||
.filter(l -> ItemEqualityType.compareItems(l.stack, stack, equalityTypes))
|
.filter(l -> ItemEqualityType.compareItems(l.stack, stack, equalityTypes) && (ignoredLock == null || !ignoredLock.equals(l.location.getPos())))
|
||||||
.mapToInt(l -> l.stack.getCount()).sum();
|
.mapToInt(l -> l.stack.getCount()).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,23 +100,13 @@ public class CraftingModuleItem extends ModuleItem {
|
||||||
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
||||||
ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||||
for (Triple<BlockPos, BlockPos, ItemStack> request : tile.craftResultRequests) {
|
for (Triple<BlockPos, BlockPos, ItemStack> request : tile.craftResultRequests) {
|
||||||
ItemStack reqItem = request.getRight();
|
ItemStack remain = request.getRight().copy();
|
||||||
for (NetworkLocation item : items) {
|
for (NetworkLocation item : items) {
|
||||||
int amount = item.getItemAmount(tile.getWorld(), reqItem, equalityTypes);
|
remain = network.requestExistingItem(item, request.getLeft(), request.getMiddle(), remain, equalityTypes);
|
||||||
amount -= network.getLockedAmount(item.getPos(), reqItem, equalityTypes);
|
if (remain.isEmpty())
|
||||||
if (amount <= 0)
|
break;
|
||||||
continue;
|
|
||||||
ItemStack remain = reqItem.copy();
|
|
||||||
if (remain.getCount() < amount)
|
|
||||||
amount = remain.getCount();
|
|
||||||
remain.shrink(amount);
|
|
||||||
while (amount > 0) {
|
|
||||||
ItemStack copy = reqItem.copy();
|
|
||||||
copy.setCount(Math.min(reqItem.getMaxStackSize(), amount));
|
|
||||||
// we don't need to do any checks here because we just calculated the max amount we can definitely extract
|
|
||||||
network.requestExistingItem(item, request.getLeft(), request.getMiddle(), copy, equalityTypes);
|
|
||||||
amount -= copy.getCount();
|
|
||||||
}
|
}
|
||||||
|
if (remain.getCount() != request.getRight().getCount()) {
|
||||||
tile.craftResultRequests.remove(request);
|
tile.craftResultRequests.remove(request);
|
||||||
// if we couldn't pull everything, log a new request
|
// if we couldn't pull everything, log a new request
|
||||||
if (!remain.isEmpty())
|
if (!remain.isEmpty())
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
||||||
int amount = location.getItemAmount(world, stack.stack, equalityTypes);
|
int amount = location.getItemAmount(world, stack.stack, equalityTypes);
|
||||||
if (amount <= 0)
|
if (amount <= 0)
|
||||||
continue;
|
continue;
|
||||||
amount -= network.getLockedAmount(location.getPos(), stack.stack, equalityTypes);
|
amount -= network.getLockedAmount(location.getPos(), stack.stack, null, equalityTypes);
|
||||||
available += amount;
|
available += amount;
|
||||||
}
|
}
|
||||||
// divide the total by the amount required to get the amount that
|
// divide the total by the amount required to get the amount that
|
||||||
|
|
|
@ -221,7 +221,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
int amount = location.getItemAmount(world, stack, ItemEqualityType.NBT);
|
int amount = location.getItemAmount(world, stack, ItemEqualityType.NBT);
|
||||||
if (amount <= 0)
|
if (amount <= 0)
|
||||||
continue;
|
continue;
|
||||||
amount -= network.getLockedAmount(location.getPos(), stack, ItemEqualityType.NBT);
|
amount -= network.getLockedAmount(location.getPos(), stack, destInventory, ItemEqualityType.NBT);
|
||||||
if (amount > 0) {
|
if (amount > 0) {
|
||||||
if (remain.getCount() < amount)
|
if (remain.getCount() < amount)
|
||||||
amount = remain.getCount();
|
amount = remain.getCount();
|
||||||
|
|
Loading…
Reference in a new issue