From 7c712adac682eb6c6e401f3f51bbf53d357e62f3 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Sat, 1 Apr 2023 22:59:59 +1000 Subject: [PATCH] swapped over to using longs for media amounts everywhere. Added CircleMishapEnv. Setup CircleCastEnv more. --- .../hexcasting/api/addldata/ADHexHolder.java | 2 +- .../api/addldata/ADMediaHolder.java | 24 +++++----- .../circles/BlockEntityAbstractImpetus.java | 21 +++++--- .../casting/circles/CircleExecutionState.java | 13 ++++- .../api/casting/eval/env/CircleCastEnv.java | 39 +++++++++++---- .../api/casting/eval/env/CircleMishapEnv.java | 48 +++++++++++++++++++ .../hexcasting/api/item/HexHolderItem.java | 2 +- .../hexcasting/api/item/MediaHolderItem.java | 16 +++---- .../hexcasting/api/utils/MediaHelper.kt | 19 ++++---- .../operators/circles/OpCircleBounds.kt | 2 +- .../casting/operators/spells/OpMakeBattery.kt | 1 + .../operators/spells/OpMakePackagedSpell.kt | 1 + .../casting/operators/spells/OpPlaceBlock.kt | 1 + .../casting/operators/spells/OpPrint.kt | 2 +- .../casting/operators/spells/OpRecharge.kt | 4 +- .../items/magic/DebugUnlockerHolder.java | 14 +++--- .../items/magic/ItemCreativeUnlocker.java | 33 +++++++++---- .../common/items/magic/ItemMediaHolder.java | 24 ++++++---- .../common/items/magic/ItemPackagedHex.java | 2 +- .../fabric/cc/adimpl/CCHexHolder.java | 2 +- .../fabric/cc/adimpl/CCMediaHolder.java | 22 ++++----- .../forge/cap/adimpl/CapItemHexHolder.java | 2 +- .../forge/cap/adimpl/CapItemMediaHolder.java | 10 ++-- .../cap/adimpl/CapStaticMediaHolder.java | 12 ++--- 24 files changed, 212 insertions(+), 104 deletions(-) create mode 100644 Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleMishapEnv.java diff --git a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADHexHolder.java b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADHexHolder.java index 3d945942..f227a718 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADHexHolder.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADHexHolder.java @@ -15,7 +15,7 @@ public interface ADHexHolder { @Nullable List getHex(ServerLevel level); - void writeHex(List patterns, int media); + void writeHex(List patterns, long media); void clearHex(); } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADMediaHolder.java b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADMediaHolder.java index 9ec11ca8..79060ed6 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADMediaHolder.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ADMediaHolder.java @@ -7,28 +7,28 @@ public interface ADMediaHolder { /** * Use {@code withdrawMedia(-1, true)} * - * @see ADMediaHolder#withdrawMedia(int, boolean) + * @see ADMediaHolder#withdrawMedia(long, boolean) */ @ApiStatus.OverrideOnly - int getMedia(); + long getMedia(); /** * Use {@code withdrawMedia(-1, true) + insertMedia(-1, true)} where possible * - * @see ADMediaHolder#insertMedia(int, boolean) - * @see ADMediaHolder#withdrawMedia(int, boolean) + * @see ADMediaHolder#insertMedia(long, boolean) + * @see ADMediaHolder#withdrawMedia(long, boolean) */ @ApiStatus.OverrideOnly - int getMaxMedia(); + long getMaxMedia(); /** * Use {@code insertMedia(media - withdrawMedia(-1, true), false)} where possible * - * @see ADMediaHolder#insertMedia(int, boolean) - * @see ADMediaHolder#withdrawMedia(int, boolean) + * @see ADMediaHolder#insertMedia(long, boolean) + * @see ADMediaHolder#withdrawMedia(long, boolean) */ @ApiStatus.OverrideOnly - void setMedia(int media); + void setMedia(long media); /** * Whether this media holder can have media inserted into it. @@ -63,7 +63,7 @@ public interface ADMediaHolder { *

* Withdrawing a negative amount will act as though you attempted to withdraw as much media as the holder contains. */ - default int withdrawMedia(int cost, boolean simulate) { + default long withdrawMedia(long cost, boolean simulate) { var mediaHere = getMedia(); if (cost < 0) { cost = mediaHere; @@ -83,9 +83,9 @@ public interface ADMediaHolder { * Inserting a negative amount will act as though you attempted to insert exactly as much media as the holder was * missing. */ - default int insertMedia(int amount, boolean simulate) { + default long insertMedia(long amount, boolean simulate) { var mediaHere = getMedia(); - int emptySpace = getMaxMedia() - mediaHere; + long emptySpace = getMaxMedia() - mediaHere; if (emptySpace <= 0) { return 0; } @@ -93,7 +93,7 @@ public interface ADMediaHolder { amount = emptySpace; } - int inserting = Math.min(amount, emptySpace); + long inserting = Math.min(amount, emptySpace); if (!simulate) { var newMedia = mediaHere + inserting; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java index dee81c51..3519be3e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java @@ -39,7 +39,7 @@ import java.util.List; */ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implements WorldlyContainer { private static final DecimalFormat DUST_AMOUNT = new DecimalFormat("###,###.##"); - private static final int MAX_CAPACITY = 2_000_000_000; + private static final long MAX_CAPACITY = 9_000_000_000_000_000_000L; public static final String TAG_EXECUTION_STATE = "executor", @@ -53,7 +53,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen @Nullable protected CircleExecutionState executionState; - protected int media = 0; + protected long media = 0; // these are null together @Nullable @@ -155,15 +155,15 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen //region media handling - public int getMedia() { + public long getMedia() { return this.media; } - public void setMedia(int media) { + public void setMedia(long media) { this.media = media; } - public int extractMediaFromInsertedItem(ItemStack stack, boolean simulate) { + public long extractMediaFromInsertedItem(ItemStack stack, boolean simulate) { if (this.media < 0) { return 0; } @@ -188,7 +188,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen this.sync(); } - public int remainingMediaCapacity() { + public long remainingMediaCapacity() { if (this.media < 0) { return 0; } @@ -203,7 +203,8 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen tag.put(TAG_EXECUTION_STATE, this.executionState.save()); } - tag.putInt(TAG_MEDIA, this.media); + tag.putLong(TAG_MEDIA, this.media); + if (this.errorMsg != null && this.errorDisplay != null) { tag.putString(TAG_ERROR_MSG, Component.Serializer.toJson(this.errorMsg)); var itemTag = new CompoundTag(); @@ -220,6 +221,12 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen } else { this.lazyExecutionState = null; } + + if (tag.contains(TAG_MEDIA, Tag.TAG_INT)) { + this.media = tag.getInt(TAG_MEDIA); + } else if (tag.contains(TAG_MEDIA, Tag.TAG_LONG)) { + this.media = tag.getLong(TAG_MEDIA); + } } public void applyScryingLensOverlay(List> lines, diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java index 21f0f746..8ca04eed 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java @@ -15,6 +15,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -38,6 +39,8 @@ public class CircleExecutionState { public Direction enteredFrom; public CastingImage currentImage; + public final AABB bounds; + protected CircleExecutionState(Set knownPositions, BlockPos currentPos, Direction enteredFrom, CastingImage currentImage) { @@ -45,12 +48,17 @@ public class CircleExecutionState { this.currentPos = currentPos; this.enteredFrom = enteredFrom; this.currentImage = currentImage; + + this.bounds = BlockEntityAbstractImpetus.getBounds(new ArrayList<>(this.knownPositions)); } // Return null if the circle does not close. public static @Nullable CircleExecutionState createNew(BlockEntityAbstractImpetus impetus) { var level = (ServerLevel) impetus.getLevel(); + if (level == null) + return null; + // Flood fill! Just like VCC all over again. // this contains tentative positions and directions entered from var todo = new Stack>(); @@ -129,6 +137,9 @@ public class CircleExecutionState { public boolean tick(BlockEntityAbstractImpetus impetus) { var world = (ServerLevel) impetus.getLevel(); + if (world == null) + return true; // if the world is null, try again next tick. + var env = new CircleCastEnv(world, impetus.getBlockPos(), impetus.getStartDirection()); var executorBlock = world.getBlockState(this.currentPos); @@ -165,7 +176,7 @@ public class CircleExecutionState { } if (found == null) { - // will never enter here if there were too manu because found will have been set + // will never enter here if there were too many because found will have been set impetus.postError( Component.translatable("hexcasting.circles.no_exits", Component.literal(this.currentPos.toShortString()).withStyle(ChatFormatting.RED)), diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java index 55f603f5..cc5eecbd 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java @@ -7,19 +7,26 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment; import at.petrak.hexcasting.api.casting.eval.MishapEnvironment; import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound; import at.petrak.hexcasting.api.misc.FrozenColorizer; +import at.petrak.hexcasting.common.lib.HexItems; +import at.petrak.hexcasting.common.lib.hex.HexEvalSounds; +import net.minecraft.Util; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; public class CircleCastEnv extends CastingEnvironment { + protected EvalSound sound = HexEvalSounds.NOTHING; + protected final BlockPos impetusLoc; protected final Direction startDir; @@ -52,27 +59,39 @@ public class CircleCastEnv extends CastingEnvironment { @Override public MishapEnvironment getMishapEnvironment() { - return null; + return new CircleMishapEnv(this.world, this.impetusLoc, this.startDir); } @Override public EvalSound getSoundType() { - return null; + return sound; } @Override public void postExecution(CastResult result) { - + this.sound = this.sound.greaterOf(result.getSound()); } @Override public Vec3 mishapSprayPos() { - return null; + return Vec3.atCenterOf(impetusLoc); } @Override public long extractMedia(long cost) { - return 0; + var entity = this.getCircle(); + if (entity == null) + return cost; + + var mediaAvailable = entity.getMedia(); + if (mediaAvailable < 0) + return 0; + + long mediaToTake = Math.min(cost, mediaAvailable); + cost -= mediaToTake; + entity.setMedia(mediaAvailable - mediaToTake); + + return cost; } @Override @@ -82,26 +101,26 @@ public class CircleCastEnv extends CastingEnvironment { @Override public InteractionHand castingHand() { - return null; + return InteractionHand.MAIN_HAND; } @Override public ItemStack getAlternateItem() { - return null; + return ItemStack.EMPTY.copy(); } @Override protected List getUsableStacks(StackDiscoveryMode mode) { - return null; + return new ArrayList<>(); // TODO: Could do something like get items in inventories adjacent to the circle? } @Override public FrozenColorizer getColorizer() { - return null; + return new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.PURPLE)), Util.NIL_UUID); } @Override public void produceParticles(ParticleSpray particles, FrozenColorizer colorizer) { - + particles.sprayParticles(this.world, colorizer); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleMishapEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleMishapEnv.java new file mode 100644 index 00000000..5a3bad8a --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleMishapEnv.java @@ -0,0 +1,48 @@ +package at.petrak.hexcasting.api.casting.eval.env; + +import at.petrak.hexcasting.api.casting.eval.MishapEnvironment; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.phys.Vec3; + +public class CircleMishapEnv extends MishapEnvironment { + protected final BlockPos impetusLoc; + protected final Direction startDir; + + protected CircleMishapEnv(ServerLevel world, BlockPos impetusLoc, Direction startDir) { + super(world, null); + this.impetusLoc = impetusLoc; + this.startDir = startDir; + } + + @Override + public void yeetHeldItemsTowards(Vec3 targetPos) { + + } + + @Override + public void dropHeldItems() { + + } + + @Override + public void drown() { + + } + + @Override + public void damage(float healthProportion) { + + } + + @Override + public void removeXp(int amount) { + + } + + @Override + public void blind(int ticks) { + + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/api/item/HexHolderItem.java b/Common/src/main/java/at/petrak/hexcasting/api/item/HexHolderItem.java index 72ea7685..1f086888 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/item/HexHolderItem.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/item/HexHolderItem.java @@ -24,7 +24,7 @@ public interface HexHolderItem extends MediaHolderItem { @Nullable List getHex(ItemStack stack, ServerLevel level); - void writeHex(ItemStack stack, List program, int media); + void writeHex(ItemStack stack, List program, long media); void clearHex(ItemStack stack); } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/item/MediaHolderItem.java b/Common/src/main/java/at/petrak/hexcasting/api/item/MediaHolderItem.java index 43456722..51dad5b8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/item/MediaHolderItem.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/item/MediaHolderItem.java @@ -11,25 +11,25 @@ import org.jetbrains.annotations.ApiStatus; */ @ApiStatus.OverrideOnly public interface MediaHolderItem { - int getMedia(ItemStack stack); + long getMedia(ItemStack stack); - int getMaxMedia(ItemStack stack); + long getMaxMedia(ItemStack stack); - void setMedia(ItemStack stack, int media); + void setMedia(ItemStack stack, long media); boolean canProvideMedia(ItemStack stack); boolean canRecharge(ItemStack stack); default float getMediaFullness(ItemStack stack) { - int max = getMaxMedia(stack); + long max = getMaxMedia(stack); if (max == 0) { return 0; } return (float) getMedia(stack) / (float) max; } - default int withdrawMedia(ItemStack stack, int cost, boolean simulate) { + default long withdrawMedia(ItemStack stack, long cost, boolean simulate) { var mediaHere = getMedia(stack); if (cost < 0) { cost = mediaHere; @@ -41,9 +41,9 @@ public interface MediaHolderItem { return Math.min(cost, mediaHere); } - default int insertMedia(ItemStack stack, int amount, boolean simulate) { + default long insertMedia(ItemStack stack, long amount, boolean simulate) { var mediaHere = getMedia(stack); - int emptySpace = getMaxMedia(stack) - mediaHere; + long emptySpace = getMaxMedia(stack) - mediaHere; if (emptySpace <= 0) { return 0; } @@ -51,7 +51,7 @@ public interface MediaHolderItem { amount = emptySpace; } - int inserting = Math.min(amount, emptySpace); + long inserting = Math.min(amount, emptySpace); if (!simulate) { var newMedia = mediaHere + inserting; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/utils/MediaHelper.kt b/Common/src/main/java/at/petrak/hexcasting/api/utils/MediaHelper.kt index a9568d8d..c7852e2d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/utils/MediaHelper.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/utils/MediaHelper.kt @@ -28,10 +28,10 @@ fun isMediaItem(stack: ItemStack): Boolean { @JvmOverloads fun extractMedia( stack: ItemStack, - cost: Int = -1, + cost: Long = -1, drainForBatteries: Boolean = false, simulate: Boolean = false -): Int { +): Long { val mediaHolder = IXplatAbstractions.INSTANCE.findMediaHolder(stack) ?: return 0 return extractMedia(mediaHolder, cost, drainForBatteries, simulate) @@ -47,10 +47,10 @@ fun extractMedia( */ fun extractMedia( holder: ADMediaHolder, - cost: Int = -1, + cost: Long = -1, drainForBatteries: Boolean = false, simulate: Boolean = false -): Int { +): Long { if (drainForBatteries && !holder.canConstructBattery()) return 0 @@ -84,11 +84,12 @@ fun compareMediaItem(aMedia: ADMediaHolder, bMedia: ADMediaHolder): Int { if (priority != 0) return priority - return aMedia.withdrawMedia(-1, true) - bMedia.withdrawMedia(-1, true) + return (aMedia.withdrawMedia(-1, true) - bMedia.withdrawMedia(-1, true)) + .coerceIn(Int.MIN_VALUE.toLong(), Int.MAX_VALUE.toLong()).toInt() } -fun mediaBarColor(media: Int, maxMedia: Int): Int { - val amt = if (maxMedia == 0) { +fun mediaBarColor(media: Long, maxMedia: Long): Int { + val amt = if (maxMedia == 0L) { 0f } else { media.toFloat() / maxMedia.toFloat() @@ -100,8 +101,8 @@ fun mediaBarColor(media: Int, maxMedia: Int): Int { return Mth.color(r / 255f, g / 255f, b / 255f) } -fun mediaBarWidth(media: Int, maxMedia: Int): Int { - val amt = if (maxMedia == 0) { +fun mediaBarWidth(media: Long, maxMedia: Long): Int { + val amt = if (maxMedia == 0L) { 0f } else { media.toFloat() / maxMedia.toFloat() diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt index b5736426..7cc6cc76 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt @@ -16,7 +16,7 @@ class OpCircleBounds(val max: Boolean) : ConstMediaAction { throw MishapNoSpellCircle() val circle = ctx.circle ?: throw MishapNoSpellCircle() - val aabb = circle.getBounds(listOf()) + val aabb = circle.executionState!!.bounds // the circle should have an execution state since it's executing this. return if (max) Vec3(aabb.maxX - 0.5, aabb.maxY - 0.5, aabb.maxZ - 0.5).asActionResult diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt index 1efd9fe5..a20a2caa 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt @@ -18,6 +18,7 @@ import net.minecraft.world.InteractionHand import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.item.ItemStack +// TODO: how to handle in cirles object OpMakeBattery : SpellAction { override val argc = 1 diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt index 52d71442..1cac1d65 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt @@ -14,6 +14,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.item.ItemStack +// TODO: How to handle in circles class OpMakePackagedSpell(val itemType: T, val cost: Int) : SpellAction { override val argc = 2 override fun execute( diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt index b1d412b4..09e6f9a2 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt @@ -21,6 +21,7 @@ import net.minecraft.world.item.context.UseOnContext import net.minecraft.world.phys.BlockHitResult import net.minecraft.world.phys.Vec3 +// TODO: how to handle in cirles object OpPlaceBlock : SpellAction { override val argc: Int get() = 1 diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt index 309386b9..f6052d55 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt @@ -31,7 +31,7 @@ object OpPrint : Action { private data class Spell(val datum: Iota) : RenderedSpell { override fun cast(ctx: CastingEnvironment) { - ctx.caster?.sendSystemMessage(datum.display()) + ctx.caster?.sendSystemMessage(datum.display()) // TODO: how to handle in cirles } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt index 374da43d..983cfb88 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt @@ -25,7 +25,7 @@ object OpRecharge : SpellAction { val (handStack, hand) = ctx.getHeldItemToOperateOn { val media = IXplatAbstractions.INSTANCE.findMediaHolder(it) - media != null && media.canRecharge() && media.insertMedia(-1, true) != 0 + media != null && media.canRecharge() && media.insertMedia(-1, true) != 0L } val media = IXplatAbstractions.INSTANCE.findMediaHolder(handStack) @@ -46,7 +46,7 @@ object OpRecharge : SpellAction { ) } - if (media.insertMedia(-1, true) == 0) + if (media.insertMedia(-1, true) == 0L) return null return Triple( diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/DebugUnlockerHolder.java b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/DebugUnlockerHolder.java index 4ebd95b3..045a6eeb 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/DebugUnlockerHolder.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/DebugUnlockerHolder.java @@ -5,17 +5,17 @@ import net.minecraft.world.item.ItemStack; public record DebugUnlockerHolder(ItemStack creativeUnlocker) implements ADMediaHolder { @Override - public int getMedia() { + public long getMedia() { return Integer.MAX_VALUE; } @Override - public int getMaxMedia() { + public long getMaxMedia() { return Integer.MAX_VALUE - 1; } @Override - public void setMedia(int media) { + public void setMedia(long media) { // NO-OP } @@ -40,15 +40,15 @@ public record DebugUnlockerHolder(ItemStack creativeUnlocker) implements ADMedia } @Override - public int withdrawMedia(int cost, boolean simulate) { - ItemCreativeUnlocker.addToIntArray(creativeUnlocker, ItemCreativeUnlocker.TAG_EXTRACTIONS, cost); + public long withdrawMedia(long cost, boolean simulate) { + ItemCreativeUnlocker.addToLongArray(creativeUnlocker, ItemCreativeUnlocker.TAG_EXTRACTIONS, cost); return cost < 0 ? getMedia() : cost; } @Override - public int insertMedia(int amount, boolean simulate) { - ItemCreativeUnlocker.addToIntArray(creativeUnlocker, ItemCreativeUnlocker.TAG_INSERTIONS, amount); + public long insertMedia(long amount, boolean simulate) { + ItemCreativeUnlocker.addToLongArray(creativeUnlocker, ItemCreativeUnlocker.TAG_INSERTIONS, amount); return amount; } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java index d8a7e6c3..7e83bf2c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java @@ -65,7 +65,10 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem { }); DiscoveryHandlers.addMediaHolderDiscoverer(harness -> { - var player = harness.getCtx().getCaster(); + var player = harness.getEnv().getCaster(); + if (player == null) + return List.of(); + if (!player.isCreative()) return List.of(); @@ -117,12 +120,12 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem { } @Override - public int getMaxMedia(ItemStack stack) { - return Integer.MAX_VALUE - 1; + public long getMaxMedia(ItemStack stack) { + return Long.MAX_VALUE - 1; } @Override - public void setMedia(ItemStack stack, int media) { + public void setMedia(ItemStack stack, long media) { // NO-OP } @@ -146,21 +149,31 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem { NBTHelper.putIntArray(stack, tag, newArr); } + public static void addToLongArray(ItemStack stack, String tag, long n) { + long[] arr = NBTHelper.getLongArray(stack, tag); + if (arr == null) { + arr = new long[0]; + } + long[] newArr = Arrays.copyOf(arr, arr.length + 1); + newArr[newArr.length - 1] = n; + NBTHelper.putLongArray(stack, tag, newArr); + } + @Override - public int withdrawMedia(ItemStack stack, int cost, boolean simulate) { + public long withdrawMedia(ItemStack stack, long cost, boolean simulate) { // In case it's withdrawn through other means if (!simulate && isDebug(stack, DISPLAY_MEDIA)) { - addToIntArray(stack, TAG_EXTRACTIONS, cost); + addToLongArray(stack, TAG_EXTRACTIONS, cost); } return cost < 0 ? getMedia(stack) : cost; } @Override - public int insertMedia(ItemStack stack, int amount, boolean simulate) { + public long insertMedia(ItemStack stack, long amount, boolean simulate) { // In case it's inserted through other means if (!simulate && isDebug(stack, DISPLAY_MEDIA)) { - addToIntArray(stack, TAG_INSERTIONS, amount); + addToLongArray(stack, TAG_INSERTIONS, amount); } return amount < 0 ? getMaxMedia(stack) : amount; @@ -180,10 +193,10 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem { } private void debugDisplay(ItemStack stack, String tag, String langKey, String allKey, Entity entity) { - int[] arr = NBTHelper.getIntArray(stack, tag); + long[] arr = NBTHelper.getLongArray(stack, tag); if (arr != null) { NBTHelper.remove(stack, tag); - for (int i : arr) { + for (long i : arr) { if (i < 0) { entity.sendSystemMessage(Component.translatable("hexcasting.debug.media_" + langKey, stack.getDisplayName(), diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemMediaHolder.java b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemMediaHolder.java index 9713d7f7..0db68c91 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemMediaHolder.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemMediaHolder.java @@ -35,29 +35,35 @@ public abstract class ItemMediaHolder extends Item implements MediaHolderItem { super(pProperties); } - public static ItemStack withMedia(ItemStack stack, int media, int maxMedia) { + public static ItemStack withMedia(ItemStack stack, long media, long maxMedia) { Item item = stack.getItem(); if (item instanceof ItemMediaHolder) { - NBTHelper.putInt(stack, TAG_MEDIA, media); - NBTHelper.putInt(stack, TAG_MAX_MEDIA, maxMedia); + NBTHelper.putLong(stack, TAG_MEDIA, media); + NBTHelper.putLong(stack, TAG_MAX_MEDIA, maxMedia); } return stack; } @Override - public int getMedia(ItemStack stack) { - return NBTHelper.getInt(stack, TAG_MEDIA); + public long getMedia(ItemStack stack) { + if (NBTHelper.hasInt(stack, TAG_MEDIA)) + return NBTHelper.getInt(stack, TAG_MEDIA); + + return NBTHelper.getLong(stack, TAG_MEDIA); } @Override - public int getMaxMedia(ItemStack stack) { - return NBTHelper.getInt(stack, TAG_MAX_MEDIA); + public long getMaxMedia(ItemStack stack) { + if (NBTHelper.hasInt(stack, TAG_MAX_MEDIA)) + return NBTHelper.getInt(stack, TAG_MAX_MEDIA); + + return NBTHelper.getLong(stack, TAG_MAX_MEDIA); } @Override - public void setMedia(ItemStack stack, int media) { - NBTHelper.putInt(stack, TAG_MEDIA, Mth.clamp(media, 0, getMaxMedia(stack))); + public void setMedia(ItemStack stack, long media) { + NBTHelper.putLong(stack, TAG_MEDIA, Mth.clamp(media, 0, getMaxMedia(stack))); } @Override 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 a7858f17..f3bcaa62 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 @@ -74,7 +74,7 @@ public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHold } @Override - public void writeHex(ItemStack stack, List program, int media) { + public void writeHex(ItemStack stack, List program, long media) { ListTag patsTag = new ListTag(); for (Iota pat : program) { patsTag.add(IotaType.serialize(pat)); diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCHexHolder.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCHexHolder.java index 69066967..2f593b45 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCHexHolder.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCHexHolder.java @@ -45,7 +45,7 @@ public abstract class CCHexHolder extends ItemComponent implements ADHexHolder { } @Override - public void writeHex(List patterns, int media) { + public void writeHex(List patterns, long media) { this.hexHolder.writeHex(this.stack, patterns, media); } diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCMediaHolder.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCMediaHolder.java index 4297730a..5dd512fd 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCMediaHolder.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/adimpl/CCMediaHolder.java @@ -25,17 +25,17 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold } @Override - public int getMedia() { + public long getMedia() { return this.mediaHolder.getMedia(this.stack); } @Override - public int getMaxMedia() { + public long getMaxMedia() { return this.mediaHolder.getMaxMedia(this.stack); } @Override - public void setMedia(int media) { + public void setMedia(long media) { this.mediaHolder.setMedia(this.stack, media); } @@ -60,12 +60,12 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold } @Override - public int withdrawMedia(int cost, boolean simulate) { + public long withdrawMedia(long cost, boolean simulate) { return this.mediaHolder.withdrawMedia(this.stack, cost, simulate); } @Override - public int insertMedia(int amount, boolean simulate) { + public long insertMedia(long amount, boolean simulate) { return this.mediaHolder.insertMedia(this.stack, amount, simulate); } } @@ -81,17 +81,17 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold } @Override - public int getMedia() { - return baseWorth.get() * stack.getCount(); + public long getMedia() { + return (long) baseWorth.get() * stack.getCount(); } @Override - public int getMaxMedia() { + public long getMaxMedia() { return getMedia(); } @Override - public void setMedia(int media) { + public void setMedia(long media) { // NO-OP } @@ -116,8 +116,8 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold } @Override - public int withdrawMedia(int cost, boolean simulate) { - int worth = baseWorth.get(); + public long withdrawMedia(long cost, boolean simulate) { + long worth = baseWorth.get(); if (cost < 0) { cost = worth * stack.getCount(); } diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemHexHolder.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemHexHolder.java index 9c9f3970..7c3d4a15 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemHexHolder.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemHexHolder.java @@ -28,7 +28,7 @@ public record CapItemHexHolder(HexHolderItem holder, } @Override - public void writeHex(List patterns, int media) { + public void writeHex(List patterns, long media) { holder.writeHex(stack, patterns, media); } diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemMediaHolder.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemMediaHolder.java index 471cbfcb..71d4bd29 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemMediaHolder.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapItemMediaHolder.java @@ -11,17 +11,17 @@ public record CapItemMediaHolder(MediaHolderItem holder, ItemStack stack) implements ADMediaHolder { @Override - public int getMedia() { + public long getMedia() { return holder.getMedia(stack); } @Override - public int getMaxMedia() { + public long getMaxMedia() { return holder.getMaxMedia(stack); } @Override - public void setMedia(int media) { + public void setMedia(long media) { holder.setMedia(stack, media); } @@ -46,12 +46,12 @@ public record CapItemMediaHolder(MediaHolderItem holder, } @Override - public int withdrawMedia(int cost, boolean simulate) { + public long withdrawMedia(long cost, boolean simulate) { return holder.withdrawMedia(stack, cost, simulate); } @Override - public int insertMedia(int amount, boolean simulate) { + public long insertMedia(long amount, boolean simulate) { return holder.insertMedia(stack, amount, simulate); } } diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticMediaHolder.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticMediaHolder.java index a131548b..48dbdb42 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticMediaHolder.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/adimpl/CapStaticMediaHolder.java @@ -12,17 +12,17 @@ public record CapStaticMediaHolder(Supplier baseWorth, int consumptionPriority, ItemStack stack) implements ADMediaHolder { @Override - public int getMedia() { - return baseWorth.get() * stack.getCount(); + public long getMedia() { + return (long) baseWorth.get() * stack.getCount(); } @Override - public int getMaxMedia() { + public long getMaxMedia() { return getMedia(); } @Override - public void setMedia(int media) { + public void setMedia(long media) { // NO-OP } @@ -47,8 +47,8 @@ public record CapStaticMediaHolder(Supplier baseWorth, } @Override - public int withdrawMedia(int cost, boolean simulate) { - int worth = baseWorth.get(); + public long withdrawMedia(long cost, boolean simulate) { + long worth = baseWorth.get(); if (cost < 0) { cost = worth * stack.getCount(); }