1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-28 08:12:18 +00:00

fix: pocket, speaker, printer, modems, cable and some mixins

This commit is contained in:
Nikita Savyolov 2021-10-01 18:34:42 +03:00
parent 967f00cd1b
commit ee82a8d75f
No known key found for this signature in database
GPG Key ID: 32C1EF023AFC184B
22 changed files with 243 additions and 188 deletions

View File

@ -26,6 +26,8 @@ import org.lwjgl.opengl.GL11;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
public final class FixedWidthFontRenderer public final class FixedWidthFontRenderer
{ {
public static final int FONT_HEIGHT = 9; public static final int FONT_HEIGHT = 9;
@ -36,9 +38,6 @@ public final class FixedWidthFontRenderer
private static final Matrix4f IDENTITY = AffineTransformation.identity() private static final Matrix4f IDENTITY = AffineTransformation.identity()
.getMatrix(); .getMatrix();
public static final Identifier FONT = new Identifier( "computercraft", "textures/gui/term_font.png" ); public static final Identifier FONT = new Identifier( "computercraft", "textures/gui/term_font.png" );
// public static final RenderLayer TYPE = Type.MAIN;
// public static final RenderLayer MONITOR_TBO = Type.MONITOR_TBO;
// public static final Shader FONT_SHADER = new Shader();
private FixedWidthFontRenderer() private FixedWidthFontRenderer()
@ -47,7 +46,7 @@ public final class FixedWidthFontRenderer
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 VertexConsumer renderer, float x, float y, @Nonnull TextBuffer text,
@Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale,
float leftMarginSize, float rightMarginSize ) float leftMarginSize, float rightMarginSize, int light )
{ {
if( backgroundColour != null ) if( backgroundColour != null )
{ {
@ -75,12 +74,12 @@ public final class FixedWidthFontRenderer
{ {
index = '?'; index = '?';
} }
drawChar( transform, renderer, x + i * FONT_WIDTH, y, index, r, g, b ); drawChar( transform, renderer, x + i * FONT_WIDTH, y, index, r, g, b, light );
} }
} }
private static void drawBackground( @Nonnull Matrix4f transform, @Nonnull BufferBuilder renderer, float x, float y, private static void drawBackground( @Nonnull Matrix4f transform, @Nonnull VertexConsumer renderer, float x, float y,
@Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, float leftMarginSize, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, float leftMarginSize,
float rightMarginSize, float height ) float rightMarginSize, float height )
{ {
@ -146,7 +145,7 @@ public final class FixedWidthFontRenderer
return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3); return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3);
} }
private static void drawChar( Matrix4f transform, BufferBuilder buffer, float x, float y, int index, float r, float g, float b ) private static void drawChar( Matrix4f transform, VertexConsumer buffer, float x, float y, int index, float r, float g, float b, int light )
{ {
// Short circuit to avoid the common case - the texture should be blank here after all. // Short circuit to avoid the common case - the texture should be blank here after all.
if( index == '\0' || index == ' ' ) if( index == '\0' || index == ' ' )
@ -163,30 +162,36 @@ public final class FixedWidthFontRenderer
buffer.vertex( transform, x, y, 0f ) buffer.vertex( transform, x, y, 0f )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
.texture( xStart / WIDTH, yStart / WIDTH ) .texture( xStart / WIDTH, yStart / WIDTH )
.light(light)
.next(); .next();
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ) buffer.vertex( transform, x, y + FONT_HEIGHT, 0f )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
.texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ) .texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
.light(light)
.next(); .next();
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ) buffer.vertex( transform, x + FONT_WIDTH, y, 0f )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
.texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ) .texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH )
.light(light)
.next(); .next();
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ) buffer.vertex( transform, x + FONT_WIDTH, y, 0f )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
.texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ) .texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH )
.light(light)
.next(); .next();
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ) buffer.vertex( transform, x, y + FONT_HEIGHT, 0f )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
.texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ) .texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
.light(light)
.next(); .next();
buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ) buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
.texture( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ) .texture( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
.light(light)
.next(); .next();
} }
private static void drawQuad( Matrix4f transform, BufferBuilder buffer, float x, float y, float width, float height, Palette palette, private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, Palette palette,
boolean greyscale, char colourIndex ) boolean greyscale, char colourIndex )
{ {
double[] colour = palette.getColour( getColour( colourIndex, Colour.BLACK ) ); double[] colour = palette.getColour( getColour( colourIndex, Colour.BLACK ) );
@ -205,7 +210,7 @@ public final class FixedWidthFontRenderer
drawQuad( transform, buffer, x, y, width, height, r, g, b ); drawQuad( transform, buffer, x, y, width, height, r, g, b );
} }
private static void drawQuad( Matrix4f transform, BufferBuilder buffer, float x, float y, float width, float height, float r, float g, float b ) private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, float r, float g, float b )
{ {
buffer.vertex( transform, x, y, 0 ) buffer.vertex( transform, x, y, 0 )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
@ -233,7 +238,7 @@ public final class FixedWidthFontRenderer
.next(); .next();
} }
public static void drawTerminalWithoutCursor( @Nonnull Matrix4f transform, @Nonnull BufferBuilder buffer, float x, float y, public static void drawTerminalWithoutCursor( @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y,
@Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize,
float leftMarginSize, float rightMarginSize ) float leftMarginSize, float rightMarginSize )
{ {
@ -276,11 +281,11 @@ public final class FixedWidthFontRenderer
palette, palette,
greyscale, greyscale,
leftMarginSize, leftMarginSize,
rightMarginSize ); rightMarginSize, FULL_BRIGHT_LIGHTMAP );
} }
} }
public static void drawCursor( @Nonnull Matrix4f transform, @Nonnull BufferBuilder buffer, float x, float y, @Nonnull Terminal terminal, public static void drawCursor( @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull Terminal terminal,
boolean greyscale ) boolean greyscale )
{ {
Palette palette = terminal.getPalette(); Palette palette = terminal.getPalette();
@ -304,11 +309,11 @@ public final class FixedWidthFontRenderer
b = (float) colour[2]; b = (float) colour[2];
} }
drawChar( transform, buffer, x + cursorX * FONT_WIDTH, y + cursorY * FONT_HEIGHT, '_', r, g, b ); drawChar( transform, buffer, x + cursorX * FONT_WIDTH, y + cursorY * FONT_HEIGHT, '_', r, g, b, FULL_BRIGHT_LIGHTMAP );
} }
} }
public static void drawTerminal( @Nonnull Matrix4f transform, @Nonnull BufferBuilder buffer, float x, float y, @Nonnull Terminal terminal, public static void drawTerminal( @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull Terminal terminal,
boolean greyscale, float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize ) boolean greyscale, float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize )
{ {
drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
@ -325,9 +330,7 @@ public final class FixedWidthFontRenderer
.getEntityVertexConsumers(); .getEntityVertexConsumers();
VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ); VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH );
drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
// buffer.end(); renderer.draw();
Tessellator.getInstance().draw();
// renderer.draw();
} }
public static void drawTerminal( float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize, public static void drawTerminal( float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize,
@ -346,25 +349,21 @@ public final class FixedWidthFontRenderer
{ {
// bindFont(); // bindFont();
// VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance()
// .getBufferBuilders() .getBufferBuilders()
// .getEntityVertexConsumers(); .getEntityVertexConsumers();
BufferBuilder buffer = Tessellator.getInstance().getBuffer(); drawEmptyTerminal( transform, renderer, x, y, width, height );
buffer.begin( VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR_TEXTURE ); renderer.draw();
drawEmptyTerminal( transform, buffer, x, y, width, height );
// buffer.end();
Tessellator.getInstance().draw();
// renderer.draw();
} }
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull BufferBuilder renderer, float x, float y, float width, public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull VertexConsumerProvider renderer, float x, float y, float width,
float height ) float height )
{ {
Colour colour = Colour.BLACK; Colour colour = Colour.BLACK;
drawQuad( transform, renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() ); drawQuad( transform, renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
} }
public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull BufferBuilder renderer, float x, float y, float width, float height ) public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull VertexConsumerProvider renderer, float x, float y, float width, float height )
{ {
Colour colour = Colour.BLACK; Colour colour = Colour.BLACK;
drawQuad( transform, renderer.getBuffer(RenderTypes.TERMINAL_BLOCKER), x, y, width, height, colour.getR(), colour.getG(), colour.getB() ); drawQuad( transform, renderer.getBuffer(RenderTypes.TERMINAL_BLOCKER), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );

View File

@ -25,14 +25,6 @@ public class GuiPrinter extends HandledScreen<ContainerPrinter>
super( container, player, title ); super( container, player, title );
} }
/*@Override
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
{
String title = getTitle().getFormattedText();
font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
font.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
}*/
@Override @Override
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks ) public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
{ {
@ -44,9 +36,8 @@ public class GuiPrinter extends HandledScreen<ContainerPrinter>
@Override @Override
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY ) protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
{ {
RenderSystem.clearColor( 1.0F, 1.0F, 1.0F, 1.0F ); RenderSystem.setShaderColor( 1.0F, 1.0F, 1.0F, 1.0F );
client.getTextureManager() RenderSystem.setShaderTexture( 0, BACKGROUND );
.bindTexture( BACKGROUND );
drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight ); drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight );
if( getScreenHandler().isPrinting() ) if( getScreenHandler().isPrinting() )

View File

@ -22,6 +22,7 @@ import org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static dan200.computercraft.client.render.PrintoutRenderer.*; import static dan200.computercraft.client.render.PrintoutRenderer.*;
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
public class GuiPrintout extends HandledScreen<ContainerHeldItem> public class GuiPrintout extends HandledScreen<ContainerHeldItem>
{ {
@ -108,7 +109,7 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY ) protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
{ {
// Draw the printout // Draw the printout
RenderSystem.clearColor( 1.0f, 1.0f, 1.0f, 1.0f ); RenderSystem.setShaderColor( 1.0f, 1.0f, 1.0f, 1.0f );
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance()
@ -116,8 +117,8 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
.getEntityVertexConsumers(); .getEntityVertexConsumers();
Matrix4f matrix = transform.peek() Matrix4f matrix = transform.peek()
.getModel(); .getModel();
drawBorder( matrix, renderer, x, y, getZOffset(), page, pages, book ); drawBorder( matrix, renderer, x, y, getZOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP );
drawText( matrix, renderer, x + X_TEXT_MARGIN, y + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, text, colours ); drawText( matrix, renderer, x + X_TEXT_MARGIN, y + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours );
renderer.draw(); renderer.draw();
} }

View File

@ -18,9 +18,7 @@ import net.minecraft.client.render.Camera;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.*;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
@ -49,17 +47,28 @@ public final class CableHighlightRenderer
state ); state );
Vec3d cameraPos = info.getPos(); Vec3d cameraPos = info.getPos();
double xOffset = pos.getX() - cameraPos.getX(); double xOffset = pos.getX() - cameraPos.getX();
double yOffset = pos.getY() - cameraPos.getY(); double yOffset = pos.getY() - cameraPos.getY();
double zOffset = pos.getZ() - cameraPos.getZ(); double zOffset = pos.getZ() - cameraPos.getZ();
Matrix4f matrix4f = stack.peek() Matrix4f matrix4f = stack.peek()
.getModel(); .getModel();
shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> { Matrix3f normal = stack.peek().getNormal();
shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> { float xDelta = (float) (x2 - x1);
float yDelta = (float) (y2 - y1);
float zDelta = (float) (z2 - z1);
float len = MathHelper.sqrt( xDelta * xDelta + yDelta * yDelta + zDelta * zDelta );
xDelta = xDelta / len;
yDelta = yDelta / len;
zDelta = zDelta / len;
consumer.vertex( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) ) consumer.vertex( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) )
.color( 0, 0, 0, 0.4f ) .color( 0, 0, 0, 0.4f )
.normal(normal, xDelta, yDelta, zDelta)
.next(); .next();
consumer.vertex( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) ) consumer.vertex( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) )
.color( 0, 0, 0, 0.4f ) .color( 0, 0, 0, 0.4f )
.normal(normal, xDelta, yDelta, zDelta)
.next(); .next();
} ); } );

