1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-14 12:10:30 +00:00

Pass lightmap variables around various renderers

- Add lightmap parameters to the text, computer and printout renderers.

 - Printouts are always rendered using the current lightmap. When
   interacting with the GUI, we use the fullbright lightmap coordinate.

 - Pocket computers render their border using the lightmap. Terminal and
   light do not use the lightmap at all.

There's some funkiness going on here with render types - it appears the
"correct" position_color_tex_lightmap render type is actually one used
for text.

Fixes #919. This bug does occur on 1.16 too, but given how complex the
rendering changes are between 1.16 and 1.17 I do /not/ want to have to
implement this twice. Sorry.
This commit is contained in:
Jonathan Coates 2021-09-19 15:49:31 +01:00
parent d0e79f310e
commit 3eb601e554
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
11 changed files with 146 additions and 140 deletions

View File

@ -5,6 +5,7 @@
*/ */
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;
import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.FrameInfo;
@ -13,18 +14,32 @@ import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
/**
* Handles rendering fixed width text and computer terminals.
*
* This class has several modes of usage:
* <ul>
* <li>{@link #drawString}: Drawing basic text without a terminal (such as for printouts). Unlike the other methods,
* this accepts a lightmap coordinate as, unlike terminals, printed pages render fullbright.</li>
* <li>{@link #drawTerminalWithoutCursor}/{@link #drawCursor}: Draw a terminal without a cursor and then draw the cursor
* separately. This is used by the monitor renderer to render the terminal to a VBO and draw the cursor dynamically.
* </li>
* <li>{@link #drawTerminal}: Draw a terminal with a cursor. This is used by the various computer GUIs to render the
* whole term.</li>
* <li>{@link #drawBlocker}: When rendering a terminal using {@link RenderTypes#TERMINAL_WITHOUT_DEPTH} you need to
* render an additional "depth blocker" on top of the monitor.</li>
* </ul>
*/
public final class FixedWidthFontRenderer public final class FixedWidthFontRenderer
{ {
private static final RenderType TYPE = RenderTypes.TERMINAL_WITH_DEPTH;
public static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" ); public static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
public static final int FONT_HEIGHT = 9; public static final int FONT_HEIGHT = 9;
@ -48,7 +63,7 @@ public final class FixedWidthFontRenderer
return 15 - Terminal.getColour( c, def ); return 15 - Terminal.getColour( c, def );
} }
private static void drawChar( Matrix4f transform, VertexConsumer buffer, float x, float y, int index, float r, float g, float b ) private static void drawChar( Matrix4f transform, VertexConsumer buffer, float x, float y, int index, float r, float g, float b, int light )
{ {
// Short circuit to avoid the common case - the texture should be blank here after all. // Short circuit to avoid the common case - the texture should be blank here after all.
if( index == '\0' || index == ' ' ) return; if( index == '\0' || index == ' ' ) return;
@ -59,12 +74,12 @@ public final class FixedWidthFontRenderer
int xStart = 1 + column * (FONT_WIDTH + 2); int xStart = 1 + column * (FONT_WIDTH + 2);
int yStart = 1 + row * (FONT_HEIGHT + 2); int yStart = 1 + row * (FONT_HEIGHT + 2);
buffer.vertex( transform, x, y, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, yStart / WIDTH ).endVertex(); buffer.vertex( transform, x, y, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, yStart / WIDTH ).uv2( light ).endVertex();
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).uv2( light ).endVertex();
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex(); buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).uv2( light ).endVertex();
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex(); buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).uv2( light ).endVertex();
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).uv2( light ).endVertex();
buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).uv2( light ).endVertex();
} }
private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, float r, float g, float b ) private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, float r, float g, float b )
@ -137,7 +152,7 @@ public final class FixedWidthFontRenderer
public static void drawString( public static void drawString(
@Nonnull Matrix4f transform, @Nonnull VertexConsumer renderer, float x, float y, @Nonnull Matrix4f transform, @Nonnull VertexConsumer renderer, float x, float y,
@Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour,
@Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize @Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize, int light
) )
{ {
if( backgroundColour != null ) if( backgroundColour != null )
@ -163,7 +178,7 @@ public final class FixedWidthFontRenderer
// Draw char // Draw char
int index = text.charAt( i ); int index = text.charAt( i );
if( index > 255 ) index = '?'; if( index > 255 ) index = '?';
drawChar( transform, renderer, x + i * FONT_WIDTH, y, index, r, g, b ); drawChar( transform, renderer, x + i * FONT_WIDTH, y, index, r, g, b, light );
} }
} }
@ -196,7 +211,7 @@ public final class FixedWidthFontRenderer
drawString( drawString(
transform, buffer, x, y + FixedWidthFontRenderer.FONT_HEIGHT * i, transform, buffer, x, y + FixedWidthFontRenderer.FONT_HEIGHT * i,
terminal.getLine( i ), terminal.getTextColourLine( i ), terminal.getBackgroundColourLine( i ), terminal.getLine( i ), terminal.getTextColourLine( i ), terminal.getBackgroundColourLine( i ),
palette, greyscale, leftMarginSize, rightMarginSize palette, greyscale, leftMarginSize, rightMarginSize, FULL_BRIGHT_LIGHTMAP
); );
} }
} }
@ -227,7 +242,7 @@ public final class FixedWidthFontRenderer
b = (float) colour[2]; b = (float) colour[2];
} }
drawChar( transform, buffer, x + cursorX * FONT_WIDTH, y + cursorY * FONT_HEIGHT, '_', r, g, b ); drawChar( transform, buffer, x + cursorX * FONT_WIDTH, y + cursorY * FONT_HEIGHT, '_', r, g, b, FULL_BRIGHT_LIGHTMAP );
} }
} }
@ -246,10 +261,10 @@ public final class FixedWidthFontRenderer
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
) )
{ {
MultiBufferSource.BufferSource renderer = Minecraft.getInstance().renderBuffers().bufferSource(); MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() );
VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ); VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH );
drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
renderer.endBatch( RenderTypes.TERMINAL_WITH_DEPTH ); renderer.endBatch();
} }
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull MultiBufferSource renderer, float x, float y, float width, float height ) public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull MultiBufferSource renderer, float x, float y, float width, float height )
@ -260,7 +275,7 @@ public final class FixedWidthFontRenderer
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, float x, float y, float width, float height ) public static void drawEmptyTerminal( @Nonnull Matrix4f transform, float x, float y, float width, float height )
{ {
MultiBufferSource.BufferSource renderer = Minecraft.getInstance().renderBuffers().bufferSource(); MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() );
drawEmptyTerminal( transform, renderer, x, y, width, height ); drawEmptyTerminal( transform, renderer, x, y, width, height );
renderer.endBatch(); renderer.endBatch();
} }

