it's compiling!

This commit is contained in:
petrak@ 2023-01-21 12:45:32 -06:00
parent ede95c4b49
commit e900e4d62b
5 changed files with 28 additions and 20 deletions

View file

@ -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 <T : Tag> Tag.downcast(type: TagType<T>): T {
}
const val ERROR_COLOR = 0xff_f800f8.toInt()
fun <T> isOfTag(registry: Registry<T>, key: ResourceKey<T>, tag: TagKey<T>): Boolean {
val maybeHolder = registry.getHolder(key)
val holder = if (maybeHolder.isPresent) maybeHolder.get() else return false
return holder.`is`(tag)
}
fun <T> isOfTag(registry: Registry<T>, loc: ResourceLocation, tag: TagKey<T>): Boolean {
val key = ResourceKey.create(registry.key(), loc);
return isOfTag(registry, key, tag)
}

View file

@ -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<ResourceKey<ActionRegistryEntry>>();
@ -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

View file

@ -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<CommandSourceStack> 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;
}
}
}

View file

@ -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"
}
]
}

View file

@ -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<Vec2> 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();