-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
646fa1b
commit 5003769
Showing
28 changed files
with
412 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
* Make interfaces use names from attached containers as fallback | ||
* Make interfaces use names from attached containers as fallback | ||
* Add interface groups | ||
* They allow you to interact with multiple interfaces as one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/io/github/mattidragon/advancednetworking/graph/node/base/CapacityNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.github.mattidragon.advancednetworking.graph.node.base; | ||
|
||
import com.mojang.datafixers.util.Either; | ||
import io.github.mattidragon.advancednetworking.graph.NetworkControllerContext; | ||
import io.github.mattidragon.nodeflow.graph.Connector; | ||
import io.github.mattidragon.nodeflow.graph.Graph; | ||
import io.github.mattidragon.nodeflow.graph.context.ContextType; | ||
import io.github.mattidragon.nodeflow.graph.data.DataType; | ||
import io.github.mattidragon.nodeflow.graph.data.DataValue; | ||
import io.github.mattidragon.nodeflow.graph.node.NodeType; | ||
import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.Storage; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.TransferVariant; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.math.Direction; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.StreamSupport; | ||
|
||
public class CapacityNode<R, V extends TransferVariant<R>> extends InterfaceNode { | ||
private final BlockApiLookup<Storage<V>, @Nullable Direction> lookup; | ||
|
||
public CapacityNode(NodeType<?> type, Graph graph, BlockApiLookup<Storage<V>, @Nullable Direction> lookup) { | ||
super(type, List.of(NetworkControllerContext.TYPE, ContextType.SERVER_WORLD), graph); | ||
this.lookup = lookup; | ||
} | ||
|
||
@Override | ||
public Connector<?>[] getOutputs() { | ||
return new Connector[] { DataType.NUMBER.makeRequiredOutput("capacity", this) }; | ||
} | ||
|
||
@Override | ||
public Connector<?>[] getInputs() { | ||
return new Connector[0]; | ||
} | ||
|
||
@Override | ||
protected Either<DataValue<?>[], Text> process(DataValue<?>[] inputs, ContextProvider context) { | ||
var controller = context.get(NetworkControllerContext.TYPE); | ||
var world = context.get(ContextType.SERVER_WORLD); | ||
var positions = findInterfaces(world, controller.graphId()); | ||
|
||
var capacity = positions.stream() | ||
.map(sidePos -> { | ||
var pos = sidePos.pos(); | ||
var side = sidePos.side(); | ||
return lookup.find(world, pos.offset(side), side.getOpposite()); | ||
}) | ||
.filter(Objects::nonNull) | ||
.flatMap(storage -> StreamSupport.stream(storage.spliterator(), false)) | ||
.mapToLong(StorageView::getCapacity) | ||
.sum(); | ||
|
||
return Either.left(new DataValue<?>[] { DataType.NUMBER.makeValue((double) capacity) }); | ||
} | ||
} |
Oops, something went wrong.