From e900e4d62b8da678c61b8c54d2da333b2ea5d93d Mon Sep 17 00:00:00 2001 From: "petrak@" Date: Sat, 21 Jan 2023 12:45:32 -0600 Subject: [PATCH] it's compiling! --- .../at/petrak/hexcasting/api/utils/HexUtils.kt | 14 ++++++++++++++ .../common/casting/PatternRegistryManifest.java | 8 +++----- .../common/command/PatternResLocArgument.java | 7 +++++-- .../thehexbook/en_us/entries/patterns/meta.json | 10 ---------- .../fabric/interop/emi/PatternRendererEMI.java | 9 ++++++--- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt b/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt index 12235ee0..c0c9e041 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt @@ -7,10 +7,14 @@ import at.petrak.hexcasting.api.casting.iota.ListIota import at.petrak.hexcasting.api.casting.math.HexCoord import at.petrak.hexcasting.common.lib.hex.HexIotaTypes import net.minecraft.ChatFormatting +import net.minecraft.core.Registry import net.minecraft.nbt.* import net.minecraft.network.chat.Component import net.minecraft.network.chat.MutableComponent import net.minecraft.network.chat.Style +import net.minecraft.resources.ResourceKey +import net.minecraft.resources.ResourceLocation +import net.minecraft.tags.TagKey import net.minecraft.world.InteractionHand import net.minecraft.world.item.ItemStack import net.minecraft.world.phys.Vec2 @@ -272,3 +276,13 @@ fun Tag.downcast(type: TagType): T { } const val ERROR_COLOR = 0xff_f800f8.toInt() +fun isOfTag(registry: Registry, key: ResourceKey, tag: TagKey): Boolean { + val maybeHolder = registry.getHolder(key) + val holder = if (maybeHolder.isPresent) maybeHolder.get() else return false + return holder.`is`(tag) +} + +fun isOfTag(registry: Registry, loc: ResourceLocation, tag: TagKey): Boolean { + val key = ResourceKey.create(registry.key(), loc); + return isOfTag(registry, key, tag) +} 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 b05b7b9c..47a1e826 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 @@ -8,6 +8,7 @@ import at.petrak.hexcasting.api.casting.math.EulerPathFinder; import at.petrak.hexcasting.api.casting.math.HexDir; import at.petrak.hexcasting.api.casting.math.HexPattern; import at.petrak.hexcasting.api.mod.HexTags; +import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.xplat.IXplatAbstractions; import com.mojang.datafixers.util.Pair; import net.minecraft.nbt.CompoundTag; @@ -50,10 +51,7 @@ public class PatternRegistryManifest { public static void processRegistry(@Nullable ServerLevel overworld) { ScrungledPatternsSave perWorldPatterns = null; if (overworld != null) { - var ds = overworld.getDataStorage(); - perWorldPatterns = ds.computeIfAbsent(ScrungledPatternsSave::load, - ScrungledPatternsSave::createEmpty, - TAG_SAVED_DATA); + perWorldPatterns = ScrungledPatternsSave.open(overworld); } var postCalculationNeeders = new ArrayList>(); @@ -61,7 +59,7 @@ public class PatternRegistryManifest { var registry = IXplatAbstractions.INSTANCE.getActionRegistry(); for (var key : registry.registryKeySet()) { var entry = registry.get(key); - if (registry.getHolderOrThrow(key).is(HexTags.Actions.PER_WORLD_PATTERN)) { + if (HexUtils.isOfTag(registry, key, HexTags.Actions.PER_WORLD_PATTERN)) { PER_WORLD_ACTIONS.add(key); // Then we need to create this only on the server, gulp diff --git a/Common/src/main/java/at/petrak/hexcasting/common/command/PatternResLocArgument.java b/Common/src/main/java/at/petrak/hexcasting/common/command/PatternResLocArgument.java index 99b3701f..f043ed05 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/command/PatternResLocArgument.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/command/PatternResLocArgument.java @@ -2,6 +2,7 @@ package at.petrak.hexcasting.common.command; import at.petrak.hexcasting.api.casting.math.HexPattern; import at.petrak.hexcasting.common.casting.PatternRegistryManifest; +import at.petrak.hexcasting.xplat.IXplatAbstractions; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; @@ -11,6 +12,7 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import java.util.concurrent.CompletableFuture; @@ -34,11 +36,12 @@ public class PatternResLocArgument extends ResourceLocationArgument { public static HexPattern getPattern( CommandContext ctx, String argumentName) throws CommandSyntaxException { var targetId = ctx.getArgument(argumentName, ResourceLocation.class); - var foundPat = PatternRegistryManifest.getCanonicalStrokesPerWorld(targetId, ctx.getSource().getLevel()); + var targetKey = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), targetId); + var foundPat = PatternRegistryManifest.getCanonicalStrokesPerWorld(targetKey, ctx.getSource().getLevel()); if (foundPat == null) { throw ERROR_UNKNOWN_PATTERN.create(targetId); } else { - return foundPat.getSecond(); + return foundPat; } } } diff --git a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/meta.json b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/meta.json index b38c35e0..a9beb442 100644 --- a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/meta.json +++ b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/meta.json @@ -29,16 +29,6 @@ { "type": "patchouli:text", "text": "hexcasting.page.meta.for_each.2" - }, - { - "type": "hexcasting:pattern", - "op_id": "hexcasting:halt", - "anchor": "hexcasting:halt", - "text": "hexcasting.page.meta.halt.1" - }, - { - "type": "patchouli:text", - "text": "hexcasting.page.meta.halt.2" } ] } diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/interop/emi/PatternRendererEMI.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/interop/emi/PatternRendererEMI.java index 1ee5f0dc..6127d55a 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/interop/emi/PatternRendererEMI.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/interop/emi/PatternRendererEMI.java @@ -1,9 +1,11 @@ package at.petrak.hexcasting.fabric.interop.emi; -import at.petrak.hexcasting.common.casting.PatternRegistryManifest; import at.petrak.hexcasting.api.casting.math.HexCoord; +import at.petrak.hexcasting.api.mod.HexTags; +import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.interop.utils.PatternDrawingUtil; import at.petrak.hexcasting.interop.utils.PatternEntry; +import at.petrak.hexcasting.xplat.IXplatAbstractions; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.datafixers.util.Pair; import dev.emi.emi.api.render.EmiRenderable; @@ -28,8 +30,9 @@ public class PatternRendererEMI implements EmiRenderable { private final List pathfinderDots; public PatternRendererEMI(ResourceLocation pattern, int w, int h) { - var entry = PatternRegistryManifest.lookupPattern(pattern); - this.strokeOrder = !entry.isPerWorld(); + var regi = IXplatAbstractions.INSTANCE.getActionRegistry(); + var entry = regi.get(pattern); + this.strokeOrder = HexUtils.isOfTag(regi, pattern, HexTags.Actions.PER_WORLD_PATTERN); var data = PatternDrawingUtil.loadPatterns(List.of(new Pair<>(entry.prototype(), HexCoord.getOrigin())), 0f, 1f); this.patterns = data.patterns();