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

@ -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) {

View file

@ -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()));