From b8563aa703663cd9029c7e90c3d09cd36ccf64ab Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Thu, 26 Jan 2023 21:11:47 +0100 Subject: [PATCH] feat: LogisticsPipes crafting integration reference issue: #8 --- .../integration/modules/LogisticsPipes.java | 27 ++++++++++++++++--- .../appeng/me/cache/RequestGridCache.java | 18 ++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main/java/appeng/integration/modules/LogisticsPipes.java b/src/main/java/appeng/integration/modules/LogisticsPipes.java index 66d10c79..b6438cdd 100644 --- a/src/main/java/appeng/integration/modules/LogisticsPipes.java +++ b/src/main/java/appeng/integration/modules/LogisticsPipes.java @@ -84,12 +84,25 @@ public class LogisticsPipes implements ILogisticsPipes, IIntegrationModule { Map stacks = new HashMap<>(); for(ItemStack s : api.getProvidedItems()) { IAEItemStack stack = AEItemStack.create(s); + int stacksize = s.stackSize; + stack.reset(); + stack.setCountRequestable(stacksize); if (stacks.containsKey(stack)) { - stacks.get(stack).incStackSize(stack.getStackSize()); + stacks.get(stack).incCountRequestable(stack.getCountRequestable()); } else { stacks.put(stack, stack); } } + for(ItemStack s : api.getCraftedItems()) { + IAEItemStack stack = AEItemStack.create(s); + stack.reset(); + if (stacks.containsKey(stack)) { + stacks.get(stack).setCraftable(true); + } else { + stack.setCraftable(true); + stacks.put(stack, stack); + } + } return stacks.keySet(); } return new HashSet<>(); @@ -104,15 +117,21 @@ public class LogisticsPipes implements ILogisticsPipes, IIntegrationModule { if (res.missing.isEmpty()) { return null; } else { - return AEItemStack.create(res.missing.get(0)); + ItemStack m = res.missing.get(0); + if (request.equals(m)) { + return AEItemStack.create(res.missing.get(0)); + } else { + return request; + } } } else { List returned = api.performRequest(request.getItemStack()); if (returned.isEmpty()) { return null; } else { - int missing = returned.get(0).stackSize; - if (missing > 0) { + ItemStack m = returned.get(0); + int missing = m.stackSize; + if (missing > 0 && request.equals(m)) { IAEItemStack newRequest = request.copy(); newRequest.decStackSize(missing); // LP should still request the items, which are available diff --git a/src/main/java/appeng/me/cache/RequestGridCache.java b/src/main/java/appeng/me/cache/RequestGridCache.java index c87a08ba..25476c29 100644 --- a/src/main/java/appeng/me/cache/RequestGridCache.java +++ b/src/main/java/appeng/me/cache/RequestGridCache.java @@ -93,9 +93,12 @@ public class RequestGridCache if (requestable.containsKey(stack)) { Requestable r = requestable.get(stack); r.addProvider(provider); - r.increaseAmount(stack.getStackSize()); + r.increaseAmount(stack.getCountRequestable()); + if (stack.isCraftable()) { + r.setCraftable(); + } } else { - Requestable r = new Requestable(stack.getStackSize()); + Requestable r = new Requestable(stack); r.addProvider(provider); requestable.put(stack, r); } @@ -151,6 +154,7 @@ public class RequestGridCache stack.reset(); Requestable r = requestable.get(s); stack.setCountRequestable(r.amount); + stack.setCraftable(r.craftable); out.add(stack); } return out; @@ -212,10 +216,12 @@ public class RequestGridCache static class Requestable { public Set providers; public long amount; + public boolean craftable; - public Requestable(long amount) { + public Requestable(IAEItemStack stack) { this.providers = new HashSet<>(); - this.amount = amount; + this.amount = stack.getCountRequestable(); + this.craftable = stack.isCraftable(); } public void addProvider(IRequestProvider provider) { @@ -225,5 +231,9 @@ public class RequestGridCache public void increaseAmount(long amount) { this.amount += amount; } + + public void setCraftable() { + this.craftable = true; + } } }