Tooltip refactoring
This commit is contained in:
parent
67d82dfc66
commit
b460e0791e
4 changed files with 36 additions and 111 deletions
|
@ -28,8 +28,8 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
|
@ -141,12 +141,35 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity implements
|
|||
}
|
||||
|
||||
// IListInfoProvider
|
||||
// TODO: translate
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
info.add(new LiteralText(Formatting.GRAY + "Input Rate: " + Formatting.GOLD + PowerSystem.getLocalizedPower(getMaxInput(EnergySide.UNKNOWN))));
|
||||
info.add(new LiteralText(Formatting.GRAY + "Input Tier: " + Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(inputTier.toString())));
|
||||
info.add(new LiteralText(Formatting.GRAY + "Output Rate: " + Formatting.GOLD + PowerSystem.getLocalizedPower(getMaxOutput(EnergySide.UNKNOWN))));
|
||||
info.add(new LiteralText(Formatting.GRAY + "Output Tier: " + Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(outputTier.toString())));
|
||||
info.add(
|
||||
new TranslatableText("reborncore.tooltip.energy.inputRate")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(": ")
|
||||
.append(PowerSystem.getLocalizedPower(getMaxInput(EnergySide.UNKNOWN)))
|
||||
.formatted(Formatting.GOLD)
|
||||
);
|
||||
info.add(
|
||||
new TranslatableText("techreborn.tooltip.input_tier")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(": ")
|
||||
.append(StringUtils.toFirstCapitalAllLowercase(inputTier.toString()))
|
||||
.formatted(Formatting.GOLD)
|
||||
);
|
||||
info.add(
|
||||
new TranslatableText("reborncore.tooltip.energy.outputRate")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(": ")
|
||||
.append(PowerSystem.getLocalizedPower(getMaxOutput(EnergySide.UNKNOWN)))
|
||||
.formatted(Formatting.GOLD)
|
||||
);
|
||||
info.add(
|
||||
new TranslatableText("techreborn.tooltip.output_tier")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(": ")
|
||||
.append(StringUtils.toFirstCapitalAllLowercase(outputTier.toString()))
|
||||
.formatted(Formatting.GOLD)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,28 +27,13 @@ package techreborn.events;
|
|||
import com.google.common.collect.Maps;
|
||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.common.BaseBlockEntityProvider;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import team.reborn.energy.Energy;
|
||||
import team.reborn.energy.EnergyHolder;
|
||||
import team.reborn.energy.EnergySide;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.items.UpgradeItem;
|
||||
import techreborn.utils.ToolTipAssistUtils;
|
||||
|
@ -84,94 +69,9 @@ public class StackToolTipHandler implements ItemTooltipCallback {
|
|||
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines, false);
|
||||
tooltipLines.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));
|
||||
}
|
||||
|
||||
|
||||
// Other section
|
||||
if (item instanceof IListInfoProvider) {
|
||||
((IListInfoProvider) item).addInfo(tooltipLines, false, false);
|
||||
} else if (item instanceof EnergyHolder) {
|
||||
LiteralText line1 = new LiteralText(PowerSystem.getLocalizedPowerNoSuffix(Energy.of(stack).getEnergy()));
|
||||
line1.append("/");
|
||||
line1.append(PowerSystem.getLocalizedPower(Energy.of(stack).getMaxStored()));
|
||||
line1.formatted(Formatting.GOLD);
|
||||
|
||||
tooltipLines.add(1, line1);
|
||||
|
||||
if (Screen.hasShiftDown()) {
|
||||
int percentage = percentage(Energy.of(stack).getMaxStored(), Energy.of(stack).getEnergy());
|
||||
MutableText line2 = StringUtils.getPercentageText(percentage);
|
||||
line2.append(" ");
|
||||
line2.formatted(Formatting.GRAY);
|
||||
line2.append(I18n.translate("reborncore.gui.tooltip.power_charged"));
|
||||
tooltipLines.add(2, line2);
|
||||
|
||||
double inputRate = ((EnergyHolder) item).getMaxInput(EnergySide.UNKNOWN);
|
||||
double outputRate = ((EnergyHolder) item).getMaxOutput(EnergySide.UNKNOWN);
|
||||
LiteralText line3 = new LiteralText("");
|
||||
if (inputRate != 0 && inputRate == outputRate){
|
||||
line3.append(I18n.translate("techreborn.tooltip.transferRate"));
|
||||
line3.append(" : ");
|
||||
line3.formatted(Formatting.GRAY);
|
||||
line3.append(PowerSystem.getLocalizedPower(inputRate));
|
||||
line3.formatted(Formatting.GOLD);
|
||||
}
|
||||
else if(inputRate != 0){
|
||||
line3.append(I18n.translate("reborncore.tooltip.energy.inputRate"));
|
||||
line3.append(" : ");
|
||||
line3.formatted(Formatting.GRAY);
|
||||
line3.append(PowerSystem.getLocalizedPower(inputRate));
|
||||
line3.formatted(Formatting.GOLD);
|
||||
}
|
||||
else if (outputRate !=0){
|
||||
line3.append(I18n.translate("reborncore.tooltip.energy.outputRate"));
|
||||
line3.append(" : ");
|
||||
line3.formatted(Formatting.GRAY);
|
||||
line3.append(PowerSystem.getLocalizedPower(outputRate));
|
||||
line3.formatted(Formatting.GOLD);
|
||||
}
|
||||
tooltipLines.add(3, line3);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if ((block instanceof BlockEntityProvider) && isTRBlock(block)) {
|
||||
BlockEntity blockEntity = ((BlockEntityProvider) block).createBlockEntity(MinecraftClient.getInstance().world);
|
||||
boolean hasData = false;
|
||||
if (stack.hasTag() && stack.getOrCreateTag().contains("blockEntity_data")) {
|
||||
CompoundTag blockEntityData = stack.getOrCreateTag().getCompound("blockEntity_data");
|
||||
if (blockEntity != null) {
|
||||
blockEntity.fromTag(block.getDefaultState(), blockEntityData);
|
||||
hasData = true;
|
||||
tooltipLines.add(new LiteralText(I18n.translate("techreborn.tooltip.has_data")).formatted(Formatting.DARK_GREEN));
|
||||
}
|
||||
}
|
||||
if (blockEntity instanceof IListInfoProvider) {
|
||||
((IListInfoProvider) blockEntity).addInfo(tooltipLines, false, hasData);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
TechReborn.LOGGER.debug("Failed to load info for " + stack.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTRItem(Item item) {
|
||||
return Registry.ITEM.getId(item).getNamespace().equals("techreborn");
|
||||
}
|
||||
|
||||
private boolean isTRBlock(Block block){
|
||||
return Registry.BLOCK.getId(block).getNamespace().contains("techreborn");
|
||||
}
|
||||
|
||||
public int percentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
|
||||
public int percentage(double MaxValue, double CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ToolTipAssistUtils {
|
|||
|
||||
public static List<Text> getUpgradeStats(TRContent.Upgrades upgradeType, int count, boolean shiftHeld) {
|
||||
List<Text> tips = new ArrayList<>();
|
||||
boolean shouldStackCalculate = true;
|
||||
boolean shouldStackCalculate = count > 1;
|
||||
|
||||
switch (upgradeType) {
|
||||
case OVERCLOCKER:
|
||||
|
@ -69,7 +69,7 @@ public class ToolTipAssistUtils {
|
|||
|
||||
// Add reminder that they can use shift to calculate the entire stack
|
||||
if (shouldStackCalculate && !shiftHeld) {
|
||||
tips.add(new LiteralText(instructColour + I18n.translate("techreborn.tooltip.more_info")));
|
||||
tips.add(new LiteralText(instructColour + I18n.translate("techreborn.tooltip.stack_info")));
|
||||
}
|
||||
|
||||
return tips;
|
||||
|
@ -88,7 +88,7 @@ public class ToolTipAssistUtils {
|
|||
String[] infoLines = info.split("\\r?\\n");
|
||||
|
||||
for (String infoLine : infoLines) {
|
||||
list.add(new LiteralText(infoColour + infoLine));
|
||||
list.add(1, new LiteralText(infoColour + infoLine));
|
||||
}
|
||||
} else {
|
||||
list.add(new LiteralText(instructColour + I18n.translate("techreborn.tooltip.more_info")));
|
||||
|
|
|
@ -810,6 +810,8 @@
|
|||
"_comment22": "Tooltips",
|
||||
"techreborn.tooltip.transferRate": "Transfer Rate",
|
||||
"techreborn.tooltip.tier": "Tier",
|
||||
"techreborn.tooltip.input_tier": "Input Tier",
|
||||
"techreborn.tooltip.output_tier": "Output Tier",
|
||||
"techreborn.tooltip.wip": "WIP Coming Soon",
|
||||
"techreborn.tooltip.inventory": "Inventory",
|
||||
"techreborn.tooltip.upgrades": "Upgrades",
|
||||
|
@ -831,7 +833,7 @@
|
|||
"techreborn.tooltip.painting_tool.apply": "Right click on covered cable to apply",
|
||||
"techreborn.tooltip.cable.can_cover": "Can be covered with wooden plates",
|
||||
"techreborn.tooltip.more_info": "Hold Shift for more info",
|
||||
"techreborn.tooltip.has_data": "Stored data",
|
||||
"techreborn.tooltip.stack_info": "Hold Shift for stack info",
|
||||
"techreborn.tooltip.omnitool_motto" : "Swiss Army Knife",
|
||||
|
||||
"_comment23": "ManualUI",
|
||||
|
|
Loading…
Add table
Reference in a new issue