View File

@ -5,12 +5,12 @@
*/ */
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.ComputerSidebar; import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.client.gui.widgets.WidgetTerminal; import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.render.ComputerBorderRenderer; import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.client.render.RenderTypes;
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase; import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -76,9 +76,10 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
public void renderBg( @Nonnull PoseStack stack, float partialTicks, int mouseX, int mouseY ) public void renderBg( @Nonnull PoseStack stack, float partialTicks, int mouseX, int mouseY )
{ {
// Draw a border around the terminal // Draw a border around the terminal
RenderSystem.setShaderColor( 1, 1, 1, 1 ); ComputerBorderRenderer.render(
RenderSystem.setShaderTexture( 0, ComputerBorderRenderer.getTexture( family ) ); ComputerBorderRenderer.getTexture( family ), terminal.x, terminal.y, getBlitOffset(),
ComputerBorderRenderer.render( terminal.x, terminal.y, getBlitOffset(), terminal.getWidth(), terminal.getHeight() ); RenderTypes.FULL_BRIGHT_LIGHTMAP, terminal.getWidth(), terminal.getHeight()
);
ComputerSidebar.renderBackground( stack, leftPos, topPos + sidebarYOffset ); ComputerSidebar.renderBackground( stack, leftPos, topPos + sidebarYOffset );
} }
} }

View File

@ -7,11 +7,11 @@ package dan200.computercraft.client.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.common.ContainerHeldItem;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -21,6 +21,7 @@ import org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static dan200.computercraft.client.render.PrintoutRenderer.*; import static dan200.computercraft.client.render.PrintoutRenderer.*;
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem> public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem>
{ {
@ -97,10 +98,10 @@ public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem>
RenderSystem.setShaderColor( 1.0f, 1.0f, 1.0f, 1.0f ); RenderSystem.setShaderColor( 1.0f, 1.0f, 1.0f, 1.0f );
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
MultiBufferSource.BufferSource renderer = Minecraft.getInstance().renderBuffers().bufferSource(); MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() );
Matrix4f matrix = transform.last().pose(); Matrix4f matrix = transform.last().pose();
drawBorder( matrix, renderer, leftPos, topPos, getBlitOffset(), page, pages, book ); drawBorder( matrix, renderer, leftPos, topPos, getBlitOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP );
drawText( matrix, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, text, colours ); drawText( matrix, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours );
renderer.endBatch(); renderer.endBatch();
} }

