From d6c0b9a015bc731f94a7da7c3fe422eb2a5c3629 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Wed, 7 Feb 2024 00:08:31 +1000 Subject: [PATCH] Provide user-visible warning for #466, two patterns with the same signature (this won't catch great patterns that could overlap with regular/each other). --- .../casting/PatternRegistryManifest.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/PatternRegistryManifest.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/PatternRegistryManifest.java index c2a8122de..66199bfba 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/PatternRegistryManifest.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/PatternRegistryManifest.java @@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.PatternShapeMatch; import at.petrak.hexcasting.api.casting.castables.SpecialHandler; import at.petrak.hexcasting.api.casting.eval.CastingEnvironment; +import at.petrak.hexcasting.api.casting.math.HexAngle; import at.petrak.hexcasting.api.casting.math.HexPattern; import at.petrak.hexcasting.api.mod.HexTags; import at.petrak.hexcasting.api.utils.HexUtils; @@ -16,12 +17,13 @@ import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; // Now an internal-only class used to do final processing on the registered stuff public class PatternRegistryManifest { - private static final ConcurrentMap> NORMAL_ACTION_LOOKUP = + private static final ConcurrentMap, ResourceKey> NORMAL_ACTION_LOOKUP = new ConcurrentHashMap<>(); /** @@ -42,8 +44,14 @@ public static void processRegistry(@Nullable ServerLevel overworld) { var registry = IXplatAbstractions.INSTANCE.getActionRegistry(); for (var key : registry.registryKeySet()) { var entry = registry.get(key); + if (entry == null) + continue; + if (!HexUtils.isOfTag(registry, key, HexTags.Actions.PER_WORLD_PATTERN)) { - NORMAL_ACTION_LOOKUP.put(entry.prototype().anglesSignature(), key); + var old = NORMAL_ACTION_LOOKUP.put(entry.prototype().getAngles(), key); + if (old != null) { + HexAPI.LOGGER.warn("Inserted %s which has same signature as %s, overriding it.".formatted(key, old)); + } } else { perWorldActionCount++; } @@ -64,6 +72,8 @@ public static Pair>> match var registry = IXplatAbstractions.INSTANCE.getSpecialHandlerRegistry(); for (var key : registry.registryKeySet()) { var factory = registry.get(key); + if (factory == null) + continue; var handler = factory.tryMatch(pat,environment); if (handler != null) { return Pair.of(handler, key); @@ -84,7 +94,7 @@ public static PatternShapeMatch matchPattern(HexPattern pat, CastingEnvironment boolean checkForAlternateStrokeOrders) { // I am PURPOSELY checking normal actions before special handlers // This way we don't get a repeat of the phial number literal incident - var sig = pat.anglesSignature(); + var sig = pat.getAngles(); if (NORMAL_ACTION_LOOKUP.containsKey(sig)) { var key = NORMAL_ACTION_LOOKUP.get(sig); return new PatternShapeMatch.Normal(key); @@ -92,7 +102,7 @@ public static PatternShapeMatch matchPattern(HexPattern pat, CastingEnvironment // Look it up in the world? var perWorldPatterns = ScrungledPatternsSave.open(environment.getWorld().getServer().overworld()); - var entry = perWorldPatterns.lookup(sig); + var entry = perWorldPatterns.lookup(pat.anglesSignature()); if (entry != null) { return new PatternShapeMatch.PerWorld(entry.key(), true); }