From b2269210fc0f66ec6876b56cefc64818ccd4c2a7 Mon Sep 17 00:00:00 2001 From: Ramid Khan Date: Sun, 11 Dec 2022 17:30:17 +1100 Subject: [PATCH] Allow corporea to work through secured networks --- .../ae2/ManaGenericStackInvStorage.java | 2 +- .../java/appbot/botania/MECorporeaNode.java | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/appbot/ae2/ManaGenericStackInvStorage.java b/src/main/java/appbot/ae2/ManaGenericStackInvStorage.java index 9362844..69648ac 100644 --- a/src/main/java/appbot/ae2/ManaGenericStackInvStorage.java +++ b/src/main/java/appbot/ae2/ManaGenericStackInvStorage.java @@ -76,7 +76,7 @@ public boolean isOutputtingPower() { public int getMaxMana() { var slots = 0; - for (int i = 0; i < inv.size(); i++) { + for (var i = 0; i < inv.size(); i++) { var key = inv.getKey(i); if (key == null || key == ManaKey.KEY) { diff --git a/src/main/java/appbot/botania/MECorporeaNode.java b/src/main/java/appbot/botania/MECorporeaNode.java index fc0ca4c..d183ee2 100644 --- a/src/main/java/appbot/botania/MECorporeaNode.java +++ b/src/main/java/appbot/botania/MECorporeaNode.java @@ -9,6 +9,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -25,13 +26,11 @@ public class MECorporeaNode extends AbstractCorporeaNode { - private final MEStorage storage; - private final IActionSource source; + private final IStorageMonitorableAccessor accessor; - public MECorporeaNode(Level level, BlockPos pos, CorporeaSpark spark, MEStorage storage, IActionSource source) { + public MECorporeaNode(Level level, BlockPos pos, CorporeaSpark spark, IStorageMonitorableAccessor accessor) { super(level, pos, spark); - this.storage = storage; - this.source = source; + this.accessor = accessor; } @Nullable @@ -39,11 +38,10 @@ public static CorporeaNode getNode(Level level, CorporeaSpark spark) { var accessor = IStorageMonitorableAccessor.SIDED.find(level, spark.getAttachPos(), Direction.UP); if (accessor != null) { - var source = IActionSource.empty(); - var storage = accessor.getInventory(source); + var storage = accessor.getInventory(IActionSource.empty()); if (storage != null) { - return new MECorporeaNode(level, spark.getAttachPos(), spark, storage, source); + return new MECorporeaNode(level, spark.getAttachPos(), spark, accessor); } } @@ -62,6 +60,18 @@ public List extractItems(CorporeaRequest request) { protected List work(CorporeaRequest request, boolean execute) { var list = new ArrayList(); + MEStorage storage; + IActionSource source; + + if (request.getEntity()instanceof Player player) { + storage = accessor.getInventory(source = IActionSource.ofPlayer(player)); + } else { + storage = accessor.getInventory(source = IActionSource.empty()); + } + + if (storage == null) { + return list; + } for (var entry : storage.getAvailableStacks()) { var amount = Ints.saturatedCast(entry.getLongValue());