From 514db30fb1d40c5a73e70c191120513166f356ea Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sun, 28 Jun 2020 16:33:03 +0100 Subject: [PATCH] Add configuration options to control terminal sizes (#475) This allows for configuring the size of computers and pocket computers, as well as the max size of monitors. There's several limitations with the current implementation, but it's still "good enough" for an initial release: - Turtles cannot be resized. - GUIs do not scale themselves, so "large" sizes will not render within the default resolution. --- build.gradle | 2 +- .../dan200/computercraft/ComputerCraft.java | 15 +- .../computercraft/client/gui/GuiComputer.java | 79 +++----- .../computercraft/client/gui/GuiTurtle.java | 8 +- .../client/render/ComputerBorderRenderer.java | 175 ++++++++++++++++++ .../client/render/ItemPocketRenderer.java | 63 ++----- .../client/render/TurtlePlayerRenderer.java | 3 +- .../dan200/computercraft/shared/Config.java | 40 ++++ .../shared/computer/blocks/TileComputer.java | 4 +- .../peripheral/monitor/TileMonitor.java | 11 +- .../pocket/core/PocketServerComputer.java | 2 +- .../shared/turtle/blocks/TileTurtle.java | 2 +- .../core/computer/ComputerBootstrap.java | 2 +- 13 files changed, 277 insertions(+), 129 deletions(-) create mode 100644 src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java diff --git a/build.gradle b/build.gradle index 69b2cb01f..bd89387a1 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ } dependencies { classpath 'com.google.code.gson:gson:2.8.1' - classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.169' + classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.179' classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2' classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0' } diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index bcac1d468..d712dc914 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -93,14 +93,17 @@ public final class ComputerCraft public static boolean genericPeripheral = false; - public static final int terminalWidth_computer = 51; - public static final int terminalHeight_computer = 19; + public static int computerTermWidth = 51; + public static int computerTermHeight = 19; - public static final int terminalWidth_turtle = 39; - public static final int terminalHeight_turtle = 13; + public static final int turtleTermWidth = 39; + public static final int turtleTermHeight = 13; - public static final int terminalWidth_pocketComputer = 26; - public static final int terminalHeight_pocketComputer = 20; + public static int pocketTermWidth = 26; + public static int pocketTermHeight = 20; + + public static int monitorWidth = 8; + public static int monitorHeight = 6; public static final class TurtleUpgrades { diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index b61cb24ff..3008c9386 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -9,6 +9,7 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.client.gui.widgets.WidgetTerminal; import dan200.computercraft.client.gui.widgets.WidgetWrapper; +import dan200.computercraft.client.render.ComputerBorderRenderer; import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.inventory.ContainerComputer; @@ -17,21 +18,18 @@ import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import org.lwjgl.glfw.GLFW; +import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER; +import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN; + public final class GuiComputer extends ContainerScreen { - public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" ); - public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" ); - public static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" ); - public static final ResourceLocation BACKGROUND_COLOUR = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_colour.png" ); - - private final ComputerFamily m_family; - private final ClientComputer m_computer; - private final int m_termWidth; - private final int m_termHeight; + private final ComputerFamily family; + private final ClientComputer computer; + private final int termWidth; + private final int termHeight; private WidgetTerminal terminal; private WidgetWrapper terminalWrapper; @@ -41,10 +39,10 @@ private GuiComputer( ) { super( container, player, title ); - m_family = container.getFamily(); - m_computer = (ClientComputer) container.getComputer(); - m_termWidth = termWidth; - m_termHeight = termHeight; + family = container.getFamily(); + computer = (ClientComputer) container.getComputer(); + this.termWidth = termWidth; + this.termHeight = termHeight; terminal = null; } @@ -52,7 +50,7 @@ public static GuiComputer create( ContainerComputer container { return new GuiComputer<>( container, inventory, component, - ComputerCraft.terminalWidth_computer, ComputerCraft.terminalHeight_computer + ComputerCraft.computerTermWidth, ComputerCraft.computerTermHeight ); } @@ -60,7 +58,7 @@ public static GuiComputer createPocket( ContainerPocket { return new GuiComputer<>( container, inventory, component, - ComputerCraft.terminalWidth_pocketComputer, ComputerCraft.terminalHeight_pocketComputer + ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight ); } @@ -78,16 +76,16 @@ protected void init() { minecraft.keyboardListener.enableRepeatEvents( true ); - int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH; - int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT; + int termPxWidth = termWidth * FixedWidthFontRenderer.FONT_WIDTH; + int termPxHeight = termHeight * FixedWidthFontRenderer.FONT_HEIGHT; - xSize = termPxWidth + 4 + 24; - ySize = termPxHeight + 4 + 24; + xSize = termPxWidth + MARGIN * 2 + BORDER * 2; + ySize = termPxHeight + MARGIN * 2 + BORDER * 2; super.init(); - terminal = new WidgetTerminal( minecraft, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 ); - terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight ); + terminal = new WidgetTerminal( minecraft, () -> computer, termWidth, termHeight, MARGIN, MARGIN, MARGIN, MARGIN ); + terminalWrapper = new WidgetWrapper( terminal, MARGIN + BORDER + guiLeft, MARGIN + BORDER + guiTop, termPxWidth, termPxHeight ); children.add( terminalWrapper ); setFocused( terminalWrapper ); @@ -124,41 +122,16 @@ public boolean keyPressed( int key, int scancode, int modifiers ) @Override public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) { - // Work out where to draw - int startX = terminalWrapper.getX() - 2; - int startY = terminalWrapper.getY() - 2; - int endX = startX + terminalWrapper.getWidth() + 4; - int endY = startY + terminalWrapper.getHeight() + 4; - // Draw terminal terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() ); // Draw a border around the terminal - RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); - switch( m_family ) - { - case NORMAL: - default: - minecraft.getTextureManager().bindTexture( BACKGROUND_NORMAL ); - break; - case ADVANCED: - minecraft.getTextureManager().bindTexture( BACKGROUND_ADVANCED ); - break; - case COMMAND: - minecraft.getTextureManager().bindTexture( BACKGROUND_COMMAND ); - break; - } - - blit( startX - 12, startY - 12, 12, 28, 12, 12 ); - blit( startX - 12, endY, 12, 40, 12, 12 ); - blit( endX, startY - 12, 24, 28, 12, 12 ); - blit( endX, endY, 24, 40, 12, 12 ); - - blit( startX, startY - 12, 0, 0, endX - startX, 12 ); - blit( startX, endY, 0, 12, endX - startX, 12 ); - - blit( startX - 12, startY, 0, 28, 12, endY - startY ); - blit( endX, startY, 36, 28, 12, endY - startY ); + RenderSystem.color4f( 1, 1, 1, 1 ); + minecraft.getTextureManager().bindTexture( ComputerBorderRenderer.getTexture( family ) ); + ComputerBorderRenderer.render( + terminalWrapper.getX() - MARGIN, terminalWrapper.getY() - MARGIN, getBlitOffset(), + terminalWrapper.getWidth() + MARGIN * 2, terminalWrapper.getHeight() + MARGIN * 2 + ); } @Override diff --git a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java index 7a43c7702..517cf140f 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java @@ -49,13 +49,13 @@ protected void init() super.init(); minecraft.keyboardListener.enableRepeatEvents( true ); - int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH; - int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT; + int termPxWidth = ComputerCraft.turtleTermWidth * FixedWidthFontRenderer.FONT_WIDTH; + int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT; terminal = new WidgetTerminal( minecraft, () -> m_computer, - ComputerCraft.terminalWidth_turtle, - ComputerCraft.terminalHeight_turtle, + ComputerCraft.turtleTermWidth, + ComputerCraft.turtleTermHeight, 2, 2, 2, 2 ); terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + guiLeft, 2 + 8 + guiTop, termPxWidth, termPxHeight ); diff --git a/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java b/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java new file mode 100644 index 000000000..9c784d7fc --- /dev/null +++ b/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java @@ -0,0 +1,175 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.client.render; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.IVertexBuilder; +import dan200.computercraft.ComputerCraft; +import dan200.computercraft.shared.computer.core.ComputerFamily; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import javax.annotation.Nonnull; + +public class ComputerBorderRenderer +{ + public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" ); + public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" ); + public static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" ); + public static final ResourceLocation BACKGROUND_COLOUR = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_colour.png" ); + + private static final Matrix4f IDENTITY = new Matrix4f(); + + static + { + IDENTITY.setIdentity(); + } + + /** + * The margin between the terminal and its border. + */ + public static final int MARGIN = 2; + + /** + * The width of the terminal border. + */ + public static final int BORDER = 12; + + private static final int CORNER_TOP_Y = 28; + private static final int CORNER_BOTTOM_Y = CORNER_TOP_Y + BORDER; + private static final int CORNER_LEFT_X = BORDER; + private static final int CORNER_RIGHT_X = CORNER_LEFT_X + BORDER; + private static final int BORDER_RIGHT_X = 36; + private static final int GAP = 4; + + private static final float TEX_SCALE = 1 / 256.0f; + + private final Matrix4f transform; + private final IVertexBuilder builder; + private final int z; + private final float r, g, b; + + public ComputerBorderRenderer( Matrix4f transform, IVertexBuilder builder, int z, float r, float g, float b ) + { + this.transform = transform; + this.builder = builder; + this.z = z; + this.r = r; + this.g = g; + this.b = b; + } + + + @Nonnull + public static ResourceLocation getTexture( @Nonnull ComputerFamily family ) + { + switch( family ) + { + case NORMAL: + default: + return BACKGROUND_NORMAL; + case ADVANCED: + return BACKGROUND_ADVANCED; + case COMMAND: + return BACKGROUND_COMMAND; + } + } + + public static void render( int x, int y, int z, int width, int height ) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX ); + + render( IDENTITY, buffer, x, y, z, width, height ); + + RenderSystem.enableAlphaTest(); + tessellator.draw(); + } + + public static void render( Matrix4f transform, IVertexBuilder buffer, int x, int y, int z, int width, int height ) + { + render( transform, buffer, x, y, z, width, height, 1, 1, 1 ); + } + + public static void render( Matrix4f transform, IVertexBuilder buffer, int x, int y, int z, int width, int height, float r, float g, float b ) + { + render( transform, buffer, x, y, z, width, height, 0, r, g, b ); + } + + public static void render( Matrix4f transform, IVertexBuilder buffer, int x, int y, int z, int width, int height, int borderHeight, float r, float g, float b ) + { + new ComputerBorderRenderer( transform, buffer, z, r, g, b ).doRender( x, y, width, height, borderHeight ); + } + + public void doRender( int x, int y, int width, int height, int bottomHeight ) + { + int endX = x + width; + int endY = y + height; + + // Vertical bars + renderLine( x - BORDER, y, 0, CORNER_TOP_Y, BORDER, endY - y ); + renderLine( endX, y, BORDER_RIGHT_X, CORNER_TOP_Y, BORDER, endY - y ); + + // Top bar + renderLine( x, y - BORDER, 0, 0, endX - x, BORDER ); + renderCorner( x - BORDER, y - BORDER, CORNER_LEFT_X, CORNER_TOP_Y ); + renderCorner( endX, y - BORDER, CORNER_RIGHT_X, CORNER_TOP_Y ); + + // Bottom bar. We allow for drawing a stretched version, which allows for additional elements (such as the + // pocket computer's lights). + if( bottomHeight <= 0 ) + { + renderLine( x, endY, 0, BORDER, endX - x, BORDER ); + renderCorner( x - BORDER, endY, CORNER_LEFT_X, CORNER_BOTTOM_Y ); + renderCorner( endX, endY, CORNER_RIGHT_X, CORNER_BOTTOM_Y ); + } + else + { + // Bottom left, middle, right. We do this in three portions: the top inner corners, an extended region for + // lights, and then the bottom outer corners. + renderTexture( x - BORDER, endY, CORNER_LEFT_X, CORNER_BOTTOM_Y, BORDER, BORDER / 2 ); + renderTexture( x, endY, 0, BORDER, width, BORDER / 2, BORDER, BORDER / 2 ); + renderTexture( endX, endY, CORNER_RIGHT_X, CORNER_BOTTOM_Y, BORDER, BORDER / 2 ); + + renderTexture( x - BORDER, endY + BORDER / 2, CORNER_LEFT_X, CORNER_BOTTOM_Y + GAP, BORDER, bottomHeight, BORDER, GAP ); + renderTexture( x, endY + BORDER / 2, 0, BORDER + GAP, width, bottomHeight, BORDER, GAP ); + renderTexture( endX, endY + BORDER / 2, CORNER_RIGHT_X, CORNER_BOTTOM_Y + GAP, BORDER, bottomHeight, BORDER, GAP ); + + renderTexture( x - BORDER, endY + bottomHeight + BORDER / 2, CORNER_LEFT_X, CORNER_BOTTOM_Y + BORDER / 2, BORDER, BORDER / 2 ); + renderTexture( x, endY + bottomHeight + BORDER / 2, 0, BORDER + BORDER / 2, width, BORDER / 2 ); + renderTexture( endX, endY + bottomHeight + BORDER / 2, CORNER_RIGHT_X, CORNER_BOTTOM_Y + BORDER / 2, BORDER, BORDER / 2 ); + } + } + + private void renderCorner( int x, int y, int u, int v ) + { + renderTexture( x, y, u, v, BORDER, BORDER, BORDER, BORDER ); + } + + private void renderLine( int x, int y, int u, int v, int width, int height ) + { + renderTexture( x, y, u, v, width, height, BORDER, BORDER ); + } + + private void renderTexture( int x, int y, int u, int v, int width, int height ) + { + renderTexture( x, y, u, v, width, height, width, height ); + } + + private void renderTexture( int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight ) + { + builder.pos( transform, x, y + height, z ).color( r, g, b, 1.0f ).tex( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); + builder.pos( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).tex( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); + builder.pos( transform, x + width, y, z ).color( r, g, b, 1.0f ).tex( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).endVertex(); + builder.pos( transform, x, y, z ).color( r, g, b, 1.0f ).tex( u * TEX_SCALE, v * TEX_SCALE ).endVertex(); + } +} diff --git a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java index 9e87d4e35..157250d56 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java @@ -7,7 +7,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.IVertexBuilder; import dan200.computercraft.ComputerCraft; import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.Terminal; @@ -27,7 +26,8 @@ import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT; import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH; -import static dan200.computercraft.client.gui.GuiComputer.*; +import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER; +import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN; /** * Emulates map rendering for pocket computers. @@ -35,8 +35,6 @@ @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT ) public final class ItemPocketRenderer extends ItemMapLikeRenderer { - private static final int MARGIN = 2; - private static final int FRAME = 12; private static final int LIGHT_HEIGHT = 8; private static final ItemPocketRenderer INSTANCE = new ItemPocketRenderer(); @@ -67,8 +65,8 @@ protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, Item int termWidth, termHeight; if( terminal == null ) { - termWidth = ComputerCraft.terminalWidth_pocketComputer; - termHeight = ComputerCraft.terminalHeight_pocketComputer; + termWidth = ComputerCraft.pocketTermWidth; + termHeight = ComputerCraft.pocketTermHeight; } else { @@ -86,7 +84,7 @@ protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, Item transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) ); transform.scale( 0.5f, 0.5f, 0.5f ); - float scale = 0.75f / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT ); + float scale = 0.75f / Math.max( width + BORDER * 2, height + BORDER * 2 + LIGHT_HEIGHT ); transform.scale( scale, scale, 0 ); transform.translate( -0.5 * width, -0.5 * height, 0 ); @@ -117,10 +115,8 @@ protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, Item private static void renderFrame( Matrix4f transform, ComputerFamily family, int colour, int width, int height ) { - Minecraft.getInstance().getTextureManager().bindTexture( colour != -1 - ? BACKGROUND_COLOUR - : family == ComputerFamily.NORMAL ? BACKGROUND_NORMAL : BACKGROUND_ADVANCED - ); + Minecraft.getInstance().getTextureManager() + .bindTexture( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) ); float r = ((colour >>> 16) & 0xFF) / 255.0f; float g = ((colour >>> 8) & 0xFF) / 255.0f; @@ -130,28 +126,7 @@ private static void renderFrame( Matrix4f transform, ComputerFamily family, int BufferBuilder buffer = tessellator.getBuffer(); buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX ); - // Top left, middle, right - renderTexture( transform, buffer, -FRAME, -FRAME, 12, 28, FRAME, FRAME, r, g, b ); - renderTexture( transform, buffer, 0, -FRAME, 0, 0, width, FRAME, r, g, b ); - renderTexture( transform, buffer, width, -FRAME, 24, 28, FRAME, FRAME, r, g, b ); - - // Left and bright border - renderTexture( transform, buffer, -FRAME, 0, 0, 28, FRAME, height, r, g, b ); - renderTexture( transform, buffer, width, 0, 36, 28, FRAME, height, r, g, b ); - - // Bottom left, middle, right. We do this in three portions: the top inner corners, an extended region for - // lights, and then the bottom outer corners. - renderTexture( transform, buffer, -FRAME, height, 12, 40, FRAME, FRAME / 2, r, g, b ); - renderTexture( transform, buffer, 0, height, 0, 12, width, FRAME / 2, r, g, b ); - renderTexture( transform, buffer, width, height, 24, 40, FRAME, FRAME / 2, r, g, b ); - - renderTexture( transform, buffer, -FRAME, height + FRAME / 2, 12, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b ); - renderTexture( transform, buffer, 0, height + FRAME / 2, 0, 16, width, LIGHT_HEIGHT, FRAME, 4, r, g, b ); - renderTexture( transform, buffer, width, height + FRAME / 2, 24, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b ); - - renderTexture( transform, buffer, -FRAME, height + LIGHT_HEIGHT + FRAME / 2, 12, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b ); - renderTexture( transform, buffer, 0, height + LIGHT_HEIGHT + FRAME / 2, 0, 12 + FRAME / 2, width, FRAME / 2, r, g, b ); - renderTexture( transform, buffer, width, height + LIGHT_HEIGHT + FRAME / 2, 24, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b ); + ComputerBorderRenderer.render( transform, buffer, 0, 0, 0, width, height, LIGHT_HEIGHT, r, g, b ); tessellator.draw(); } @@ -168,26 +143,12 @@ private static void renderLight( Matrix4f transform, int colour, int width, int Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR ); - buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( transform, width, height + LIGHT_HEIGHT + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( transform, width, height + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.pos( transform, width, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.pos( transform, width, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); tessellator.draw(); RenderSystem.enableTexture(); } - - private static void renderTexture( Matrix4f transform, IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, float r, float g, float b ) - { - renderTexture( transform, builder, x, y, textureX, textureY, width, height, width, height, r, g, b ); - } - - private static void renderTexture( Matrix4f transform, IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, int textureWidth, int textureHeight, float r, float g, float b ) - { - float scale = 1 / 255.0f; - builder.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( textureX * scale, (textureY + textureHeight) * scale ).endVertex(); - builder.pos( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).tex( (textureX + textureWidth) * scale, (textureY + textureHeight) * scale ).endVertex(); - builder.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( (textureX + textureWidth) * scale, textureY * scale ).endVertex(); - builder.pos( transform, x, y, 0 ).color( r, g, b, 1.0f ).tex( textureX * scale, textureY * scale ).endVertex(); - } } diff --git a/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java b/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java index 4c00145f9..4e7cb8e70 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java @@ -7,7 +7,6 @@ package dan200.computercraft.client.render; import com.mojang.blaze3d.matrix.MatrixStack; -import dan200.computercraft.client.gui.GuiComputer; import dan200.computercraft.shared.turtle.core.TurtlePlayer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -27,7 +26,7 @@ public TurtlePlayerRenderer( EntityRendererManager renderManager ) @Override public ResourceLocation getEntityTexture( @Nonnull TurtlePlayer entity ) { - return GuiComputer.BACKGROUND_NORMAL; + return ComputerBorderRenderer.BACKGROUND_NORMAL; } @Override diff --git a/src/main/java/dan200/computercraft/shared/Config.java b/src/main/java/dan200/computercraft/shared/Config.java index bfa177156..812ef4c9c 100644 --- a/src/main/java/dan200/computercraft/shared/Config.java +++ b/src/main/java/dan200/computercraft/shared/Config.java @@ -73,6 +73,15 @@ public final class Config private static final ConfigValue turtlesCanPush; private static final ConfigValue> turtleDisabledActions; + private static final ConfigValue computerTermWidth; + private static final ConfigValue computerTermHeight; + + private static final ConfigValue pocketTermWidth; + private static final ConfigValue pocketTermHeight; + + private static final ConfigValue monitorWidth; + private static final ConfigValue monitorHeight; + private static final ConfigValue genericPeripheral; private static final ConfigValue monitorRenderer; @@ -262,6 +271,28 @@ private Config() {} builder.pop(); } + { + builder.comment( "Configure the size of various computer's terminals.\n" + + "Larger terminals require more bandwidth, so use with care." ).push( "term_sizes" ); + + builder.comment( "Terminal size of computers" ).push( "computer" ); + computerTermWidth = builder.defineInRange( "width", ComputerCraft.computerTermWidth, 1, 255 ); + computerTermHeight = builder.defineInRange( "height", ComputerCraft.computerTermHeight, 1, 255 ); + builder.pop(); + + builder.comment( "Terminal size of pocket computers" ).push( "pocket_computer" ); + pocketTermWidth = builder.defineInRange( "width", ComputerCraft.pocketTermWidth, 1, 255 ); + pocketTermHeight = builder.defineInRange( "height", ComputerCraft.pocketTermHeight, 1, 255 ); + builder.pop(); + + builder.comment( "Maximum size of monitors (in blocks)" ).push( "monitor" ); + monitorWidth = builder.defineInRange( "width", ComputerCraft.monitorWidth, 1, 32 ); + monitorHeight = builder.defineInRange( "height", ComputerCraft.monitorHeight, 1, 32 ); + builder.pop(); + + builder.pop(); + } + { builder.comment( "Options for various experimental features. These are not guaranteed to be stable, and may change or be removed across versions." ); builder.push( "experimental" ); @@ -335,6 +366,15 @@ public static void sync() ComputerCraft.turtleDisabledActions.clear(); for( String value : turtleDisabledActions.get() ) ComputerCraft.turtleDisabledActions.add( getAction( value ) ); + // Terminal size + ComputerCraft.computerTermWidth = computerTermWidth.get(); + ComputerCraft.computerTermHeight = computerTermHeight.get(); + ComputerCraft.pocketTermWidth = pocketTermWidth.get(); + ComputerCraft.pocketTermHeight = pocketTermHeight.get(); + ComputerCraft.monitorWidth = monitorWidth.get(); + ComputerCraft.monitorHeight = monitorHeight.get(); + + // Experimental ComputerCraft.genericPeripheral = genericPeripheral.get(); // Client diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java index 82d10dea2..e03862b3f 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java @@ -43,8 +43,8 @@ protected ServerComputer createComputer( int instanceID, int id ) ComputerFamily family = getFamily(); ServerComputer computer = new ServerComputer( getWorld(), id, label, instanceID, family, - ComputerCraft.terminalWidth_computer, - ComputerCraft.terminalHeight_computer + ComputerCraft.computerTermWidth, + ComputerCraft.computerTermHeight ); computer.setPosition( getPos() ); return computer; diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java index 92603cae8..129f5f783 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -41,9 +41,6 @@ public class TileMonitor extends TileGeneric public static final double RENDER_MARGIN = 0.5 / 16.0; public static final double RENDER_PIXEL_SCALE = 1.0 / 64.0; - private static final int MAX_WIDTH = 8; - private static final int MAX_HEIGHT = 6; - private static final String NBT_X = "XIndex"; private static final String NBT_Y = "YIndex"; private static final String NBT_WIDTH = "Width"; @@ -473,7 +470,7 @@ private boolean mergeLeft() if( left == null || left.m_yIndex != 0 || left.m_height != m_height ) return false; int width = left.m_width + m_width; - if( width > MAX_WIDTH ) return false; + if( width > ComputerCraft.monitorWidth ) return false; TileMonitor origin = left.getOrigin(); if( origin != null ) origin.resize( width, m_height ); @@ -487,7 +484,7 @@ private boolean mergeRight() if( right == null || right.m_yIndex != 0 || right.m_height != m_height ) return false; int width = m_width + right.m_width; - if( width > MAX_WIDTH ) return false; + if( width > ComputerCraft.monitorWidth ) return false; TileMonitor origin = getOrigin(); if( origin != null ) origin.resize( width, m_height ); @@ -501,7 +498,7 @@ private boolean mergeUp() if( above == null || above.m_xIndex != 0 || above.m_width != m_width ) return false; int height = above.m_height + m_height; - if( height > MAX_HEIGHT ) return false; + if( height > ComputerCraft.monitorHeight ) return false; TileMonitor origin = getOrigin(); if( origin != null ) origin.resize( m_width, height ); @@ -515,7 +512,7 @@ private boolean mergeDown() if( below == null || below.m_xIndex != 0 || below.m_width != m_width ) return false; int height = m_height + below.m_height; - if( height > MAX_HEIGHT ) return false; + if( height > ComputerCraft.monitorHeight ) return false; TileMonitor origin = below.getOrigin(); if( origin != null ) origin.resize( m_width, height ); diff --git a/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java b/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java index df671793b..e165daf95 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java @@ -41,7 +41,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces public PocketServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family ) { - super( world, computerID, label, instanceID, family, ComputerCraft.terminalWidth_pocketComputer, ComputerCraft.terminalHeight_pocketComputer ); + super( world, computerID, label, instanceID, family, ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight ); } @Nullable diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index bb7feed4a..2d52d0ef9 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -87,7 +87,7 @@ protected ServerComputer createComputer( int instanceID, int id ) { ServerComputer computer = new ServerComputer( getWorld(), id, label, instanceID, getFamily(), - ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle + ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight ); computer.setPosition( getPos() ); computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) ); diff --git a/src/test/java/dan200/computercraft/core/computer/ComputerBootstrap.java b/src/test/java/dan200/computercraft/core/computer/ComputerBootstrap.java index 21b55613b..3675c14d2 100644 --- a/src/test/java/dan200/computercraft/core/computer/ComputerBootstrap.java +++ b/src/test/java/dan200/computercraft/core/computer/ComputerBootstrap.java @@ -45,7 +45,7 @@ public static void run( IWritableMount mount, Consumer setup, int maxT ComputerCraft.logComputerErrors = true; ComputerCraft.maxMainComputerTime = ComputerCraft.maxMainGlobalTime = Integer.MAX_VALUE; - Terminal term = new Terminal( ComputerCraft.terminalWidth_computer, ComputerCraft.terminalHeight_computer ); + Terminal term = new Terminal( ComputerCraft.computerTermWidth, ComputerCraft.computerTermHeight ); final Computer computer = new Computer( new BasicEnvironment( mount ), term, 0 ); AssertApi api = new AssertApi();