Skip to content

Commit

Permalink
Make capacity nodes use the correct type and add check to prevent thi…
Browse files Browse the repository at this point in the history
…s issue in the future
  • Loading branch information
MattiDragon committed Aug 7, 2024
1 parent 7e0fe70 commit 36372c7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/4.0.1+1.21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fixed issue where capacity nodes where unusable
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
import io.github.mattidragon.advancednetworking.graph.node.redstone.ReadRedstoneNode;
import io.github.mattidragon.advancednetworking.graph.node.redstone.SetRedstoneNode;
import io.github.mattidragon.advancednetworking.graph.node.redstone.WriteRedstoneNode;
import io.github.mattidragon.nodeflow.graph.Graph;
import io.github.mattidragon.nodeflow.graph.GraphEnvironment;
import io.github.mattidragon.nodeflow.graph.data.DataType;
import io.github.mattidragon.nodeflow.graph.node.NodeType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.registry.tag.TagKey;

import static io.github.mattidragon.advancednetworking.AdvancedNetworking.id;
Expand Down Expand Up @@ -105,5 +109,29 @@ public static void register() {
NodeType.register(FLUID_COUNT, id("fluid_count"));
NodeType.register(FLUID_CAPACITY, id("fluid_capacity"));
NodeType.register(EMPTY_FLUID_STREAM, id("empty_fluid_stream"));

verifyNodeTypes();
}

public static void verifyNodeTypes() {
// Only check in dev in case some other mod does something stupid
if (!FabricLoader.getInstance().isDevelopmentEnvironment()) return;

RuntimeException combined = null;
var graph = new Graph(GraphEnvironment.builder().addDataTypes(DataType.BOOLEAN).build());
for (var expectedType : NodeType.REGISTRY) {
var actualType = expectedType.generator().apply(graph).type;
if (actualType != expectedType) {
var e = new IllegalStateException("Node type %s produced node with type %s. This is a bug!".formatted(expectedType, actualType));
if (combined == null) {
combined = e;
} else {
combined.addSuppressed(e);
}
}
}
if (combined != null) {
throw combined;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

public class FluidCapacityNode extends CapacityNode<Fluid, FluidVariant> {
public FluidCapacityNode(Graph graph) {
super(ModNodeTypes.FLUID_COUNT, graph, FluidStorage.SIDED);
super(ModNodeTypes.FLUID_CAPACITY, graph, FluidStorage.SIDED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

public class ItemCapacityNode extends CapacityNode<Item, ItemVariant> {
public ItemCapacityNode(Graph graph) {
super(ModNodeTypes.ITEM_COUNT, graph, ItemStorage.SIDED);
super(ModNodeTypes.ITEM_CAPACITY, graph, ItemStorage.SIDED);
}
}

0 comments on commit 36372c7

Please sign in to comment.