Added translation for upgrades

This commit is contained in:
drcrazy 2020-10-29 17:24:38 +03:00
parent f5107cacd0
commit 3645c156be
3 changed files with 23 additions and 30 deletions

View file

@ -25,7 +25,7 @@
package techreborn.events; package techreborn.events;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.event.client.ItemTooltipCallback; import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
@ -37,7 +37,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import reborncore.api.IListInfoProvider; import reborncore.api.IListInfoProvider;
@ -51,27 +50,20 @@ import techreborn.TechReborn;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import techreborn.items.UpgradeItem; import techreborn.items.UpgradeItem;
import techreborn.utils.ToolTipAssistUtils; import techreborn.utils.ToolTipAssistUtils;
import techreborn.utils.WIP;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class StackToolTipHandler implements ItemTooltipCallback { public class StackToolTipHandler implements ItemTooltipCallback {
private static final ArrayList<Block> wipBlocks = new ArrayList<>();
public static final Map<Item, Boolean> ITEM_ID = Maps.newHashMap(); public static final Map<Item, Boolean> ITEM_ID = Maps.newHashMap();
public static void setup() { public static void setup() {
ItemTooltipCallback.EVENT.register(new StackToolTipHandler()); ItemTooltipCallback.EVENT.register(new StackToolTipHandler());
// WIP injection
// wipBlocks.add(TRContent.Machine.NAME.block);
} }
@Override @Override
public void getTooltip(ItemStack stack, TooltipContext tooltipContext, List<Text> components) { public void getTooltip(ItemStack stack, TooltipContext tooltipContext, List<Text> tooltipLines) {
Item item = stack.getItem(); Item item = stack.getItem();
if (!ITEM_ID.computeIfAbsent(item, this::isTRItem)) if (!ITEM_ID.computeIfAbsent(item, this::isTRItem))
@ -80,25 +72,21 @@ public class StackToolTipHandler implements ItemTooltipCallback {
// Machine info and upgrades helper section // Machine info and upgrades helper section
Block block = Block.getBlockFromItem(item); Block block = Block.getBlockFromItem(item);
if (wipBlocks.contains(block) || block instanceof WIP) {
components.add(new TranslatableText("techreborn.tooltip.wip").formatted(Formatting.RED));
}
if (block instanceof BaseBlockEntityProvider) { if (block instanceof BaseBlockEntityProvider) {
ToolTipAssistUtils.addInfo(item.getTranslationKey(), components); ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines);
} }
if (item instanceof UpgradeItem) { if (item instanceof UpgradeItem) {
UpgradeItem upgrade = (UpgradeItem) item; UpgradeItem upgrade = (UpgradeItem) item;
ToolTipAssistUtils.addInfo(item.getTranslationKey(), components, false); ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines, false);
components.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown())); tooltipLines.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));
} }
// Other section // Other section
if (item instanceof IListInfoProvider) { if (item instanceof IListInfoProvider) {
((IListInfoProvider) item).addInfo(components, false, false); ((IListInfoProvider) item).addInfo(tooltipLines, false, false);
} else if (stack.getItem() instanceof EnergyHolder) { } else if (stack.getItem() instanceof EnergyHolder) {
LiteralText line1 = new LiteralText(PowerSystem.getLocalizedPowerNoSuffix(Energy.of(stack).getEnergy())); LiteralText line1 = new LiteralText(PowerSystem.getLocalizedPowerNoSuffix(Energy.of(stack).getEnergy()));
line1.append("/"); line1.append("/");
@ -107,14 +95,14 @@ public class StackToolTipHandler implements ItemTooltipCallback {
line1.append(PowerSystem.getDisplayPower().abbreviation); line1.append(PowerSystem.getDisplayPower().abbreviation);
line1.formatted(Formatting.GOLD); line1.formatted(Formatting.GOLD);
components.add(1, line1); tooltipLines.add(1, line1);
if (Screen.hasShiftDown()) { if (Screen.hasShiftDown()) {
int percentage = percentage(Energy.of(stack).getMaxStored(), Energy.of(stack).getEnergy()); int percentage = percentage(Energy.of(stack).getMaxStored(), Energy.of(stack).getEnergy());
Formatting color = StringUtils.getPercentageColour(percentage); Formatting color = StringUtils.getPercentageColour(percentage);
components.add(2, new LiteralText(color + "" + percentage + "%" + Formatting.GRAY + " Charged")); tooltipLines.add(2, new LiteralText(color + "" + percentage + "%" + Formatting.GRAY + " Charged"));
// TODO: show both input and output rates // TODO: show both input and output rates
components.add(3, new LiteralText(Formatting.GRAY + "I/O Rate: " + Formatting.GOLD + PowerSystem.getLocalizedPower(((EnergyHolder) item).getMaxInput(EnergySide.UNKNOWN)))); tooltipLines.add(3, new LiteralText(Formatting.GRAY + "I/O Rate: " + Formatting.GOLD + PowerSystem.getLocalizedPower(((EnergyHolder) item).getMaxInput(EnergySide.UNKNOWN))));
} }
} else { } else {
try { try {
@ -125,10 +113,10 @@ public class StackToolTipHandler implements ItemTooltipCallback {
CompoundTag blockEntityData = stack.getTag().getCompound("blockEntity_data"); CompoundTag blockEntityData = stack.getTag().getCompound("blockEntity_data");
blockEntity.fromTag(blockEntity.getCachedState(), blockEntityData); blockEntity.fromTag(blockEntity.getCachedState(), blockEntityData);
hasData = true; hasData = true;
components.add(new LiteralText("Block data contained").formatted(Formatting.DARK_GREEN)); tooltipLines.add(new LiteralText("Block data contained").formatted(Formatting.DARK_GREEN));
} }
if (blockEntity instanceof IListInfoProvider) { if (blockEntity instanceof IListInfoProvider) {
((IListInfoProvider) blockEntity).addInfo(components, false, hasData); ((IListInfoProvider) blockEntity).addInfo(tooltipLines, false, hasData);
} }
} }
} catch (NullPointerException e) { } catch (NullPointerException e) {

View file

@ -53,23 +53,23 @@ public class ToolTipAssistUtils {
switch (upgradeType) { switch (upgradeType) {
case OVERCLOCKER: case OVERCLOCKER:
tips.add(getPositive("Speed increase", calculateValue(TechRebornConfig.overclockerSpeed * 100, count, shiftHeld), "%")); tips.add(getPositive(I18n.translate("techreborn.tooltip.upgrade.speed_increase"), calculateValue(TechRebornConfig.overclockerSpeed * 100, count, shiftHeld), "%"));
tips.add(getNegative("Energy increase", calculateValue(TechRebornConfig.overclockerPower * 100, count, shiftHeld), "%")); tips.add(getNegative(I18n.translate("techreborn.tooltip.upgrade.energy_increase"), calculateValue(TechRebornConfig.overclockerPower * 100, count, shiftHeld), "%"));
break; break;
case TRANSFORMER: case TRANSFORMER:
shouldStackCalculate = false; shouldStackCalculate = false;
break; break;
case ENERGY_STORAGE: case ENERGY_STORAGE:
tips.add(getPositive("Storage increase", calculateValue(TechRebornConfig.energyStoragePower, count, shiftHeld), " E")); tips.add(getPositive(I18n.translate("techreborn.tooltip.upgrade.storage_increase"), calculateValue(TechRebornConfig.energyStoragePower, count, shiftHeld), " E"));
break; break;
case SUPERCONDUCTOR: case SUPERCONDUCTOR:
tips.add(getPositive("Increased flow by: ", calculateValue(Math.pow(2, (TechRebornConfig.superConductorCount + 2)) * 100, count, shiftHeld), "%")); tips.add(getPositive(I18n.translate("techreborn.tooltip.upgrade.flow_increase"), calculateValue(Math.pow(2, (TechRebornConfig.superConductorCount + 2)) * 100, count, shiftHeld), "%"));
break; break;
} }
// Add reminder that they can use shift to calculate the entire stack // Add reminder that they can use shift to calculate the entire stack
if (shouldStackCalculate && !shiftHeld) { if (shouldStackCalculate && !shiftHeld) {
tips.add(new LiteralText(instructColour + "Hold shift for stack calculation")); tips.add(new LiteralText(instructColour + I18n.translate("techreborn.tooltip.more_info")));
} }
return tips; return tips;
@ -91,7 +91,7 @@ public class ToolTipAssistUtils {
list.add(new LiteralText(infoColour + infoLine)); list.add(new LiteralText(infoColour + infoLine));
} }
} else { } else {
list.add(new LiteralText(instructColour + "Hold shift for info")); list.add(new LiteralText(instructColour + I18n.translate("techreborn.tooltip.more_info")));
} }
} }
} }

