Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning when actions have same pattern #612

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading