diff --git a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADIotaHolder.java b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADIotaHolder.java index 3c74745928..195a5ff92f 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADIotaHolder.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADIotaHolder.java @@ -15,7 +15,7 @@ public interface ADIotaHolder { default Iota readIota(ServerLevel world) { var tag = readIotaTag(); if (tag != null) { - return HexUtils.deserializeWithCodec(tag, Iota.getCodec(world)); + return HexUtils.deserializeWithCodec(tag, Iota.CODEC.get().codec()); } else { return null; } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/ResolvedPattern.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/ResolvedPattern.kt index 99941a1d6b..d99050e2a4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/ResolvedPattern.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/ResolvedPattern.kt @@ -1,11 +1,15 @@ package at.petrak.hexcasting.api.casting.eval +import at.petrak.hexcasting.api.HexAPI import at.petrak.hexcasting.api.casting.math.HexCoord import at.petrak.hexcasting.api.casting.math.HexPattern import at.petrak.hexcasting.api.utils.NBTBuilder +import at.petrak.hexcasting.api.utils.deserializeWithCodec +import at.petrak.hexcasting.api.utils.serializeWithCodec import com.mojang.serialization.Codec import com.mojang.serialization.codecs.RecordCodecBuilder import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.NbtOps import java.util.* @@ -23,12 +27,7 @@ data class ResolvedPattern(val pattern: HexPattern, val origin: HexCoord, var ty get() = origin.r @Deprecated("Use the CODEC instead.") - fun serializeToNBT() = NBTBuilder { - "Pattern" %= pattern.serializeToNBT() - "OriginQ" %= origin.q - "OriginR" %= origin.r - "Valid" %= type.name.lowercase(Locale.ROOT) - } + fun serializeToNBT() = this.serializeWithCodec(CODEC) companion object { @JvmField @@ -45,11 +44,6 @@ data class ResolvedPattern(val pattern: HexPattern, val origin: HexCoord, var ty @Deprecated("Use the CODEC instead.") @JvmStatic - fun fromNBT(tag: CompoundTag): ResolvedPattern { - val pattern = HexPattern.fromNBT(tag.getCompound("Pattern")) - val origin = HexCoord(tag.getInt("OriginQ"), tag.getInt("OriginR")) - val valid = ResolvedPatternType.fromString(tag.getString("Valid")) - return ResolvedPattern(pattern, origin, valid) - } + fun fromNBT(tag: CompoundTag): ResolvedPattern = tag.deserializeWithCodec(CODEC)!! } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapEntityNotFound.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapEntityNotFound.kt index 55f1a136e8..cea000fd42 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapEntityNotFound.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapEntityNotFound.kt @@ -1,6 +1,7 @@ package at.petrak.hexcasting.api.casting.mishaps import at.petrak.hexcasting.api.casting.eval.CastingEnvironment +import at.petrak.hexcasting.api.casting.iota.GarbageIota import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.pigment.FrozenPigment import at.petrak.hexcasting.api.utils.aqua @@ -10,13 +11,32 @@ import net.minecraft.world.entity.Entity import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.item.DyeColor -class MishapEntityNotFound : Mishap() { +class MishapEntityNotFound( + val perpetrator: Iota, + val reverseIdx: Int, +) : Mishap() { override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment = dyeColor(DyeColor.BROWN) override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList) { + stack[stack.size - 1 - reverseIdx] = GarbageIota(); } override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = - error("entity_not_found") + error( + "entity_not_found", reverseIdx, + perpetrator.display() + ) + companion object { + @JvmStatic + fun ofType(perpetrator: Iota, reverseIdx: Int): MishapEntityNotFound { + return of(perpetrator, reverseIdx) + } + + @JvmStatic + fun of(perpetrator: Iota, reverseIdx: Int): MishapEntityNotFound { + val key = "hexcasting.mishap.entity_not_found" + return MishapEntityNotFound(perpetrator, reverseIdx) + } + } } \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapOthersName.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapOthersName.kt index d916a4e1ba..64d9a1f535 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapOthersName.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapOthersName.kt @@ -34,17 +34,14 @@ class MishapOthersName(val confidant: Player) : Mishap() { * If `caster` is non-null, it will ignore that when checking. */ @JvmStatic - fun getTrueNameFromDatum(datum: Iota, caster: Player?, world: ServerLevel): Player? { + fun getTrueNameFromDatum(datum: Iota, caster: Player?): Player? { val poolToSearch = ArrayDeque() poolToSearch.addLast(datum) while (poolToSearch.isNotEmpty()) { val datumToCheck = poolToSearch.removeFirst() - if (datumToCheck is EntityIota && datumToCheck.isTrueName) { - val player = datumToCheck.getEntity(world) as Player - if (player != caster) - return player - } + if (datumToCheck is EntityIota && datumToCheck.uuid != caster?.uuid) + return datumToCheck.getEntity(caster?.level() as ServerLevel) as? Player val datumSubIotas = datumToCheck.subIotas() if (datumSubIotas != null) poolToSearch.addAll(datumSubIotas) @@ -54,8 +51,8 @@ class MishapOthersName(val confidant: Player) : Mishap() { } @JvmStatic - fun getTrueNameFromArgs(datums: List, caster: Player?, world: ServerLevel): Player? { - return datums.firstNotNullOfOrNull { getTrueNameFromDatum(it, caster, world) } + fun getTrueNameFromArgs(datums: List, caster: Player?): Player? { + return datums.firstNotNullOfOrNull { getTrueNameFromDatum(it, caster) } } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/item/IotaHolderItem.java b/Common/src/main/java/at/petrak/hexcasting/api/item/IotaHolderItem.java index b2fe3e5b58..f7475a6fb3 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/item/IotaHolderItem.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/item/IotaHolderItem.java @@ -46,7 +46,7 @@ default Iota readIota(ItemStack stack, ServerLevel world) { var tag = dh.readIotaTag(stack); if (tag != null) { - return HexUtils.deserializeWithCodec(tag, Iota.getCodec(world)); + return HexUtils.deserializeWithCodec(tag, Iota.CODEC.get().codec()); } else { return null; } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java index 03b6a917f3..8c4250069c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java @@ -43,7 +43,7 @@ public CompoundTag getIotaTag() { public void setNewMapping(HexPattern pattern, Iota iota) { var previouslyEmpty = this.pattern == null; this.pattern = pattern; - this.iotaTag = (CompoundTag) HexUtils.serializeWithCodec(iota, Iota.getCodec()); + this.iotaTag = (CompoundTag) HexUtils.serializeWithCodec(iota, Iota.CODEC.get().codec()); if (previouslyEmpty) { var oldBs = this.getBlockState(); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEntitySlate.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEntitySlate.java index 63489e8c0e..2eec827fe7 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEntitySlate.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/BlockEntitySlate.java @@ -2,6 +2,7 @@ import at.petrak.hexcasting.api.block.HexBlockEntity; import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.client.render.HexPatternPoints; import at.petrak.hexcasting.common.lib.HexBlockEntities; import net.minecraft.core.BlockPos; @@ -10,6 +11,8 @@ import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + public class BlockEntitySlate extends HexBlockEntity { public static final String TAG_PATTERN = "pattern"; @@ -24,7 +27,7 @@ public BlockEntitySlate(BlockPos pos, BlockState state) { @Override protected void saveModData(CompoundTag tag) { if (this.pattern != null) { - tag.put(TAG_PATTERN, this.pattern.serializeToNBT()); + tag.put(TAG_PATTERN, Objects.requireNonNull(HexUtils.serializeWithCodec(this.pattern, HexPattern.CODEC))); } else { tag.put(TAG_PATTERN, new CompoundTag()); } @@ -35,7 +38,7 @@ protected void loadModData(CompoundTag tag) { if (tag.contains(TAG_PATTERN, Tag.TAG_COMPOUND)) { CompoundTag patternTag = tag.getCompound(TAG_PATTERN); if (HexPattern.isPattern(patternTag)) { - this.pattern = HexPattern.fromNBT(patternTag); + this.pattern = HexUtils.deserializeWithCodec(patternTag, HexPattern.CODEC); } else { this.pattern = null; } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockRedstoneImpetus.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockRedstoneImpetus.java index 58b3ac7c18..164f8fa08f 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockRedstoneImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockRedstoneImpetus.java @@ -54,7 +54,7 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla if (datumContainer != null) { var stored = datumContainer.readIota(level); if (stored instanceof EntityIota eieio) { - var entity = eieio.getEntity(); + var entity = eieio.getEntity((ServerLevel) pLevel); if (entity instanceof Player player) { // phew, we got something tile.setPlayer(player.getGameProfile(), entity.getUUID()); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/command/ListPerWorldPatternsCommand.java b/Common/src/main/java/at/petrak/hexcasting/common/command/ListPerWorldPatternsCommand.java index f39e14d47f..c5c45ad7d8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/command/ListPerWorldPatternsCommand.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/command/ListPerWorldPatternsCommand.java @@ -100,7 +100,7 @@ private static int giveAll(CommandSourceStack source, Collection t var tag = new CompoundTag(); tag.putString(ItemScroll.TAG_OP_ID, key.location().toString()); - tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT()); + tag.put(ItemScroll.TAG_PATTERN, HexUtils.serializeWithCodec(pat, HexPattern.CODEC)); var stack = new ItemStack(HexItems.SCROLL_LARGE); stack.setTag(tag); @@ -134,7 +134,7 @@ private static int giveOne(CommandSourceStack source, Collection t if (!targets.isEmpty()) { var tag = new CompoundTag(); tag.putString(ItemScroll.TAG_OP_ID, patternName.toString()); - tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT()); + tag.put(ItemScroll.TAG_PATTERN, HexUtils.serializeWithCodec(pat, HexPattern.CODEC)); var stack = new ItemStack(HexItems.SCROLL_LARGE); stack.setTag(tag); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/entities/EntityWallScroll.java b/Common/src/main/java/at/petrak/hexcasting/common/entities/EntityWallScroll.java index cd9ab651cb..de6879b066 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/entities/EntityWallScroll.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/entities/EntityWallScroll.java @@ -71,7 +71,7 @@ public EntityWallScroll(Level world, BlockPos pos, Direction dir, ItemStack scro public void recalculateDisplay() { CompoundTag patternTag = NBTHelper.getCompound(scroll, ItemScroll.TAG_PATTERN); if (patternTag != null) { - this.pattern = HexPattern.fromNBT(patternTag); + this.pattern = HexUtils.deserializeWithCodec(patternTag, HexPattern.CODEC); if (this.level().isClientSide) { var pair = RenderLib.getCenteredPattern(pattern, 128f / 3 * blockSize, 128f / 3 * blockSize, 16f / 3 * blockSize); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemPackagedHex.java b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemPackagedHex.java index 27f238dda5..339e94a652 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemPackagedHex.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemPackagedHex.java @@ -77,7 +77,7 @@ public boolean hasHex(ItemStack stack) { var out = new ArrayList(); for (var patTag : patsTag) { CompoundTag tag = NBTHelper.getAsCompound(patTag); - out.add(HexUtils.deserializeWithCodec(tag, Iota.getCodec(level))); + out.add(HexUtils.deserializeWithCodec(tag, Iota.CODEC.get().codec())); } return out; } @@ -86,7 +86,7 @@ public boolean hasHex(ItemStack stack) { public void writeHex(ItemStack stack, List program, @Nullable FrozenPigment pigment, long media) { ListTag patsTag = new ListTag(); for (Iota pat : program) { - patsTag.add(HexUtils.serializeWithCodec(pat, Iota.getCodec())); + patsTag.add(HexUtils.serializeWithCodec(pat, Iota.CODEC.get().codec())); } NBTHelper.putList(stack, TAG_PROGRAM, patsTag); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemAbacus.java b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemAbacus.java index 21e7e6ea56..613d6552da 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemAbacus.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemAbacus.java @@ -31,7 +31,7 @@ public ItemAbacus(Properties pProperties) { public @Nullable CompoundTag readIotaTag(ItemStack stack) { var datum = new DoubleIota(NBTHelper.getDouble(stack, TAG_VALUE)); - return (CompoundTag) HexUtils.serializeWithCodec(datum, Iota.getCodec()); + return (CompoundTag) HexUtils.serializeWithCodec(datum, Iota.CODEC.get().codec()); } @Override diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemFocus.java b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemFocus.java index 304252a1d9..56957bc471 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemFocus.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemFocus.java @@ -60,7 +60,7 @@ public void writeDatum(ItemStack stack, Iota datum) { stack.removeTagKey(TAG_DATA); stack.removeTagKey(TAG_SEALED); } else if (!isSealed(stack)) { - NBTHelper.put(stack, TAG_DATA, HexUtils.serializeWithCodec(datum, Iota.getCodec())); + NBTHelper.put(stack, TAG_DATA, HexUtils.serializeWithCodec(datum, Iota.CODEC.get().codec())); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemScroll.java b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemScroll.java index 96241ea367..3443dc4da5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemScroll.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemScroll.java @@ -4,6 +4,7 @@ import at.petrak.hexcasting.api.casting.iota.PatternIota; import at.petrak.hexcasting.api.casting.math.HexPattern; import at.petrak.hexcasting.api.item.IotaHolderItem; +import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.api.utils.NBTHelper; import at.petrak.hexcasting.client.gui.PatternTooltipComponent; import at.petrak.hexcasting.common.entities.EntityWallScroll; @@ -77,7 +78,7 @@ public boolean canWrite(ItemStack stack, Iota datum) { public void writeDatum(ItemStack stack, Iota datum) { if (this.canWrite(stack, datum)) { if (datum instanceof PatternIota pat) { - NBTHelper.putCompound(stack, TAG_PATTERN, pat.getPattern().serializeToNBT()); + NBTHelper.put(stack, TAG_PATTERN, HexUtils.serializeWithCodec(pat.getPattern(), HexPattern.CODEC)); } else if (datum == null) { NBTHelper.remove(stack, TAG_PATTERN); } @@ -144,7 +145,7 @@ public Component getName(ItemStack pStack) { public Optional getTooltipImage(ItemStack stack) { var compound = NBTHelper.getCompound(stack, ItemScroll.TAG_PATTERN); if (compound != null) { - var pattern = HexPattern.fromNBT(compound); + var pattern = HexUtils.deserializeWithCodec(compound, HexPattern.CODEC); return Optional.of(new PatternTooltip( pattern, NBTHelper.hasString(stack, ItemScroll.TAG_OP_ID) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSlate.java b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSlate.java index 6ad6f5b51b..a5f87e2b80 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSlate.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSlate.java @@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.casting.iota.PatternIota; import at.petrak.hexcasting.api.casting.math.HexPattern; import at.petrak.hexcasting.api.item.IotaHolderItem; +import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.api.utils.NBTHelper; import at.petrak.hexcasting.client.gui.PatternTooltipComponent; import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate; @@ -105,7 +106,7 @@ public void writeDatum(ItemStack stack, Iota datum) { } } else if (datum instanceof PatternIota pat) { var beTag = NBTHelper.getOrCreateCompound(stack, "BlockEntityTag"); - beTag.put(BlockEntitySlate.TAG_PATTERN, pat.getPattern().serializeToNBT()); + beTag.put(BlockEntitySlate.TAG_PATTERN, HexUtils.serializeWithCodec(pat.getPattern(), HexPattern.CODEC)); } } } @@ -117,7 +118,7 @@ public Optional getTooltipImage(ItemStack stack) { if (bet != null && bet.contains(BlockEntitySlate.TAG_PATTERN, Tag.TAG_COMPOUND)) { var patTag = bet.getCompound(BlockEntitySlate.TAG_PATTERN); if (!patTag.isEmpty()) { - var pattern = HexPattern.fromNBT(patTag); + var pattern = HexUtils.deserializeWithCodec(patTag, HexPattern.CODEC); return Optional.of(new PatternTooltip(pattern, PatternTooltipComponent.SLATE_BG)); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSpellbook.java b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSpellbook.java index 6618ec760f..6c32cb600d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSpellbook.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSpellbook.java @@ -153,14 +153,14 @@ public void writeDatum(ItemStack stack, Iota datum) { pages.remove(key); NBTHelper.remove(NBTHelper.getCompound(stack, TAG_SEALED), key); } else { - pages.put(key, HexUtils.serializeWithCodec(datum, Iota.getCodec())); + pages.put(key, HexUtils.serializeWithCodec(datum, Iota.CODEC.get().codec())); } if (pages.isEmpty()) { NBTHelper.remove(stack, TAG_PAGES); } } else if (datum != null) { - NBTHelper.getOrCreateCompound(stack, TAG_PAGES).put(key, HexUtils.serializeWithCodec(datum, Iota.getCodec())); + NBTHelper.getOrCreateCompound(stack, TAG_PAGES).put(key, HexUtils.serializeWithCodec(datum, Iota.CODEC.get().codec())); } else { NBTHelper.remove(NBTHelper.getCompound(stack, TAG_SEALED), key); } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemThoughtKnot.java b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemThoughtKnot.java index 2d5b7880f4..4d29a198d5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemThoughtKnot.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemThoughtKnot.java @@ -46,7 +46,7 @@ public boolean canWrite(ItemStack stack, @Nullable Iota iota) { @Override public void writeDatum(ItemStack stack, @Nullable Iota iota) { if (iota != null) { - NBTHelper.put(stack, TAG_DATA, HexUtils.serializeWithCodec(iota, Iota.getCodec())); + NBTHelper.put(stack, TAG_DATA, HexUtils.serializeWithCodec(iota, Iota.CODEC.get().codec())); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/loot/AddPerWorldPatternToScrollFunc.java b/Common/src/main/java/at/petrak/hexcasting/common/loot/AddPerWorldPatternToScrollFunc.java index 30c9f97370..2788d98e86 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/loot/AddPerWorldPatternToScrollFunc.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/loot/AddPerWorldPatternToScrollFunc.java @@ -1,6 +1,7 @@ package at.petrak.hexcasting.common.loot; import at.petrak.hexcasting.api.casting.ActionRegistryEntry; +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.common.casting.PatternRegistryManifest; @@ -49,7 +50,7 @@ public static ItemStack doStatic(ItemStack stack, LootContext ctx) { var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ctx.getLevel().getServer().overworld()); var tag = new CompoundTag(); tag.putString(ItemScroll.TAG_OP_ID, key.location().toString()); - tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT()); + tag.put(ItemScroll.TAG_PATTERN, HexUtils.serializeWithCodec(pat, HexPattern.CODEC)); stack.getOrCreateTag().merge(tag); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpellPatternC2S.java b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpellPatternC2S.java index ce19d966b3..0b18ac3041 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpellPatternC2S.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpellPatternC2S.java @@ -3,7 +3,9 @@ import at.petrak.hexcasting.api.casting.eval.ResolvedPattern; import at.petrak.hexcasting.api.casting.eval.env.StaffCastEnv; import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.utils.HexUtils; import io.netty.buffer.ByteBuf; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; @@ -32,12 +34,12 @@ public ResourceLocation getFabricId() { public static MsgNewSpellPatternC2S deserialize(ByteBuf buffer) { var buf = new FriendlyByteBuf(buffer); var hand = buf.readEnum(InteractionHand.class); - var pattern = HexPattern.fromNBT(buf.readNbt()); + var pattern = HexUtils.deserializeWithCodec(buf.readNbt(), HexPattern.CODEC); var resolvedPatternsLen = buf.readInt(); var resolvedPatterns = new ArrayList(resolvedPatternsLen); for (int i = 0; i < resolvedPatternsLen; i++) { - resolvedPatterns.add(ResolvedPattern.fromNBT(buf.readNbt())); + resolvedPatterns.add(HexUtils.deserializeWithCodec(buf.readNbt(), ResolvedPattern.CODEC)); } return new MsgNewSpellPatternC2S(hand, pattern, resolvedPatterns); } @@ -45,10 +47,10 @@ public static MsgNewSpellPatternC2S deserialize(ByteBuf buffer) { @Override public void serialize(FriendlyByteBuf buf) { buf.writeEnum(handUsed); - buf.writeNbt(this.pattern.serializeToNBT()); + buf.writeNbt((CompoundTag) HexUtils.serializeWithCodec(this.pattern, HexPattern.CODEC)); buf.writeInt(this.resolvedPatterns.size()); for (var pat : this.resolvedPatterns) { - buf.writeNbt(pat.serializeToNBT()); + buf.writeNbt((CompoundTag) HexUtils.serializeWithCodec(pat, ResolvedPattern.CODEC)); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpiralPatternsS2C.java b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpiralPatternsS2C.java index 9c5a02180c..dcf07f92bd 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpiralPatternsS2C.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewSpiralPatternsS2C.java @@ -1,9 +1,11 @@ package at.petrak.hexcasting.common.msgs; import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.xplat.IClientXplatAbstractions; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -25,7 +27,7 @@ public static MsgNewSpiralPatternsS2C deserialize(ByteBuf buffer) { var buf = new FriendlyByteBuf(buffer); var player = buf.readUUID(); - var patterns = buf.readCollection(ArrayList::new, buff -> HexPattern.fromNBT(buf.readNbt())); + var patterns = buf.readCollection(ArrayList::new, buff -> HexUtils.deserializeWithCodec(buf.readNbt(), HexPattern.CODEC)); var lifetime = buf.readInt(); @@ -35,7 +37,7 @@ public static MsgNewSpiralPatternsS2C deserialize(ByteBuf buffer) { @Override public void serialize(FriendlyByteBuf buf) { buf.writeUUID(playerUUID); - buf.writeCollection(patterns, (buff, pattern) -> buff.writeNbt(pattern.serializeToNBT())); + buf.writeCollection(patterns, (buff, pattern) -> buff.writeNbt((CompoundTag) HexUtils.serializeWithCodec(pattern, HexPattern.CODEC))); buf.writeInt(lifetime); } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgOpenSpellGuiS2C.java b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgOpenSpellGuiS2C.java index a06e608bdb..b4e20144bd 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgOpenSpellGuiS2C.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgOpenSpellGuiS2C.java @@ -1,6 +1,8 @@ package at.petrak.hexcasting.common.msgs; import at.petrak.hexcasting.api.casting.eval.ResolvedPattern; +import at.petrak.hexcasting.api.casting.iota.PatternIota; +import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.client.gui.GuiSpellcasting; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; @@ -47,7 +49,7 @@ public static MsgOpenSpellGuiS2C deserialize(ByteBuf buffer) { public void serialize(FriendlyByteBuf buf) { buf.writeEnum(this.hand); - buf.writeCollection(this.patterns, (fbb, pat) -> fbb.writeNbt(pat.serializeToNBT())); + buf.writeCollection(this.patterns, (fbb, pat) -> fbb.writeNbt((CompoundTag) HexUtils.serializeWithCodec(pat, ResolvedPattern.CODEC))); buf.writeCollection(this.stack, FriendlyByteBuf::writeNbt); buf.writeNbt(this.ravenmind); diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 index 3852f6c057..daf933ad96 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 @@ -990,6 +990,8 @@ no_bool: "the iota encountered at %s was %s, not a bool", empty_stack: "the stack was empty at %s", }, + + entity_not_found: "the entity referenced by %s at index %s of the stack could not be found" }, // ^ mishap diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCItemIotaHolder.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCItemIotaHolder.java index 0b94fa551a..a973ca690d 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCItemIotaHolder.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCItemIotaHolder.java @@ -62,7 +62,7 @@ public Static(ItemStack stack, Function provider) { @Override public @Nullable CompoundTag readIotaTag() { var iota = this.provider.apply(this.stack); - return iota == null ? null : (CompoundTag) HexUtils.serializeWithCodec(iota, Iota.getCodec()); + return iota == null ? null : (CompoundTag) HexUtils.serializeWithCodec(iota, Iota.CODEC.get().codec()); } @Override diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticIotaHolder.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticIotaHolder.java index f94cd93455..266bb5fc61 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticIotaHolder.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticIotaHolder.java @@ -3,6 +3,7 @@ import at.petrak.hexcasting.api.addldata.ADIotaHolder; import at.petrak.hexcasting.api.casting.iota.Iota; import at.petrak.hexcasting.api.casting.iota.IotaType; +import at.petrak.hexcasting.api.utils.HexUtils; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; @@ -17,7 +18,7 @@ public record CapStaticIotaHolder(Function provider, public @Nullable CompoundTag readIotaTag() { var iota = provider.apply(stack); - return iota == null ? null : IotaType.serialize(iota); + return iota == null ? null : (CompoundTag) HexUtils.serializeWithCodec(iota, Iota.getCodec()); } @Override