Fixes to lighting / tooltips / font rendering / item rendering

This commit is contained in:
raoulvdberge
2020-01-14 01:32:40 +01:00
parent af3f0743be
commit 06b8d65134
11 changed files with 156 additions and 76 deletions

View File

@@ -46,7 +46,7 @@ public class GridTab implements IGridTab {
@Override
public void drawIcon(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer) {
if (!icon.isEmpty()) {
RenderSystem.setupGuiFlatDiffuseLighting();
RenderSystem.setupGui3DDiffuseLighting();
itemDrawer.draw(x, y, icon);
} else {

View File

@@ -1,5 +1,6 @@
package com.raoulvdberge.refinedstorage.screen;
import com.mojang.blaze3d.systems.RenderSystem;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.render.RenderSettings;
import net.minecraft.client.gui.widget.TextFieldWidget;

View File

@@ -14,6 +14,7 @@ import com.raoulvdberge.refinedstorage.screen.widget.CheckBoxWidget;
import com.raoulvdberge.refinedstorage.screen.widget.sidebutton.SideButton;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
@@ -39,6 +40,10 @@ import java.util.*;
import java.util.function.Consumer;
public abstract class BaseScreen<T extends Container> extends ContainerScreen<T> {
public static final int Z_LEVEL_ITEMS = 100;
public static final int Z_LEVEL_TOOLTIPS = 500;
public static final int Z_LEVEL_QTY = 300;
private static final Map<String, ResourceLocation> TEXTURE_CACHE = new HashMap<>();
private static final Map<Class, Queue<Consumer>> ACTIONS = new HashMap<>();
@@ -274,24 +279,26 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
}
public void renderItem(int x, int y, ItemStack stack) {
renderItem(x, y, stack, false, null, RenderSettings.INSTANCE.getSecondaryColor());
renderItem(x, y, stack, false, null, 0);
}
public void renderItem(int x, int y, ItemStack stack, boolean overlay, @Nullable String text, int textColor) {
try {
itemRenderer.zLevel = 200.0F;
setBlitOffset(Z_LEVEL_ITEMS);
itemRenderer.zLevel = Z_LEVEL_ITEMS;
itemRenderer.renderItemIntoGUI(stack, x, y);
if (overlay) {
this.itemRenderer.renderItemOverlayIntoGUI(font, stack, x, y, "");
itemRenderer.renderItemOverlayIntoGUI(font, stack, x, y, "");
}
setBlitOffset(0);
itemRenderer.zLevel = 0;
if (text != null) {
renderQuantity(x, y, text, textColor);
}
itemRenderer.zLevel = 0.0F;
} catch (Throwable t) {
logger.warn("Couldn't render stack: " + stack.getItem().toString(), t);
}
@@ -301,7 +308,7 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
boolean large = minecraft.getForceUnicodeFont() || RS.CLIENT_CONFIG.getGrid().getLargeFont();
RenderSystem.pushMatrix();
RenderSystem.translatef(x, y, 1);
RenderSystem.translatef(x, y, Z_LEVEL_QTY);
if (!large) {
RenderSystem.scalef(0.5f, 0.5f, 1);
@@ -329,9 +336,7 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
}
public void renderString(int x, int y, String message, int color) {
RenderSystem.disableLighting();
font.drawString(message, x, y, color);
RenderSystem.enableLighting();
}
public void renderTooltip(int x, int y, String lines) {
@@ -343,9 +348,7 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
}
public void renderTooltip(@Nonnull ItemStack stack, int x, int y, List<String> lines) {
RenderSystem.disableLighting();
GuiUtils.drawHoveringText(stack, lines, x, y, width - guiLeft, height, -1, font);
RenderSystem.enableLighting();
GuiUtils.drawHoveringText(stack, lines, x, y, width, height, -1, font);
}
protected void onPreInit() {

View File

@@ -89,7 +89,7 @@ public class ControllerScreen extends BaseScreen<ControllerContainer> {
int slot = scrollbar.getOffset() * 2;
RenderSystem.setupGuiFlatDiffuseLighting();
RenderSystem.setupGui3DDiffuseLighting();
List<ClientNode> nodes = ControllerTile.NODES.getValue();

View File

@@ -54,12 +54,7 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
}
@Override
public List<IFilter> getFilters() {
return null;
}
@Override
public void drawTooltip(int x, int y, int xSize, int ySize, FontRenderer fontRenderer) {
public void drawTooltip(int x, int y, int screenWidth, int screenHeight, FontRenderer fontRenderer) {
List<String> textLines = Lists.newArrayList(requested.getItem() != null ? requested.getItem().getDisplayName().getFormattedText() : requested.getFluid().getDisplayName().getFormattedText());
List<String> smallTextLines = Lists.newArrayList();
@@ -71,13 +66,18 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
smallTextLines.add(String.format("%02d:%02d", minutes, seconds));
smallTextLines.add(String.format("%d%%", completionPercentage));
RenderUtils.drawTooltipWithSmallText(textLines, smallTextLines, true, ItemStack.EMPTY, x, y, xSize, ySize, fontRenderer);
RenderUtils.drawTooltipWithSmallText(textLines, smallTextLines, true, ItemStack.EMPTY, x, y, screenWidth, screenHeight, fontRenderer);
}
@Override
public List<IFilter> getFilters() {
return null;
}
@Override
public void drawIcon(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer) {
if (requested.getItem() != null) {
RenderSystem.setupGuiFlatDiffuseLighting();
RenderSystem.setupGui3DDiffuseLighting();
itemDrawer.draw(x, y, requested.getItem());
} else {
@@ -255,7 +255,7 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
int item = scrollbar != null ? scrollbar.getOffset() * 3 : 0;
RenderSystem.setupGuiFlatDiffuseLighting();
RenderSystem.setupGui3DDiffuseLighting();
int x = 7;
int y = 20;

View File

@@ -168,8 +168,6 @@ public class AlternativesScreen extends BaseScreen {
int x = 8;
int y = 20;
RenderSystem.setupGuiFlatDiffuseLighting();
for (int i = 0; i < lines.size(); ++i) {
boolean visible = i >= scrollbar.getOffset() && i < scrollbar.getOffset() + getVisibleRows();
@@ -284,6 +282,7 @@ public class AlternativesScreen extends BaseScreen {
@Override
public void render(int x, int y) {
RenderSystem.color4f(1,1,1,1);
renderItem(x + 3, y + 2, item);
renderString(x + 4 + 19, y + 7, item.getDisplayName().getFormattedText());
}

View File

@@ -142,7 +142,7 @@ public class CraftingPreviewScreen extends BaseScreen {
renderString(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy + 6, scale), output.getDisplayName().getFormattedText());
RenderSystem.popMatrix();
RenderSystem.setupGuiFlatDiffuseLighting();
RenderSystem.setupGui3DDiffuseLighting();
RenderSystem.enableDepthTest();
renderItem(x + 5, yy, output);
RenderHelper.disableStandardItemLighting();
@@ -165,7 +165,7 @@ public class CraftingPreviewScreen extends BaseScreen {
} else {
int slot = scrollbar != null ? (scrollbar.getOffset() * 3) : 0;
RenderSystem.setupGuiFlatDiffuseLighting();
RenderSystem.setupGui3DDiffuseLighting();
RenderSystem.enableDepthTest();
this.hoveringStack = null;

View File

@@ -365,13 +365,13 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
if (RenderUtils.inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isGridActive()) {
int color = grid.isGridActive() ? -2130706433 : 0xFF5B5B5B;
RenderSystem.pushMatrix();
RenderSystem.disableLighting();
RenderSystem.disableDepthTest();
RenderSystem.colorMask(true, true, true, false);
fillGradient(x, y, x + 16, y + 16, color, color);
RenderSystem.colorMask(true, true, true, true);
RenderSystem.enableLighting();
RenderSystem.enableDepthTest();
RenderSystem.popMatrix();
}
slot++;
@@ -409,7 +409,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
ItemStack stack = gridStack instanceof ItemGridStack ? ((ItemGridStack) gridStack).getStack() : ItemStack.EMPTY;
RenderUtils.drawTooltipWithSmallText(textLines, smallTextLines, RS.CLIENT_CONFIG.getGrid().getDetailedTooltip(), stack, mouseX, mouseY, xSize, ySize, font);
RenderUtils.drawTooltipWithSmallText(textLines, smallTextLines, RS.CLIENT_CONFIG.getGrid().getDetailedTooltip(), stack, mouseX, mouseY, width, height, font);
}
@Override

View File

@@ -159,7 +159,7 @@ public class TabListWidget {
public void drawTooltip(FontRenderer fontRenderer, int mouseX, int mouseY) {
if (tabHovering >= 0 && tabHovering < tabs.get().size()) {
tabs.get().get(tabHovering).drawTooltip(mouseX, mouseY, gui.getXSize(), gui.getYSize(), fontRenderer);
tabs.get().get(tabHovering).drawTooltip(mouseX, mouseY, gui.width, gui.height, fontRenderer);
}
}

View File

@@ -236,6 +236,11 @@ public class ClientSetup {
RenderTypeLookup.setRenderLayer(RSBlocks.RELAY, cutout);
RenderTypeLookup.setRenderLayer(RSBlocks.SECURITY_MANAGER, cutout);
RenderTypeLookup.setRenderLayer(RSBlocks.WIRELESS_TRANSMITTER, cutout);
RenderTypeLookup.setRenderLayer(RSBlocks.IMPORTER, cutout);
RenderTypeLookup.setRenderLayer(RSBlocks.EXPORTER, cutout);
RenderTypeLookup.setRenderLayer(RSBlocks.EXTERNAL_STORAGE, cutout);
RenderTypeLookup.setRenderLayer(RSBlocks.CONSTRUCTOR, cutout);
RenderTypeLookup.setRenderLayer(RSBlocks.DESTRUCTOR, cutout);
// TODO ClientRegistry.bindTileEntitySpecialRenderer(StorageMonitorTile.class, new StorageMonitorTileRenderer());

View File

@@ -2,13 +2,15 @@ package com.raoulvdberge.refinedstorage.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.render.Styles;
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
@@ -101,44 +103,39 @@ public final class RenderUtils {
// @Volatile: Copied with some tweaks from GuiUtils#drawHoveringText(@Nonnull final ItemStack stack, List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font)
public static void drawTooltipWithSmallText(List<String> textLines, List<String> smallTextLines, boolean showSmallText, @Nonnull ItemStack stack, int mouseX, int mouseY, int screenWidth, int screenHeight, FontRenderer fontRenderer) {
if (!textLines.isEmpty()) {
RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mouseX, mouseY, screenWidth, screenHeight, -1, fontRenderer);
if (MinecraftForge.EVENT_BUS.post(event)) {
return;
}
// RS begin - definitions
int maxTextWidth = -1;
FontRenderer font = Minecraft.getInstance().fontRenderer;
float textScale = Minecraft.getInstance().getForceUnicodeFont() ? 1F : 0.7F;
// RS end
if (!textLines.isEmpty())
{
RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font);
if (MinecraftForge.EVENT_BUS.post(event))
return;
mouseX = event.getX();
mouseY = event.getY();
screenWidth = event.getScreenWidth();
screenHeight = event.getScreenHeight();
FontRenderer font = event.getFontRenderer();
// RS BEGIN
float textScale = Minecraft.getInstance().getForceUnicodeFont() ? 1F : 0.7F;
// RS END
maxTextWidth = event.getMaxWidth();
font = event.getFontRenderer();
RenderSystem.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
RenderSystem.disableLighting();
RenderSystem.disableDepthTest();
int tooltipTextWidth = 0;
for (String textLine : textLines) {
for (String textLine : textLines)
{
int textLineWidth = font.getStringWidth(textLine);
if (textLineWidth > tooltipTextWidth) {
if (textLineWidth > tooltipTextWidth)
tooltipTextWidth = textLineWidth;
}
}
// RS BEGIN
if (showSmallText) {
int size;
for (String smallText : smallTextLines) {
size = (int) (font.getStringWidth(smallText) * textScale);
int size = (int) (font.getStringWidth(smallText) * textScale);
if (size > tooltipTextWidth) {
tooltipTextWidth = size;
@@ -147,17 +144,65 @@ public final class RenderUtils {
}
// RS END
boolean needsWrap = false;
int titleLinesCount = 1;
int tooltipX = mouseX + 12;
if (tooltipX + tooltipTextWidth + 4 > screenWidth)
{
tooltipX = mouseX - 16 - tooltipTextWidth;
if (tooltipX < 4) // if the tooltip doesn't fit on the screen
{
if (mouseX > screenWidth / 2)
tooltipTextWidth = mouseX - 12 - 8;
else
tooltipTextWidth = screenWidth - 16 - mouseX;
needsWrap = true;
}
}
if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth)
{
tooltipTextWidth = maxTextWidth;
needsWrap = true;
}
if (needsWrap)
{
int wrappedTooltipWidth = 0;
List<String> wrappedTextLines = new ArrayList<String>();
for (int i = 0; i < textLines.size(); i++)
{
String textLine = textLines.get(i);
List<String> wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth);
if (i == 0)
titleLinesCount = wrappedLine.size();
for (String line : wrappedLine)
{
int lineWidth = font.getStringWidth(line);
if (lineWidth > wrappedTooltipWidth)
wrappedTooltipWidth = lineWidth;
wrappedTextLines.add(line);
}
}
tooltipTextWidth = wrappedTooltipWidth;
textLines = wrappedTextLines;
if (mouseX > screenWidth / 2)
tooltipX = mouseX - 16 - tooltipTextWidth;
else
tooltipX = mouseX + 12;
}
int tooltipY = mouseY - 12;
int tooltipHeight = 8;
if (textLines.size() > 1) {
if (textLines.size() > 1)
{
tooltipHeight += (textLines.size() - 1) * 10;
if (textLines.size() > titleLinesCount) {
tooltipHeight += 2;
}
if (textLines.size() > titleLinesCount)
tooltipHeight += 2; // gap between title lines and next lines
}
// RS BEGIN
@@ -166,65 +211,92 @@ public final class RenderUtils {
}
// RS END
if (tooltipY + tooltipHeight + 6 > screenHeight) {
tooltipY = screenHeight - tooltipHeight - 6;
}
if (tooltipY < 4)
tooltipY = 4;
else if (tooltipY + tooltipHeight + 4 > screenHeight)
tooltipY = screenHeight - tooltipHeight - 4;
final int zLevel = BaseScreen.Z_LEVEL_TOOLTIPS;
int backgroundColor = 0xF0100010;
int borderColorStart = 0x505000FF;
int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, textLines, tooltipX, tooltipY, font, backgroundColor, borderColorStart, borderColorEnd);
MinecraftForge.EVENT_BUS.post(colorEvent);
backgroundColor = colorEvent.getBackground();
borderColorStart = colorEvent.getBorderStart();
borderColorEnd = colorEvent.getBorderEnd();
final int zLevel = 300;
final int backgroundColor = 0xF0100010;
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
final int borderColorStart = 0x505000FF;
final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, textLines, tooltipX, tooltipY, font, tooltipTextWidth, tooltipHeight));
IRenderTypeBuffer.Impl renderType = IRenderTypeBuffer.func_228455_a_(Tessellator.getInstance().getBuffer());
MatrixStack textStack = new MatrixStack();
textStack.func_227861_a_(0.0D, 0.0D, (double)zLevel);
Matrix4f textLocation = textStack.func_227866_c_().func_227870_a_();
int tooltipTop = tooltipY;
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber)
{
String line = textLines.get(lineNumber);
font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1);
if (line != null)
font.func_228079_a_(line, (float)tooltipX, (float)tooltipY, -1, true, textLocation, renderType, false, 0, 15728880);
if (lineNumber + 1 == titleLinesCount) {
if (lineNumber + 1 == titleLinesCount)
tooltipY += 2;
}
tooltipY += 10;
}
renderType.func_228461_a_();
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, textLines, tooltipX, tooltipTop, font, tooltipTextWidth, tooltipHeight));
// RS BEGIN
if (showSmallText) {
RenderSystem.pushMatrix();
RenderSystem.scalef(textScale, textScale, 1);
int y = tooltipTop + tooltipHeight - 6;
for (int i = smallTextLines.size() - 1; i >= 0; --i) {
font.drawStringWithShadow(
// This is FontRenderer#drawStringWithShadow but with a custom MatrixStack
RenderSystem.enableAlphaTest();
// FontRenderer#drawStringWithShadow - call to func_228078_a_ (private)
MatrixStack smallTextStack = new MatrixStack();
smallTextStack.func_227861_a_(0.0D, 0.0D, (double)zLevel);
smallTextStack.func_227862_a_(textScale, textScale, 1);
IRenderTypeBuffer.Impl lvt_7_1_ = IRenderTypeBuffer.func_228455_a_(Tessellator.getInstance().getBuffer());
font.func_228079_a_(
TextFormatting.GRAY + smallTextLines.get(i),
RenderUtils.getOffsetOnScale(tooltipX, textScale),
RenderUtils.getOffsetOnScale(y - (Minecraft.getInstance().getForceUnicodeFont() ? 2 : 0), textScale),
-1
-1,
true,
smallTextStack.func_227866_c_().func_227870_a_(),
lvt_7_1_,
false,
0,
15728880
);
lvt_7_1_.func_228461_a_();
y -= 9;
}
RenderSystem.popMatrix();
}
// RS END
RenderSystem.enableLighting();
RenderSystem.enableDepthTest();
RenderSystem.setupGuiFlatDiffuseLighting();
RenderSystem.enableRescaleNormal();
}
}