Fixes NPE on empty tooltips (#4546)
This commit is contained in:
@@ -191,10 +191,14 @@ public abstract class AEBaseScreen<T extends AEBaseContainer> extends ContainerS
|
||||
}
|
||||
|
||||
protected void drawTooltip(MatrixStack matrices, int x, int y, ITextComponent message) {
|
||||
String[] lines = message.getString().split("\n"); // FIXME FABRIC
|
||||
List<ITextComponent> textLines = Arrays.stream(lines).map(StringTextComponent::new)
|
||||
.collect(Collectors.toList());
|
||||
this.drawTooltip(matrices, x, y, textLines);
|
||||
String tooltipText = message.getString();
|
||||
|
||||
if (!tooltipText.isEmpty()) {
|
||||
String[] lines = tooltipText.split("\n"); // FIXME FABRIC
|
||||
List<ITextComponent> textLines = Arrays.stream(lines).map(StringTextComponent::new)
|
||||
.collect(Collectors.toList());
|
||||
this.drawTooltip(matrices, x, y, textLines);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME FABRIC: move out to json (?)
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
public abstract class CustomSlotWidget extends AbstractGui implements ITooltip {
|
||||
private final int x;
|
||||
@@ -39,7 +40,7 @@ public abstract class CustomSlotWidget extends AbstractGui implements ITooltip {
|
||||
|
||||
@Override
|
||||
public ITextComponent getMessage() {
|
||||
return null;
|
||||
return StringTextComponent.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
|
||||
package appeng.client.gui.widgets;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
/**
|
||||
* AEBaseGui controlled Tooltip Interface.
|
||||
@@ -26,10 +29,13 @@ import net.minecraft.util.text.ITextComponent;
|
||||
public interface ITooltip {
|
||||
|
||||
/**
|
||||
* returns the tooltip message.
|
||||
* Returns the tooltip message.
|
||||
*
|
||||
* Should use {@link StringTextComponent#EMPTY} for no tooltip
|
||||
*
|
||||
* @return tooltip message
|
||||
*/
|
||||
@Nonnull
|
||||
ITextComponent getMessage();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package appeng.fluids.client.gui.widgets;
|
||||
|
||||
import java.awt.TextComponent;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
@@ -12,6 +13,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
@@ -84,7 +86,7 @@ public class FluidSlotWidget extends CustomSlotWidget {
|
||||
if (fluid != null) {
|
||||
return new TranslationTextComponent(fluid.getFluidStack().getTranslationKey());
|
||||
}
|
||||
return null;
|
||||
return StringTextComponent.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user