Skip to content

Commit bff730d

Browse files
committed
Rewrite printout rendering
- The current page is always centred when rendering in a GUI, with the turned pages moving from the sides. - Pages are no longer evenly distributed from the centre - they follow an exponential decay curve, so ones further out are closer together (a bit like an open book). - Render pages and books in item frames/in-hand (rather than just single pages). This currently does some very dirty things with z values in order to prevent z-fighting. It would be nice to avoid that, though the other solution of turning off the z mask causes issues when drawing the bounding box.
1 parent 3871463 commit bff730d

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

src/main/java/dan200/computercraft/client/gui/GuiPrintout.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import dan200.computercraft.shared.media.items.ItemPrintout;
1212
import net.minecraft.client.gui.inventory.GuiContainer;
1313
import net.minecraft.client.renderer.GlStateManager;
14-
import net.minecraft.util.ResourceLocation;
1514
import org.lwjgl.input.Mouse;
1615

1716
import java.io.IOException;
@@ -20,10 +19,6 @@
2019

2120
public class GuiPrintout extends GuiContainer
2221
{
23-
public static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printout.png" );
24-
public static final int X_SIZE = 172;
25-
public static final int Y_SIZE = 209;
26-
2722
private final boolean m_book;
2823
private final int m_pages;
2924
private final TextBuffer[] m_text;
@@ -33,23 +28,18 @@ public class GuiPrintout extends GuiContainer
3328
public GuiPrintout( ContainerHeldItem container )
3429
{
3530
super( container );
36-
m_book = (ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book);
3731

3832
String[] text = ItemPrintout.getText( container.getStack() );
3933
m_text = new TextBuffer[ text.length ];
40-
for( int i = 0; i < m_text.length; ++i )
41-
{
42-
m_text[ i ] = new TextBuffer( text[ i ] );
43-
}
34+
for( int i = 0; i < m_text.length; ++i ) m_text[ i ] = new TextBuffer( text[ i ] );
35+
4436
String[] colours = ItemPrintout.getColours( container.getStack() );
4537
m_colours = new TextBuffer[ colours.length ];
46-
for( int i = 0; i < m_colours.length; ++i )
47-
{
48-
m_colours[ i ] = new TextBuffer( colours[ i ] );
49-
}
38+
for( int i = 0; i < m_colours.length; ++i ) m_colours[ i ] = new TextBuffer( colours[ i ] );
5039

51-
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
5240
m_page = 0;
41+
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
42+
m_book = ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book;
5343
}
5444

5545
@Override

src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@
22

33
import dan200.computercraft.ComputerCraft;
44
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
5-
import dan200.computercraft.client.gui.GuiPrintout;
65
import dan200.computercraft.core.terminal.TextBuffer;
76
import dan200.computercraft.shared.util.Palette;
87
import net.minecraft.client.Minecraft;
98
import net.minecraft.client.renderer.BufferBuilder;
109
import net.minecraft.client.renderer.GlStateManager;
1110
import net.minecraft.client.renderer.Tessellator;
1211
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
12+
import net.minecraft.util.ResourceLocation;
1313
import org.lwjgl.opengl.GL11;
1414

1515
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
1616
import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE;
1717

1818
public class PrintoutRenderer
1919
{
20-
private static final double SIZE = 256.0;
20+
private static final ResourceLocation BG = new ResourceLocation( "computercraft", "textures/gui/printout.png" );
21+
private static final double BG_SIZE = 256.0;
2122

2223
/**
2324
* Width of a page
2425
*/
25-
private static final int X_SIZE = 172;
26+
public static final int X_SIZE = 172;
2627

2728
/**
2829
* Height of a page
2930
*/
30-
private static final int Y_SIZE = 209;
31+
public static final int Y_SIZE = 209;
3132

3233
/**
3334
* Padding between the left and right of a page and the text
@@ -75,7 +76,7 @@ public static void drawText( int x, int y, int start, String[] text, String[] co
7576
public static void drawBorder( double x, double y, double z, int page, int pages, boolean isBook )
7677
{
7778
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
78-
Minecraft.getMinecraft().getTextureManager().bindTexture( GuiPrintout.BACKGROUND );
79+
Minecraft.getMinecraft().getTextureManager().bindTexture( BG );
7980

8081
Tessellator tessellator = Tessellator.getInstance();
8182
BufferBuilder buffer = tessellator.getBuffer();
@@ -140,18 +141,18 @@ public static void drawBorder( double x, double y, double z, int page, int pages
140141

141142
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double u, double v, double width, double height )
142143
{
143-
buffer.pos( x, y + height, z ).tex( u / SIZE, (v + height) / SIZE ).endVertex();
144-
buffer.pos( x + width, y + height, z ).tex( (u + width) / SIZE, (v + height) / SIZE ).endVertex();
145-
buffer.pos( x + width, y, z ).tex( (u + width) / SIZE, v / SIZE ).endVertex();
146-
buffer.pos( x, y, z ).tex( u / SIZE, v / SIZE ).endVertex();
144+
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
145+
buffer.pos( x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
146+
buffer.pos( x + width, y, z ).tex( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex();
147+
buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
147148
}
148149

149150
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double width, double height, double u, double v, double tWidth, double tHeight )
150151
{
151-
buffer.pos( x, y + height, z ).tex( u / SIZE, (v + tHeight) / SIZE ).endVertex();
152-
buffer.pos( x + width, y + height, z ).tex( (u + tWidth) / SIZE, (v + tHeight) / SIZE ).endVertex();
153-
buffer.pos( x + width, y, z ).tex( (u + tWidth) / SIZE, v / SIZE ).endVertex();
154-
buffer.pos( x, y, z ).tex( u / SIZE, v / SIZE ).endVertex();
152+
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
153+
buffer.pos( x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
154+
buffer.pos( x + width, y, z ).tex( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex();
155+
buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
155156
}
156157

157158
public static double offsetAt( int page )

0 commit comments

Comments
 (0)