Skip to content

Commit

Permalink
Warning when actions have same pattern (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object authored May 8, 2024
2 parents efc8899 + c3b7474 commit db42d9d
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, ResourceKey<ActionRegistryEntry>> NORMAL_ACTION_LOOKUP =
private static final ConcurrentMap<List<HexAngle>, ResourceKey<ActionRegistryEntry>> NORMAL_ACTION_LOOKUP =
new ConcurrentHashMap<>();

/**
Expand All @@ -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++;
}
Expand All @@ -64,6 +72,8 @@ public static Pair<SpecialHandler, ResourceKey<SpecialHandler.Factory<?>>> 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);
Expand All @@ -84,15 +94,15 @@ 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);
}

// 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);
}
Expand Down

0 comments on commit db42d9d

Please sign in to comment.