Fix tooltip for cables. Closes #2915
This commit is contained in:
parent
40b58b4ce5
commit
420a165f6b
2 changed files with 28 additions and 15 deletions
|
@ -59,7 +59,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CableBlockEntity extends BlockEntity
|
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.
|
// Can't use SimpleEnergyStorage because the cable type is not available when the BE is constructed.
|
||||||
final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
|
final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -165,7 +165,9 @@ public class CableBlockEntity extends BlockEntity
|
||||||
|
|
||||||
void appendTargets(List<OfferedEnergyStorage> targetStorages) {
|
void appendTargets(List<OfferedEnergyStorage> targetStorages) {
|
||||||
ServerWorld serverWorld = (ServerWorld) world;
|
ServerWorld serverWorld = (ServerWorld) world;
|
||||||
if (serverWorld == null) { return; }
|
if (serverWorld == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Update our targets if necessary.
|
// Update our targets if necessary.
|
||||||
if (targets == null) {
|
if (targets == null) {
|
||||||
|
@ -263,22 +265,22 @@ public class CableBlockEntity extends BlockEntity
|
||||||
@Override
|
@Override
|
||||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||||
info.add(
|
info.add(
|
||||||
new TranslatableText("techreborn.tooltip.transferRate")
|
new TranslatableText("techreborn.tooltip.transferRate")
|
||||||
.formatted(Formatting.GRAY)
|
.formatted(Formatting.GRAY)
|
||||||
.append(": ")
|
.append(": ")
|
||||||
.append(PowerSystem.getLocalizedPower(getCableType().transferRate))
|
.append(PowerSystem.getLocalizedPower(getCableType().transferRate))
|
||||||
.formatted(Formatting.GOLD)
|
.formatted(Formatting.GOLD)
|
||||||
.append("/t")
|
.append("/t")
|
||||||
);
|
);
|
||||||
|
|
||||||
info.add(
|
info.add(
|
||||||
new TranslatableText("techreborn.tooltip.tier")
|
new TranslatableText("techreborn.tooltip.tier")
|
||||||
.formatted(Formatting.GRAY)
|
.formatted(Formatting.GRAY)
|
||||||
.append(": ")
|
.append(": ")
|
||||||
.append(
|
.append(
|
||||||
new LiteralText(StringUtils.toFirstCapitalAllLowercase(getCableType().tier.toString()))
|
new LiteralText(StringUtils.toFirstCapitalAllLowercase(getCableType().tier.toString()))
|
||||||
.formatted(Formatting.GOLD)
|
.formatted(Formatting.GOLD)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!getCableType().canKill) {
|
if (!getCableType().canKill) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.item.TooltipContext;
|
import net.minecraft.client.item.TooltipContext;
|
||||||
|
@ -43,8 +44,11 @@ import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import reborncore.api.IListInfoProvider;
|
||||||
import reborncore.common.BaseBlockEntityProvider;
|
import reborncore.common.BaseBlockEntityProvider;
|
||||||
|
import techreborn.blocks.cable.CableBlock;
|
||||||
import techreborn.events.OreDepthSyncHandler;
|
import techreborn.events.OreDepthSyncHandler;
|
||||||
import techreborn.init.TRContent;
|
import techreborn.init.TRContent;
|
||||||
import techreborn.items.DynamicCellItem;
|
import techreborn.items.DynamicCellItem;
|
||||||
|
@ -93,6 +97,13 @@ public class StackToolTipHandler implements ItemTooltipCallback {
|
||||||
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines);
|
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) {
|
if (item instanceof UpgradeItem upgrade) {
|
||||||
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines, false);
|
ToolTipAssistUtils.addInfo(item.getTranslationKey(), tooltipLines, false);
|
||||||
tooltipLines.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()));
|
||||||
|
|
Loading…
Reference in a new issue