View File

@ -5,12 +5,13 @@
*/ */
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.*; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -54,14 +55,16 @@ public class ComputerBorderRenderer
private final Matrix4f transform; private final Matrix4f transform;
private final VertexConsumer builder; private final VertexConsumer builder;
private final int light;
private final int z; private final int z;
private final float r, g, b; private final float r, g, b;
public ComputerBorderRenderer( Matrix4f transform, VertexConsumer builder, int z, float r, float g, float b ) public ComputerBorderRenderer( Matrix4f transform, VertexConsumer builder, int z, int light, float r, float g, float b )
{ {
this.transform = transform; this.transform = transform;
this.builder = builder; this.builder = builder;
this.z = z; this.z = z;
this.light = light;
this.r = r; this.r = r;
this.g = g; this.g = g;
this.b = b; this.b = b;
@ -83,32 +86,22 @@ public class ComputerBorderRenderer
} }
} }
public static void render( int x, int y, int z, int width, int height ) public static RenderType getRenderType( ResourceLocation location )
{ {
RenderSystem.setShader( GameRenderer::getPositionColorTexShader ); // See note in RenderTypes about why we use text rather than anything intuitive.
Tesselator tessellator = Tesselator.getInstance(); return RenderType.text( location );
BufferBuilder buffer = tessellator.getBuilder();
buffer.begin( VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX );
render( IDENTITY, buffer, x, y, z, width, height );
// TODO: RenderSystem.enableAlphaTest();
tessellator.end();
} }
public static void render( Matrix4f transform, VertexConsumer buffer, int x, int y, int z, int width, int height ) public static void render( ResourceLocation location, int x, int y, int z, int light, int width, int height )
{ {
render( transform, buffer, x, y, z, width, height, 1, 1, 1 ); MultiBufferSource.BufferSource source = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() );
render( IDENTITY, source.getBuffer( getRenderType( location ) ), x, y, z, light, width, height, false, 1, 1, 1 );
source.endBatch();
} }
public static void render( Matrix4f transform, VertexConsumer buffer, int x, int y, int z, int width, int height, float r, float g, float b ) public static void render( Matrix4f transform, VertexConsumer buffer, int x, int y, int z, int light, int width, int height, boolean withLight, float r, float g, float b )
{ {
render( transform, buffer, x, y, z, width, height, false, r, g, b ); new ComputerBorderRenderer( transform, buffer, z, light, r, g, b ).doRender( x, y, width, height, withLight );
}
public static void render( Matrix4f transform, VertexConsumer buffer, int x, int y, int z, int width, int height, boolean withLight, float r, float g, float b )
{
new ComputerBorderRenderer( transform, buffer, z, r, g, b ).doRender( x, y, width, height, withLight );
} }
public void doRender( int x, int y, int width, int height, boolean withLight ) public void doRender( int x, int y, int width, int height, boolean withLight )
@ -158,9 +151,9 @@ public class ComputerBorderRenderer
private void renderTexture( int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight ) private void renderTexture( int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight )
{ {
builder.vertex( transform, x, y + height, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); builder.vertex( transform, x, y + height, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).uv2( light ).endVertex();
builder.vertex( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); builder.vertex( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).uv2( light ).endVertex();
builder.vertex( transform, x + width, y, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).endVertex(); builder.vertex( transform, x + width, y, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).uv2( light ).endVertex();
builder.vertex( transform, x, y, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, v * TEX_SCALE ).endVertex(); builder.vertex( transform, x, y, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, v * TEX_SCALE ).uv2( light ).endVertex();
} }
} }

View File

