This commit is contained in:
yrsegal@gmail.com 2022-07-02 23:59:10 -04:00
parent 21ce790bb7
commit 287fadc8ce
4 changed files with 46 additions and 16 deletions

View file

@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingHarness;
import at.petrak.hexcasting.api.spell.casting.SpellCircleContext;
import at.petrak.hexcasting.api.spell.iota.PatternIota;
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,7 +535,7 @@ 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;
}
@ -541,19 +546,33 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
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;
}
}

View file

@ -407,6 +407,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

View file

@ -35,6 +35,18 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem {
&& 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 MediaHolderItem {
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));

View file

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