Skip to content

Commit

Permalink
Allow corporea to work through secured networks
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Dec 11, 2022
1 parent f1b4c10 commit b226921
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/appbot/ae2/ManaGenericStackInvStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/appbot/botania/MECorporeaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,25 +26,22 @@

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
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);
}
}

Expand All @@ -62,6 +60,18 @@ public List<ItemStack> extractItems(CorporeaRequest request) {

protected List<ItemStack> work(CorporeaRequest request, boolean execute) {
var list = new ArrayList<ItemStack>();
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());
Expand Down

0 comments on commit b226921

Please sign in to comment.