diff --git a/build.gradle b/build.gradle index 98eb01cc3..3c0b386da 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { classpath 'com.google.code.gson:gson:2.8.1' - classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.159' + classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.169' classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2' classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0' } diff --git a/gradle.properties b/gradle.properties index ff2a4ac96..1cc272285 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,5 @@ mod_version=1.86.2 # Minecraft properties (update mods.toml when changing) mc_version=1.15.2 -forge_version=31.0.13 -mappings_version=20200124-1.15.1 +forge_version=31.1.41 +mappings_version=20200410-1.15.1 diff --git a/src/main/java/dan200/computercraft/client/ClientRegistry.java b/src/main/java/dan200/computercraft/client/ClientRegistry.java index 3fca61a07..7f0338538 100644 --- a/src/main/java/dan200/computercraft/client/ClientRegistry.java +++ b/src/main/java/dan200/computercraft/client/ClientRegistry.java @@ -76,7 +76,7 @@ public final class ClientRegistry @SubscribeEvent public static void onTextureStitchEvent( TextureStitchEvent.Pre event ) { - if( !event.getMap().getBasePath().equals( PlayerContainer.LOCATION_BLOCKS_TEXTURE ) ) return; + if( !event.getMap().getTextureLocation().equals( PlayerContainer.LOCATION_BLOCKS_TEXTURE ) ) return; for( String extra : EXTRA_TEXTURES ) { diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 93b8e59b9..af95acd67 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -254,7 +254,7 @@ public final class FixedWidthFontRenderer } public static void drawTerminal( - float x, float y, @Nonnull Terminal terminal, boolean greyscale, + @Nonnull Matrix4f transform, float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize ) { @@ -264,26 +264,39 @@ public final class FixedWidthFontRenderer IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); IVertexBuilder buffer = renderer.getBuffer( TYPE ); - drawTerminal( IDENTITY, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); + drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); renderer.finish( TYPE ); } + public static void drawTerminal( + float x, float y, @Nonnull Terminal terminal, boolean greyscale, + float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize + ) + { + drawTerminal( IDENTITY, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); + } + public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height ) { Colour colour = Colour.BLACK; drawQuad( transform, renderer.getBuffer( TYPE ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() ); } - public static void drawEmptyTerminal( float x, float y, float width, float height ) + public static void drawEmptyTerminal( @Nonnull Matrix4f transform, float x, float y, float width, float height ) { Minecraft.getInstance().getTextureManager().bindTexture( FONT ); RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP ); IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); - drawEmptyTerminal( IDENTITY, renderer, x, y, width, height ); + drawEmptyTerminal( transform, renderer, x, y, width, height ); renderer.finish(); } + public static void drawEmptyTerminal( float x, float y, float width, float height ) + { + drawEmptyTerminal( IDENTITY, x, y, width, height ); + } + public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height ) { Colour colour = Colour.BLACK; @@ -296,10 +309,10 @@ public final class FixedWidthFontRenderer private static final VertexFormat FORMAT = DefaultVertexFormats.POSITION_COLOR_TEX; - static final RenderType MAIN = RenderType.get( + static final RenderType MAIN = RenderType.makeType( "terminal_font", FORMAT, GL_MODE, 1024, false, false, // useDelegate, needsSorting - RenderType.State.builder() + RenderType.State.getBuilder() .texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap .alpha( DEFAULT_ALPHA ) .lightmap( LIGHTMAP_DISABLED ) @@ -307,10 +320,10 @@ public final class FixedWidthFontRenderer .build( false ) ); - static final RenderType BLOCKER = RenderType.get( + static final RenderType BLOCKER = RenderType.makeType( "terminal_blocker", FORMAT, GL_MODE, 256, false, false, // useDelegate, needsSorting - RenderType.State.builder() + RenderType.State.getBuilder() .texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap .alpha( DEFAULT_ALPHA ) .writeMask( DEPTH_WRITE ) diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index efdbd2e3e..086ebff27 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -38,12 +38,12 @@ public final class ComputerCraftProxyClient registerContainers(); // While turtles themselves are not transparent, their upgrades may be. - RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleNormal, RenderType.translucent() ); - RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleAdvanced, RenderType.translucent() ); + RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleNormal, RenderType.getTranslucent() ); + RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleAdvanced, RenderType.getTranslucent() ); // Monitors' textures have transparent fronts and so count as cutouts. - RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorNormal, RenderType.cutout() ); - RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorAdvanced, RenderType.cutout() ); + RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorNormal, RenderType.getCutout() ); + RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorAdvanced, RenderType.getCutout() ); // Setup TESRs ClientRegistry.bindTileEntityRenderer( TileMonitor.FACTORY_NORMAL, TileEntityMonitorRenderer::new ); diff --git a/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java b/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java index a780d5bdc..42b6c90c3 100644 --- a/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java @@ -67,8 +67,8 @@ public final class CableHighlightRenderer double yOffset = pos.getY() - cameraPos.getY(); double zOffset = pos.getZ() - cameraPos.getZ(); - IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() ); - Matrix4f matrix4f = event.getMatrix().getLast().getPositionMatrix(); + IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() ); + Matrix4f matrix4f = event.getMatrix().getLast().getMatrix(); shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> { buffer.pos( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) ) .color( 0, 0, 0, 0.4f ).endVertex(); diff --git a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java new file mode 100644 index 000000000..9e87d4e35 --- /dev/null +++ b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java @@ -0,0 +1,193 @@ +/* + * 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.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; +import dan200.computercraft.shared.computer.core.ClientComputer; +import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.pocket.items.ItemPocketComputer; +import dan200.computercraft.shared.util.Colour; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.item.ItemStack; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderHandEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.lwjgl.opengl.GL11; + +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.*; + +/** + * Emulates map rendering for pocket computers. + */ +@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(); + + private ItemPocketRenderer() + { + } + + @SubscribeEvent + public static void onRenderInHand( RenderHandEvent event ) + { + ItemStack stack = event.getItemStack(); + if( !(stack.getItem() instanceof ItemPocketComputer) ) return; + + event.setCanceled( true ); + INSTANCE.renderItemFirstPerson( + event.getMatrixStack(), event.getBuffers(), event.getLight(), + event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() + ); + } + + @Override + protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack ) + { + ClientComputer computer = ItemPocketComputer.createClientComputer( stack ); + Terminal terminal = computer == null ? null : computer.getTerminal(); + + int termWidth, termHeight; + if( terminal == null ) + { + termWidth = ComputerCraft.terminalWidth_pocketComputer; + termHeight = ComputerCraft.terminalHeight_pocketComputer; + } + else + { + termWidth = terminal.getWidth(); + termHeight = terminal.getHeight(); + } + + int width = termWidth * FONT_WIDTH + MARGIN * 2; + int height = termHeight * FONT_HEIGHT + MARGIN * 2; + + // Setup various transformations. Note that these are partially adapted from the corresponding method + // in ItemRenderer + transform.push(); + transform.rotate( Vector3f.YP.rotationDegrees( 180f ) ); + 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 ); + transform.scale( scale, scale, 0 ); + transform.translate( -0.5 * width, -0.5 * height, 0 ); + + // Render the main frame + ItemPocketComputer item = (ItemPocketComputer) stack.getItem(); + ComputerFamily family = item.getFamily(); + int frameColour = item.getColour( stack ); + + Matrix4f matrix = transform.getLast().getMatrix(); + renderFrame( matrix, family, frameColour, width, height ); + + // Render the light + int lightColour = ItemPocketComputer.getLightState( stack ); + if( lightColour == -1 ) lightColour = Colour.BLACK.getHex(); + renderLight( matrix, lightColour, width, height ); + + if( computer != null && terminal != null ) + { + FixedWidthFontRenderer.drawTerminal( matrix, MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN ); + } + else + { + FixedWidthFontRenderer.drawEmptyTerminal( matrix, 0, 0, width, height ); + } + + transform.pop(); + } + + 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 + ); + + float r = ((colour >>> 16) & 0xFF) / 255.0f; + float g = ((colour >>> 8) & 0xFF) / 255.0f; + float b = (colour & 0xFF) / 255.0f; + + Tessellator tessellator = Tessellator.getInstance(); + 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 ); + + tessellator.draw(); + } + + private static void renderLight( Matrix4f transform, int colour, int width, int height ) + { + RenderSystem.enableBlend(); + RenderSystem.disableTexture(); + + float r = ((colour >>> 16) & 0xFF) / 255.0f; + float g = ((colour >>> 8) & 0xFF) / 255.0f; + float b = (colour & 0xFF) / 255.0f; + + 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(); + + 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/ItemPrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java index 65c2c8e99..5fa6ada5d 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java @@ -36,7 +36,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer { } - // TODO: @SubscribeEvent + @SubscribeEvent public static void onRenderInHand( RenderHandEvent event ) { ItemStack stack = event.getItemStack(); @@ -53,7 +53,6 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack ) { transform.rotate( Vector3f.XP.rotationDegrees( 180f ) ); - transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) ); transform.scale( 0.42f, 0.42f, -0.42f ); transform.translate( -0.5f, -0.48f, 0.0f ); @@ -105,7 +104,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer transform.scale( scale, scale, scale ); transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 ); - Matrix4f matrix = transform.getLast().getPositionMatrix(); + Matrix4f matrix = transform.getLast().getMatrix(); drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book ); drawText( matrix, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) diff --git a/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java b/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java index 7a5d7d0fd..54e8c80b9 100644 --- a/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java @@ -66,8 +66,8 @@ public final class MonitorHighlightRenderer transformStack.translate( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() ); // I wish I could think of a better way to do this - IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() ); - Matrix4f transform = transformStack.getLast().getPositionMatrix(); + IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() ); + Matrix4f transform = transformStack.getLast().getMatrix(); if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 0, UP ); if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 1, UP ); if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, transform, 1, 0, 0, UP ); diff --git a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java index bbe95c9c0..53f1c358e 100644 --- a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java @@ -167,10 +167,10 @@ public final class PrintoutRenderer private static final class Type extends RenderState { - static final RenderType TYPE = RenderType.get( + static final RenderType TYPE = RenderType.makeType( "printout_background", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 1024, false, false, // useDelegate, needsSorting - RenderType.State.builder() + RenderType.State.getBuilder() .texture( new RenderState.TextureState( BG, false, false ) ) // blur, minimap .alpha( DEFAULT_ALPHA ) .lightmap( LIGHTMAP_DISABLED ) diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 4562bf199..ed4827e52 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -106,13 +106,13 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer float xMargin = (float) (MARGIN / xScale); float yMargin = (float) (MARGIN / yScale); - Matrix4f matrix = transform.getLast().getPositionMatrix(); + Matrix4f matrix = transform.getLast().getMatrix(); if( redraw ) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder builder = tessellator.getBuffer(); - builder.begin( FixedWidthFontRenderer.TYPE.getGlMode(), FixedWidthFontRenderer.TYPE.getVertexFormat() ); + builder.begin( FixedWidthFontRenderer.TYPE.getDrawMode(), FixedWidthFontRenderer.TYPE.getVertexFormat() ); FixedWidthFontRenderer.drawTerminalWithoutCursor( IDENTITY, builder, 0, 0, terminal, !originTerminal.isColour(), yMargin, yMargin, xMargin, xMargin @@ -126,11 +126,11 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer // render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick // for now. IVertexBuilder buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE ); - FixedWidthFontRenderer.TYPE.enable(); + FixedWidthFontRenderer.TYPE.setupRenderState(); vbo.bindBuffer(); FixedWidthFontRenderer.TYPE.getVertexFormat().setupBufferState( 0L ); - vbo.draw( matrix, FixedWidthFontRenderer.TYPE.getGlMode() ); + vbo.draw( matrix, FixedWidthFontRenderer.TYPE.getDrawMode() ); VertexBuffer.unbindBuffer(); FixedWidthFontRenderer.TYPE.getVertexFormat().clearBufferState(); @@ -143,14 +143,14 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer else { FixedWidthFontRenderer.drawEmptyTerminal( - transform.getLast().getPositionMatrix(), renderer, + transform.getLast().getMatrix(), renderer, -MARGIN, MARGIN, (float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2) ); } FixedWidthFontRenderer.drawBlocker( - transform.getLast().getPositionMatrix(), renderer, + transform.getLast().getMatrix(), renderer, (float) -TileMonitor.RENDER_MARGIN, (float) TileMonitor.RENDER_MARGIN, (float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2) ); diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java index b6eb8d6a8..91162280b 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java @@ -87,7 +87,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer transform.rotate( mc.getRenderManager().getCameraOrientation() ); transform.scale( -0.025f, -0.025f, 0.025f ); - Matrix4f matrix = transform.getLast().getPositionMatrix(); + Matrix4f matrix = transform.getLast().getMatrix(); int opacity = (int) (mc.gameSettings.getTextBackgroundOpacity( 0.25f ) * 255) << 24; float width = -font.getStringWidth( label ) / 2.0f; font.renderString( label, width, (float) 0, 0x20ffffff, false, matrix, renderer, true, opacity, lightmapCoord ); diff --git a/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java b/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java index 14d113fbb..f99b61264 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java +++ b/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java @@ -42,7 +42,7 @@ public class TurtleSmartItemModel implements IBakedModel stack.translate( 0, 0, 1 ); identity = TransformationMatrix.identity(); - flip = new TransformationMatrix( stack.getLast().getPositionMatrix() ); + flip = new TransformationMatrix( stack.getLast().getMatrix() ); } private static class TurtleModelCombination @@ -97,15 +97,14 @@ public class TurtleSmartItemModel implements IBakedModel private final IBakedModel familyModel; private final IBakedModel colourModel; - private HashMap m_cachedModels; - private ItemOverrideList m_overrides; + private final HashMap m_cachedModels = new HashMap<>(); + private final ItemOverrideList m_overrides; public TurtleSmartItemModel( IBakedModel familyModel, IBakedModel colourModel ) { this.familyModel = familyModel; this.colourModel = colourModel; - m_cachedModels = new HashMap<>(); m_overrides = new ItemOverrideList() { @Nonnull diff --git a/src/main/java/dan200/computercraft/client/render_old/ItemPocketRenderer.java b/src/main/java/dan200/computercraft/client/render_old/ItemPocketRenderer.java deleted file mode 100644 index d3134d854..000000000 --- a/src/main/java/dan200/computercraft/client/render_old/ItemPocketRenderer.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * 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.matrix.MatrixStack; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.IVertexBuilder; -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.client.FrameInfo; -import dan200.computercraft.client.gui.FixedWidthFontRenderer; -import dan200.computercraft.core.terminal.Terminal; -import dan200.computercraft.core.terminal.TextBuffer; -import dan200.computercraft.shared.computer.core.ClientComputer; -import dan200.computercraft.shared.computer.core.ComputerFamily; -import dan200.computercraft.shared.pocket.items.ItemPocketComputer; -import dan200.computercraft.shared.util.Colour; -import dan200.computercraft.shared.util.Palette; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.RenderSpecificHandEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import org.lwjgl.opengl.GL11; - -import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*; -import static dan200.computercraft.client.gui.GuiComputer.*; - -/** - * Emulates map rendering for pocket computers. - */ -@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(); - - private ItemPocketRenderer() - { - } - - @SubscribeEvent - public static void renderItem( RenderSpecificHandEvent event ) - { - ItemStack stack = event.getItemStack(); - if( !(stack.getItem() instanceof ItemPocketComputer) ) return; - - event.setCanceled( true ); - Minecraft minecraft = Minecraft.getInstance(); - INSTANCE.renderItemFirstPerson( - event.getMatrixStack(), minecraft.func_228019_au_().func_228487_b_(), - minecraft.getRenderManager().func_229085_a_( minecraft.player, event.getPartialTicks() ), - event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() - ); - } - - @Override - protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack ) - { - ClientComputer computer = ItemPocketComputer.createClientComputer( stack ); - Terminal terminal = computer == null ? null : computer.getTerminal(); - - int termWidth, termHeight; - if( terminal == null ) - { - termWidth = ComputerCraft.terminalWidth_pocketComputer; - termHeight = ComputerCraft.terminalHeight_pocketComputer; - } - else - { - termWidth = terminal.getWidth(); - termHeight = terminal.getHeight(); - } - - int width = termWidth * FONT_WIDTH + MARGIN * 2; - int height = termHeight * FONT_HEIGHT + MARGIN * 2; - - // Setup various transformations. Note that these are partially adapted from the corresponding method - // in ItemRenderer - transform.push(); - // TODO: RenderSystem.disableLighting(); - // TODO: RenderSystem.disableDepthTest(); - - RenderSystem.rotatef( 180f, 0f, 1f, 0f ); - RenderSystem.rotatef( 180f, 0f, 0f, 1f ); - transform.scale( 0.5f, 0.5f, 0.5f ); - - float scale = 0.75f / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT ); - transform.scale( scale, scale, 0 ); - transform.translate( -0.5 * width, -0.5 * height, 0 ); - - // Render the main frame - ItemPocketComputer item = (ItemPocketComputer) stack.getItem(); - ComputerFamily family = item.getFamily(); - int frameColour = item.getColour( stack ); - renderFrame( family, frameColour, width, height ); - - // Render the light - int lightColour = ItemPocketComputer.getLightState( stack ); - if( lightColour == -1 ) lightColour = Colour.Black.getHex(); - renderLight( lightColour, width, height ); - - if( computer != null && terminal != null ) - { - // If we've a computer and terminal then attempt to render it. - renderTerminal( terminal, !computer.isColour() ); - } - else - { - // Otherwise render a plain background - Minecraft.getInstance().getTextureManager().bindTexture( BACKGROUND ); - - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - - Colour black = Colour.Black; - buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION ); - renderTexture( buffer, 0, 0, 0, 0, width, height, black.getR(), black.getG(), black.getB() ); - tessellator.draw(); - } - - // TODO: RenderSystem.enableDepthTest(); - // TODO: RenderSystem.enableLighting(); - transform.pop(); - } - - private static void renderFrame( ComputerFamily family, int colour, int width, int height ) - { - - Minecraft.getInstance().getTextureManager().bindTexture( colour != -1 - ? BACKGROUND_COLOUR - : family == ComputerFamily.Normal ? BACKGROUND_NORMAL : BACKGROUND_ADVANCED - ); - - float r = ((colour >>> 16) & 0xFF) / 255.0f; - float g = ((colour >>> 8) & 0xFF) / 255.0f; - float b = (colour & 0xFF) / 255.0f; - - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR ); - - // Top left, middle, right - renderTexture( buffer, -FRAME, -FRAME, 12, 28, FRAME, FRAME, r, g, b ); - renderTexture( buffer, 0, -FRAME, 0, 0, width, FRAME, r, g, b ); - renderTexture( buffer, width, -FRAME, 24, 28, FRAME, FRAME, r, g, b ); - - // Left and bright border - renderTexture( buffer, -FRAME, 0, 0, 28, FRAME, height, r, g, b ); - renderTexture( 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( buffer, -FRAME, height, 12, 40, FRAME, FRAME / 2, r, g, b ); - renderTexture( buffer, 0, height, 0, 12, width, FRAME / 2, r, g, b ); - renderTexture( buffer, width, height, 24, 40, FRAME, FRAME / 2, r, g, b ); - - renderTexture( buffer, -FRAME, height + FRAME / 2, 12, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b ); - renderTexture( buffer, 0, height + FRAME / 2, 0, 16, width, LIGHT_HEIGHT, FRAME, 4, r, g, b ); - renderTexture( buffer, width, height + FRAME / 2, 24, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b ); - - renderTexture( buffer, -FRAME, height + LIGHT_HEIGHT + FRAME / 2, 12, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b ); - renderTexture( buffer, 0, height + LIGHT_HEIGHT + FRAME / 2, 0, 12 + FRAME / 2, width, FRAME / 2, r, g, b ); - renderTexture( buffer, width, height + LIGHT_HEIGHT + FRAME / 2, 24, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b ); - - tessellator.draw(); - } - - private static void renderLight( int colour, int width, int height ) - { - RenderSystem.enableBlend(); - RenderSystem.disableTexture(); - - float r = ((colour >>> 16) & 0xFF) / 255.0f; - float g = ((colour >>> 8) & 0xFF) / 255.0f; - float b = (colour & 0xFF) / 255.0f; - - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR ); - buffer.pos( width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( width, height + LIGHT_HEIGHT + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( width, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex(); - - tessellator.draw(); - RenderSystem.enableTexture(); - } - - private static void renderTerminal( Terminal terminal, boolean greyscale ) - { - synchronized( terminal ) - { - int termWidth = terminal.getWidth(); - int termHeight = terminal.getHeight(); - - FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance(); - Palette palette = terminal.getPalette(); - - // Render top/bottom borders - TextBuffer emptyLine = new TextBuffer( ' ', termWidth ); - fontRenderer.drawString( - emptyLine, MARGIN, 0, - terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), MARGIN, MARGIN, greyscale, palette - ); - fontRenderer.drawString( - emptyLine, MARGIN, 2 * MARGIN + (termHeight - 1) * FixedWidthFontRenderer.FONT_HEIGHT, - terminal.getTextColourLine( termHeight - 1 ), terminal.getBackgroundColourLine( termHeight - 1 ), MARGIN, MARGIN, greyscale, palette - ); - - // Render the actual text - for( int line = 0; line < termWidth; line++ ) - { - TextBuffer text = terminal.getLine( line ); - TextBuffer colour = terminal.getTextColourLine( line ); - TextBuffer backgroundColour = terminal.getBackgroundColourLine( line ); - fontRenderer.drawString( - text, MARGIN, MARGIN + line * FONT_HEIGHT, - colour, backgroundColour, MARGIN, MARGIN, greyscale, palette - ); - } - - // And render the cursor; - int tx = terminal.getCursorX(), ty = terminal.getCursorY(); - if( terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink() && - tx >= 0 && ty >= 0 && tx < termWidth && ty < termHeight ) - { - TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 ); - fontRenderer.drawString( - new TextBuffer( '_', 1 ), MARGIN + FONT_WIDTH * tx, MARGIN + FONT_HEIGHT * ty, - cursorColour, null, 0, 0, greyscale, palette - ); - } - } - } - - private static void renderTexture( IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, float r, float g, float b ) - { - renderTexture( builder, x, y, textureX, textureY, width, height, width, height, r, g, b ); - } - - private static void renderTexture( 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( x, y + height, 0 ).tex( textureX * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex(); - builder.pos( x + width, y + height, 0 ).tex( (textureX + textureWidth) * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex(); - builder.pos( x + width, y, 0 ).tex( (textureX + textureWidth) * scale, textureY * scale ).color( r, g, b, 1.0f ).endVertex(); - builder.pos( x, y, 0 ).tex( textureX * scale, textureY * scale ).color( r, g, b, 1.0f ).endVertex(); - } -} diff --git a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java index f570adaec..156378cdd 100644 --- a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java @@ -7,7 +7,10 @@ package dan200.computercraft.shared.util; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.gson.*; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.JSONUtils;