diff --git a/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockEntityAbstractImpetus.java b/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockEntityAbstractImpetus.java index 15528529..6b4b792b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockEntityAbstractImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/block/circle/BlockEntityAbstractImpetus.java @@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext; import at.petrak.hexcasting.api.spell.casting.CastingHarness; import at.petrak.hexcasting.api.spell.casting.SpellCircleContext; import at.petrak.hexcasting.api.utils.ManaHelper; +import at.petrak.hexcasting.common.items.magic.ItemCreativeUnlocker; import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexSounds; import at.petrak.hexcasting.xplat.IXplatAbstractions; @@ -117,10 +118,14 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen LocalPlayer observer, ClientLevel world, Direction hitFace, InteractionHand lensHand) { if (world.getBlockEntity(pos) instanceof BlockEntityAbstractImpetus beai) { - var dustCount = (float) beai.getMana() / (float) ManaConstants.DUST_UNIT; - var dustCmp = new TranslatableComponent("hexcasting.tooltip.lens.impetus.mana", - String.format("%.2f", dustCount)); - lines.add(new Pair<>(new ItemStack(HexItems.AMETHYST_DUST), dustCmp)); + if (beai.getMana() < 0) { + lines.add(new Pair<>(new ItemStack(HexItems.AMETHYST_DUST), ItemCreativeUnlocker.infiniteMedia(world))); + } else { + var dustCount = (float) beai.getMana() / (float) ManaConstants.DUST_UNIT; + var dustCmp = new TranslatableComponent("hexcasting.tooltip.lens.impetus.mana", + String.format("%.2f", dustCount)); + lines.add(new Pair<>(new ItemStack(HexItems.AMETHYST_DUST), dustCmp)); + } var mishap = this.getLastMishap(); if (mishap != null) { @@ -530,30 +535,37 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen @Override public boolean canPlaceItem(int index, ItemStack stack) { - var manamount = extractMana(stack, true); + var manamount = extractManaFromItem(stack, true); return manamount > 0; } - @Override - public void clearContent() { - this.mana = 0; - this.stopCasting(); - this.sync(); - } - - public int extractMana(ItemStack stack, boolean simulate) { + public int extractManaFromItem(ItemStack stack, boolean simulate) { + if (this.mana < 0) + return 0; return ManaHelper.extractMana(stack, remainingManaCapacity(), true, simulate); } public void insertMana(ItemStack stack) { - var manamount = extractMana(stack, false); - if (manamount > 0) { - this.mana += manamount; - this.sync(); + if (getMana() >= 0 && !stack.isEmpty() && stack.getItem() == HexItems.CREATIVE_UNLOCKER) { + setInfiniteMana(); + stack.shrink(1); + } else { + var manamount = extractManaFromItem(stack, false); + if (manamount > 0) { + this.mana += manamount; + this.sync(); + } } } + public void setInfiniteMana() { + this.mana = -1; + this.sync(); + } + public int remainingManaCapacity() { + if (this.mana < 0) + return 0; return MAX_CAPACITY - this.mana; } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt b/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt index 1861a03d..9547313d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt @@ -368,6 +368,9 @@ class CastingHarness private constructor( val tile = this.ctx.world.getBlockEntity(this.ctx.spellCircle.impetusPos) if (tile is BlockEntityAbstractImpetus) { val manaAvailable = tile.mana + if (manaAvailable < 0) + return 0 + val manaToTake = min(costLeft, manaAvailable) costLeft -= manaToTake tile.mana = manaAvailable - manaToTake 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 33c46cef..7232871b 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 @@ -35,6 +35,18 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem { && stack.getHoverName().getString().toLowerCase(Locale.ROOT).contains("debug"); } + public static Component infiniteMedia(Level level) { + String prefix = "item.hexcasting.creative_unlocker."; + + String emphasis = Language.getInstance().getOrDefault(prefix + "for_emphasis"); + MutableComponent emphasized = new TextComponent(""); + for (int i = 0; i < emphasis.length(); i++) { + emphasized.append(rainbow(new TextComponent("" + emphasis.charAt(i)), i, level)); + } + + return emphasized; + } + private static final String TAG_EXTRACTIONS = "extractions"; public ItemCreativeUnlocker(Properties properties) { @@ -154,11 +166,7 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem { TooltipFlag isAdvanced) { String prefix = "item.hexcasting.creative_unlocker."; - String emphasis = Language.getInstance().getOrDefault(prefix + "for_emphasis"); - MutableComponent emphasized = new TextComponent(""); - for (int i = 0; i < emphasis.length(); i++) { - emphasized.append(rainbow(new TextComponent("" + emphasis.charAt(i)), i, level)); - } + Component emphasized = infiniteMedia(level); MutableComponent modName = new TranslatableComponent(prefix + "mod_name").withStyle( (s) -> s.withColor(HEX_COLOR)); diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/storage/FabricImpetusStorage.kt b/Fabric/src/main/java/at/petrak/hexcasting/fabric/storage/FabricImpetusStorage.kt index b1edda89..b2369c7c 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/storage/FabricImpetusStorage.kt +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/storage/FabricImpetusStorage.kt @@ -26,7 +26,7 @@ class FabricImpetusStorage(val impetus: BlockEntityAbstractImpetus) : SingleSlot fun insertStack(stack: ItemStack, transaction: TransactionContext) { val copied = stack.copy() - val extractable = impetus.extractMana(stack, false) + val extractable = impetus.extractManaFromItem(stack, false) manaToTake -= extractable val taken = 64 - stack.count itemsConsumed += taken.toLong() diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeImpetusCapability.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeImpetusCapability.java index c05f03a7..f624a21c 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeImpetusCapability.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeImpetusCapability.java @@ -29,7 +29,7 @@ public record ForgeImpetusCapability(BlockEntityAbstractImpetus impetus) impleme if (!simulate) { impetus.insertMana(stack); } else { - impetus.extractMana(stack, false); // Mana goes nowhere, since nothing is actually being done + impetus.extractManaFromItem(stack, false); // Mana goes nowhere, since nothing is actually being done } return stack;