View File

@ -89,7 +89,7 @@ public abstract class ItemMapLikeRenderer
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( rX * 20.0F ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( rX * 20.0F ) );
transform.scale( 2.0F, 2.0F, 2.0F ); transform.scale( 2.0F, 2.0F, 2.0F );
renderItem( transform, render, stack ); renderItem( transform, render, stack, combinedLight );
} }
/** /**
@ -133,7 +133,7 @@ public abstract class ItemMapLikeRenderer
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( f2 * -45f ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( f2 * -45f ) );
transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( offset * f2 * -30f ) ); transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( offset * f2 * -30f ) );
renderItem( transform, render, stack ); renderItem( transform, render, stack, combinedLight );
transform.pop(); transform.pop();
} }
@ -145,5 +145,5 @@ public abstract class ItemMapLikeRenderer
* @param render The buffer to render to * @param render The buffer to render to
* @param stack The stack to render * @param stack The stack to render
*/ */
protected abstract void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack ); protected abstract void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light );
} }

View File

@ -15,13 +15,10 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.*;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3f; import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -42,7 +39,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
} }
@Override @Override
protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack ) protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light )
{ {
ClientComputer computer = ItemPocketComputer.createClientComputer( stack ); ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
Terminal terminal = computer == null ? null : computer.getTerminal(); Terminal terminal = computer == null ? null : computer.getTerminal();
@ -80,7 +77,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
Matrix4f matrix = transform.peek() Matrix4f matrix = transform.peek()
.getModel(); .getModel();
renderFrame( matrix, family, frameColour, width, height ); renderFrame( matrix, render, family, frameColour, light, width, height );
// Render the light // Render the light
int lightColour = ItemPocketComputer.getLightState( stack ); int lightColour = ItemPocketComputer.getLightState( stack );
@ -92,7 +89,12 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
if( computer != null && terminal != null ) if( computer != null && terminal != null )
{ {
FixedWidthFontRenderer.drawTerminal( matrix, MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN ); FixedWidthFontRenderer.drawTerminal(
matrix, render.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH ),
MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN
);
FixedWidthFontRenderer.drawBlocker( transform.peek().getModel(), render, 0, 0, width, height );
} }
else else
{ {
@ -102,24 +104,20 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
transform.pop(); transform.pop();
} }
private static void renderFrame( Matrix4f transform, ComputerFamily family, int colour, int width, int height ) private static void renderFrame( Matrix4f transform, VertexConsumerProvider render, ComputerFamily family, int colour, int light, int width, int height )
{ {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
MinecraftClient.getInstance() MinecraftClient.getInstance()
.getTextureManager() .getTextureManager()
.bindTexture( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) ); .bindTexture( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) );
Identifier texture = colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family );
float r = ((colour >>> 16) & 0xFF) / 255.0f; float r = ((colour >>> 16) & 0xFF) / 255.0f;
float g = ((colour >>> 8) & 0xFF) / 255.0f; float g = ((colour >>> 8) & 0xFF) / 255.0f;
float b = (colour & 0xFF) / 255.0f; float b = (colour & 0xFF) / 255.0f;
Tessellator tessellator = Tessellator.getInstance(); ComputerBorderRenderer.render( transform, render.getBuffer( RenderLayer.getText( texture ) ), 0, 0, 0, light, width, height, true, r, g, b );
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin( VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE );
// ComputerBorderRenderer.render( transform, buffer, 0, 0, 0, width, height, true, r, g, b );
tessellator.draw();
} }
private static void renderLight( Matrix4f transform, int colour, int width, int height ) private static void renderLight( Matrix4f transform, int colour, int width, int height )