@ -26,9 +26,10 @@ public abstract class ItemMapLikeRenderer
* @param transform The matrix transformation stack * @param transform The matrix transformation stack
* @param render The buffer to render to * @param render The buffer to render to
* @param stack The stack to render * @param stack The stack to render
* @param light The packed lightmap coordinates.
* @see ItemInHandRenderer#renderItem(LivingEntity, ItemStack, ItemTransforms.TransformType, boolean, PoseStack, MultiBufferSource, int) * @see ItemInHandRenderer#renderItem(LivingEntity, ItemStack, ItemTransforms.TransformType, boolean, PoseStack, MultiBufferSource, int)
*/ */
protected abstract void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack ); protected abstract void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack, int light );
protected void renderItemFirstPerson( PoseStack transform, MultiBufferSource render, int lightTexture, InteractionHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack ) protected void renderItemFirstPerson( PoseStack transform, MultiBufferSource render, int lightTexture, InteractionHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack )
{ {
@ -90,7 +91,7 @@ public abstract class ItemMapLikeRenderer
transform.mulPose( Vector3f.XP.rotationDegrees( f2 * -45f ) ); transform.mulPose( Vector3f.XP.rotationDegrees( f2 * -45f ) );
transform.mulPose( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) ); transform.mulPose( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) );
renderItem( transform, render, stack ); renderItem( transform, render, stack, combinedLight );
transform.popPose(); transform.popPose();
} }
@ -135,6 +136,6 @@ public abstract class ItemMapLikeRenderer
transform.mulPose( Vector3f.XP.rotationDegrees( rX * 20.0F ) ); transform.mulPose( Vector3f.XP.rotationDegrees( rX * 20.0F ) );
transform.scale( 2.0F, 2.0F, 2.0F ); transform.scale( 2.0F, 2.0F, 2.0F );
renderItem( transform, render, stack ); renderItem( transform, render, stack, combinedLight );
} }
} }

View File

@ -54,7 +54,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
} }
@Override @Override
protected void renderItem( PoseStack transform, MultiBufferSource renderer, ItemStack stack ) protected void renderItem( PoseStack transform, MultiBufferSource renderer, ItemStack stack, int light )
{ {
ClientComputer computer = ItemPocketComputer.createClientComputer( stack ); ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
Terminal terminal = computer == null ? null : computer.getTerminal(); Terminal terminal = computer == null ? null : computer.getTerminal();
@ -91,7 +91,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
int frameColour = item.getColour( stack ); int frameColour = item.getColour( stack );
Matrix4f matrix = transform.last().pose(); Matrix4f matrix = transform.last().pose();
renderFrame( matrix, renderer, family, frameColour, width, height ); renderFrame( matrix, renderer, family, frameColour, light, width, height );
// Render the light // Render the light
int lightColour = ItemPocketComputer.getLightState( stack ); int lightColour = ItemPocketComputer.getLightState( stack );
@ -114,7 +114,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
transform.popPose(); transform.popPose();
} }
private static void renderFrame( Matrix4f transform, MultiBufferSource render, ComputerFamily family, int colour, int width, int height ) private static void renderFrame( Matrix4f transform, MultiBufferSource render, ComputerFamily family, int colour, int light, int width, int height )
{ {
ResourceLocation texture = colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ); ResourceLocation texture = colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family );
@ -122,7 +122,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
float g = ((colour >>> 8) & 0xFF) / 255.0f; float g = ((colour >>> 8) & 0xFF) / 255.0f;
float b = (colour & 0xFF) / 255.0f; float b = (colour & 0xFF) / 255.0f;
ComputerBorderRenderer.render( transform, render.getBuffer( RenderTypes.positionColorTex( texture ) ), 0, 0, 0, width, height, true, r, g, b ); ComputerBorderRenderer.render( transform, render.getBuffer( ComputerBorderRenderer.getRenderType( texture ) ), 0, 0, 0, light, width, height, true, r, g, b );
} }
private static void renderLight( Matrix4f transform, MultiBufferSource render, int colour, int width, int height ) private static void renderLight( Matrix4f transform, MultiBufferSource render, int colour, int width, int height )

View File

