diff --git a/src/main/java/turniplabs/halplibe/helper/BlockHelper.java b/src/main/java/turniplabs/halplibe/helper/BlockHelper.java index 729ebc7..613a830 100644 --- a/src/main/java/turniplabs/halplibe/helper/BlockHelper.java +++ b/src/main/java/turniplabs/halplibe/helper/BlockHelper.java @@ -56,18 +56,20 @@ public static int findLength(int id, int terminate) { /** * Allows halplibe to automatically figure out where to insert the runs + * @param modid an identifier for the mod, can be anything, but should be something the user can identify * @param runs a toml object representing configured registry runs * @param neededIds the number of needed ids * if this changes after the mod has been configured (i.e. mod updated and now has more blocks) it'll find new, valid runs to put those blocks into * @param function the function to run for registering items */ - public static void reserveRuns(Toml runs, int neededIds, Consumer function) { + public static void reserveRuns(String modid, Toml runs, int neededIds, Consumer function) { RunLengthConfig cfg = new RunLengthConfig(runs, neededIds); cfg.register(reserves); RegistryHelper.scheduleSmartRegistry( () -> { - IdSupplier supplier = new IdSupplier(reserves, cfg, neededIds); + IdSupplier supplier = new IdSupplier(modid, reserves, cfg, neededIds); function.accept(supplier); + supplier.validate(); } ); } diff --git a/src/main/java/turniplabs/halplibe/helper/ItemHelper.java b/src/main/java/turniplabs/halplibe/helper/ItemHelper.java index e733a5f..83b2f06 100644 --- a/src/main/java/turniplabs/halplibe/helper/ItemHelper.java +++ b/src/main/java/turniplabs/halplibe/helper/ItemHelper.java @@ -57,18 +57,20 @@ public static int findLength(int id, int terminate) { /** * Allows halplibe to automatically figure out where to insert the runs + * @param modid an identifier for the mod, can be anything, but should be something the user can identify * @param runs a toml object representing configured registry runs * @param neededIds the number of needed ids * if this changes after the mod has been configured (i.e. mod updated and now has more items) it'll find new, valid runs to put those items into * @param function the function to run for registering items */ - public static void reserveRuns(Toml runs, int neededIds, Consumer function) { + public static void reserveRuns(String modid, Toml runs, int neededIds, Consumer function) { RunLengthConfig cfg = new RunLengthConfig(runs, neededIds); cfg.register(reserves); RegistryHelper.scheduleSmartRegistry( () -> { - IdSupplier supplier = new IdSupplier(reserves, cfg, neededIds); + IdSupplier supplier = new IdSupplier(modid, reserves, cfg, neededIds); function.accept(supplier); + supplier.validate(); } ); } diff --git a/src/main/java/turniplabs/halplibe/util/registry/IdSupplier.java b/src/main/java/turniplabs/halplibe/util/registry/IdSupplier.java index 50e0005..435b86e 100644 --- a/src/main/java/turniplabs/halplibe/util/registry/IdSupplier.java +++ b/src/main/java/turniplabs/halplibe/util/registry/IdSupplier.java @@ -1,11 +1,13 @@ package turniplabs.halplibe.util.registry; -import turniplabs.halplibe.util.registry.error.RequestOutOfBounds; +import turniplabs.halplibe.util.registry.error.RequestCutShortException; +import turniplabs.halplibe.util.registry.error.RequestOutOfBoundsException; import java.util.ArrayList; import java.util.List; public class IdSupplier { + String modid; RunReserves reserves; RunLengthConfig cfg; int max; @@ -15,7 +17,8 @@ public class IdSupplier { /* if this is true, the reservations will get optimized when being written */ boolean hasUnreserved = false; - public IdSupplier(RunReserves reserves, RunLengthConfig cfg, int max) { + public IdSupplier(String modid, RunReserves reserves, RunLengthConfig cfg, int max) { + this.modid = modid; this.reserves = reserves; this.cfg = cfg; this.max = max; @@ -80,7 +83,7 @@ public int next() { } if (done > max) { - throw new RequestOutOfBounds("A mod has gotten more ids than it has requested."); + throw new RequestOutOfBoundsException(modid + " has grabbed more ids than it has requested."); } done++; @@ -152,4 +155,10 @@ public void ensureFree(int amount) { reservationEnd = reservationStart + reserves.runLengthFinder.apply(reservationStart, max - done); current = 0; } + + public void validate() { + if (done != max) { + throw new RequestCutShortException(modid + " did not use up all requested ids."); + } + } } diff --git a/src/main/java/turniplabs/halplibe/util/registry/error/RequestCutShortException.java b/src/main/java/turniplabs/halplibe/util/registry/error/RequestCutShortException.java new file mode 100644 index 0000000..7836556 --- /dev/null +++ b/src/main/java/turniplabs/halplibe/util/registry/error/RequestCutShortException.java @@ -0,0 +1,7 @@ +package turniplabs.halplibe.util.registry.error; + +public class RequestCutShortException extends RuntimeException { + public RequestCutShortException(String message) { + super(message); + } +} diff --git a/src/main/java/turniplabs/halplibe/util/registry/error/RequestOutOfBounds.java b/src/main/java/turniplabs/halplibe/util/registry/error/RequestOutOfBounds.java deleted file mode 100644 index 0a81fd3..0000000 --- a/src/main/java/turniplabs/halplibe/util/registry/error/RequestOutOfBounds.java +++ /dev/null @@ -1,7 +0,0 @@ -package turniplabs.halplibe.util.registry.error; - -public class RequestOutOfBounds extends RuntimeException { - public RequestOutOfBounds(String message) { - super(message); - } -} diff --git a/src/main/java/turniplabs/halplibe/util/registry/error/RequestOutOfBoundsException.java b/src/main/java/turniplabs/halplibe/util/registry/error/RequestOutOfBoundsException.java new file mode 100644 index 0000000..4d71098 --- /dev/null +++ b/src/main/java/turniplabs/halplibe/util/registry/error/RequestOutOfBoundsException.java @@ -0,0 +1,7 @@ +package turniplabs.halplibe.util.registry.error; + +public class RequestOutOfBoundsException extends RuntimeException { + public RequestOutOfBoundsException(String message) { + super(message); + } +}