Phials now always show media amounts (in dust)

This commit is contained in:
yrsegal@gmail.com 2022-08-25 21:05:26 -04:00
parent 7e780b5dca
commit 0ba1c36ad9
4 changed files with 47 additions and 22 deletions

View file

@ -43,6 +43,7 @@ import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import java.text.DecimalFormat;
import java.util.*;
public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implements WorldlyContainer {
@ -55,6 +56,8 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
TAG_MANA = "mana",
TAG_LAST_MISHAP = "last_mishap";
private static final DecimalFormat DUST_AMOUNT = new DecimalFormat("###,###.##");
@Nullable
private UUID activator = null;
@Nullable
@ -120,9 +123,8 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
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));
var dustCmp = new TranslatableComponent("hexcasting.tooltip.mana",
DUST_AMOUNT.format(beai.getMana() / (float) ManaConstants.DUST_UNIT));
lines.add(new Pair<>(new ItemStack(HexItems.AMETHYST_DUST), dustCmp));
}

View file

@ -219,8 +219,6 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
return copy;
}
private static final TextColor HEX_COLOR = TextColor.fromRgb(0xb38ef3);
private static MutableComponent rainbow(MutableComponent component, int shift, Level level) {
if (level == null) {
return component.withStyle(ChatFormatting.WHITE);
@ -233,16 +231,14 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents,
TooltipFlag isAdvanced) {
String prefix = "item.hexcasting.creative_unlocker.";
Component emphasized = infiniteMedia(level);
MutableComponent modName = new TranslatableComponent(prefix + "mod_name").withStyle(
(s) -> s.withColor(HEX_COLOR));
MutableComponent modName = new TranslatableComponent("item.hexcasting.creative_unlocker.mod_name").withStyle(
(s) -> s.withColor(ItemManaHolder.HEX_COLOR));
tooltipComponents.add(
new TranslatableComponent(prefix + "tooltip.0", emphasized).withStyle(ChatFormatting.GRAY));
tooltipComponents.add(new TranslatableComponent(prefix + "tooltip.1", modName).withStyle(ChatFormatting.GRAY));
new TranslatableComponent("hexcasting.spelldata.onitem", emphasized).withStyle(ChatFormatting.GRAY));
tooltipComponents.add(new TranslatableComponent("item.hexcasting.creative_unlocker.tooltip", modName).withStyle(ChatFormatting.GRAY));
}
private static void addChildren(Advancement root, List<Advancement> out) {

View file

@ -1,10 +1,12 @@
package at.petrak.hexcasting.common.items.magic;
import at.petrak.hexcasting.api.item.ManaHolderItem;
import at.petrak.hexcasting.api.misc.ManaConstants;
import at.petrak.hexcasting.api.utils.ManaHelper;
import at.petrak.hexcasting.api.utils.NBTHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextColor;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.util.Mth;
import net.minecraft.world.item.Item;
@ -13,12 +15,24 @@ import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.List;
public abstract class ItemManaHolder extends Item implements ManaHolderItem {
public static final String TAG_MANA = "hexcasting:mana";
public static final String TAG_MAX_MANA = "hexcasting:start_mana";
public static final TextColor HEX_COLOR = TextColor.fromRgb(0xb38ef3);
private static final DecimalFormat PERCENTAGE = new DecimalFormat("####");
static {
PERCENTAGE.setRoundingMode(RoundingMode.DOWN);
}
private static final DecimalFormat DUST_AMOUNT = new DecimalFormat("###,###.##");
public ItemManaHolder(Properties pProperties) {
super(pProperties);
}
@ -75,12 +89,24 @@ public abstract class ItemManaHolder extends Item implements ManaHolderItem {
@Override
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
TooltipFlag pIsAdvanced) {
if (pIsAdvanced.isAdvanced() && getMaxMana(pStack) > 0) {
var maxMana = getMaxMana(pStack);
if (maxMana > 0) {
var mana = getMana(pStack);
var fullness = getManaFullness(pStack);
var color = TextColor.fromRgb(ManaHelper.manaBarColor(mana, maxMana));
var manaAmount = new TextComponent(DUST_AMOUNT.format(mana / (float) ManaConstants.DUST_UNIT));
var percentFull = new TextComponent(PERCENTAGE.format(100f * fullness) + "%");
var maxCapacity = new TranslatableComponent("hexcasting.tooltip.mana", DUST_AMOUNT.format(maxMana / (float) ManaConstants.DUST_UNIT));
manaAmount.withStyle(style -> style.withColor(HEX_COLOR));
maxCapacity.withStyle(style -> style.withColor(HEX_COLOR));
percentFull.withStyle(style -> style.withColor(color));
pTooltipComponents.add(
new TranslatableComponent("item.hexcasting.manaholder.amount",
String.format("%,d", getMana(pStack)),
String.format("%,d", getMaxMana(pStack)),
100f * getManaFullness(pStack)).withStyle(ChatFormatting.GRAY));
new TranslatableComponent("hexcasting.tooltip.mana_amount.advanced",
manaAmount, maxCapacity, percentFull));
}
super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced);

View file

@ -16,7 +16,6 @@
"item.hexcasting.trinket": "Trinket",
"item.hexcasting.artifact": "Artifact",
"item.hexcasting.battery": "Phial of Media",
"item.hexcasting.manaholder.amount": "N*merical Mana: %s/%s (%.0f%%)",
"item.hexcasting.amethyst_dust": "Amethyst Dust",
"item.hexcasting.charged_amethyst": "Charged Amethyst",
"item.hexcasting.lens": "Scrying Lens",
@ -66,9 +65,8 @@
"item.hexcasting.pride_colorizer_transgender": "Transgender Pigment",
"item.hexcasting.uuid_colorizer": "Soulglimmer Pigment",
"item.hexcasting.creative_unlocker": "The Media Cube",
"item.hexcasting.creative_unlocker.tooltip.0": "Contains %s.",
"item.hexcasting.creative_unlocker.for_emphasis": "INFINITE MEDIA",
"item.hexcasting.creative_unlocker.tooltip.1": "Consume to unlock all %s knowledge.",
"item.hexcasting.creative_unlocker.tooltip": "Consume to unlock all %s knowledge.",
"item.hexcasting.creative_unlocker.mod_name": "Hexcasting",
@ -123,7 +121,6 @@
"hexcasting.tooltip.abacus": "%d",
"hexcasting.tooltip.abacus.reset": "Reset to 0",
"hexcasting.tooltip.abacus.reset.nice": "nice",
"hexcasting.tooltip.lens.impetus.mana": "%s dust",
"hexcasting.tooltip.lens.impetus.storedplayer": "Bound to %s",
"hexcasting.tooltip.lens.impetus.storedplayer.none": "Unbound",
"hexcasting.tooltip.lens.pattern.invalid": "Invalid Pattern",
@ -141,6 +138,10 @@
"hexcasting.spelldata.entity.whoknows": "An Entity (this should only show up if this was stored before the 0.5.0 update, use Scribe's Reflection, Scribe's Gambit to fix)",
"hexcasting.spelldata.akashic.nopos": "The owning record does not know of any iota here (this is a bug)",
"hexcasting.tooltip.mana": "%s dust",
"hexcasting.tooltip.mana_amount": "Contains: %s (%s)",
"hexcasting.tooltip.mana_amount.advanced": "Contains: %s/%s (%s)",
"gui.hexcasting.spellcasting": "Hex Grid",
"tag.hexcasting.wands": "Hex Staves",
"tag.hexcasting.akashic_logs": "Edified Logs",
@ -631,7 +632,7 @@
"hexcasting.page.hexcasting.2": "To do this, I can craft one of three types of magic items: $(l:items/hexcasting)$(item)Cyphers/$, $(l:items/hexcasting)$(item)Trinkets/$, or $(l:items/hexcasting)$(item)Artifacts/$. All of them hold the patterns of a given _Hex inside, along with a small battery containing _media.$(br2)Simply holding one and pressing $(thing)$(k:use)/$ will cast the patterns inside, as if the holder had cast them out of a staff, using its internal battery.",
"hexcasting.page.hexcasting.3": "Each item has its own quirks:$(br2)$(l:items/hexcasting)$(item)Cyphers/$ are fragile, destroyed after their internal _media reserves are gone, and $(italic)cannot/$ be recharged;$(br2)$(l:items/hexcasting)$(item)Trinkets/$ can be cast as much as the holder likes, as long as there's enough _media left, but become useless afterwards until recharged;",
"hexcasting.page.hexcasting.4": "$(l:items/hexcasting)$(item)Artifacts/$ are the most powerful of all-- after their _media is depleted, they can use $(l:items/amethyst)$(item)Amethyst/$ from the holder's inventory to pay for the _Hex, just as I do when casting with a $(l:items/staff)$(item)Staff/$. Of course, this also means the spell might consume their mind if there's not enough $(l:items/amethyst)$(item)Amethyst/$.$(br2)Once I've made an empty magic item in a mundane crafting bench, I infuse the _Hex into it using (what else but) a spell appropriate to the item. $(l:patterns/spells/hexcasting)I've catalogued the patterns here./$",
"hexcasting.page.hexcasting.5": "Each infusion spell requires an entity and a list of patterns on the stack. The entity must be a _media-holding item entity (i.e. $(l:items/amethyst)$(item)amethyst/$ crystals, dropped on the ground); the entity is consumed and forms the battery.$(br2)Usefully, it seems that the _media in the battery is not consumed in chunks as it is when casting with a $(l:items/staff)$(item)Staff/$-- rather, the _media \"melts down\" into one continuous pool. Thus, if I store a _Hex that only costs one $(l:items/amethyst)$(item)Amethyst Dust/$'s worth of mana, a $(l:items/amethyst)$(item)Charged Crystal/$ used as the battery will allow me to cast it 10 times.",
"hexcasting.page.hexcasting.5": "Each infusion spell requires an entity and a list of patterns on the stack. The entity must be a _media-holding item entity (i.e. $(l:items/amethyst)$(item)amethyst/$ crystals, dropped on the ground); the entity is consumed and forms the battery.$(br2)Usefully, it seems that the _media in the battery is not consumed in chunks as it is when casting with a $(l:items/staff)$(item)Staff/$-- rather, the _media \"melts down\" into one continuous pool. Thus, if I store a _Hex that only costs one $(l:items/amethyst)$(item)Amethyst Dust/$'s worth of media, a $(l:items/amethyst)$(item)Charged Crystal/$ used as the battery will allow me to cast it 10 times.",
"hexcasting.page.hexcasting.crafting.desc": "$(italic)We have a saying in our field: \"Magic isn't\". It doesn't \"just work,\" it doesn't respond to your thoughts, you can't throw fireballs or create a roast dinner from thin air or turn a bunch of muggers into frogs and snails./$",
"hexcasting.entry.phials": "Phials of Media",