mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +00:00 
			
		
		
		
	Merge pull request #2 from ga2mer/fabric
Pocket, speaker, printer, modems, cable
This commit is contained in:
		| @@ -26,6 +26,8 @@ import org.lwjgl.opengl.GL11; | ||||
| import javax.annotation.Nonnull; | ||||
| import javax.annotation.Nullable; | ||||
|  | ||||
| import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP; | ||||
|  | ||||
| public final class FixedWidthFontRenderer | ||||
| { | ||||
|     public static final int FONT_HEIGHT = 9; | ||||
| @@ -36,9 +38,6 @@ public final class FixedWidthFontRenderer | ||||
|     private static final Matrix4f IDENTITY = AffineTransformation.identity() | ||||
|         .getMatrix(); | ||||
|     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() | ||||
| @@ -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, | ||||
|                                    @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, | ||||
|                                    float leftMarginSize, float rightMarginSize ) | ||||
|                                    float leftMarginSize, float rightMarginSize, int light ) | ||||
|     { | ||||
|         if( backgroundColour != null ) | ||||
|         { | ||||
| @@ -75,7 +74,7 @@ public final class FixedWidthFontRenderer | ||||
|             { | ||||
|                 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 ); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| @@ -146,7 +145,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, 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. | ||||
|         if( index == '\0' || index == ' ' ) | ||||
| @@ -163,26 +162,32 @@ public final class FixedWidthFontRenderer | ||||
|         buffer.vertex( transform, x, y, 0f ) | ||||
|             .color( r, g, b, 1.0f ) | ||||
|             .texture( xStart / WIDTH, yStart / WIDTH ) | ||||
|             .light(light) | ||||
|             .next(); | ||||
|         buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ) | ||||
|             .color( r, g, b, 1.0f ) | ||||
|             .texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ) | ||||
|             .light(light) | ||||
|             .next(); | ||||
|         buffer.vertex( transform, x + FONT_WIDTH, y, 0f ) | ||||
|             .color( r, g, b, 1.0f ) | ||||
|             .texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ) | ||||
|             .light(light) | ||||
|             .next(); | ||||
|         buffer.vertex( transform, x + FONT_WIDTH, y, 0f ) | ||||
|             .color( r, g, b, 1.0f ) | ||||
|             .texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ) | ||||
|             .light(light) | ||||
|             .next(); | ||||
|         buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ) | ||||
|             .color( r, g, b, 1.0f ) | ||||
|             .texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ) | ||||
|             .light(light) | ||||
|             .next(); | ||||
|         buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ) | ||||
|             .color( r, g, b, 1.0f ) | ||||
|             .texture( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ) | ||||
|             .light(light) | ||||
|             .next(); | ||||
|     } | ||||
|  | ||||
| @@ -276,7 +281,7 @@ public final class FixedWidthFontRenderer | ||||
|                 palette, | ||||
|                 greyscale, | ||||
|                 leftMarginSize, | ||||
|                 rightMarginSize ); | ||||
|                 rightMarginSize, FULL_BRIGHT_LIGHTMAP ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -304,7 +309,7 @@ public final class FixedWidthFontRenderer | ||||
|                 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 ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -25,14 +25,6 @@ public class GuiPrinter extends HandledScreen<ContainerPrinter> | ||||
|         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 | ||||
|     public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks ) | ||||
|     { | ||||
| @@ -44,9 +36,8 @@ public class GuiPrinter extends HandledScreen<ContainerPrinter> | ||||
|     @Override | ||||
|     protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY ) | ||||
|     { | ||||
|         RenderSystem.clearColor( 1.0F, 1.0F, 1.0F, 1.0F ); | ||||
|         client.getTextureManager() | ||||
|             .bindTexture( BACKGROUND ); | ||||
|         RenderSystem.setShaderColor( 1.0F, 1.0F, 1.0F, 1.0F ); | ||||
|         RenderSystem.setShaderTexture( 0, BACKGROUND ); | ||||
|         drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight ); | ||||
|  | ||||
|         if( getScreenHandler().isPrinting() ) | ||||
|   | ||||
| @@ -22,6 +22,7 @@ import org.lwjgl.glfw.GLFW; | ||||
| import javax.annotation.Nonnull; | ||||
|  | ||||
| import static dan200.computercraft.client.render.PrintoutRenderer.*; | ||||
| import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP; | ||||
|  | ||||
| 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 ) | ||||
|     { | ||||
|         // 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(); | ||||
|  | ||||
|         VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() | ||||
| @@ -116,8 +117,8 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem> | ||||
|             .getEntityVertexConsumers(); | ||||
|         Matrix4f matrix = transform.peek() | ||||
|             .getModel(); | ||||
|         drawBorder( matrix, renderer, x, y, getZOffset(), page, pages, book ); | ||||
|         drawText( matrix, renderer, x + X_TEXT_MARGIN, y + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, text, colours ); | ||||
|         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, FULL_BRIGHT_LIGHTMAP, text, colours ); | ||||
|         renderer.draw(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -18,9 +18,7 @@ import net.minecraft.client.render.Camera; | ||||
| import net.minecraft.client.render.VertexConsumer; | ||||
| import net.minecraft.client.util.math.MatrixStack; | ||||
| import net.minecraft.entity.Entity; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.util.math.Matrix4f; | ||||
| import net.minecraft.util.math.Vec3d; | ||||
| import net.minecraft.util.math.*; | ||||
| import net.minecraft.util.shape.VoxelShape; | ||||
|  | ||||
| @Environment( EnvType.CLIENT ) | ||||
| @@ -49,17 +47,28 @@ public final class CableHighlightRenderer | ||||
|             state ); | ||||
|  | ||||
|         Vec3d cameraPos = info.getPos(); | ||||
|  | ||||
|         double xOffset = pos.getX() - cameraPos.getX(); | ||||
|         double yOffset = pos.getY() - cameraPos.getY(); | ||||
|         double zOffset = pos.getZ() - cameraPos.getZ(); | ||||
|         Matrix4f matrix4f = stack.peek() | ||||
|             .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) ) | ||||
|                 .color( 0, 0, 0, 0.4f ) | ||||
|                 .normal(normal, xDelta, yDelta, zDelta) | ||||
|                 .next(); | ||||
|             consumer.vertex( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) ) | ||||
|                 .color( 0, 0, 0, 0.4f ) | ||||
|                 .normal(normal, xDelta, yDelta, zDelta) | ||||
|                 .next(); | ||||
|         } ); | ||||
|  | ||||
|   | ||||
| @@ -89,7 +89,7 @@ public abstract class ItemMapLikeRenderer | ||||
|         transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( rX * 20.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_Y.getDegreesQuaternion( offset * f2 * -30f ) ); | ||||
|  | ||||
|         renderItem( transform, render, stack ); | ||||
|         renderItem( transform, render, stack, combinedLight ); | ||||
|  | ||||
|         transform.pop(); | ||||
|     } | ||||
| @@ -145,5 +145,5 @@ public abstract class ItemMapLikeRenderer | ||||
|      * @param render    The buffer to render to | ||||
|      * @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 ); | ||||
| } | ||||
|   | ||||
| @@ -15,13 +15,10 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.pocket.items.ItemPocketComputer; | ||||
| import dan200.computercraft.shared.util.Colour; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.client.render.BufferBuilder; | ||||
| 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.render.*; | ||||
| import net.minecraft.client.util.math.MatrixStack; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.util.Identifier; | ||||
| import net.minecraft.util.math.Vec3f; | ||||
| import net.minecraft.util.math.Matrix4f; | ||||
| import org.lwjgl.opengl.GL11; | ||||
| @@ -42,7 +39,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer | ||||
|     } | ||||
|  | ||||
|     @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 ); | ||||
|         Terminal terminal = computer == null ? null : computer.getTerminal(); | ||||
| @@ -80,7 +77,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer | ||||
|  | ||||
|         Matrix4f matrix = transform.peek() | ||||
|             .getModel(); | ||||
|         renderFrame( matrix, family, frameColour, width, height ); | ||||
|         renderFrame( matrix, render, family, frameColour, light, width, height ); | ||||
|  | ||||
|         // Render the light | ||||
|         int lightColour = ItemPocketComputer.getLightState( stack ); | ||||
| @@ -92,7 +89,12 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer | ||||
|  | ||||
|         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 | ||||
|         { | ||||
| @@ -102,24 +104,20 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer | ||||
|         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(); | ||||
|         MinecraftClient.getInstance() | ||||
|             .getTextureManager() | ||||
|             .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 g = ((colour >>> 8) & 0xFF) / 255.0f; | ||||
|         float b = (colour & 0xFF) / 255.0f; | ||||
|  | ||||
|         Tessellator tessellator = Tessellator.getInstance(); | ||||
|         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(); | ||||
|         ComputerBorderRenderer.render( transform, render.getBuffer( RenderLayer.getText( texture ) ), 0, 0, 0, light, width, height, true, r, g, b ); | ||||
|     } | ||||
|  | ||||
|     private static void renderLight( Matrix4f transform, int colour, int width, int height ) | ||||
|   | ||||
| @@ -31,16 +31,16 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer | ||||
|     } | ||||
|  | ||||
|     @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.scale( 0.42f, 0.42f, -0.42f ); | ||||
|         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 ); | ||||
|         boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK; | ||||
| @@ -72,11 +72,11 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer | ||||
|  | ||||
|         Matrix4f matrix = transform.peek() | ||||
|             .getModel(); | ||||
|         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 ) ); | ||||
|         drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book, light ); | ||||
|         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) ) | ||||
|         { | ||||
| @@ -89,7 +89,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer | ||||
|         matrixStack.scale( 0.95f, 0.95f, -0.95f ); | ||||
|         matrixStack.translate( -0.5f, -0.5f, 0.0f ); | ||||
|  | ||||
|         drawPrintout( matrixStack, consumerProvider, stack ); | ||||
|         drawPrintout( matrixStack, consumerProvider, stack, light ); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|   | ||||
| @@ -40,7 +40,6 @@ public final class PrintoutRenderer | ||||
|      * Size of the leather cover. | ||||
|      */ | ||||
|     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; | ||||
|     /** | ||||
|      * Width of the extra page texture. | ||||
| @@ -51,9 +50,9 @@ public final class 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++ ) | ||||
|         { | ||||
|             FixedWidthFontRenderer.drawString( transform, | ||||
| @@ -66,13 +65,14 @@ public final class PrintoutRenderer | ||||
|                 Palette.DEFAULT, | ||||
|                 false, | ||||
|                 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++ ) | ||||
|         { | ||||
|             FixedWidthFontRenderer.drawString( transform, | ||||
| @@ -85,16 +85,17 @@ public final class PrintoutRenderer | ||||
|                 Palette.DEFAULT, | ||||
|                 false, | ||||
|                 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 rightPages = pages - page - 1; | ||||
|  | ||||
|         VertexConsumer buffer = Tessellator.getInstance().getBuffer(); | ||||
|         VertexConsumer buffer = renderer.getBuffer(RenderTypes.PRINTOUT_BACKGROUND); | ||||
|  | ||||
|         if( isBook ) | ||||
|         { | ||||
| @@ -104,8 +105,8 @@ public final class PrintoutRenderer | ||||
|             float right = x + X_SIZE + offset - 4; | ||||
|  | ||||
|             // 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, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 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, light ); | ||||
|  | ||||
|             // Draw centre panel (just stretched texture, sorry). | ||||
|             drawTexture( transform, | ||||
| @@ -118,34 +119,35 @@ public final class PrintoutRenderer | ||||
|                 COVER_X + COVER_SIZE / 2.0f, | ||||
|                 COVER_SIZE, | ||||
|                 COVER_SIZE, | ||||
|                 Y_SIZE ); | ||||
|                 Y_SIZE, | ||||
|                 light ); | ||||
|  | ||||
|             float borderX = left; | ||||
|             while( borderX < right ) | ||||
|             { | ||||
|                 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 + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (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, light ); | ||||
|                 borderX += thisWidth; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // 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++ ) | ||||
|         { | ||||
|             drawTexture( transform, buffer, x - offsetAt( n ), y, z - 1e-3f * n, | ||||
|                 // 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 | ||||
|         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++ ) | ||||
|         { | ||||
|             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. | ||||
|                 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 ))); | ||||
|     } | ||||
|  | ||||
|     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 ) | ||||
|             .texture( u / BG_SIZE, (v + height) / BG_SIZE ) | ||||
|             .next(); | ||||
|         buffer.vertex( matrix, x + width, y + height, z ) | ||||
|             .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(); | ||||
|         vertex( buffer, matrix, x, y + height, z, u / BG_SIZE, (v + height) / BG_SIZE, light ); | ||||
|         vertex( buffer, matrix, x + width, y + height, z, (u + width) / BG_SIZE, (v + height) / BG_SIZE, light ); | ||||
|         vertex( buffer, matrix, x + width, y, z, (u + width) / BG_SIZE, v / BG_SIZE, light ); | ||||
|         vertex( buffer, matrix, x, y, z, u / BG_SIZE, v / BG_SIZE, light ); | ||||
|     } | ||||
|  | ||||
|     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 ) | ||||
|             .texture( u / BG_SIZE, (v + tHeight) / BG_SIZE ) | ||||
|             .next(); | ||||
|         buffer.vertex( matrix, x + width, y + height, z ) | ||||
|             .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(); | ||||
|         vertex( buffer, matrix, x, y + height, z, u / BG_SIZE, (v + tHeight) / BG_SIZE, light ); | ||||
|         vertex( buffer, matrix, x + width, y + height, z, (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE, light ); | ||||
|         vertex( buffer, matrix, x + width, y, z, (u + tWidth) / BG_SIZE, v / BG_SIZE, light ); | ||||
|         vertex( buffer, matrix, x, y, z, u / BG_SIZE, v / BG_SIZE, light ); | ||||
|     } | ||||
|  | ||||
|     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", | ||||
|             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 ); | ||||
|         } | ||||
|         buffer.vertex( matrix, x, y, z ).color( 255, 255, 255, 255 ).texture( u, v ).light( light ).next(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -21,6 +21,11 @@ public class RenderTypes { | ||||
|     public static final RenderLayer MONITOR_TBO = Types.MONITOR_TBO; | ||||
|     public static final RenderLayer TERMINAL_BLOCKER = Types.BLOCKER; | ||||
|     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 | ||||
|     static MonitorTextureBufferShader getMonitorTextureBufferShader() | ||||
| @@ -80,6 +85,24 @@ public class RenderTypes { | ||||
|                 .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 ) | ||||
|         { | ||||
|             super( name, setup, destroy ); | ||||
|   | ||||
| @@ -18,6 +18,7 @@ import org.spongepowered.asm.mixin.Mixin; | ||||
| import org.spongepowered.asm.mixin.injection.At; | ||||
| import org.spongepowered.asm.mixin.injection.Inject; | ||||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||||
| import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||||
|  | ||||
| /** | ||||
|  * Captures block drops. | ||||
| @@ -27,14 +28,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||||
| @Mixin( Block.class ) | ||||
| public class MixinBlock | ||||
| { | ||||
| //    @Inject( method = "dropStack", | ||||
| //        at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z" ), | ||||
| //        cancellable = true ) | ||||
| //    private static void dropStack( World world, BlockPos pos, ItemStack stack, CallbackInfo callbackInfo ) | ||||
| //    { | ||||
| //        if( DropConsumer.onHarvestDrops( world, itemEntitySupplier.get().getBlockPos(), stack ) ) | ||||
| //        { | ||||
| //            callbackInfo.cancel(); | ||||
| //        } | ||||
| //    } | ||||
|     @Inject( method = "dropStack(Lnet/minecraft/world/World;Ljava/util/function/Supplier;Lnet/minecraft/item/ItemStack;)V", | ||||
|         at = @At( | ||||
|             value = "INVOKE", | ||||
|             target = "Lnet/minecraft/entity/ItemEntity;setToDefaultPickupDelay()V" | ||||
|         ), | ||||
|         locals = LocalCapture.CAPTURE_FAILSOFT, | ||||
|         cancellable = true ) | ||||
|     private static void dropStack( World world, Supplier<ItemEntity> itemEntitySupplier, ItemStack stack, CallbackInfo callbackInfo, ItemEntity itemEntity ) | ||||
|     { | ||||
|         if( DropConsumer.onHarvestDrops( world, itemEntity.getBlockPos(), stack ) ) | ||||
|         { | ||||
|             callbackInfo.cancel(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -22,14 +22,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||||
| @Mixin( Entity.class ) | ||||
| public class MixinEntity | ||||
| { | ||||
| //    @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" ), | ||||
| //        cancellable = true ) | ||||
| //    public void dropStack( ItemStack stack, float height, CallbackInfoReturnable<ItemEntity> callbackInfo ) | ||||
| //    { | ||||
| //        if( DropConsumer.onLivingDrops( (Entity) (Object) this, stack ) ) | ||||
| //        { | ||||
| //            callbackInfo.setReturnValue( null ); | ||||
| //        } | ||||
| //    } | ||||
|     @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" ), | ||||
|         cancellable = true ) | ||||
|     public void dropStack( ItemStack stack, float height, CallbackInfoReturnable<ItemEntity> callbackInfo ) | ||||
|     { | ||||
|         if( DropConsumer.onLivingDrops( (Entity) (Object) this, stack ) ) | ||||
|         { | ||||
|             callbackInfo.setReturnValue( null ); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -12,27 +12,40 @@ import net.fabricmc.api.Environment; | ||||
| import net.minecraft.client.render.VertexConsumerProvider; | ||||
| import net.minecraft.client.render.entity.ItemFrameEntityRenderer; | ||||
| import net.minecraft.client.util.math.MatrixStack; | ||||
| import net.minecraft.entity.EntityType; | ||||
| import net.minecraft.entity.decoration.ItemFrameEntity; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import org.spongepowered.asm.mixin.Mixin; | ||||
| import org.spongepowered.asm.mixin.injection.At; | ||||
| import org.spongepowered.asm.mixin.injection.Inject; | ||||
| import org.spongepowered.asm.mixin.injection.Slice; | ||||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||||
|  | ||||
| @Mixin( ItemFrameEntityRenderer.class ) | ||||
| @Environment( EnvType.CLIENT ) | ||||
| 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( | ||||
|         ItemFrameEntity itemFrameEntity, float f, float g, MatrixStack matrixStack, | ||||
|         VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo info | ||||
|         VertexConsumerProvider vertexConsumerProvider, int itemFrameEntityLight, CallbackInfo info | ||||
|     ) | ||||
|     { | ||||
|         ItemStack stack = itemFrameEntity.getHeldItemStack(); | ||||
|         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(); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -29,10 +29,11 @@ public class MixinWorld | ||||
|     @Shadow | ||||
|     protected boolean iteratingTickingBlockEntities; | ||||
|  | ||||
| //    @Inject( method = "setBlockEntity", at = @At( "HEAD" ) ) | ||||
|     public void setBlockEntity( BlockPos pos, @Nullable BlockEntity entity, CallbackInfo info ) | ||||
|     @Inject( method = "addBlockEntity", at = @At( "HEAD" ) ) | ||||
|     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 ); | ||||
|         } | ||||
| @@ -40,9 +41,10 @@ public class MixinWorld | ||||
|  | ||||
|     private static void setWorld( BlockEntity entity, Object world ) | ||||
|     { | ||||
|         System.out.println("setWorld"); | ||||
|         if( entity.getWorld() != world && entity instanceof TileGeneric ) | ||||
|         { | ||||
| //            entity.setLocation( (World) world, entity.getPos() ); //TODO why? | ||||
|             entity.setWorld( (World) world ); //TODO why? | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -44,6 +44,7 @@ import dan200.computercraft.shared.turtle.items.ItemTurtle; | ||||
| import dan200.computercraft.shared.turtle.upgrades.*; | ||||
| //import dan200.computercraft.shared.util.FixedPointTileEntityType; | ||||
| 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.*; | ||||
| @@ -90,31 +91,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, false ) ); | ||||
|         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", | ||||
|             new BlockWirelessModem( properties(), 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", | ||||
|             new BlockWirelessModem( properties(), 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", | ||||
|             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() | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap; | ||||
| import dan200.computercraft.api.ComputerCraftAPI; | ||||
| import dan200.computercraft.shared.ComputerCraftRegistry; | ||||
| import dan200.computercraft.shared.common.BlockGeneric; | ||||
| import dan200.computercraft.shared.peripheral.printer.TilePrinter; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.BlockState; | ||||
| import net.minecraft.block.ShapeContext; | ||||
| @@ -271,4 +272,11 @@ public class BlockCable extends BlockGeneric implements Waterloggable | ||||
|                 .with( DOWN, false ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public BlockEntity createBlockEntity(BlockPos pos, BlockState state) | ||||
|     { | ||||
|         return new TileCable(ComputerCraftRegistry.ModTiles.CABLE, pos, state); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -6,12 +6,18 @@ | ||||
|  | ||||
| package dan200.computercraft.shared.peripheral.modem.wired; | ||||
|  | ||||
| import dan200.computercraft.shared.ComputerCraftRegistry; | ||||
| import dan200.computercraft.shared.common.BlockGeneric; | ||||
| import dan200.computercraft.shared.peripheral.speaker.TileSpeaker; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.BlockState; | ||||
| import net.minecraft.block.entity.BlockEntity; | ||||
| import net.minecraft.block.entity.BlockEntityType; | ||||
| import net.minecraft.state.StateManager; | ||||
| import net.minecraft.state.property.BooleanProperty; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
|  | ||||
| import javax.annotation.Nullable; | ||||
|  | ||||
| public class BlockWiredModemFull extends BlockGeneric | ||||
| { | ||||
| @@ -31,4 +37,11 @@ public class BlockWiredModemFull extends BlockGeneric | ||||
|     { | ||||
|         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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -6,12 +6,17 @@ | ||||
|  | ||||
| package dan200.computercraft.shared.peripheral.modem.wireless; | ||||
|  | ||||
| import dan200.computercraft.shared.ComputerCraftRegistry; | ||||
| 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.wired.TileWiredModemFull; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.BlockState; | ||||
| import net.minecraft.block.ShapeContext; | ||||
| import net.minecraft.block.Waterloggable; | ||||
| import net.minecraft.block.entity.BlockEntity; | ||||
| import net.minecraft.block.entity.BlockEntityType; | ||||
| import net.minecraft.fluid.FluidState; | ||||
| 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 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 ); | ||||
|         this.family = family; | ||||
|         setDefaultState( getStateManager().getDefaultState() | ||||
|             .with( FACING, Direction.NORTH ) | ||||
|             .with( ON, false ) | ||||
| @@ -95,4 +103,19 @@ public class BlockWirelessModem extends BlockGeneric implements Waterloggable | ||||
|     { | ||||
|         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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -8,6 +8,7 @@ package dan200.computercraft.shared.peripheral.printer; | ||||
|  | ||||
| import dan200.computercraft.shared.ComputerCraftRegistry; | ||||
| import dan200.computercraft.shared.common.BlockGeneric; | ||||
| import dan200.computercraft.shared.computer.blocks.TileComputer; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.BlockState; | ||||
| import net.minecraft.block.entity.BlockEntity; | ||||
| @@ -88,4 +89,11 @@ public class BlockPrinter extends BlockGeneric | ||||
|     { | ||||
|         properties.add( FACING, TOP, BOTTOM ); | ||||
|     } | ||||
|  | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public BlockEntity createBlockEntity(BlockPos pos, BlockState state) | ||||
|     { | ||||
|         return new TilePrinter(ComputerCraftRegistry.ModTiles.PRINTER, pos, state); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -188,7 +188,6 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent | ||||
|     @Override | ||||
|     public NbtCompound writeNbt( @Nonnull NbtCompound nbt ) | ||||
|     { | ||||
|     	super.writeNbt( nbt ); | ||||
|         if( customName != null ) | ||||
|         { | ||||
|             nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) ); | ||||
| @@ -205,7 +204,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent | ||||
|         // Write inventory | ||||
|         Inventories.writeNbt( nbt, inventory ); | ||||
|  | ||||
|         return nbt; | ||||
|         return super.writeNbt( nbt ); | ||||
|     } | ||||
|  | ||||
|     boolean isPrinting() | ||||
|   | ||||
| @@ -8,6 +8,7 @@ package dan200.computercraft.shared.peripheral.speaker; | ||||
|  | ||||
| import dan200.computercraft.shared.ComputerCraftRegistry; | ||||
| import dan200.computercraft.shared.common.BlockGeneric; | ||||
| import dan200.computercraft.shared.turtle.blocks.TileTurtle; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.BlockState; | ||||
| import net.minecraft.block.entity.BlockEntity; | ||||
| @@ -17,6 +18,7 @@ import net.minecraft.item.ItemPlacementContext; | ||||
| import net.minecraft.state.StateManager; | ||||
| import net.minecraft.state.property.DirectionProperty; | ||||
| import net.minecraft.state.property.Properties; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.util.math.Direction; | ||||
| import net.minecraft.world.World; | ||||
|  | ||||
| @@ -48,6 +50,13 @@ public class BlockSpeaker extends BlockGeneric | ||||
|         properties.add( FACING ); | ||||
|     } | ||||
|  | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public BlockEntity createBlockEntity(BlockPos pos, BlockState state) | ||||
|     { | ||||
|         return new TileSpeaker(ComputerCraftRegistry.ModTiles.SPEAKER, pos, state); | ||||
|     } | ||||
|  | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public <T extends BlockEntity> BlockEntityTicker<T> getTicker( World world, BlockState state, BlockEntityType<T> type){ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Cloud Chagnon
					Cloud Chagnon