From dda5236d842a1918ac84783d5519c98566c7e915 Mon Sep 17 00:00:00 2001 From: coolsa Date: Thu, 30 Sep 2021 15:59:20 -0600 Subject: [PATCH] opening a terminal works, placing blocks does not. --- .../client/gui/FixedWidthFontRenderer.java | 61 +++++++++++-------- .../client/render/PrintoutRenderer.java | 4 +- .../render/TileEntityMonitorRenderer.java | 21 +++++-- .../shared/ComputerCraftRegistry.java | 44 ++++++++----- .../modem/wireless/TileWirelessModem.java | 3 +- 5 files changed, 83 insertions(+), 50 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 72d9ec931..8b52d4c98 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -44,11 +44,13 @@ public final class FixedWidthFontRenderer { bindFont(); - VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() - .getBufferBuilders() - .getEntityVertexConsumers(); +// VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() +// .getBufferBuilders() +// .getEntityVertexConsumers(); + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + buffer.begin( VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR_TEXTURE ); drawString( IDENTITY, - Tessellator.getInstance().getBuffer(), + buffer, x, y, text, @@ -58,7 +60,9 @@ public final class FixedWidthFontRenderer greyscale, leftMarginSize, rightMarginSize ); - renderer.draw(); +// renderer.draw(); +// buffer.end(); + Tessellator.getInstance().draw(); } private static void bindFont() @@ -69,7 +73,7 @@ public final class FixedWidthFontRenderer RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP ); } - public static void drawString( @Nonnull Matrix4f transform, @Nonnull VertexConsumer renderer, float x, float y, @Nonnull TextBuffer text, + public static void drawString( @Nonnull Matrix4f transform, @Nonnull BufferBuilder renderer, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize ) { @@ -104,7 +108,7 @@ public final class FixedWidthFontRenderer } - private static void drawBackground( @Nonnull Matrix4f transform, @Nonnull VertexConsumer renderer, float x, float y, + private static void drawBackground( @Nonnull Matrix4f transform, @Nonnull BufferBuilder renderer, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize, float height ) { @@ -170,7 +174,7 @@ public final class FixedWidthFontRenderer return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3); } - 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, BufferBuilder buffer, float x, float y, int index, float r, float g, float b ) { // Short circuit to avoid the common case - the texture should be blank here after all. if( index == '\0' || index == ' ' ) @@ -210,7 +214,7 @@ public final class FixedWidthFontRenderer .next(); } - private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, Palette palette, + private static void drawQuad( Matrix4f transform, BufferBuilder buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex ) { double[] colour = palette.getColour( getColour( colourIndex, Colour.BLACK ) ); @@ -229,7 +233,7 @@ public final class FixedWidthFontRenderer drawQuad( transform, buffer, x, y, width, height, r, g, b ); } - 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, BufferBuilder buffer, float x, float y, float width, float height, float r, float g, float b ) { buffer.vertex( transform, x, y, 0 ) .color( r, g, b, 1.0f ) @@ -257,7 +261,7 @@ public final class FixedWidthFontRenderer .next(); } - public static void drawTerminalWithoutCursor( @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, + public static void drawTerminalWithoutCursor( @Nonnull Matrix4f transform, @Nonnull BufferBuilder buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize ) { @@ -304,7 +308,7 @@ public final class FixedWidthFontRenderer } } - public static void drawCursor( @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull Terminal terminal, + public static void drawCursor( @Nonnull Matrix4f transform, @Nonnull BufferBuilder buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale ) { Palette palette = terminal.getPalette(); @@ -332,7 +336,7 @@ public final class FixedWidthFontRenderer } } - public static void drawTerminal( @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull Terminal terminal, + public static void drawTerminal( @Nonnull Matrix4f transform, @Nonnull BufferBuilder buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize ) { drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); @@ -344,12 +348,15 @@ public final class FixedWidthFontRenderer { bindFont(); - VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() - .getBufferBuilders() - .getEntityVertexConsumers(); - VertexConsumer buffer = Tessellator.getInstance().getBuffer(); +// VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() +// .getBufferBuilders() +// .getEntityVertexConsumers(); + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + buffer.begin( VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR_TEXTURE ); drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); - renderer.draw(); +// buffer.end(); + Tessellator.getInstance().draw(); +// renderer.draw(); } public static void drawTerminal( float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize, @@ -367,21 +374,25 @@ public final class FixedWidthFontRenderer { bindFont(); - VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() - .getBufferBuilders() - .getEntityVertexConsumers(); - drawEmptyTerminal( transform, renderer, x, y, width, height ); - renderer.draw(); +// VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() +// .getBufferBuilders() +// .getEntityVertexConsumers(); + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + buffer.begin( VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR_TEXTURE ); + drawEmptyTerminal( transform, buffer, x, y, width, height ); +// buffer.end(); + Tessellator.getInstance().draw(); +// renderer.draw(); } - public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull VertexConsumerProvider renderer, float x, float y, float width, + public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull BufferBuilder renderer, float x, float y, float width, float height ) { Colour colour = Colour.BLACK; drawQuad( transform, Tessellator.getInstance().getBuffer(), x, y, width, height, colour.getR(), colour.getG(), colour.getB() ); } - public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull VertexConsumerProvider renderer, float x, float y, float width, float height ) + public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull BufferBuilder renderer, float x, float y, float width, float height ) { Colour colour = Colour.BLACK; drawQuad( transform, Tessellator.getInstance().getBuffer(), x, y, width, height, colour.getR(), colour.getG(), colour.getB() ); diff --git a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java index 8e255509e..e9400fffe 100644 --- a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java @@ -53,7 +53,7 @@ public final class PrintoutRenderer public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, TextBuffer[] text, TextBuffer[] colours ) { - VertexConsumer buffer = Tessellator.getInstance().getBuffer(); + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) { FixedWidthFontRenderer.drawString( transform, @@ -72,7 +72,7 @@ public final class PrintoutRenderer public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, String[] text, String[] colours ) { - VertexConsumer buffer = Tessellator.getInstance().getBuffer(); + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) { FixedWidthFontRenderer.drawString( transform, diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 1ac740c93..0c92cb8e9 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -100,13 +100,16 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer new TileMonitor( ModTiles.MONITOR_ADVANCED, false, blockPos, blockState ), ModBlocks.MONITOR_ADVANCED ) .build(); - public static final BlockEntityType COMPUTER_NORMAL = FabricBlockEntityTypeBuilder.create( - ( blockPos, blockState ) -> new TileComputer( ComputerFamily.NORMAL, ModTiles.COMPUTER_NORMAL, blockPos, blockState ), - ModBlocks.COMPUTER_NORMAL ).build(); + public static final BlockEntityType COMPUTER_NORMAL = (BlockEntityType) ofBlock(() -> ModBlocks.COMPUTER_NORMAL, + "computer_normal", + ( blockPos, blockState ) -> new TileComputer( ComputerFamily.NORMAL, ModTiles.COMPUTER_NORMAL, blockPos, blockState )); public static final BlockEntityType COMPUTER_ADVANCED = FabricBlockEntityTypeBuilder .create( ( blockPos, blockState ) -> new TileComputer( ComputerFamily.ADVANCED, ModTiles.COMPUTER_ADVANCED, blockPos, blockState ), ModBlocks.COMPUTER_ADVANCED ) @@ -193,9 +196,18 @@ public final class ComputerCraftRegistry public static final BlockEntityType WIRELESS_MODEM_NORMAL = FabricBlockEntityTypeBuilder.create( ( blockPos, blockState ) -> new TileWirelessModem( ModTiles.WIRELESS_MODEM_NORMAL, false, blockPos, blockState ), ModBlocks.WIRELESS_MODEM_NORMAL ).build(); - public static final BlockEntityType WIRELESS_MODEM_ADVANCED = FabricBlockEntityTypeBuilder.create( - ( blockPos, blockState ) -> new TileWirelessModem( ModTiles.WIRELESS_MODEM_ADVANCED, true, blockPos, blockState ), - ModBlocks.WIRELESS_MODEM_ADVANCED ).build(); + public static final BlockEntityType WIRELESS_MODEM_ADVANCED = Registry.register( BLOCK_ENTITY_TYPE, + new Identifier( MOD_ID, "wireless_modem_advanced" ), + FabricBlockEntityTypeBuilder.create( + ( blockPos, blockState ) -> new TileWirelessModem( ModTiles.WIRELESS_MODEM_ADVANCED, true, blockPos, blockState ), + ModBlocks.WIRELESS_MODEM_ADVANCED ).build() ); + + private static BlockEntityType ofBlock( Supplier block, String id, Factory factory) + { + return Registry.register( BLOCK_ENTITY_TYPE, + new Identifier( MOD_ID, id ), + FabricBlockEntityTypeBuilder.create(factory, block.get()).build() ); + } } public static final class ModItems diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java index aa72a41b3..b7559ca6d 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java @@ -8,6 +8,7 @@ package dan200.computercraft.shared.peripheral.modem.wireless; import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheralTile; +import dan200.computercraft.shared.ComputerCraftRegistry.ModTiles; import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.peripheral.modem.ModemPeripheral; import dan200.computercraft.shared.peripheral.modem.ModemState; @@ -31,7 +32,7 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile public TileWirelessModem( BlockEntityType type, boolean advanced, BlockPos pos, BlockState state ) { - super( type, pos, state ); + super( ModTiles.WIRELESS_MODEM_ADVANCED, pos, state ); this.advanced = advanced; modem = new Peripheral( this ); }