@ -11,6 +11,7 @@ import com.mojang.math.Vector3f;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderHandEvent;
@ -50,13 +51,13 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
} }
@Override @Override
protected void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack ) protected void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack, int light )
{ {
transform.mulPose( Vector3f.XP.rotationDegrees( 180f ) ); transform.mulPose( Vector3f.XP.rotationDegrees( 180f ) );
transform.scale( 0.42f, 0.42f, -0.42f ); transform.scale( 0.42f, 0.42f, -0.42f );
transform.translate( -0.5f, -0.48f, 0.0f ); transform.translate( -0.5f, -0.48f, 0.0f );
drawPrintout( transform, render, stack ); drawPrintout( transform, render, stack, light );
} }
@SubscribeEvent @SubscribeEvent
@ -74,10 +75,11 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
transform.scale( 0.95f, 0.95f, -0.95f ); transform.scale( 0.95f, 0.95f, -0.95f );
transform.translate( -0.5f, -0.5f, 0.0f ); transform.translate( -0.5f, -0.5f, 0.0f );
drawPrintout( transform, event.getBuffers(), stack ); int light = event.getEntityItemFrame().getType() == EntityType.GLOW_ITEM_FRAME ? 0xf000d2 : event.getLight(); // See getLightVal.
drawPrintout( transform, event.getBuffers(), stack, light );
} }
private static void drawPrintout( PoseStack transform, MultiBufferSource render, ItemStack stack ) private static void drawPrintout( PoseStack transform, MultiBufferSource render, ItemStack stack, int light )
{ {
int pages = ItemPrintout.getPageCount( stack ); int pages = ItemPrintout.getPageCount( stack );
boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK; boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK;
@ -105,9 +107,10 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 ); transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
Matrix4f matrix = transform.last().pose(); Matrix4f matrix = transform.last().pose();
drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book ); drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book, light );
drawText( matrix, render, drawText(
X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) matrix, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, light,
ItemPrintout.getText( stack ), ItemPrintout.getColours( stack )
); );
} }
} }

View File

