1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-15 14:07:38 +00:00

opening a terminal works, placing blocks does not.

This commit is contained in:
coolsa
2021-09-30 15:59:20 -06:00
parent e4271ff6f7
commit dda5236d84
5 changed files with 83 additions and 50 deletions

View File

@@ -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() );

View File

@@ -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,

View File

@@ -100,13 +100,16 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
// Draw the background blocker
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
buffer.begin( VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR_TEXTURE );
FixedWidthFontRenderer.drawBlocker( transform.peek().getModel(),
renderer,
buffer,
(float) -TileMonitor.RENDER_MARGIN,
(float) TileMonitor.RENDER_MARGIN,
(float) (xSize + 2 * TileMonitor.RENDER_MARGIN),
(float) -(ySize + TileMonitor.RENDER_MARGIN * 2) );
// buffer.end();
Tessellator.getInstance().draw();
// Set the contents slightly off the surface to prevent z-fighting
transform.translate( 0.0, 0.0, 0.001 );
@@ -127,7 +130,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
// Sneaky hack here: we get a buffer now in order to flush existing ones and set up the appropriate
// render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick
// for now.
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
buffer = Tessellator.getInstance().getBuffer();
buffer.begin( VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR_TEXTURE );
// FixedWidthFontRenderer.TYPE.startDrawing();
@@ -139,19 +142,24 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
// To go along with sneaky hack above: make sure state changes are undone. I would have thought this would
// happen automatically after these buffers are drawn, but chests will render weird around monitors without this.
buffer.end();
// buffer.end();
Tessellator.getInstance().draw();
transform.pop();
}
else
{
buffer = Tessellator.getInstance().getBuffer();
buffer.begin( VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR_TEXTURE );
FixedWidthFontRenderer.drawEmptyTerminal( transform.peek()
.getModel(),
renderer,
buffer,
-MARGIN,
MARGIN,
(float) (xSize + 2 * MARGIN),
(float) -(ySize + MARGIN * 2) );
// buffer.end();
Tessellator.getInstance().draw();
}
transform.pop();
@@ -224,6 +232,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
.next();
buffer.vertex( pixelWidth + xMargin, pixelHeight + yMargin, 0 )
.next();
// buffer.end();
tessellator.draw();
GlStateManager._glUseProgram( 0 );
@@ -236,7 +245,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder builder = tessellator.getBuffer();
builder.begin( VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR_TEXTURE );
builder.begin( VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR_TEXTURE );
FixedWidthFontRenderer.drawTerminalWithoutCursor( IDENTITY,
builder,
0,

View File

@@ -43,10 +43,12 @@ import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import dan200.computercraft.shared.turtle.items.ItemTurtle;
import dan200.computercraft.shared.turtle.upgrades.*;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder.Factory;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
@@ -61,6 +63,7 @@ import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import java.util.Objects;
@@ -91,31 +94,31 @@ public final class ComputerCraftRegistry
public static final class ModBlocks
{
public static final BlockComputer COMPUTER_NORMAL = register( "computer_normal",
new BlockComputer( properties(), ComputerFamily.NORMAL, ModTiles.COMPUTER_NORMAL ) );
new BlockComputer( properties(), ComputerFamily.NORMAL, ComputerCraftRegistry.ModTiles.COMPUTER_NORMAL ) );
public static final BlockComputer COMPUTER_ADVANCED = register( "computer_advanced",
new BlockComputer( properties(),
ComputerFamily.ADVANCED,
ModTiles.COMPUTER_ADVANCED ) );
ComputerCraftRegistry.ModTiles.COMPUTER_ADVANCED ) );
public static final BlockComputer COMPUTER_COMMAND = register( "computer_command",
new BlockComputer( FabricBlockSettings.copyOf( Blocks.STONE )
.strength( -1, 6000000.0F ),
ComputerFamily.COMMAND,
ModTiles.COMPUTER_COMMAND ) );
ComputerCraftRegistry.ModTiles.COMPUTER_COMMAND ) );
public static final BlockTurtle TURTLE_NORMAL = register( "turtle_normal",
new BlockTurtle( turtleProperties(), ComputerFamily.NORMAL, ModTiles.TURTLE_NORMAL ) );
new BlockTurtle( turtleProperties(), ComputerFamily.NORMAL, ComputerCraftRegistry.ModTiles.TURTLE_NORMAL ) );
public static final BlockTurtle TURTLE_ADVANCED = register( "turtle_advanced",
new BlockTurtle( turtleProperties(), ComputerFamily.ADVANCED, ModTiles.TURTLE_ADVANCED ) );
new BlockTurtle( turtleProperties(), ComputerFamily.ADVANCED, ComputerCraftRegistry.ModTiles.TURTLE_ADVANCED ) );
public static final BlockSpeaker SPEAKER = register( "speaker", new BlockSpeaker( properties() ) );
public static final BlockDiskDrive DISK_DRIVE = register( "disk_drive", new BlockDiskDrive( properties() ) );
public static final BlockPrinter PRINTER = register( "printer", new BlockPrinter( properties() ) );
public static final BlockMonitor MONITOR_NORMAL = register( "monitor_normal", new BlockMonitor( properties(), ModTiles.MONITOR_NORMAL ) );
public static final BlockMonitor MONITOR_ADVANCED = register( "monitor_advanced", new BlockMonitor( properties(), ModTiles.MONITOR_ADVANCED ) );
public static final BlockMonitor MONITOR_NORMAL = register( "monitor_normal", new BlockMonitor( properties(), ComputerCraftRegistry.ModTiles.MONITOR_NORMAL ) );
public static final BlockMonitor MONITOR_ADVANCED = register( "monitor_advanced", new BlockMonitor( properties(), ComputerCraftRegistry.ModTiles.MONITOR_ADVANCED ) );
public static final BlockWirelessModem WIRELESS_MODEM_NORMAL = register( "wireless_modem_normal",
new BlockWirelessModem( properties(), ModTiles.WIRELESS_MODEM_NORMAL ) );
new BlockWirelessModem( properties(), ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_NORMAL ) );
public static final BlockWirelessModem WIRELESS_MODEM_ADVANCED = register( "wireless_modem_advanced",
new BlockWirelessModem( properties(), ModTiles.WIRELESS_MODEM_ADVANCED ) );
new BlockWirelessModem( properties(), ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_ADVANCED ) );
public static final BlockWiredModemFull WIRED_MODEM_FULL = register( "wired_modem_full",
new BlockWiredModemFull( emProperties(), ModTiles.WIRED_MODEM_FULL ) );
new BlockWiredModemFull( emProperties(), ComputerCraftRegistry.ModTiles.WIRED_MODEM_FULL ) );
public static final BlockCable CABLE = register( "cable", new BlockCable( emProperties() ) );
private static Block.Settings properties()
@@ -157,9 +160,9 @@ public final class ComputerCraftRegistry
.create( ( blockPos, blockState ) -> new TileMonitor( ModTiles.MONITOR_ADVANCED, false, blockPos, blockState ),
ModBlocks.MONITOR_ADVANCED )
.build();
public static final BlockEntityType<TileComputer> COMPUTER_NORMAL = FabricBlockEntityTypeBuilder.create(
( blockPos, blockState ) -> new TileComputer( ComputerFamily.NORMAL, ModTiles.COMPUTER_NORMAL, blockPos, blockState ),
ModBlocks.COMPUTER_NORMAL ).build();
public static final BlockEntityType<TileComputer> COMPUTER_NORMAL = (BlockEntityType<TileComputer>) ofBlock(() -> ModBlocks.COMPUTER_NORMAL,
"computer_normal",
( blockPos, blockState ) -> new TileComputer( ComputerFamily.NORMAL, ModTiles.COMPUTER_NORMAL, blockPos, blockState ));
public static final BlockEntityType<TileComputer> 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<TileWirelessModem> 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<TileWirelessModem> 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<TileWirelessModem> 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 <T extends BlockEntity> BlockEntityType<? extends T> ofBlock( Supplier<Block> block, String id, Factory<? extends T> factory)
{
return Registry.register( BLOCK_ENTITY_TYPE,
new Identifier( MOD_ID, id ),
FabricBlockEntityTypeBuilder.create(factory, block.get()).build() );
}
}
public static final class ModItems

View File

@@ -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<? extends TileWirelessModem> 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 );
}