From 3645a4eade74dc46f64ba2ae750e70c89fd4d4f3 Mon Sep 17 00:00:00 2001 From: gamma-delta <29877714+gamma-delta@users.noreply.github.com> Date: Fri, 8 Apr 2022 16:13:29 -0500 Subject: [PATCH] make special handlers also have resource locations --- .../java/at/petrak/hexcasting/api/PatternRegistry.kt | 12 +++++++----- .../hexcasting/common/casting/CastingHarness.kt | 2 +- .../hexcasting/common/casting/RegisterPatterns.java | 8 ++------ src/main/resources/assets/hexcasting/lang/en_us.json | 1 + 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt b/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt index 13e8e7cf..f8373cbf 100644 --- a/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt +++ b/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt @@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentMap */ object PatternRegistry { private val operatorLookup = ConcurrentHashMap() - private val specialHandlers: ConcurrentLinkedDeque = ConcurrentLinkedDeque() + private val specialHandlers: ConcurrentLinkedDeque = ConcurrentLinkedDeque() // Map signatures to the "preferred" direction they start in and their operator ID. private val regularPatternLookup: ConcurrentMap = @@ -60,7 +60,7 @@ object PatternRegistry { * Add a special handler, to take an arbitrary pattern and return whatever kind of operator you like. */ @JvmStatic - fun addSpecialHandler(handler: SpecialHandler) { + fun addSpecialHandler(handler: SpecialHandlerEntry) { this.specialHandlers.add(handler) } @@ -75,13 +75,13 @@ object PatternRegistry { * Internal use only. */ @JvmStatic - fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair { + fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair { // Pipeline: // patterns are registered here every time the game boots // when we try to look for (handler in specialHandlers) { - val op = handler.handlePattern(pat) - if (op != null) return Pair(op, null) + val op = handler.handler.handlePattern(pat) + if (op != null) return Pair(op, handler.id) } // Is it global? @@ -143,6 +143,8 @@ object PatternRegistry { fun handlePattern(pattern: HexPattern): Operator? } + data class SpecialHandlerEntry(val id: ResourceLocation, val handler: SpecialHandler) + class RegisterPatternException(msg: String) : java.lang.Exception(msg) private data class RegularEntry(val preferredStart: HexDir, val opId: ResourceLocation) diff --git a/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt b/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt index 74936eec..74abe1bf 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt +++ b/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt @@ -62,7 +62,7 @@ class CastingHarness private constructor( if (this.ctx.spellCircle == null) this.ctx.caster.awardStat(HexStatistics.PATTERNS_DRAWN) - var operatorIdPair: Pair? = null + var operatorIdPair: Pair? = null try { // wouldn't it be nice to be able to go paren' // i guess i'll call it paren2 diff --git a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java index 3ad9145c..d03f8f41 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java +++ b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java @@ -1,6 +1,5 @@ package at.petrak.hexcasting.common.casting; -import at.petrak.hexcasting.HexMod; import at.petrak.hexcasting.api.PatternRegistry; import at.petrak.hexcasting.api.spell.Operator; import at.petrak.hexcasting.api.spell.SpellDatum; @@ -37,7 +36,6 @@ public class RegisterPatterns { // I guess this means the client will have a big empty map for patterns @SubscribeEvent public static void registerSpellPatterns(FMLCommonSetupEvent evt) { - int count = 0; try { // In general: // - CCW is the normal or construction version @@ -365,7 +363,7 @@ public class RegisterPatterns { } // Add zilde->number - PatternRegistry.addSpecialHandler(pat -> { + PatternRegistry.addSpecialHandler(new PatternRegistry.SpecialHandlerEntry(prefix("number"), pat -> { var sig = pat.anglesSignature(); if (sig.startsWith("aqaa") || sig.startsWith("dedd")) { var negate = sig.startsWith("dedd"); @@ -390,8 +388,6 @@ public class RegisterPatterns { } else { return null; } - }); - - HexMod.getLogger().info("Registered {} patterns", count); + })); } } diff --git a/src/main/resources/assets/hexcasting/lang/en_us.json b/src/main/resources/assets/hexcasting/lang/en_us.json index d18a6e5c..e4d298b3 100644 --- a/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/src/main/resources/assets/hexcasting/lang/en_us.json @@ -251,6 +251,7 @@ "hexcasting.spell.hexcasting:const/vec/ny": "Vector Reflection -Y", "hexcasting.spell.hexcasting:const/vec/nz": "Vector Reflection -Z", "hexcasting.spell.hexcasting:const/vec/0": "Vector Reflection Zero", + "hexcasting.spell.hexcasting:number": "Numerical Reflection", "hexcasting.spell.unknown": "Special Handler", "hexcasting.mishap.invalid_pattern": "That pattern isn't associated with any action",