creeping towards compilation

This commit is contained in:
petrak@ 2023-01-21 11:53:23 -06:00
parent 5d8b7a61eb
commit ede95c4b49
20 changed files with 217 additions and 155 deletions

View file

@ -29,7 +29,6 @@ import at.petrak.hexcasting.common.casting.PatternRegistryManifest
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.ChatFormatting
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.Tag
import net.minecraft.network.chat.Component
@ -476,6 +475,8 @@ class CastingHarness private constructor(
}
}
// TODO: replace this once we can read things from the client
/*
if (out != null) {
val display = if (iota is PatternIota) {
PatternNameHelper.representationForPattern(iota.pattern)
@ -484,6 +485,7 @@ class CastingHarness private constructor(
} else iota.display()
displayPatternDebug(this.escapeNext, displayDepth, display)
}
*/
return out
}

View file

@ -129,10 +129,8 @@ data class HexPattern(public val startDir: HexDir, public val angles: MutableLis
@JvmStatic
fun isPattern(tag: CompoundTag): Boolean {
return tag.contains(TAG_START_DIR, Tag.TAG_ANY_NUMERIC.toInt()) && tag.contains(
TAG_ANGLES,
Tag.TAG_BYTE_ARRAY.toInt()
)
return tag.contains(TAG_START_DIR, Tag.TAG_ANY_NUMERIC.toInt())
&& tag.contains(TAG_ANGLES, Tag.TAG_BYTE_ARRAY.toInt())
}
@JvmStatic

View file

@ -54,7 +54,7 @@ public interface IotaHolderItem {
/**
* What is this considered to contain when nothing can be read?
* <p>
* TODO i'm not sure what this exists for
* TODO i'm not sure what this isCastable for
*/
@Nullable
default Iota emptyIota(ItemStack stack) {
@ -97,7 +97,7 @@ public interface IotaHolderItem {
void writeDatum(ItemStack stack, @Nullable Iota iota);
static void appendHoverText(IotaHolderItem self, ItemStack stack, List<Component> components,
TooltipFlag flag) {
TooltipFlag flag) {
var datumTag = self.readIotaTag(stack);
if (datumTag != null) {
var cmp = HexIotaTypes.getDisplay(datumTag);

View file

@ -1,29 +0,0 @@
package at.petrak.hexcasting.api.utils;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.casting.eval.SpecialPatterns;
import at.petrak.hexcasting.api.casting.iota.PatternIota;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
public class PatternNameHelper {
public static Component representationForPattern(HexPattern pattern) {
if (pattern.sigsEqual(SpecialPatterns.CONSIDERATION)) {
return Component.translatable("hexcasting.spell.hexcasting:escape").withStyle(ChatFormatting.LIGHT_PURPLE);
} else if (pattern.sigsEqual(SpecialPatterns.INTROSPECTION)) {
return Component.translatable("hexcasting.spell.hexcasting:open_paren").withStyle(ChatFormatting.LIGHT_PURPLE);
} else if (pattern.sigsEqual(SpecialPatterns.RETROSPECTION)) {
return Component.translatable("hexcasting.spell.hexcasting:close_paren").withStyle(ChatFormatting.LIGHT_PURPLE);
}
var action = PatternRegistryManifest.lookupPatternByShape(pattern);
if (action != null) {
return action.getDisplayName();
}
return new PatternIota(pattern).display(); // TODO: this should be merged into iota.display once Great Spells
// can be identified by name
}
}

View file

@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.PatternShapeMatch;
import at.petrak.hexcasting.api.casting.SpecialHandler;
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.xplat.IXplatAbstractions;
@ -18,22 +19,28 @@ import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentMap;
// Now an internal-only class used to do final processing on the registered stuff
public class PatternRegistryManifest {
// Map actions to their entry except for the per-world ones. Client and server side
public static final ConcurrentMap<String, ResourceKey<ActionRegistryEntry>> NORMAL_ACTION_LOOKUP =
/* Map actions to their entry except for the per-world ones
*
* This can be static because the patterns that are per-world don't change in one server lifecycle.
*/
private static final ConcurrentMap<String, ResourceKey<ActionRegistryEntry>> NORMAL_ACTION_LOOKUP =
new ConcurrentHashMap<>();
// On the server side, where we know such things, the jumbled patterns
//
// SERVER SIDE ONLY
public static final ConcurrentMap<String, ResourceKey<ActionRegistryEntry>> PER_WORLD_ACTION_LOOKUP =
new ConcurrentHashMap<>();
/**
* A set of all the per-world patterns. This doesn't store <em>what</em> they are, just that
* they exist.
*/
private static final ConcurrentLinkedDeque<ResourceKey<ActionRegistryEntry>> PER_WORLD_ACTIONS =
new ConcurrentLinkedDeque<>();
/**
* Process the registry!
@ -45,7 +52,7 @@ public class PatternRegistryManifest {
if (overworld != null) {
var ds = overworld.getDataStorage();
perWorldPatterns = ds.computeIfAbsent(ScrungledPatternsSave::load,
ScrungledPatternsSave::create,
ScrungledPatternsSave::createEmpty,
TAG_SAVED_DATA);
}
@ -55,6 +62,8 @@ public class PatternRegistryManifest {
for (var key : registry.registryKeySet()) {
var entry = registry.get(key);
if (registry.getHolderOrThrow(key).is(HexTags.Actions.PER_WORLD_PATTERN)) {
PER_WORLD_ACTIONS.add(key);
// Then we need to create this only on the server, gulp
if (perWorldPatterns != null) {
var precalced = perWorldPatterns.lookup.get(entry.prototype().anglesSignature());
@ -73,15 +82,17 @@ public class PatternRegistryManifest {
if (perWorldPatterns != null) {
for (var postNeederKey : postCalculationNeeders) {
var entry = registry.get(postNeederKey);
var scrungledSig = scrunglePattern(entry.prototype(), overworld.getSeed());
PER_WORLD_ACTION_LOOKUP.put(scrungledSig, postNeederKey);
var regiEntry = registry.get(postNeederKey);
var scrungledPat = scrunglePattern(regiEntry.prototype(), overworld.getSeed());
var entry = new PerWorldEntry(postNeederKey, scrungledPat.getStartDir());
perWorldPatterns.lookup.put(scrungledPat.anglesSignature(), entry);
}
}
HexAPI.LOGGER.info(("We're on the %s! Loaded %d regular actions, %d per-world actions, and %d special " +
"handlers").formatted(
(overworld == null) ? "client" : "server", NORMAL_ACTION_LOOKUP.size(), PER_WORLD_ACTION_LOOKUP.size(),
(overworld == null) ? "client" : "server", NORMAL_ACTION_LOOKUP.size(), PER_WORLD_ACTIONS.size(),
IXplatAbstractions.INSTANCE.getSpecialHandlerRegistry().size()
));
}
@ -121,13 +132,10 @@ public class PatternRegistryManifest {
}
// Look it up in the world?
var ds = overworld.getDataStorage();
ScrungledPatternsSave perWorldPatterns =
ds.computeIfAbsent(ScrungledPatternsSave::load, ScrungledPatternsSave::create,
TAG_SAVED_DATA);
var perWorldPatterns = ScrungledPatternsSave.open(overworld);
if (perWorldPatterns.lookup.containsKey(sig)) {
var key = perWorldPatterns.lookup.get(sig);
return new PatternShapeMatch.PerWorld(key, true);
var entry = perWorldPatterns.lookup.get(sig);
return new PatternShapeMatch.PerWorld(entry.key(), true);
}
if (checkForAlternateStrokeOrders) {
@ -142,59 +150,123 @@ public class PatternRegistryManifest {
return new PatternShapeMatch.Nothing();
}
@Nullable
public static HexPattern getCanonicalStrokesPerWorld(ResourceKey<ActionRegistryEntry> key, ServerLevel overworld) {
var perWorldPatterns = ScrungledPatternsSave.open(overworld);
if (perWorldPatterns.reverseLookup.containsKey(key)) {
var sig = perWorldPatterns.reverseLookup.get(key);
var entry = perWorldPatterns.lookup.get(sig);
return HexPattern.fromAngles(sig, entry.canonicalStartDir());
} else {
return null;
}
}
/**
* Get the IDs of all the patterns marked as per-world
*/
public static Collection<ResourceKey<ActionRegistryEntry>> getAllPerWorldActions() {
return PER_WORLD_ACTIONS;
}
/**
* Maps angle sigs to resource locations and their preferred start dir so we can look them up in the main registry
* Save this on the world in case the random algorithm changes.
*/
public static class ScrungledPatternsSave extends SavedData {
private static final String TAG_DIR = "startDir";
private static final String TAG_KEY = "key";
// Maps scrungled signatures to their keys.
private final Map<String, ResourceKey<ActionRegistryEntry>> lookup;
/**
* Maps scrungled signatures to their keys.
*/
private final Map<String, PerWorldEntry> lookup;
public ScrungledPatternsSave(Map<String, ResourceKey<ActionRegistryEntry>> lookup) {
/**
* Reverse-maps resource keys to their signature; you can use that in {@code lookup}.
* <p>
* This way we can look up things if we know their resource key, for commands and such
*/
private final Map<ResourceKey<ActionRegistryEntry>, String> reverseLookup;
public ScrungledPatternsSave(Map<String, PerWorldEntry> lookup) {
this.lookup = lookup;
this.reverseLookup = new HashMap<>();
this.lookup.forEach((sig, entry) -> {
this.reverseLookup.put(entry.key, sig);
});
}
@Override
public CompoundTag save(CompoundTag tag) {
this.lookup.forEach((sig, key) -> tag.putString(sig, key.location().toString()));
// We don't save the reverse lookup cause we can reconstruct it when loading.
this.lookup.forEach((sig, entry) -> {
var inner = new CompoundTag();
inner.putByte(TAG_DIR, (byte) entry.canonicalStartDir.ordinal());
inner.putString(TAG_KEY, entry.key().location().toString());
tag.put(sig, inner);
});
return tag;
}
private static ScrungledPatternsSave load(CompoundTag tag) {
var registryKey = IXplatAbstractions.INSTANCE.getActionRegistry().key();
var map = new HashMap<String, ResourceKey<ActionRegistryEntry>>();
var map = new HashMap<String, PerWorldEntry>();
for (var sig : tag.getAllKeys()) {
var keyStr = tag.getString(sig);
var key = ResourceKey.create(registryKey, new ResourceLocation(keyStr));
var inner = tag.getCompound(sig);
map.put(sig, key);
var rawDir = inner.getByte(TAG_DIR);
var rawKey = inner.getString(TAG_KEY);
var dir = HexDir.values()[rawDir];
var key = ResourceKey.create(registryKey, new ResourceLocation(rawKey));
map.put(sig, new PerWorldEntry(key, dir));
}
return new ScrungledPatternsSave(map);
}
public static ScrungledPatternsSave create() {
public static ScrungledPatternsSave createEmpty() {
var save = new ScrungledPatternsSave(new HashMap<>());
return save;
}
public static ScrungledPatternsSave createFromScratch(long seed) {
var map = new HashMap<String, PerWorldEntry>();
for (var key : PER_WORLD_ACTIONS) {
var regiEntry = IXplatAbstractions.INSTANCE.getActionRegistry().get(key);
var scrungled = scrunglePattern(regiEntry.prototype(), seed);
map.put(scrungled.anglesSignature(), new PerWorldEntry(key, scrungled.getStartDir()));
}
return new ScrungledPatternsSave(map);
}
public static ScrungledPatternsSave open(ServerLevel overworld) {
return overworld.getDataStorage().computeIfAbsent(
ScrungledPatternsSave::load, ScrungledPatternsSave::createEmpty, TAG_SAVED_DATA);
}
}
private record PerWorldEntry(ResourceKey<ActionRegistryEntry> key, HexDir canonicalStartDir) {
}
public static final String DATA_VERSION = "0.1.0";
public static final String TAG_SAVED_DATA = "hexcasting.per-world-patterns." + DATA_VERSION;
/**
* Find a valid alternate drawing for this pattern that won't collide with anything pre-existing
*/
private static String scrunglePattern(HexPattern prototype, long seed) {
var scrungled = EulerPathFinder.findAltDrawing(prototype, seed, it -> {
private static HexPattern scrunglePattern(HexPattern prototype, long seed) {
return EulerPathFinder.findAltDrawing(prototype, seed, it -> {
var sig = it.anglesSignature();
return !NORMAL_ACTION_LOOKUP.containsKey(sig);
});
return scrungled.anglesSignature();
}
}

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.common.command;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.casting.iota.PatternIota;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.common.items.ItemScroll;
import at.petrak.hexcasting.common.lib.HexItems;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@ -57,36 +57,36 @@ public class ListPatternsCommand {
}
private static int list(CommandSourceStack source) {
var lookup = PatternRegistryManifest.getPerWorldPatterns(source.getLevel());
var listing = lookup.entrySet()
var keys = PatternRegistryManifest.getAllPerWorldActions();
var listing = keys
.stream()
.sorted((a, b) -> compareResLoc(a.getValue().getFirst(), b.getValue().getFirst()))
.sorted((a, b) -> compareResLoc(a.location(), b.location()))
.toList();
var ow = source.getLevel().getServer().overworld();
source.sendSuccess(Component.translatable("command.hexcasting.pats.listing"), false);
for (var pair : listing) {
source.sendSuccess(Component.literal(pair.getValue().getFirst().toString())
for (var key : listing) {
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ow);
source.sendSuccess(Component.literal(key.location().toString())
.append(": ")
.append(new PatternIota(HexPattern.fromAngles(pair.getKey(), pair.getValue().getSecond()))
.display()), false);
.append(new PatternIota(pat).display()), false);
}
return lookup.size();
return keys.size();
}
private static int giveAll(CommandSourceStack source, Collection<ServerPlayer> targets) {
if (!targets.isEmpty()) {
var lookup = PatternRegistryManifest.getPerWorldPatterns(source.getLevel());
var lookup = PatternRegistryManifest.getAllPerWorldActions();
var ow = source.getLevel().getServer().overworld();
lookup.forEach((sig, entry) -> {
var opId = entry.getFirst();
var startDir = entry.getSecond();
lookup.forEach(key -> {
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ow);
var tag = new CompoundTag();
tag.putString(ItemScroll.TAG_OP_ID, opId.toString());
tag.put(ItemScroll.TAG_PATTERN,
HexPattern.fromAngles(sig, startDir).serializeToNBT());
tag.putString(ItemScroll.TAG_OP_ID, key.location().toString());
tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT());
var stack = new ItemStack(HexItems.SCROLL_LARGE);
stack.setTag(tag);

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.command;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
@ -28,26 +28,17 @@ public class PatternResLocArgument extends ResourceLocationArgument {
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return SharedSuggestionProvider.suggest(
PatternRegistryManifest.getAllPerWorldPatternNames().stream().map(Object::toString), builder);
PatternRegistryManifest.getAllPerWorldActions().stream().map(key -> key.location().toString()), builder);
}
public static HexPattern getPattern(
CommandContext<CommandSourceStack> ctx, String pName) throws CommandSyntaxException {
var targetId = ctx.getArgument(pName, ResourceLocation.class);
var lookup = PatternRegistryManifest.getPerWorldPatterns(ctx.getSource().getLevel());
HexPattern foundPat = null;
for (var sig : lookup.keySet()) {
var rhs = lookup.get(sig);
if (rhs.getFirst().equals(targetId)) {
foundPat = HexPattern.fromAngles(sig, rhs.getSecond());
break;
}
}
CommandContext<CommandSourceStack> ctx, String argumentName) throws CommandSyntaxException {
var targetId = ctx.getArgument(argumentName, ResourceLocation.class);
var foundPat = PatternRegistryManifest.getCanonicalStrokesPerWorld(targetId, ctx.getSource().getLevel());
if (foundPat == null) {
throw ERROR_UNKNOWN_PATTERN.create(targetId);
} else {
return foundPat;
return foundPat.getSecond();
}
}
}

View file

@ -14,7 +14,7 @@ public class RecalcPatternsCommand {
var world = ctx.getSource().getServer().overworld();
var ds = world.getDataStorage();
ds.set(PatternRegistryManifest.TAG_SAVED_DATA,
PatternRegistryManifest.ScrungledPatternsSave.create(world.getSeed()));
PatternRegistryManifest.ScrungledPatternsSave.createEmpty());
ctx.getSource().sendSuccess(
Component.translatable("command.hexcasting.recalc"), true);

View file

@ -34,7 +34,7 @@ public class ItemStaff extends Item {
if (!world.isClientSide() && player instanceof ServerPlayer serverPlayer) {
var harness = IXplatAbstractions.INSTANCE.getHarness(serverPlayer, hand);
var patterns = IXplatAbstractions.INSTANCE.getPatterns(serverPlayer);
var patterns = IXplatAbstractions.INSTANCE.getPatternsSavedInUi(serverPlayer);
var descs = harness.generateDescs();
IXplatAbstractions.INSTANCE.sendPacketToPlayer(serverPlayer,

View file

@ -1,6 +1,5 @@
package at.petrak.hexcasting.common.lib.hex;
import at.petrak.hexcasting.api.misc.MediaConstants;
import at.petrak.hexcasting.api.casting.Action;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.iota.BooleanIota;
@ -9,6 +8,7 @@ import at.petrak.hexcasting.api.casting.iota.NullIota;
import at.petrak.hexcasting.api.casting.iota.Vec3Iota;
import at.petrak.hexcasting.api.casting.math.HexDir;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.misc.MediaConstants;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.casting.operators.*;
import at.petrak.hexcasting.common.casting.operators.akashic.OpAkashicRead;
@ -37,6 +37,9 @@ import at.petrak.hexcasting.common.casting.operators.spells.sentinel.OpGetSentin
import at.petrak.hexcasting.common.casting.operators.spells.sentinel.OpGetSentinelWayfind;
import at.petrak.hexcasting.common.casting.operators.stack.*;
import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.interop.pehkui.OpGetScale;
import at.petrak.hexcasting.interop.pehkui.OpSetScale;
import at.petrak.hexcasting.interop.pehkui.PehkuiInterop;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
@ -536,7 +539,17 @@ public class HexActions {
public static final ActionRegistryEntry DECONSTRUCT = make("deconstruct",
new ActionRegistryEntry(HexPattern.fromAngles("aaqwqaa", HexDir.SOUTH_WEST), OpUnCons.INSTANCE));
private static ActionRegistryEntry make(String name, ActionRegistryEntry are) {
// Xplat interops
static {
if (PehkuiInterop.isActive()) {
make("interop/pehkui/get",
new ActionRegistryEntry(HexPattern.fromAngles("aawawwawwa", HexDir.NORTH_WEST), OpGetScale.INSTANCE));
make("interop/pehkui/set",
new ActionRegistryEntry(HexPattern.fromAngles("ddwdwwdwwd", HexDir.NORTH_EAST), OpSetScale.INSTANCE));
}
}
public static ActionRegistryEntry make(String name, ActionRegistryEntry are) {
var old = ACTIONS.put(modLoc(name), are);
if (old != null) {
throw new IllegalArgumentException("Typo? Duplicate id " + name);

View file

@ -1,7 +1,6 @@
package at.petrak.hexcasting.common.loot;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.common.items.ItemScroll;
import at.petrak.hexcasting.common.lib.HexLootFunctions;
import com.google.gson.JsonDeserializationContext;
@ -14,6 +13,9 @@ import net.minecraft.world.level.storage.loot.functions.LootItemConditionalFunct
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
/**
* Slap a random per-world pattern on the scroll
*/
public class PatternScrollFunc extends LootItemConditionalFunction {
public PatternScrollFunc(LootItemCondition[] lootItemConditions) {
super(lootItemConditions);
@ -22,17 +24,15 @@ public class PatternScrollFunc extends LootItemConditionalFunction {
@Override
protected ItemStack run(ItemStack stack, LootContext ctx) {
var rand = ctx.getRandom();
var worldLookup = PatternRegistryManifest.getPerWorldPatterns(ctx.getLevel());
var worldLookup = PatternRegistryManifest.getAllPerWorldActions();
var keys = worldLookup.keySet().stream().toList();
var sig = keys.get(rand.nextInt(keys.size()));
var keys = worldLookup.stream().toList();
var key = keys.get(rand.nextInt(keys.size()));
var entry = worldLookup.get(sig);
var opId = entry.getFirst();
var startDir = entry.getSecond();
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ctx.getLevel().getServer().overworld());
var tag = new CompoundTag();
tag.putString(ItemScroll.TAG_OP_ID, opId.toString());
tag.put(ItemScroll.TAG_PATTERN, HexPattern.fromAngles(sig, startDir).serializeToNBT());
tag.putString(ItemScroll.TAG_OP_ID, key.location().toString());
tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT());
stack.getOrCreateTag().merge(tag);

View file

@ -18,6 +18,7 @@ public class HexInterop {
}
public static final class Fabric {
// TODO: the ID for this mod changed, fix that, #362
public static final String GRAVITY_CHANGER_API_ID = "gravitychanger";
public static final String TRINKETS_API_ID = "trinkets";
}

View file

@ -1,10 +1,12 @@
package at.petrak.hexcasting.interop.patchouli;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.casting.math.HexCoord;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.google.gson.annotations.SerializedName;
import com.mojang.datafixers.util.Pair;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import vazkii.patchouli.api.IVariable;
@ -23,8 +25,11 @@ public class LookupPatternComponent extends AbstractPatternComponent {
@Override
public List<Pair<HexPattern, HexCoord>> getPatterns(UnaryOperator<IVariable> lookup) {
var entry = PatternRegistryManifest.lookupPattern(this.opName);
this.strokeOrder = !entry.isPerWorld();
var key = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), this.opName);
var entry = IXplatAbstractions.INSTANCE.getActionRegistry().get(key);
this.strokeOrder =
!IXplatAbstractions.INSTANCE.getActionRegistry().getHolderOrThrow(key).is(HexTags.Actions.PER_WORLD_PATTERN);
return List.of(new Pair<>(entry.prototype(), HexCoord.getOrigin()));
}

View file

@ -1,22 +1,16 @@
package at.petrak.hexcasting.interop.pehkui;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.casting.math.HexDir;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.interop.HexInterop;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.world.entity.Entity;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
public class PehkuiInterop {
public static void init() {
try {
PatternRegistryManifest.mapPattern(HexPattern.fromAngles("aawawwawwa", HexDir.NORTH_WEST),
modLoc("interop/pehkui/get"), OpGetScale.INSTANCE);
PatternRegistryManifest.mapPattern(HexPattern.fromAngles("ddwdwwdwwd", HexDir.NORTH_EAST),
modLoc("interop/pehkui/set"), OpSetScale.INSTANCE);
} catch (PatternRegistryManifest.RegisterPatternException e) {
e.printStackTrace();
}
// for future work
}
public static boolean isActive() {
return IXplatAbstractions.INSTANCE.isModPresent(HexInterop.PEHKUI_ID);
}
/**

View file

@ -93,7 +93,7 @@ public interface IXplatAbstractions {
CastingHarness getHarness(ServerPlayer player, InteractionHand hand);
List<ResolvedPattern> getPatterns(ServerPlayer player);
List<ResolvedPattern> getPatternsSavedInUi(ServerPlayer player);
void clearCastingData(ServerPlayer player);

View file

@ -2,6 +2,9 @@ package at.petrak.hexcasting.fabric
import at.petrak.hexcasting.api.HexAPI.modLoc
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
import at.petrak.hexcasting.api.casting.ActionRegistryEntry
import at.petrak.hexcasting.api.casting.math.HexDir
import at.petrak.hexcasting.api.casting.math.HexPattern
import at.petrak.hexcasting.api.mod.HexStatistics
import at.petrak.hexcasting.common.blocks.behavior.HexComposting
import at.petrak.hexcasting.common.blocks.behavior.HexStrippables
@ -22,6 +25,9 @@ import at.petrak.hexcasting.common.misc.BrainsweepingEvents
import at.petrak.hexcasting.common.misc.PlayerPositionRecorder
import at.petrak.hexcasting.common.recipe.HexRecipeStuffRegistry
import at.petrak.hexcasting.fabric.event.VillagerConversionCallback
import at.petrak.hexcasting.fabric.interop.gravity.GravityApiInterop
import at.petrak.hexcasting.fabric.interop.gravity.OpChangeGravity
import at.petrak.hexcasting.fabric.interop.gravity.OpGetGravity
import at.petrak.hexcasting.fabric.network.FabricPacketHandler
import at.petrak.hexcasting.fabric.recipe.FabricModConditionalIngredient
import at.petrak.hexcasting.fabric.recipe.FabricUnsealedIngredient
@ -96,7 +102,9 @@ object FabricHexInitializer : ModInitializer {
}
fun initRegistries() {
private fun initRegistries() {
fabricOnlyRegistration()
HexSounds.registerSounds(bind(Registry.SOUND_EVENT))
HexBlocks.registerBlocks(bind(Registry.BLOCK))
HexBlocks.registerBlockItems(bind(Registry.ITEM))
@ -125,6 +133,22 @@ object FabricHexInitializer : ModInitializer {
AkashicTreeGrower.init()
// Done with soft implements in forge
butYouCouldBeFire()
HexStatistics.register()
}
// sorry lex (not sorry)
private fun fabricOnlyRegistration() {
if (GravityApiInterop.isActive()) {
HexActions.make("interop/gravity/get",
ActionRegistryEntry(HexPattern.fromAngles("wawawddew", HexDir.NORTH_EAST), OpGetGravity))
HexActions.make("interop/gravity/set",
ActionRegistryEntry(HexPattern.fromAngles("wdwdwaaqw", HexDir.NORTH_WEST), OpChangeGravity))
}
}
private fun butYouCouldBeFire() {
val flameOn = FlammableBlockRegistry.getDefaultInstance()
for (log in listOf(
HexBlocks.EDIFIED_LOG,
@ -165,8 +189,6 @@ object FabricHexInitializer : ModInitializer {
)) {
flameOn.add(leaves, 60, 30)
}
HexStatistics.register()
}
private fun <T> bind(registry: Registry<in T>): BiConsumer<T, ResourceLocation> =

View file

@ -1,20 +1,13 @@
package at.petrak.hexcasting.fabric.interop.gravity;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.casting.math.HexDir;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
import at.petrak.hexcasting.interop.HexInterop;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
public class GravityApiInterop {
public static void init() {
try {
PatternRegistryManifest.mapPattern(HexPattern.fromAngles("wawawddew", HexDir.NORTH_EAST),
modLoc("interop/gravity/get"), OpGetGravity.INSTANCE);
PatternRegistryManifest.mapPattern(HexPattern.fromAngles("wdwdwaaqw", HexDir.NORTH_WEST),
modLoc("interop/gravity/set"), OpChangeGravity.INSTANCE);
} catch (PatternRegistryManifest.RegisterPatternException e) {
e.printStackTrace();
}
}
public static boolean isActive() {
return IXplatAbstractions.INSTANCE.isModPresent(HexInterop.Fabric.GRAVITY_CHANGER_API_ID);
}
}

View file

@ -207,7 +207,7 @@ public class FabricXplatImpl implements IXplatAbstractions {
}
@Override
public List<ResolvedPattern> getPatterns(ServerPlayer player) {
public List<ResolvedPattern> getPatternsSavedInUi(ServerPlayer player) {
var cc = HexCardinalComponents.PATTERNS.get(player);
return cc.getPatterns();
}
@ -400,11 +400,11 @@ public class FabricXplatImpl implements IXplatAbstractions {
);
private static final Supplier<Registry<SpecialHandler.Factory<?>>> SPECIAL_HANDLER_REGISTRY =
Suppliers.memoize(() ->
FabricRegistryBuilder.from(new MappedRegistry<SpecialHandler.Factory<?>>(
ResourceKey.createRegistryKey(modLoc("special_handler")),
Lifecycle.stable(), null))
.buildAndRegister()
);
FabricRegistryBuilder.from(new MappedRegistry<SpecialHandler.Factory<?>>(
ResourceKey.createRegistryKey(modLoc("special_handler")),
Lifecycle.stable(), null))
.buildAndRegister()
);
private static final Supplier<Registry<IotaType<?>>> IOTA_TYPE_REGISTRY = Suppliers.memoize(() ->
FabricRegistryBuilder.from(new DefaultedRegistry<IotaType<?>>(
HexAPI.MOD_ID + ":null", ResourceKey.createRegistryKey(modLoc("iota_type")),

View file

@ -28,7 +28,7 @@ public class CapSyncers {
x.setSentinel(player, x.getSentinel(proto));
x.setColorizer(player, x.getColorizer(proto));
x.setHarness(player, x.getHarness(proto, InteractionHand.MAIN_HAND));
x.setPatterns(player, x.getPatterns(proto));
x.setPatterns(player, x.getPatternsSavedInUi(proto));
}
@SubscribeEvent

View file

@ -244,7 +244,7 @@ public class ForgeXplatImpl implements IXplatAbstractions {
}
@Override
public List<ResolvedPattern> getPatterns(ServerPlayer player) {
public List<ResolvedPattern> getPatternsSavedInUi(ServerPlayer player) {
ListTag patternsTag = player.getPersistentData().getList(TAG_PATTERNS, Tag.TAG_COMPOUND);
List<ResolvedPattern> patterns = new ArrayList<>(patternsTag.size());
@ -423,9 +423,9 @@ public class ForgeXplatImpl implements IXplatAbstractions {
);
private static final Supplier<Registry<SpecialHandler.Factory<?>>> SPECIAL_HANDLER_REGISTRY =
Suppliers.memoize(() ->
ForgeAccessorRegistry.hex$registerSimple(
ResourceKey.createRegistryKey(modLoc("special_handler")), null)
);
ForgeAccessorRegistry.hex$registerSimple(
ResourceKey.createRegistryKey(modLoc("special_handler")), null)
);
private static final Supplier<Registry<IotaType<?>>> IOTA_TYPE_REGISTRY = Suppliers.memoize(() ->
ForgeAccessorRegistry.hex$registerDefaulted(
ResourceKey.createRegistryKey(modLoc("iota_type")),