View File

@ -31,16 +31,16 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
} }
@Override @Override
protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack ) protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light )
{ {
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( 180f ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( 180f ) );
transform.scale( 0.42f, 0.42f, -0.42f ); transform.scale( 0.42f, 0.42f, -0.42f );
transform.translate( -0.5f, -0.48f, 0.0f ); transform.translate( -0.5f, -0.48f, 0.0f );
drawPrintout( transform, render, stack ); drawPrintout( transform, render, stack, light );
} }
private static void drawPrintout( MatrixStack transform, VertexConsumerProvider render, ItemStack stack ) private static void drawPrintout( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light )
{ {
int pages = ItemPrintout.getPageCount( stack ); int pages = ItemPrintout.getPageCount( stack );
boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK; boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK;
@ -72,11 +72,11 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
Matrix4f matrix = transform.peek() Matrix4f matrix = transform.peek()
.getModel(); .getModel();
drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book ); drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book, light );
drawText( matrix, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) ); drawText( matrix, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, light, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) );
} }
public boolean renderInFrame( MatrixStack matrixStack, VertexConsumerProvider consumerProvider, ItemStack stack ) public boolean renderInFrame( MatrixStack matrixStack, VertexConsumerProvider consumerProvider, ItemStack stack, int light )
{ {
if( !(stack.getItem() instanceof ItemPrintout) ) if( !(stack.getItem() instanceof ItemPrintout) )
{ {
@ -89,7 +89,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
matrixStack.scale( 0.95f, 0.95f, -0.95f ); matrixStack.scale( 0.95f, 0.95f, -0.95f );
matrixStack.translate( -0.5f, -0.5f, 0.0f ); matrixStack.translate( -0.5f, -0.5f, 0.0f );
drawPrintout( matrixStack, consumerProvider, stack ); drawPrintout( matrixStack, consumerProvider, stack, light );
return true; return true;
} }

View File

@ -40,7 +40,6 @@ public final class PrintoutRenderer
* Size of the leather cover. * Size of the leather cover.
*/ */
public static final int COVER_SIZE = 12; public static final int COVER_SIZE = 12;
private static final Identifier BG = new Identifier( "computercraft", "textures/gui/printout.png" );
private static final float BG_SIZE = 256.0f; private static final float BG_SIZE = 256.0f;
/** /**
* Width of the extra page texture. * Width of the extra page texture.
@ -51,9 +50,9 @@ public final class PrintoutRenderer
private PrintoutRenderer() {} private PrintoutRenderer() {}
public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, TextBuffer[] text, TextBuffer[] colours ) public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours )
{ {
/*VertexConsumer buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE ); VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT );
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
{ {
FixedWidthFontRenderer.drawString( transform, FixedWidthFontRenderer.drawString( transform,
@ -66,13 +65,14 @@ public final class PrintoutRenderer
Palette.DEFAULT, Palette.DEFAULT,
false, false,
0, 0,
0 ); 0,
}*/ light );
}
} }
public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, String[] text, String[] colours ) public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, int light, String[] text, String[] colours )
{ {
/*VertexConsumer buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE ); VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT );
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
{ {
FixedWidthFontRenderer.drawString( transform, FixedWidthFontRenderer.drawString( transform,
@ -85,16 +85,17 @@ public final class PrintoutRenderer
Palette.DEFAULT, Palette.DEFAULT,
false, false,
0, 0,
0 ); 0,
}*/ light );
}
} }
public static void drawBorder( Matrix4f transform, VertexConsumerProvider renderer, float x, float y, float z, int page, int pages, boolean isBook ) public static void drawBorder( Matrix4f transform, VertexConsumerProvider renderer, float x, float y, float z, int page, int pages, boolean isBook, int light )
{ {
int leftPages = page; int leftPages = page;
int rightPages = pages - page - 1; int rightPages = pages - page - 1;
VertexConsumer buffer = Tessellator.getInstance().getBuffer(); VertexConsumer buffer = renderer.getBuffer(RenderTypes.PRINTOUT_BACKGROUND);
if( isBook ) if( isBook )
{ {
@ -104,8 +105,8 @@ public final class PrintoutRenderer
float right = x + X_SIZE + offset - 4; float right = x + X_SIZE + offset - 4;
// Left and right border // Left and right border
drawTexture( transform, buffer, left - 4, y - 8, z - 0.02f, COVER_X, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2 ); drawTexture( transform, buffer, left - 4, y - 8, z - 0.02f, COVER_X, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
drawTexture( transform, buffer, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2 ); drawTexture( transform, buffer, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
// Draw centre panel (just stretched texture, sorry). // Draw centre panel (just stretched texture, sorry).
drawTexture( transform, drawTexture( transform,
@ -118,34 +119,35 @@ public final class PrintoutRenderer
COVER_X + COVER_SIZE / 2.0f, COVER_X + COVER_SIZE / 2.0f,
COVER_SIZE, COVER_SIZE,
COVER_SIZE, COVER_SIZE,
Y_SIZE ); Y_SIZE,
light );
float borderX = left; float borderX = left;
while( borderX < right ) while( borderX < right )
{ {
double thisWidth = Math.min( right - borderX, X_SIZE ); double thisWidth = Math.min( right - borderX, X_SIZE );
drawTexture( transform, buffer, borderX, y - 8, z - 0.02f, 0, COVER_Y, (float) thisWidth, COVER_SIZE ); drawTexture( transform, buffer, borderX, y - 8, z - 0.02f, 0, COVER_Y, (float) thisWidth, COVER_SIZE, light );
drawTexture( transform, buffer, borderX, y + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE ); drawTexture( transform, buffer, borderX, y + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE, light );
borderX += thisWidth; borderX += thisWidth;
} }
} }
// Left half // Left half
drawTexture( transform, buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2.0f, Y_SIZE ); drawTexture( transform, buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2.0f, Y_SIZE, light );
for( int n = 0; n <= leftPages; n++ ) for( int n = 0; n <= leftPages; n++ )
{ {
drawTexture( transform, buffer, x - offsetAt( n ), y, z - 1e-3f * n, drawTexture( transform, buffer, x - offsetAt( n ), y, z - 1e-3f * n,
// Use the left "bold" fold for the outermost page // Use the left "bold" fold for the outermost page
n == leftPages ? 0 : X_FOLD_SIZE, 0, X_FOLD_SIZE, Y_SIZE ); n == leftPages ? 0 : X_FOLD_SIZE, 0, X_FOLD_SIZE, Y_SIZE, light );
} }
// Right half // Right half
drawTexture( transform, buffer, x + X_SIZE / 2.0f, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2.0f, 0, X_SIZE / 2.0f, Y_SIZE ); drawTexture( transform, buffer, x + X_SIZE / 2.0f, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2.0f, 0, X_SIZE / 2.0f, Y_SIZE, light );
for( int n = 0; n <= rightPages; n++ ) for( int n = 0; n <= rightPages; n++ )
{ {
drawTexture( transform, buffer, x + (X_SIZE - X_FOLD_SIZE) + offsetAt( n ), y, z - 1e-3f * n, drawTexture( transform, buffer, x + (X_SIZE - X_FOLD_SIZE) + offsetAt( n ), y, z - 1e-3f * n,
// Two folds, then the main page. Use the right "bold" fold for the outermost page. // Two folds, then the main page. Use the right "bold" fold for the outermost page.
X_FOLD_SIZE * 2 + X_SIZE + (n == rightPages ? X_FOLD_SIZE : 0), 0, X_FOLD_SIZE, Y_SIZE ); X_FOLD_SIZE * 2 + X_SIZE + (n == rightPages ? X_FOLD_SIZE : 0), 0, X_FOLD_SIZE, Y_SIZE, light );
} }
} }
@ -154,55 +156,25 @@ public final class PrintoutRenderer
return (float) (32 * (1 - Math.pow( 1.2, -page ))); return (float) (32 * (1 - Math.pow( 1.2, -page )));
} }
private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float u, float v, float width, float height ) private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float u, float v, float width, float height, int light )
{ {
buffer.vertex( matrix, x, y + height, z ) vertex( buffer, matrix, x, y + height, z, u / BG_SIZE, (v + height) / BG_SIZE, light );
.texture( u / BG_SIZE, (v + height) / BG_SIZE ) vertex( buffer, matrix, x + width, y + height, z, (u + width) / BG_SIZE, (v + height) / BG_SIZE, light );
.next(); vertex( buffer, matrix, x + width, y, z, (u + width) / BG_SIZE, v / BG_SIZE, light );
buffer.vertex( matrix, x + width, y + height, z ) vertex( buffer, matrix, x, y, z, u / BG_SIZE, v / BG_SIZE, light );
.texture( (u + width) / BG_SIZE, (v + height) / BG_SIZE )
.next();
buffer.vertex( matrix, x + width, y, z )
.texture( (u + width) / BG_SIZE, v / BG_SIZE )
.next();
buffer.vertex( matrix, x, y, z )
.texture( u / BG_SIZE, v / BG_SIZE )
.next();
} }
private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float width, float height, float u, float v, private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float width, float height, float u, float v,
float tWidth, float tHeight ) float tWidth, float tHeight, int light )
{ {
buffer.vertex( matrix, x, y + height, z ) vertex( buffer, matrix, x, y + height, z, u / BG_SIZE, (v + tHeight) / BG_SIZE, light );
.texture( u / BG_SIZE, (v + tHeight) / BG_SIZE ) vertex( buffer, matrix, x + width, y + height, z, (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE, light );
.next(); vertex( buffer, matrix, x + width, y, z, (u + tWidth) / BG_SIZE, v / BG_SIZE, light );
buffer.vertex( matrix, x + width, y + height, z ) vertex( buffer, matrix, x, y, z, u / BG_SIZE, v / BG_SIZE, light );
.texture( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE )
.next();
buffer.vertex( matrix, x + width, y, z )
.texture( (u + tWidth) / BG_SIZE, v / BG_SIZE )
.next();
buffer.vertex( matrix, x, y, z )
.texture( u / BG_SIZE, v / BG_SIZE )
.next();
} }
private static final class Type extends RenderLayer private static void vertex( VertexConsumer buffer, Matrix4f matrix, float x, float y, float z, float u, float v, int light )
{ {
static final RenderLayer TYPE = null;/*RenderLayer.of( "printout_background", buffer.vertex( matrix, x, y, z ).color( 255, 255, 255, 255 ).texture( u, v ).light( light ).next();
VertexFormats.POSITION_TEXTURE,
VertexFormat.DrawMode.QUADS,
1024,
// useDelegate, needsSorting
RenderLayer.MultiPhaseParameters.builder()
.texture( new RenderPhase.Texture( BG, false, false ) ) // blur, minimap
.transparency( TRANSLUCENT_TRANSPARENCY )
.lightmap( DISABLE_LIGHTMAP )
.build( false ));*/
private Type( String name, VertexFormat vertexFormat, VertexFormat.DrawMode drawMode, int expectedBufferSize, boolean hasCrumbling, boolean translucent, RenderLayer.MultiPhaseParameters phases, Runnable setup, Runnable destroy )
{
super( name, vertexFormat, drawMode, expectedBufferSize, hasCrumbling, hasCrumbling, setup, destroy );
}
} }
} }

