fix custom Tooltips (#2698)

* fix custom tooltip extensions not working

* changelog
This commit is contained in:
Darkere
2020-10-04 15:06:27 +02:00
committed by GitHub
parent ffc600ec38
commit 5578655cbd
6 changed files with 27 additions and 12 deletions

View File

@@ -6,6 +6,7 @@
- Fixed crash when opening Controller GUI (Darkere)
- Fixed dye being consumed without effect in some cases (Darkere)
- Fixed deadlock caused by Portable Grid (Darkere)
- Fixed custom tooltips not working in the Grid (Darkere)
### 1.9.6
- Port to Minecraft 1.16.3 (raoulvdberge)

View File

@@ -410,7 +410,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
}
private void drawGridTooltip(MatrixStack matrixStack, IGridStack gridStack, int mouseX, int mouseY) {
List<ITextComponent> textLines = gridStack.getTooltip();
List<ITextComponent> textLines = gridStack.getTooltip(true);
List<String> smallTextLines = Lists.newArrayList();
if (!gridStack.isCraftable()) {

View File

@@ -15,7 +15,7 @@ public class TooltipGridFilter implements Predicate<IGridStack> {
@Override
public boolean test(IGridStack stack) {
List<ITextComponent> tooltip = stack.getTooltip();
List<ITextComponent> tooltip = stack.getTooltip(false);
for (int i = 1; i < tooltip.size(); ++i) {
if (tooltip.get(i).getString().toLowerCase().contains(this.tooltip.toLowerCase())) {

View File

@@ -130,14 +130,21 @@ public class FluidGridStack implements IGridStack {
}
@Override
public List<ITextComponent> getTooltip() {
if (cachedTooltip == null) {
public List<ITextComponent> getTooltip(boolean bypassCache) {
if (bypassCache || cachedTooltip == null) {
List<ITextComponent> tooltip;
try {
cachedTooltip = Arrays.asList(stack.getDisplayName());
tooltip = Arrays.asList(stack.getDisplayName());
} catch (Throwable t) {
logger.warn("Could not retrieve fluid tooltip of " + stack.getFluid().getRegistryName().toString(), t);
cachedTooltip = Arrays.asList(new StringTextComponent("<Error>"));
tooltip = Arrays.asList(new StringTextComponent("<Error>"));
}
if (bypassCache) {
return tooltip;
} else {
cachedTooltip = tooltip;
}
}

View File

@@ -26,7 +26,7 @@ public interface IGridStack {
Set<String> getTags();
List<ITextComponent> getTooltip();
List<ITextComponent> getTooltip(boolean bypassCache);
int getQuantity();

View File

@@ -141,15 +141,22 @@ public class ItemGridStack implements IGridStack {
}
@Override
public List<ITextComponent> getTooltip() {
if (cachedTooltip == null) {
public List<ITextComponent> getTooltip(boolean bypassCache) {
if (bypassCache || cachedTooltip == null) {
List<ITextComponent> tooltip;
try {
cachedTooltip = RenderUtils.getTooltipFromItem(stack);
tooltip = RenderUtils.getTooltipFromItem(stack);
} catch (Throwable t) {
logger.warn("Could not retrieve item tooltip of " + stack.getItem().toString(), t);
cachedTooltip = new ArrayList<>();
cachedTooltip.add(new StringTextComponent("<Error>"));
tooltip = new ArrayList<>();
tooltip.add(new StringTextComponent("<Error>"));
}
if (bypassCache) {
return tooltip;
} else {
cachedTooltip = tooltip;
}
}