Fix tooltip for cables. Closes #2915

This commit is contained in:
drcrazy 2022-05-06 02:15:59 +03:00
parent 40b58b4ce5
commit 420a165f6b
2 changed files with 28 additions and 15 deletions

View file

@ -59,7 +59,7 @@ import java.util.ArrayList;
import java.util.List;
public class CableBlockEntity extends BlockEntity
implements BlockEntityTicker<CableBlockEntity>, IListInfoProvider, IToolDrop {
implements BlockEntityTicker<CableBlockEntity>, IListInfoProvider, IToolDrop {
// Can't use SimpleEnergyStorage because the cable type is not available when the BE is constructed.
final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
@Override
@ -165,7 +165,9 @@ public class CableBlockEntity extends BlockEntity
void appendTargets(List<OfferedEnergyStorage> targetStorages) {
ServerWorld serverWorld = (ServerWorld) world;
if (serverWorld == null) { return; }
if (serverWorld == null) {
return;
}
// Update our targets if necessary.
if (targets == null) {
@ -263,22 +265,22 @@ public class CableBlockEntity extends BlockEntity
@Override
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
info.add(
new TranslatableText("techreborn.tooltip.transferRate")
.formatted(Formatting.GRAY)
.append(": ")
.append(PowerSystem.getLocalizedPower(getCableType().transferRate))
.formatted(Formatting.GOLD)
.append("/t")
new TranslatableText("techreborn.tooltip.transferRate")
.formatted(Formatting.GRAY)
.append(": ")
.append(PowerSystem.getLocalizedPower(getCableType().transferRate))
.formatted(Formatting.GOLD)
.append("/t")
);
info.add(
new TranslatableText("techreborn.tooltip.tier")
.formatted(Formatting.GRAY)
.append(": ")
.append(
new LiteralText(StringUtils.toFirstCapitalAllLowercase(getCableType().tier.toString()))
.formatted(Formatting.GOLD)
)
new TranslatableText("techreborn.tooltip.tier")
.formatted(Formatting.GRAY)
.append(": ")
.append(
new LiteralText(StringUtils.toFirstCapitalAllLowercase(getCableType().tier.toString()))
.formatted(Formatting.GOLD)
)
);
if (!getCableType().canKill) {

View file

@ -30,6 +30,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.item.TooltipContext;
@ -43,8 +44,11 @@ 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.BlockPos;
import net.minecraft.util.registry.Registry;
import reborncore.api.IListInfoProvider;
import reborncore.common.BaseBlockEntityProvider;
import techreborn.blocks.cable.CableBlock;
import techreborn.events.OreDepthSyncHandler;
import techreborn.init.TRContent;
import techreborn.items.DynamicCellItem;
@ -93,6 +97,13 @@ public class StackToolTipHandler implements ItemTooltipCallback {
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines);
}
if (block instanceof CableBlock cable) {
BlockEntity blockEntity = cable.createBlockEntity(BlockPos.ORIGIN, block.getDefaultState());
if (blockEntity != null) {
((IListInfoProvider) blockEntity).addInfo(tooltipLines, false, false);
}
}
if (item instanceof UpgradeItem upgrade) {
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines, false);
tooltipLines.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));