View File

@ -21,6 +21,11 @@ public class RenderTypes {
public static final RenderLayer MONITOR_TBO = Types.MONITOR_TBO; public static final RenderLayer MONITOR_TBO = Types.MONITOR_TBO;
public static final RenderLayer TERMINAL_BLOCKER = Types.BLOCKER; public static final RenderLayer TERMINAL_BLOCKER = Types.BLOCKER;
public static final RenderLayer TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH; public static final RenderLayer TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH;
public static final RenderLayer PRINTOUT_TEXT = Types.PRINTOUT_TEXT;
public static final RenderLayer PRINTOUT_BACKGROUND = RenderLayer.getText(new Identifier( "computercraft", "textures/gui/printout.png" ));
public static final RenderLayer POSITION_COLOR = Types.POSITION_COLOR;
@Nonnull @Nonnull
static MonitorTextureBufferShader getMonitorTextureBufferShader() static MonitorTextureBufferShader getMonitorTextureBufferShader()
@ -80,6 +85,24 @@ public class RenderTypes {
.build( false ) .build( false )
); );
static final RenderLayer PRINTOUT_TEXT = RenderLayer.of(
"printout_text", VertexFormats.POSITION_COLOR_TEXTURE_LIGHT, GL_MODE, 1024,
false, false, // useDelegate, needsSorting
RenderLayer.MultiPhaseParameters.builder()
.texture( TERM_FONT_TEXTURE )
.shader( RenderPhase.TEXT_SHADER )
.lightmap(RenderPhase.ENABLE_LIGHTMAP)
.build( false )
);
static final RenderLayer POSITION_COLOR = RenderLayer.of(
"position_color", VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.QUADS, 128,
false, false, // useDelegate, needsSorting
RenderLayer.MultiPhaseParameters.builder()
.shader( COLOR_SHADER )
.build( false )
);
private Types( String name, Runnable setup, Runnable destroy ) private Types( String name, Runnable setup, Runnable destroy )
{ {
super( name, setup, destroy ); super( name, setup, destroy );

View File

@ -102,20 +102,6 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER); double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER); 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(),
// 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 );
// Draw the contents // Draw the contents
Terminal terminal = originTerminal.getTerminal(); Terminal terminal = originTerminal.getTerminal();
if( terminal != null ) if( terminal != null )
@ -150,17 +136,13 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
} }
else else
{ {
buffer = Tessellator.getInstance().getBuffer();
buffer.begin( VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR_TEXTURE );
FixedWidthFontRenderer.drawEmptyTerminal( transform.peek() FixedWidthFontRenderer.drawEmptyTerminal( transform.peek()
.getModel(), .getModel(),
buffer, renderer,
-MARGIN, -MARGIN,
MARGIN, MARGIN,
(float) (xSize + 2 * MARGIN), (float) (xSize + 2 * MARGIN),
(float) -(ySize + MARGIN * 2) ); (float) -(ySize + MARGIN * 2) );
// buffer.end();
Tessellator.getInstance().draw();
} }
transform.pop(); transform.pop();

