Skip to content

Commit

Permalink
1.20 fix fluid sprites not rendering in gui without .getBlitOffset() …
Browse files Browse the repository at this point in the history
…or vertexbuilders
  • Loading branch information
Lothrazar committed Jun 13, 2023
1 parent 54794c8 commit d03719c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 80 deletions.
11 changes: 5 additions & 6 deletions src/main/java/com/lothrazar/cyclic/gui/FluidBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import com.lothrazar.cyclic.registry.TextureRegistry;
import com.lothrazar.cyclic.render.FluidRenderMap;
import com.lothrazar.cyclic.render.FluidRenderMap.FluidFlow;
import com.lothrazar.cyclic.render.RenderUtils;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.material.Fluids;
Expand Down Expand Up @@ -78,12 +76,13 @@ public void draw(GuiGraphics gg, FluidStack fluid) {
}
int xPosition = x + 1;
int yPosition = y + 1;
int yOffset = height - 2;
int maximum = height - 2;
int desiredWidth = width - 2;
int desiredHeight = fluidAmount - 2;
int blitoffset = AbstractContainerScreen.SLOT_ITEM_BLIT_OFFSET;// ???????? TODO: matrixPoseStack.getBlitOffset();
RenderUtils.drawTiledSprite(gg, xPosition, yPosition, yOffset, desiredWidth, desiredHeight, sprite, width - 2, width - 2, blitoffset);
// drawTiledSprite(gg, xPosition,yPosition,yOffset, width - 2, fluidAmount - 2, sprite);
// the .getBlitOffset() no longer exists.
//good news we can drop vertexbuilder sprites and use gg blit this way
// RenderUtils.drawTiledSprite(gg, xPosition,yPosition,yOffset, width - 2, fluidAmount - 2, sprite);
gg.blit(xPosition, yPosition + (maximum - desiredHeight), 0, desiredWidth, desiredHeight, sprite);
if (fluid.getFluid() == Fluids.WATER) {
RenderSystem.setShaderColor(1, 1, 1, 1); //un-apply the water filter
}
Expand Down
74 changes: 0 additions & 74 deletions src/main/java/com/lothrazar/cyclic/render/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@
import org.joml.Matrix4f;
import com.lothrazar.cyclic.data.Model3D;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -45,74 +39,6 @@
*/
public class RenderUtils {

/**
* used by fluid gui screen rendering Thanks to Mekanism https://github.com/mekanism/Mekanism which uses compatible MIT License
*
* @param xPosition
* @param yPosition
* @param yOffset
* @param desiredWidth
* @param desiredHeight
* @param sprite
* @param textureWidth
* @param textureHeight
* @param zLevel
*/
public static void drawTiledSprite(GuiGraphics gg, int xPosition, int yPosition, int yOffset, int desiredWidth, int desiredHeight, TextureAtlasSprite sprite, int textureWidth,
int textureHeight, int zLevel) {
if (desiredWidth == 0 || desiredHeight == 0 || textureWidth == 0 || textureHeight == 0) {
return;
}
var matrix = gg.pose().last().pose();
// Minecraft.getInstance().textureManager.bind(InventoryMenu.BLOCK_ATLAS);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
int xTileCount = desiredWidth / textureWidth;
int xRemainder = desiredWidth - (xTileCount * textureWidth);
int yTileCount = desiredHeight / textureHeight;
int yRemainder = desiredHeight - (yTileCount * textureHeight);
int yStart = yPosition + yOffset;
float uMin = sprite.getU0();
float uMax = sprite.getU1();
float vMin = sprite.getV0();
float vMax = sprite.getV1();
float uDif = uMax - uMin;
float vDif = vMax - vMin;
RenderSystem.enableBlend();
// RenderSystem.enableAlphaTest();
BufferBuilder vertexBuffer = Tesselator.getInstance().getBuilder();
vertexBuffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
// vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormat.POSITION_TEX);
for (int xTile = 0; xTile <= xTileCount; xTile++) {
int width = (xTile == xTileCount) ? xRemainder : textureWidth;
if (width == 0) {
break;
}
int x = xPosition + (xTile * textureWidth);
int maskRight = textureWidth - width;
int shiftedX = x + textureWidth - maskRight;
float uMaxLocal = uMax - (uDif * maskRight / textureWidth);
for (int yTile = 0; yTile <= yTileCount; yTile++) {
int height = (yTile == yTileCount) ? yRemainder : textureHeight;
if (height == 0) {
//Note: We don't want to fully break out because our height will be zero if we are looking to
// draw the remainder, but there is no remainder as it divided evenly
break;
}
int y = yStart - ((yTile + 1) * textureHeight);
int maskTop = textureHeight - height;
float vMaxLocal = vMax - (vDif * maskTop / textureHeight);
vertexBuffer.vertex(matrix, x, y + textureHeight, zLevel).uv(uMin, vMaxLocal).endVertex();
vertexBuffer.vertex(matrix, shiftedX, y + textureHeight, zLevel).uv(uMaxLocal, vMaxLocal).endVertex();
vertexBuffer.vertex(matrix, shiftedX, y + maskTop, zLevel).uv(uMaxLocal, vMin).endVertex();
vertexBuffer.vertex(matrix, x, y + maskTop, zLevel).uv(uMin, vMin).endVertex();
}
}
vertexBuffer.end();
// BufferUploader.end(vertexBuffer);
// RenderSystem.disableAlphaTest();
RenderSystem.disableBlend();
}

private static void renderCube(Matrix4f matrix, VertexConsumer builder, BlockPos pos, Color color, float alpha) {
float red = color.getRed() / 255f, green = color.getGreen() / 255f, blue = color.getBlue() / 255f;
Expand Down

0 comments on commit d03719c

Please sign in to comment.