@ -54,32 +54,34 @@ public final class PrintoutRenderer
private PrintoutRenderer() {} private PrintoutRenderer() {}
public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, TextBuffer[] text, TextBuffer[] colours ) public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours )
{ {
VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ); VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT );
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
{ {
FixedWidthFontRenderer.drawString( transform, buffer, FixedWidthFontRenderer.drawString( transform, buffer,
x, y + line * FONT_HEIGHT, text[start + line], colours[start + line], null, Palette.DEFAULT, x, y + line * FONT_HEIGHT, text[start + line], colours[start + line], null, Palette.DEFAULT,
false, 0, 0 false, 0, 0,
light
); );
} }
} }
public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, String[] text, String[] colours ) public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, int light, String[] text, String[] colours )
{ {
VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ); VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT );
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
{ {
FixedWidthFontRenderer.drawString( transform, buffer, FixedWidthFontRenderer.drawString( transform, buffer,
x, y + line * FONT_HEIGHT, x, y + line * FONT_HEIGHT,
new TextBuffer( text[start + line] ), new TextBuffer( colours[start + line] ), new TextBuffer( text[start + line] ), new TextBuffer( colours[start + line] ),
null, Palette.DEFAULT, false, 0, 0 null, Palette.DEFAULT, false, 0, 0,
light
); );
} }
} }
public static void drawBorder( Matrix4f transform, MultiBufferSource renderer, float x, float y, float z, int page, int pages, boolean isBook ) public static void drawBorder( Matrix4f transform, MultiBufferSource renderer, float x, float y, float z, int page, int pages, boolean isBook, int light )
{ {
int leftPages = page; int leftPages = page;
int rightPages = pages - page - 1; int rightPages = pages - page - 1;
@ -94,64 +96,70 @@ public final class PrintoutRenderer
float right = x + X_SIZE + offset - 4; float right = x + X_SIZE + offset - 4;
// Left and right border // Left and right border
drawTexture( transform, buffer, left - 4, y - 8, z - 0.02f, COVER_X, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2 ); drawTexture( transform, buffer, left - 4, y - 8, z - 0.02f, COVER_X, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
drawTexture( transform, buffer, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2 ); drawTexture( transform, buffer, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
// Draw centre panel (just stretched texture, sorry). // Draw centre panel (just stretched texture, sorry).
drawTexture( transform, buffer, drawTexture( transform, buffer,
x - offset, y, z - 0.02f, X_SIZE + offset * 2, Y_SIZE, x - offset, y, z - 0.02f, X_SIZE + offset * 2, Y_SIZE,
COVER_X + COVER_SIZE / 2.0f, COVER_SIZE, COVER_SIZE, Y_SIZE COVER_X + COVER_SIZE / 2.0f, COVER_SIZE, COVER_SIZE, Y_SIZE,
light
); );
float borderX = left; float borderX = left;
while( borderX < right ) while( borderX < right )
{ {
double thisWidth = Math.min( right - borderX, X_SIZE ); double thisWidth = Math.min( right - borderX, X_SIZE );
drawTexture( transform, buffer, borderX, y - 8, z - 0.02f, 0, COVER_Y, (float) thisWidth, COVER_SIZE ); drawTexture( transform, buffer, borderX, y - 8, z - 0.02f, 0, COVER_Y, (float) thisWidth, COVER_SIZE, light );
drawTexture( transform, buffer, borderX, y + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE ); drawTexture( transform, buffer, borderX, y + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE, light );
borderX += thisWidth; borderX += thisWidth;
} }
} }
// Left half // Left half
drawTexture( transform, buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2.0f, Y_SIZE ); drawTexture( transform, buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2.0f, Y_SIZE, light );
for( int n = 0; n <= leftPages; n++ ) for( int n = 0; n <= leftPages; n++ )
{ {
drawTexture( transform, buffer, drawTexture( transform, buffer,
x - offsetAt( n ), y, z - 1e-3f * n, x - offsetAt( n ), y, z - 1e-3f * n,
// Use the left "bold" fold for the outermost page // Use the left "bold" fold for the outermost page
n == leftPages ? 0 : X_FOLD_SIZE, 0, n == leftPages ? 0 : X_FOLD_SIZE, 0,
X_FOLD_SIZE, Y_SIZE X_FOLD_SIZE, Y_SIZE, light
); );
} }
// Right half // Right half
drawTexture( transform, buffer, x + X_SIZE / 2.0f, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2.0f, 0, X_SIZE / 2.0f, Y_SIZE ); drawTexture( transform, buffer, x + X_SIZE / 2.0f, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2.0f, 0, X_SIZE / 2.0f, Y_SIZE, light );
for( int n = 0; n <= rightPages; n++ ) for( int n = 0; n <= rightPages; n++ )
{ {
drawTexture( transform, buffer, drawTexture( transform, buffer,
x + (X_SIZE - X_FOLD_SIZE) + offsetAt( n ), y, z - 1e-3f * n, x + (X_SIZE - X_FOLD_SIZE) + offsetAt( n ), y, z - 1e-3f * n,
// Two folds, then the main page. Use the right "bold" fold for the outermost page. // Two folds, then the main page. Use the right "bold" fold for the outermost page.
X_FOLD_SIZE * 2 + X_SIZE + (n == rightPages ? X_FOLD_SIZE : 0), 0, X_FOLD_SIZE * 2 + X_SIZE + (n == rightPages ? X_FOLD_SIZE : 0), 0,
X_FOLD_SIZE, Y_SIZE X_FOLD_SIZE, Y_SIZE, light
); );
} }
} }
private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float u, float v, float width, float height ) private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float u, float v, float width, float height, int light )
{ {
buffer.vertex( matrix, x, y + height, z ).uv( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); vertex( buffer, matrix, x, y + height, z, u / BG_SIZE, (v + height) / BG_SIZE, light );
buffer.vertex( matrix, x + width, y + height, z ).uv( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); vertex( buffer, matrix, x + width, y + height, z, (u + width) / BG_SIZE, (v + height) / BG_SIZE, light );
buffer.vertex( matrix, x + width, y, z ).uv( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex(); vertex( buffer, matrix, x + width, y, z, (u + width) / BG_SIZE, v / BG_SIZE, light );
buffer.vertex( matrix, x, y, z ).uv( u / BG_SIZE, v / BG_SIZE ).endVertex(); vertex( buffer, matrix, x, y, z, u / BG_SIZE, v / BG_SIZE, light );
} }
private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float width, float height, float u, float v, float tWidth, float tHeight ) private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float width, float height, float u, float v, float tWidth, float tHeight, int light )
{ {
buffer.vertex( matrix, x, y + height, z ).uv( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); vertex( buffer, matrix, x, y + height, z, u / BG_SIZE, (v + tHeight) / BG_SIZE, light );
buffer.vertex( matrix, x + width, y + height, z ).uv( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); vertex( buffer, matrix, x + width, y + height, z, (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE, light );
buffer.vertex( matrix, x + width, y, z ).uv( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex(); vertex( buffer, matrix, x + width, y, z, (u + tWidth) / BG_SIZE, v / BG_SIZE, light );
buffer.vertex( matrix, x, y, z ).uv( u / BG_SIZE, v / BG_SIZE ).endVertex(); vertex( buffer, matrix, x, y, z, u / BG_SIZE, v / BG_SIZE, light );
}
private static void vertex( VertexConsumer buffer, Matrix4f matrix, float x, float y, float z, float u, float v, int light )
{
buffer.vertex( matrix, x, y, z ).color( 255, 255, 255, 255 ).uv( u, v ).uv2( light ).endVertex();
} }
public static float offsetAt( int page ) public static float offsetAt( int page )

View File

@ -9,8 +9,6 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import net.minecraft.Util;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.client.renderer.ShaderInstance;
@ -22,11 +20,12 @@ import net.minecraftforge.fml.common.Mod;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.function.Function;
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD ) @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
public class RenderTypes public class RenderTypes
{ {
public static final int FULL_BRIGHT_LIGHTMAP = (0xF << 4) | (0xF << 20);
private static MonitorTextureBufferShader monitorTboShader; private static MonitorTextureBufferShader monitorTboShader;
private static ShaderInstance terminalShader; private static ShaderInstance terminalShader;
@ -34,16 +33,18 @@ public class RenderTypes
public static final RenderType TERMINAL_BLOCKER = Types.TERMINAL_BLOCKER; public static final RenderType TERMINAL_BLOCKER = Types.TERMINAL_BLOCKER;
public static final RenderType TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH; public static final RenderType TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH;
public static final RenderType MONITOR_TBO = Types.MONITOR_TBO; public static final RenderType MONITOR_TBO = Types.MONITOR_TBO;
public static final RenderType PRINTOUT_TEXT = Types.PRINTOUT_TEXT;
public static final RenderType PRINTOUT_BACKGROUND = Types.PRINTOUT_BACKGROUND; /**
* This looks wrong (it should be POSITION_COLOR_TEX_LIGHTMAP surely!) but the fragment/vertex shader for that
* appear to entirely ignore the lightmap.
*
* Note that vanilla maps do the same, so this isn't unreasonable.
*/
public static final RenderType PRINTOUT_BACKGROUND = RenderType.text( new ResourceLocation( "computercraft", "textures/gui/printout.png" ) );
public static final RenderType POSITION_COLOR = Types.POSITION_COLOR; public static final RenderType POSITION_COLOR = Types.POSITION_COLOR;
public static RenderType positionColorTex( ResourceLocation location )
{
return Types.POSITION_COLOR_TEX.apply( location );
}
@Nonnull @Nonnull
static MonitorTextureBufferShader getMonitorTextureBufferShader() static MonitorTextureBufferShader getMonitorTextureBufferShader()
{ {
@ -88,6 +89,7 @@ public class RenderTypes
); );
private static final VertexFormat TERM_FORMAT = DefaultVertexFormat.POSITION_COLOR_TEX; private static final VertexFormat TERM_FORMAT = DefaultVertexFormat.POSITION_COLOR_TEX;
private static final VertexFormat.Mode TERM_MODE = VertexFormat.Mode.TRIANGLES; private static final VertexFormat.Mode TERM_MODE = VertexFormat.Mode.TRIANGLES;
private static final ShaderStateShard TERM_SHADER = new ShaderStateShard( RenderTypes::getTerminalShader );
static final RenderType MONITOR_TBO = RenderType.create( static final RenderType MONITOR_TBO = RenderType.create(
"monitor_tbo", DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.TRIANGLE_STRIP, 128, "monitor_tbo", DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.TRIANGLE_STRIP, 128,
@ -100,32 +102,44 @@ public class RenderTypes
); );
static final RenderType TERMINAL_WITHOUT_DEPTH = RenderType.create( static final RenderType TERMINAL_WITHOUT_DEPTH = RenderType.create(
"monitor_basic", TERM_FORMAT, TERM_MODE, 1024, "terminal_without_depth", TERM_FORMAT, TERM_MODE, 1024,
false, false, // useDelegate, needsSorting false, false, // useDelegate, needsSorting
RenderType.CompositeState.builder() RenderType.CompositeState.builder()
.setTextureState( TERM_FONT_TEXTURE ) .setTextureState( TERM_FONT_TEXTURE )
.setShaderState( new ShaderStateShard( RenderTypes::getTerminalShader ) ) .setShaderState( TERM_SHADER )
.setWriteMaskState( COLOR_WRITE ) .setWriteMaskState( COLOR_WRITE )
.createCompositeState( false ) .createCompositeState( false )
); );
static final RenderType TERMINAL_BLOCKER = RenderType.create( static final RenderType TERMINAL_BLOCKER = RenderType.create(
"monitor_blocker", TERM_FORMAT, TERM_MODE, 256, "terminal_blocker", TERM_FORMAT, TERM_MODE, 256,
false, false, // useDelegate, needsSorting false, false, // useDelegate, needsSorting
RenderType.CompositeState.builder() RenderType.CompositeState.builder()
.setTextureState( TERM_FONT_TEXTURE ) .setTextureState( TERM_FONT_TEXTURE )
.setShaderState( new ShaderStateShard( RenderTypes::getTerminalShader ) ) .setShaderState( TERM_SHADER )
.setWriteMaskState( DEPTH_WRITE ) .setWriteMaskState( DEPTH_WRITE )
.setLightmapState( NO_LIGHTMAP )
.createCompositeState( false ) .createCompositeState( false )
); );
static final RenderType TERMINAL_WITH_DEPTH = RenderType.create( static final RenderType TERMINAL_WITH_DEPTH = RenderType.create(
"basic_terminal", TERM_FORMAT, TERM_MODE, 1024, "terminal_with_depth", TERM_FORMAT, TERM_MODE, 1024,
false, false, // useDelegate, needsSorting false, false, // useDelegate, needsSorting
RenderType.CompositeState.builder() RenderType.CompositeState.builder()
.setTextureState( TERM_FONT_TEXTURE ) .setTextureState( TERM_FONT_TEXTURE )
.setShaderState( POSITION_COLOR_TEX_SHADER ) .setShaderState( TERM_SHADER )
.createCompositeState( false )
);
/**
* A variant of {@link #TERMINAL_WITH_DEPTH} which uses the lightmap rather than rendering fullbright.
*/
static final RenderType PRINTOUT_TEXT = RenderType.create(
"printout_text", DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, TERM_MODE, 1024,
false, false, // useDelegate, needsSorting
RenderType.CompositeState.builder()
.setTextureState( TERM_FONT_TEXTURE )
.setShaderState( RenderStateShard.RENDERTYPE_TEXT_SHADER )
.setLightmapState( RenderStateShard.LIGHTMAP )
.createCompositeState( false ) .createCompositeState( false )
); );
@ -137,31 +151,6 @@ public class RenderTypes
.createCompositeState( false ) .createCompositeState( false )
); );
static final Function<ResourceLocation, RenderType> POSITION_COLOR_TEX = Util.memoize( location ->
{
return RenderType.create(
"position_color_tex", DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, 1024,
false, false, // useDelegate, needsSorting
RenderType.CompositeState.builder()
.setTextureState( new RenderStateShard.TextureStateShard( location, false, false ) )// blur, minimap
.setShaderState( POSITION_COLOR_TEX_SHADER )
.createCompositeState( false )
);
} );
static final RenderType PRINTOUT_BACKGROUND = RenderType.create(
"printout_background", DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.QUADS, 1024,
false, false, // useDelegate, needsSorting
RenderType.CompositeState.builder()
.setTextureState( new RenderStateShard.TextureStateShard(
new ResourceLocation( "computercraft", "textures/gui/printout.png" ),
false, false // blur, minimap
) )
.setShaderState( new RenderStateShard.ShaderStateShard( GameRenderer::getPositionTexShader ) )
.setLightmapState( NO_LIGHTMAP )
.createCompositeState( false )
);
private Types( String name, Runnable setup, Runnable destroy ) private Types( String name, Runnable setup, Runnable destroy )
{ {
super( name, setup, destroy ); super( name, setup, destroy );

View File

@ -24,11 +24,6 @@ public class BasicCustomLoader<T extends ModelBuilder<T>> extends CustomLoaderBu
this.extra = extra; this.extra = extra;
} }
public static <T extends ModelBuilder<T>> BiFunction<T, ExistingFileHelper, CustomLoaderBuilder<T>> makeFactory( ResourceLocation id )
{
return makeFactory( id, j -> { } );
}
public static <T extends ModelBuilder<T>> BiFunction<T, ExistingFileHelper, CustomLoaderBuilder<T>> makeFactory( ResourceLocation id, Consumer<JsonObject> extra ) public static <T extends ModelBuilder<T>> BiFunction<T, ExistingFileHelper, CustomLoaderBuilder<T>> makeFactory( ResourceLocation id, Consumer<JsonObject> extra )
{ {
return ( parent, x ) -> new BasicCustomLoader<>( id, parent, x, extra ); return ( parent, x ) -> new BasicCustomLoader<>( id, parent, x, extra );