View File

@ -18,6 +18,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
/** /**
* Captures block drops. * Captures block drops.
@ -27,14 +28,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin( Block.class ) @Mixin( Block.class )
public class MixinBlock public class MixinBlock
{ {
// @Inject( method = "dropStack", @Inject( method = "dropStack(Lnet/minecraft/world/World;Ljava/util/function/Supplier;Lnet/minecraft/item/ItemStack;)V",
// at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z" ), at = @At(
// cancellable = true ) value = "INVOKE",
// private static void dropStack( World world, BlockPos pos, ItemStack stack, CallbackInfo callbackInfo ) target = "Lnet/minecraft/entity/ItemEntity;setToDefaultPickupDelay()V"
// { ),
// if( DropConsumer.onHarvestDrops( world, itemEntitySupplier.get().getBlockPos(), stack ) ) locals = LocalCapture.CAPTURE_FAILSOFT,
// { cancellable = true )
// callbackInfo.cancel(); private static void dropStack( World world, Supplier<ItemEntity> itemEntitySupplier, ItemStack stack, CallbackInfo callbackInfo, ItemEntity itemEntity )
// } {
// } if( DropConsumer.onHarvestDrops( world, itemEntity.getBlockPos(), stack ) )
{
callbackInfo.cancel();
}
}
} }

View File

@ -22,14 +22,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin( Entity.class ) @Mixin( Entity.class )
public class MixinEntity public class MixinEntity
{ {
// @Inject( method = "dropStack(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/ItemEntity;", @Inject( method = "dropStack(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/ItemEntity;",
// at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z" ), at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z" ),
// cancellable = true ) cancellable = true )
// public void dropStack( ItemStack stack, float height, CallbackInfoReturnable<ItemEntity> callbackInfo ) public void dropStack( ItemStack stack, float height, CallbackInfoReturnable<ItemEntity> callbackInfo )
// { {
// if( DropConsumer.onLivingDrops( (Entity) (Object) this, stack ) ) if( DropConsumer.onLivingDrops( (Entity) (Object) this, stack ) )
// { {
// callbackInfo.setReturnValue( null ); callbackInfo.setReturnValue( null );
// } }
// } }
} }

View File

@ -12,27 +12,40 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.ItemFrameEntityRenderer; import net.minecraft.client.render.entity.ItemFrameEntityRenderer;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin( ItemFrameEntityRenderer.class ) @Mixin( ItemFrameEntityRenderer.class )
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
public class MixinItemFrameEntityRenderer public class MixinItemFrameEntityRenderer
{ {
@Inject( method = "render", at = @At( "HEAD" ), cancellable = true ) @Inject(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lnet/minecraft/util/math/Quaternion;)V",
ordinal = 2,
shift = At.Shift.AFTER
),
cancellable = true )
private void renderItem( private void renderItem(
ItemFrameEntity itemFrameEntity, float f, float g, MatrixStack matrixStack, ItemFrameEntity itemFrameEntity, float f, float g, MatrixStack matrixStack,
VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo info VertexConsumerProvider vertexConsumerProvider, int itemFrameEntityLight, CallbackInfo info
) )
{ {
ItemStack stack = itemFrameEntity.getHeldItemStack(); ItemStack stack = itemFrameEntity.getHeldItemStack();
if( stack.getItem() instanceof ItemPrintout ) if( stack.getItem() instanceof ItemPrintout )
{ {
ItemPrintoutRenderer.INSTANCE.renderInFrame( matrixStack, vertexConsumerProvider, stack ); int light = itemFrameEntity.getType() == EntityType.GLOW_ITEM_FRAME ? 0xf000d2 : itemFrameEntityLight; // See getLightVal.
ItemPrintoutRenderer.INSTANCE.renderInFrame( matrixStack, vertexConsumerProvider, stack, light );
// TODO: need to find how to make if instead return, like it doing Forge
matrixStack.pop();
info.cancel(); info.cancel();
} }
} }

View File

@ -29,10 +29,11 @@ public class MixinWorld
@Shadow @Shadow
protected boolean iteratingTickingBlockEntities; protected boolean iteratingTickingBlockEntities;
// @Inject( method = "setBlockEntity", at = @At( "HEAD" ) ) @Inject( method = "addBlockEntity", at = @At( "HEAD" ) )
public void setBlockEntity( BlockPos pos, @Nullable BlockEntity entity, CallbackInfo info ) public void addBlockEntity( @Nullable BlockEntity entity, CallbackInfo info )
{ {
if( entity != null && !entity.isRemoved() && entity.getWorld().isInBuildLimit(pos) && iteratingTickingBlockEntities ) System.out.println("addBlockEntity");
if( entity != null && !entity.isRemoved() && entity.getWorld().isInBuildLimit(entity.getPos()) && iteratingTickingBlockEntities )
{ {
setWorld( entity, this ); setWorld( entity, this );
} }
@ -40,9 +41,10 @@ public class MixinWorld
private static void setWorld( BlockEntity entity, Object world ) private static void setWorld( BlockEntity entity, Object world )
{ {
System.out.println("setWorld");
if( entity.getWorld() != world && entity instanceof TileGeneric ) if( entity.getWorld() != world && entity instanceof TileGeneric )
{ {
// entity.setLocation( (World) world, entity.getPos() ); //TODO why? entity.setWorld( (World) world ); //TODO why?
} }
} }

View File

@ -111,9 +111,9 @@ public final class ComputerCraftRegistry
public static final BlockMonitor MONITOR_NORMAL = register( "monitor_normal", new BlockMonitor( properties(), ModTiles.MONITOR_NORMAL, false ) ); public static final BlockMonitor MONITOR_NORMAL = register( "monitor_normal", new BlockMonitor( properties(), ModTiles.MONITOR_NORMAL, false ) );
public static final BlockMonitor MONITOR_ADVANCED = register( "monitor_advanced", new BlockMonitor( properties(), ModTiles.MONITOR_ADVANCED, true ) ); public static final BlockMonitor MONITOR_ADVANCED = register( "monitor_advanced", new BlockMonitor( properties(), ModTiles.MONITOR_ADVANCED, true ) );
public static final BlockWirelessModem WIRELESS_MODEM_NORMAL = register( "wireless_modem_normal", public static final BlockWirelessModem WIRELESS_MODEM_NORMAL = register( "wireless_modem_normal",
new BlockWirelessModem( properties(), ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_NORMAL ) ); new BlockWirelessModem( properties(), ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_NORMAL, ComputerFamily.NORMAL ) );
public static final BlockWirelessModem WIRELESS_MODEM_ADVANCED = register( "wireless_modem_advanced", public static final BlockWirelessModem WIRELESS_MODEM_ADVANCED = register( "wireless_modem_advanced",
new BlockWirelessModem( properties(), ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_ADVANCED ) ); new BlockWirelessModem( properties(), ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_ADVANCED, ComputerFamily.ADVANCED ) );
public static final BlockWiredModemFull WIRED_MODEM_FULL = register( "wired_modem_full", public static final BlockWiredModemFull WIRED_MODEM_FULL = register( "wired_modem_full",
new BlockWiredModemFull( emProperties(), ComputerCraftRegistry.ModTiles.WIRED_MODEM_FULL ) ); new BlockWiredModemFull( emProperties(), ComputerCraftRegistry.ModTiles.WIRED_MODEM_FULL ) );
public static final BlockCable CABLE = register( "cable", new BlockCable( emProperties() ) ); public static final BlockCable CABLE = register( "cable", new BlockCable( emProperties() ) );

View File

@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap;
import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.shared.ComputerCraftRegistry; import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
@ -271,4 +272,11 @@ public class BlockCable extends BlockGeneric implements Waterloggable
.with( DOWN, false ); .with( DOWN, false );
} }
} }
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
{
return new TileCable(ComputerCraftRegistry.ModTiles.CABLE, pos, state);
}
} }

View File

@ -6,12 +6,18 @@
package dan200.computercraft.shared.peripheral.modem.wired; package dan200.computercraft.shared.peripheral.modem.wired;
import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.peripheral.speaker.TileSpeaker;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.math.BlockPos;
import javax.annotation.Nullable;
public class BlockWiredModemFull extends BlockGeneric public class BlockWiredModemFull extends BlockGeneric
{ {
@ -31,4 +37,11 @@ public class BlockWiredModemFull extends BlockGeneric
{ {
builder.add( MODEM_ON, PERIPHERAL_ON ); builder.add( MODEM_ON, PERIPHERAL_ON );
} }
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
{
return new TileWiredModemFull(ComputerCraftRegistry.ModTiles.WIRED_MODEM_FULL, pos, state);
}
} }

View File

@ -6,12 +6,17 @@
package dan200.computercraft.shared.peripheral.modem.wireless; package dan200.computercraft.shared.peripheral.modem.wireless;
import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.peripheral.modem.ModemShapes; import dan200.computercraft.shared.peripheral.modem.ModemShapes;
import dan200.computercraft.shared.peripheral.modem.wired.TileWiredModemFull;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.block.Waterloggable; import net.minecraft.block.Waterloggable;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
@ -36,9 +41,12 @@ public class BlockWirelessModem extends BlockGeneric implements Waterloggable
public static final DirectionProperty FACING = Properties.FACING; public static final DirectionProperty FACING = Properties.FACING;
public static final BooleanProperty ON = BooleanProperty.of( "on" ); public static final BooleanProperty ON = BooleanProperty.of( "on" );
public BlockWirelessModem( Settings settings, BlockEntityType<? extends TileWirelessModem> type ) private final ComputerFamily family;
public BlockWirelessModem(Settings settings, BlockEntityType<? extends TileWirelessModem> type, ComputerFamily family)
{ {
super( settings, type ); super( settings, type );
this.family = family;
setDefaultState( getStateManager().getDefaultState() setDefaultState( getStateManager().getDefaultState()
.with( FACING, Direction.NORTH ) .with( FACING, Direction.NORTH )
.with( ON, false ) .with( ON, false )
@ -95,4 +103,19 @@ public class BlockWirelessModem extends BlockGeneric implements Waterloggable
{ {
builder.add( FACING, ON, WATERLOGGED ); builder.add( FACING, ON, WATERLOGGED );
} }
public BlockEntityType<? extends TileWirelessModem> getTypeByFamily(ComputerFamily family)
{
return switch (family) {
case ADVANCED -> ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_ADVANCED;
default -> ComputerCraftRegistry.ModTiles.WIRELESS_MODEM_NORMAL;
};
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
{
return new TileWirelessModem(getTypeByFamily(family), family == ComputerFamily.ADVANCED, pos, state);
}
} }

View File

@ -32,7 +32,7 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile
public TileWirelessModem( BlockEntityType<? extends TileWirelessModem> type, boolean advanced, BlockPos pos, BlockState state ) public TileWirelessModem( BlockEntityType<? extends TileWirelessModem> type, boolean advanced, BlockPos pos, BlockState state )
{ {
super( ModTiles.WIRELESS_MODEM_ADVANCED, pos, state ); super( type, pos, state );
this.advanced = advanced; this.advanced = advanced;
modem = new Peripheral( this ); modem = new Peripheral( this );
} }

View File

@ -8,6 +8,7 @@ package dan200.computercraft.shared.peripheral.printer;
import dan200.computercraft.shared.ComputerCraftRegistry; import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
@ -88,4 +89,11 @@ public class BlockPrinter extends BlockGeneric
{ {
properties.add( FACING, TOP, BOTTOM ); properties.add( FACING, TOP, BOTTOM );
} }
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
{
return new TilePrinter(ComputerCraftRegistry.ModTiles.PRINTER, pos, state);
}
} }

View File

@ -188,7 +188,6 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public NbtCompound writeNbt( @Nonnull NbtCompound nbt ) public NbtCompound writeNbt( @Nonnull NbtCompound nbt )
{ {
super.writeNbt( nbt );
if( customName != null ) if( customName != null )
{ {
nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) ); nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) );
@ -205,7 +204,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
// Write inventory // Write inventory
Inventories.writeNbt( nbt, inventory ); Inventories.writeNbt( nbt, inventory );
return nbt; return super.writeNbt( nbt );
} }
boolean isPrinting() boolean isPrinting()

View File

@ -8,6 +8,7 @@ package dan200.computercraft.shared.peripheral.speaker;
import dan200.computercraft.shared.ComputerCraftRegistry; import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
@ -17,6 +18,7 @@ import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty; import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -47,11 +49,18 @@ public class BlockSpeaker extends BlockGeneric
{ {
properties.add( FACING ); properties.add( FACING );
} }
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
{
return new TileSpeaker(ComputerCraftRegistry.ModTiles.SPEAKER, pos, state);
}
@Nullable @Nullable
@Override @Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker( World world, BlockState state, BlockEntityType<T> type){ public <T extends BlockEntity> BlockEntityTicker<T> getTicker( World world, BlockState state, BlockEntityType<T> type){
return world.isClient ? null : BlockSpeaker.checkType( type, ComputerCraftRegistry.ModTiles.SPEAKER, TileSpeaker::tick ); return world.isClient ? null : BlockSpeaker.checkType( type, ComputerCraftRegistry.ModTiles.SPEAKER, TileSpeaker::tick );
} }
} }