From 649acbae1c33bd5a54a7072ae000cfea9b988bec Mon Sep 17 00:00:00 2001 From: SquidDev Date: Thu, 30 Jan 2020 10:07:47 +0000 Subject: [PATCH] Add back item frame rendering for printouts Also fix a recipe loading issue, due to capitalisation of enums --- .../computercraft/client/gui/GuiPrintout.java | 12 +- .../ItemMapLikeRenderer.java | 28 +++-- .../ItemPrintoutRenderer.java | 65 +++++----- .../client/render/PrintoutRenderer.java | 118 ++++++++++-------- .../computercraft/shared/util/RecipeUtil.java | 22 +--- .../recipes/computer_advanced_upgrade.json | 2 +- .../pocket_computer_advanced_upgrade.json | 2 +- .../recipes/turtle_advanced.json | 2 +- .../recipes/turtle_advanced_upgrade.json | 2 +- .../computercraft/recipes/turtle_normal.json | 2 +- 10 files changed, 137 insertions(+), 118 deletions(-) rename src/main/java/dan200/computercraft/client/{render_old => render}/ItemMapLikeRenderer.java (80%) rename src/main/java/dan200/computercraft/client/{render_old => render}/ItemPrintoutRenderer.java (58%) diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java index 9c609be91..37927e62a 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java @@ -9,7 +9,11 @@ import com.mojang.blaze3d.systems.RenderSystem; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.media.items.ItemPrintout; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.TransformationMatrix; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; import org.lwjgl.glfw.GLFW; @@ -18,6 +22,8 @@ import static dan200.computercraft.client.render.PrintoutRenderer.*; public class GuiPrintout extends ContainerScreen { + private static final Matrix4f IDENTITY = TransformationMatrix.identity().getMatrix(); + private final boolean m_book; private final int m_pages; private final TextBuffer[] m_text; @@ -91,8 +97,10 @@ public class GuiPrintout extends ContainerScreen RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); RenderSystem.enableDepthTest(); - drawBorder( guiLeft, guiTop, getBlitOffset(), m_page, m_pages, m_book ); - drawText( guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); + IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); + drawBorder( IDENTITY, renderer, guiLeft, guiTop, getBlitOffset(), m_page, m_pages, m_book ); + drawText( IDENTITY, renderer, guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); + renderer.finish(); } @Override diff --git a/src/main/java/dan200/computercraft/client/render_old/ItemMapLikeRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java similarity index 80% rename from src/main/java/dan200/computercraft/client/render_old/ItemMapLikeRenderer.java rename to src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java index 8a5472c99..f25deea79 100644 --- a/src/main/java/dan200/computercraft/client/render_old/ItemMapLikeRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java @@ -52,13 +52,16 @@ public abstract class ItemMapLikeRenderer /** * Renders the item to one side of the player. * + * @param transform The matrix transformation stack + * @param render The buffer to render to + * @param combinedLight The current light level * @param side The side to render on * @param equipProgress The equip progress of this item * @param swingProgress The swing progress of this item * @param stack The stack to render * @see FirstPersonRenderer#renderMapFirstPersonSide(MatrixStack, IRenderTypeBuffer, int, float, HandSide, float, ItemStack) */ - private void renderItemFirstPersonSide( MatrixStack transform, IRenderTypeBuffer render, int lightTexture, HandSide side, float equipProgress, float swingProgress, ItemStack stack ) + private void renderItemFirstPersonSide( MatrixStack transform, IRenderTypeBuffer render, int combinedLight, HandSide side, float equipProgress, float swingProgress, ItemStack stack ) { Minecraft minecraft = Minecraft.getInstance(); float offset = side == HandSide.RIGHT ? 1f : -1f; @@ -68,8 +71,8 @@ public abstract class ItemMapLikeRenderer if( !minecraft.player.isInvisible() ) { transform.push(); - transform.rotate( Vector3f.field_229183_f_.func_229187_a_( offset * 10f ) ); - minecraft.getFirstPersonRenderer().renderArmFirstPerson( transform, render, lightTexture, equipProgress, swingProgress, side ); + transform.rotate( Vector3f.ZP.rotationDegrees( offset * 10f ) ); + minecraft.getFirstPersonRenderer().renderArmFirstPerson( transform, render, combinedLight, equipProgress, swingProgress, side ); transform.pop(); } @@ -83,8 +86,8 @@ public abstract class ItemMapLikeRenderer float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) ); float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI ); transform.translate( offset * f3, f4 - 0.3f * f2, f5 ); - transform.rotate( Vector3f.field_229179_b_.func_229187_a_( f2 * -45f ) ); - transform.rotate( Vector3f.field_229181_d_.func_229187_a_( offset * f2 * -30f ) ); + transform.rotate( Vector3f.XP.rotationDegrees( f2 * -45f ) ); + transform.rotate( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) ); renderItem( transform, render, stack ); @@ -94,13 +97,16 @@ public abstract class ItemMapLikeRenderer /** * Render an item in the middle of the screen. * + * @param transform The matrix transformation stack + * @param render The buffer to render to + * @param combinedLight The current light level * @param pitch The pitch of the player * @param equipProgress The equip progress of this item * @param swingProgress The swing progress of this item * @param stack The stack to render * @see FirstPersonRenderer#renderMapFirstPerson(MatrixStack, IRenderTypeBuffer, int, float, float, float) */ - private void renderItemFirstPersonCenter( MatrixStack transform, IRenderTypeBuffer render, int lightTexture, float pitch, float equipProgress, float swingProgress, ItemStack stack ) + private void renderItemFirstPersonCenter( MatrixStack transform, IRenderTypeBuffer render, int combinedLight, float pitch, float equipProgress, float swingProgress, ItemStack stack ) { Minecraft minecraft = Minecraft.getInstance(); FirstPersonRenderer renderer = minecraft.getFirstPersonRenderer(); @@ -114,18 +120,18 @@ public abstract class ItemMapLikeRenderer float pitchAngle = renderer.getMapAngleFromPitch( pitch ); transform.translate( 0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f ); - transform.rotate( Vector3f.field_229179_b_.func_229187_a_( pitchAngle * -85.0f ) ); + transform.rotate( Vector3f.XP.rotationDegrees( pitchAngle * -85.0f ) ); if( !minecraft.player.isInvisible() ) { transform.push(); - transform.rotate( Vector3f.field_229181_d_.func_229187_a_( 90.0F ) ); - renderer.renderArm( transform, render, lightTexture, HandSide.RIGHT ); - renderer.renderArm( transform, render, lightTexture, HandSide.LEFT ); + transform.rotate( Vector3f.YP.rotationDegrees( 90.0F ) ); + renderer.renderArm( transform, render, combinedLight, HandSide.RIGHT ); + renderer.renderArm( transform, render, combinedLight, HandSide.LEFT ); transform.pop(); } float rX = MathHelper.sin( swingRt * (float) Math.PI ); - transform.rotate( Vector3f.field_229179_b_.func_229187_a_( rX * 20.0F ) ); + transform.rotate( Vector3f.XP.rotationDegrees( rX * 20.0F ) ); transform.scale( 2.0F, 2.0F, 2.0F ); renderItem( transform, render, stack ); diff --git a/src/main/java/dan200/computercraft/client/render_old/ItemPrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java similarity index 58% rename from src/main/java/dan200/computercraft/client/render_old/ItemPrintoutRenderer.java rename to src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java index eee8e191d..65c2c8e99 100644 --- a/src/main/java/dan200/computercraft/client/render_old/ItemPrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java @@ -5,13 +5,16 @@ */ package dan200.computercraft.client.render; -import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.matrix.MatrixStack; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.media.items.ItemPrintout; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderItemInFrameEvent; -import net.minecraftforge.client.event.RenderSpecificHandEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -33,31 +36,28 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer { } - @SubscribeEvent - public static void onRenderInHand( RenderSpecificHandEvent event ) + // TODO: @SubscribeEvent + public static void onRenderInHand( RenderHandEvent event ) { ItemStack stack = event.getItemStack(); if( !(stack.getItem() instanceof ItemPrintout) ) return; event.setCanceled( true ); - INSTANCE.renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() ); + INSTANCE.renderItemFirstPerson( + event.getMatrixStack(), event.getBuffers(), event.getLight(), + event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() + ); } @Override - protected void renderItem( ItemStack stack ) + protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack ) { - // Setup various transformations. Note that these are partially adapated from the corresponding method - // in FirstPersonRenderer.renderFirstPersonMap - RenderSystem.disableLighting(); + transform.rotate( Vector3f.XP.rotationDegrees( 180f ) ); + transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) ); + transform.scale( 0.42f, 0.42f, -0.42f ); + transform.translate( -0.5f, -0.48f, 0.0f ); - RenderSystem.rotatef( 180f, 0f, 1f, 0f ); - RenderSystem.rotatef( 180f, 0f, 0f, 1f ); - RenderSystem.scalef( 0.42f, 0.42f, -0.42f ); - RenderSystem.translatef( -0.5f, -0.48f, 0.0f ); - - drawPrintout( stack ); - - RenderSystem.enableLighting(); + drawPrintout( transform, render, stack ); } @SubscribeEvent @@ -65,24 +65,20 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer { ItemStack stack = event.getItem(); if( !(stack.getItem() instanceof ItemPrintout) ) return; - event.setCanceled( true ); - RenderSystem.disableLighting(); + MatrixStack transform = event.getMatrix(); // Move a little bit forward to ensure we're not clipping with the frame - RenderSystem.translatef( 0.0f, 0.0f, -0.001f ); - RenderSystem.rotatef( 180f, 0f, 0f, 1f ); - RenderSystem.scalef( 0.95f, 0.95f, -0.95f ); - RenderSystem.translatef( -0.5f, -0.5f, 0.0f ); + transform.translate( 0.0f, 0.0f, -0.001f ); + transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) ); + transform.scale( 0.95f, 0.95f, -0.95f ); + transform.translate( -0.5f, -0.5f, 0.0f ); - drawPrintout( stack ); - - RenderSystem.enableLighting(); - RenderSystem.disableBlend(); + drawPrintout( transform, event.getBuffers(), stack ); } - private static void drawPrintout( ItemStack stack ) + private static void drawPrintout( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack ) { int pages = ItemPrintout.getPageCount( stack ); boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK; @@ -105,11 +101,14 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer double max = Math.max( visualHeight, visualWidth ); // Scale the printout to fit correctly. - double scale = 1.0 / max; - RenderSystem.scaled( scale, scale, scale ); - RenderSystem.translated( (max - width) / 2.0, (max - height) / 2.0, 0.0 ); + float scale = (float) (1.0 / max); + transform.scale( scale, scale, scale ); + transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 ); - drawBorder( 0, 0, -0.01, 0, pages, book ); - drawText( X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) ); + Matrix4f matrix = transform.getLast().getPositionMatrix(); + drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book ); + drawText( matrix, render, + X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) + ); } } diff --git a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java index b1e81a556..bbe95c9c0 100644 --- a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java @@ -5,15 +5,14 @@ */ package dan200.computercraft.client.render; -import com.mojang.blaze3d.platform.GlStateManager.DestFactor; -import com.mojang.blaze3d.platform.GlStateManager.SourceFactor; -import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.IVertexBuilder; import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Palette; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderState; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @@ -61,66 +60,71 @@ public final class PrintoutRenderer private PrintoutRenderer() {} - public static void drawText( int x, int y, int start, TextBuffer[] text, TextBuffer[] colours ) + public static void drawText( Matrix4f transform, IRenderTypeBuffer renderer, int x, int y, int start, TextBuffer[] text, TextBuffer[] colours ) { + IVertexBuilder buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE ); for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) { - FixedWidthFontRenderer.drawString( + FixedWidthFontRenderer.drawString( transform, buffer, x, y + line * FONT_HEIGHT, text[start + line], colours[start + line], null, Palette.DEFAULT, false, 0, 0 ); } } - public static void drawBorder( double x, double y, double z, int page, int pages, boolean isBook ) + public static void drawText( Matrix4f transform, IRenderTypeBuffer renderer, int x, int y, int start, String[] text, String[] colours ) { - RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); - RenderSystem.enableBlend(); - RenderSystem.enableTexture(); - RenderSystem.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO ); - - Minecraft.getInstance().getTextureManager().bindTexture( BG ); - - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX ); + IVertexBuilder buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE ); + for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) + { + FixedWidthFontRenderer.drawString( transform, buffer, + x, y + line * FONT_HEIGHT, + new TextBuffer( text[start + line] ), new TextBuffer( colours[start + line] ), + null, Palette.DEFAULT, false, 0, 0 + ); + } + } + public static void drawBorder( Matrix4f transform, IRenderTypeBuffer renderer, float x, float y, float z, int page, int pages, boolean isBook ) + { int leftPages = page; int rightPages = pages - page - 1; + IVertexBuilder buffer = renderer.getBuffer( Type.TYPE ); + if( isBook ) { // Border - double offset = offsetAt( pages ); - final double left = x - 4 - offset; - final double right = x + X_SIZE + offset - 4; + float offset = offsetAt( pages ); + float left = x - 4 - offset; + float right = x + X_SIZE + offset - 4; // Left and right border - drawTexture( buffer, left - 4, y - 8, z - 0.02, COVER_X, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2 ); - drawTexture( buffer, right, y - 8, z - 0.02, 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 ); + drawTexture( transform, buffer, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2 ); // Draw centre panel (just stretched texture, sorry). - drawTexture( buffer, - x - offset, y, z - 0.02, X_SIZE + offset * 2, Y_SIZE, + drawTexture( transform, buffer, + x - offset, y, z - 0.02f, X_SIZE + offset * 2, Y_SIZE, COVER_X + COVER_SIZE / 2.0f, COVER_SIZE, COVER_SIZE, Y_SIZE ); - double borderX = left; + float borderX = left; while( borderX < right ) { double thisWidth = Math.min( right - borderX, X_SIZE ); - drawTexture( buffer, borderX, y - 8, z - 0.02, 0, COVER_Y, (float) thisWidth, COVER_SIZE ); - drawTexture( buffer, borderX, y + Y_SIZE - 4, z - 0.02, 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 ); + drawTexture( transform, buffer, borderX, y + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE ); borderX += thisWidth; } } // Left half - drawTexture( 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 ); for( int n = 0; n <= leftPages; n++ ) { - drawTexture( buffer, - x - offsetAt( n ), y, z - 1e-3 * 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 @@ -128,38 +132,54 @@ public final class PrintoutRenderer } // Right half - drawTexture( 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 ); for( int n = 0; n <= rightPages; n++ ) { - drawTexture( buffer, - x + (X_SIZE - X_FOLD_SIZE) + offsetAt( n ), y, z - 1e-3 * 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 ); } - - tessellator.draw(); } - private static void drawTexture( BufferBuilder buffer, double x, double y, double z, float u, float v, float width, float height ) + private static void drawTexture( Matrix4f matrix, IVertexBuilder buffer, float x, float y, float z, float u, float v, float width, float height ) { - buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); - buffer.pos( x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); - buffer.pos( x + width, y, z ).tex( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex(); - buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.pos( matrix, x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); + buffer.pos( matrix, x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); + buffer.pos( matrix, x + width, y, z ).tex( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.pos( matrix, x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex(); } - private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double width, double height, float u, float v, float tWidth, float tHeight ) + private static void drawTexture( Matrix4f matrix, IVertexBuilder buffer, float x, float y, float z, float width, float height, float u, float v, float tWidth, float tHeight ) { - buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); - buffer.pos( x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); - buffer.pos( x + width, y, z ).tex( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex(); - buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.pos( matrix, x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); + buffer.pos( matrix, x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); + buffer.pos( matrix, x + width, y, z ).tex( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.pos( matrix, x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex(); } - public static double offsetAt( int page ) + public static float offsetAt( int page ) { - return 32 * (1 - Math.pow( 1.2, -page )); + return (float) (32 * (1 - Math.pow( 1.2, -page ))); + } + + private static final class Type extends RenderState + { + static final RenderType TYPE = RenderType.get( + "printout_background", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 1024, + false, false, // useDelegate, needsSorting + RenderType.State.builder() + .texture( new RenderState.TextureState( BG, false, false ) ) // blur, minimap + .alpha( DEFAULT_ALPHA ) + .lightmap( LIGHTMAP_DISABLED ) + .build( false ) + ); + + private Type( String name, Runnable setup, Runnable destroy ) + { + super( name, setup, destroy ); + } } } diff --git a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java index 1f4179a77..f570adaec 100644 --- a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java @@ -103,28 +103,14 @@ public final class RecipeUtil return new ShapedTemplate( width, height, ingredients ); } - public static NonNullList getIngredients( JsonObject json ) - { - NonNullList ingredients = NonNullList.create(); - for( JsonElement ele : JSONUtils.getJsonArray( json, "ingredients" ) ) - { - ingredients.add( Ingredient.deserialize( ele ) ); - } - - if( ingredients.isEmpty() ) throw new JsonParseException( "No ingredients for recipe" ); - return ingredients; - } - public static ComputerFamily getFamily( JsonObject json, String name ) { String familyName = JSONUtils.getString( json, name ); - try + for( ComputerFamily family : ComputerFamily.values() ) { - return ComputerFamily.valueOf( familyName ); - } - catch( IllegalArgumentException e ) - { - throw new JsonSyntaxException( "Unknown computer family '" + familyName + "' for field " + name ); + if( family.name().equalsIgnoreCase( familyName ) ) return family; } + + throw new JsonSyntaxException( "Unknown computer family '" + familyName + "' for field " + name ); } } diff --git a/src/main/resources/data/computercraft/recipes/computer_advanced_upgrade.json b/src/main/resources/data/computercraft/recipes/computer_advanced_upgrade.json index e6de6b37e..eb0b5c792 100644 --- a/src/main/resources/data/computercraft/recipes/computer_advanced_upgrade.json +++ b/src/main/resources/data/computercraft/recipes/computer_advanced_upgrade.json @@ -9,6 +9,6 @@ "#": { "tag": "forge:ingots/gold" }, "C": { "item": "computercraft:computer_normal" } }, - "family": "Advanced", + "family": "advanced", "result": { "item": "computercraft:computer_advanced" } } diff --git a/src/main/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json b/src/main/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json index 79ee81b41..3409ce78f 100644 --- a/src/main/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json +++ b/src/main/resources/data/computercraft/recipes/pocket_computer_advanced_upgrade.json @@ -9,6 +9,6 @@ "#": { "tag": "forge:ingots/gold" }, "C": { "item": "computercraft:pocket_computer_normal" } }, - "family": "Advanced", + "family": "advanced", "result": { "item": "computercraft:pocket_computer_advanced" } } diff --git a/src/main/resources/data/computercraft/recipes/turtle_advanced.json b/src/main/resources/data/computercraft/recipes/turtle_advanced.json index 7da7f9017..1325043f6 100644 --- a/src/main/resources/data/computercraft/recipes/turtle_advanced.json +++ b/src/main/resources/data/computercraft/recipes/turtle_advanced.json @@ -10,6 +10,6 @@ "C": { "item": "computercraft:computer_advanced" }, "I": { "tag": "forge:chests/wooden" } }, - "family": "Advanced", + "family": "advanced", "result": { "item": "computercraft:turtle_advanced" } } diff --git a/src/main/resources/data/computercraft/recipes/turtle_advanced_upgrade.json b/src/main/resources/data/computercraft/recipes/turtle_advanced_upgrade.json index 79f4444ea..294854de1 100644 --- a/src/main/resources/data/computercraft/recipes/turtle_advanced_upgrade.json +++ b/src/main/resources/data/computercraft/recipes/turtle_advanced_upgrade.json @@ -10,6 +10,6 @@ "B": { "tag": "forge:storage_blocks/gold" }, "C": { "item": "computercraft:turtle_normal" } }, - "family": "Advanced", + "family": "advanced", "result": { "item": "computercraft:turtle_advanced" } } diff --git a/src/main/resources/data/computercraft/recipes/turtle_normal.json b/src/main/resources/data/computercraft/recipes/turtle_normal.json index f432bdf3c..00a6cddc6 100644 --- a/src/main/resources/data/computercraft/recipes/turtle_normal.json +++ b/src/main/resources/data/computercraft/recipes/turtle_normal.json @@ -10,6 +10,6 @@ "C": { "item": "computercraft:computer_normal" }, "I": { "tag": "forge:chests/wooden" } }, - "family": "Normal", + "family": "normal", "result": { "item": "computercraft:turtle_normal" } }