View file

@ -711,7 +711,7 @@
"techreborn.message.nightgen": "Panel in reduced sunlight", "techreborn.message.nightgen": "Panel in reduced sunlight",
"techreborn.message.zerogen": "Panel obstructed from sky", "techreborn.message.zerogen": "Panel obstructed from sky",
"techreborn.message.info.item.techreborn.overclocker_upgrade": "Increases speed at the cost of more energy", "techreborn.message.info.item.techreborn.overclocker_upgrade": "Increases speed at the cost of more energy used per tick",
"techreborn.message.info.item.techreborn.transformer_upgrade": "Increase energy tier", "techreborn.message.info.item.techreborn.transformer_upgrade": "Increase energy tier",
"techreborn.message.info.item.techreborn.energy_storage_upgrade": "Increase energy store", "techreborn.message.info.item.techreborn.energy_storage_upgrade": "Increase energy store",
"techreborn.message.info.item.techreborn.superconductor_upgrade": "Increases energy flow rate", "techreborn.message.info.item.techreborn.superconductor_upgrade": "Increases energy flow rate",
@ -813,6 +813,10 @@
"techreborn.tooltip.wip": "WIP Coming Soon", "techreborn.tooltip.wip": "WIP Coming Soon",
"techreborn.tooltip.inventory": "Inventory", "techreborn.tooltip.inventory": "Inventory",
"techreborn.tooltip.upgrades": "Upgrades", "techreborn.tooltip.upgrades": "Upgrades",
"techreborn.tooltip.upgrade.speed_increase": "Speed increase",
"techreborn.tooltip.upgrade.energy_increase": "Energy increase",
"techreborn.tooltip.upgrade.storage_increase": "Storage increase",
"techreborn.tooltip.upgrade.flow_increase": "Increased flow by",
"techreborn.tooltip.alarm": "Shift right-click to change sound", "techreborn.tooltip.alarm": "Shift right-click to change sound",
"techreborn.tooltip.invalid_basin_placement": "Resin basin must be placed on a valid rubber tree.", "techreborn.tooltip.invalid_basin_placement": "Resin basin must be placed on a valid rubber tree.",
"techreborn.tooltip.generationRate.day": "Generation Rate Day", "techreborn.tooltip.generationRate.day": "Generation Rate Day",
@ -824,6 +828,7 @@
"techreborn.tooltip.painting_tool.select": "Shift right click on block to set style", "techreborn.tooltip.painting_tool.select": "Shift right click on block to set style",
"techreborn.tooltip.painting_tool.apply": "Right click on covered cable to apply", "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.cable.can_cover": "Can be covered with wooden plates",
"techreborn.tooltip.more_info": "Hold Shift for more info",
"_comment23": "ManualUI", "_comment23": "ManualUI",
"techreborn.manual.wiki": "Online wiki", "techreborn.manual.wiki": "Online wiki",