diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..66d760891 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: Release + +on: + release: + types: + - published + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/cache@v2 + with: + path: | + ~/.gradle/loom-cache + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle- + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: 17 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build and publish with Gradle + run: ./gradlew build publish + env: + CURSEFORGE: ${{ secrets.CURSEFORGE }} + MODRINTH: ${{ secrets.MODRINTH }} + CHANGELOG: ${{ github.event.release.body }} + - name: Upload GitHub release + uses: AButler/upload-release-assets@v2.0 + with: + files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar' + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitmodules b/.gitmodules index 6b19bfd04..269697c87 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "src/main/resources/resourcepacks/overhaul"] path = src/main/resources/resourcepacks/overhaul url = https://github.com/cc-orgs/cc-overhaul + branch = main diff --git a/build.gradle b/build.gradle index 9888692b1..1660f66c8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,8 @@ plugins { id "com.github.hierynomus.license" version "0.16.1" id "org.jetbrains.kotlin.jvm" version "1.5.21" id 'fabric-loom' version '0.10-SNAPSHOT' + id "com.modrinth.minotaur" version "2.+" + id 'com.matthewprenger.cursegradle' version '1.4.0' } def javaVersion = JavaLanguageVersion.of(17) @@ -247,3 +249,51 @@ publishing { // mavenLocal() } } + +if (System.getenv("MODRINTH")) { + modrinth { + token = System.getenv("MODRINTH") + + projectId = "eldBwa5V" + versionName = "[" + ((String) project.mc_version) + "] " + version + versionNumber = version + versionType = "release" + uploadFile = remapJar + gameVersions = [((String) project.mc_version)] + loaders = ["fabric"] + changelog = System.getenv("CHANGELOG") + } + + remapJar { + finalizedBy project.tasks.modrinth + } +} + +if (System.getenv("CURSEFORGE")) { + curseforge { + apiKey = System.getenv("CURSEFORGE") + + project { + id = "462672" + releaseType = "release" + displayName = "[" + ((String) project.mc_version) + "] " + version + changelog = System.getenv("CHANGELOG") + changelogType = "markdown" + addGameVersion ((String) project.mc_version) + addGameVersion "Fabric" + mainArtifact(remapJar) + + afterEvaluate { + uploadTask.dependsOn("remapJar") + } + } + + options { + forgeGradleIntegration = false + } + } + + remapJar { + finalizedBy project.tasks.curseforge + } +} diff --git a/gradle.properties b/gradle.properties index 08f781ba1..e5df156c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,12 +2,12 @@ org.gradle.jvmargs=-Xmx3G # Mod properties -mod_version=1.100.2 +mod_version=1.100.5 # Minecraft properties -mc_version=1.18.1 -fabric_api_version=0.44.0+1.18 -fabric_loader_version=0.12.12 +mc_version=1.18.2 +fabric_api_version=0.47.8+1.18.2 +fabric_loader_version=0.13.3 cloth_api_version=2.0.54 cloth_config_version=6.0.42 diff --git a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java index c17710cca..ec5f3714e 100644 --- a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java +++ b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java @@ -22,7 +22,6 @@ import dan200.computercraft.core.apis.ApiFactories; import dan200.computercraft.core.asm.GenericMethod; import dan200.computercraft.core.filesystem.FileMount; import dan200.computercraft.core.filesystem.ResourceMount; -import dan200.computercraft.fabric.mixin.MinecraftServerAccess; import dan200.computercraft.shared.*; import dan200.computercraft.shared.peripheral.modem.wired.TileCable; import dan200.computercraft.shared.peripheral.modem.wired.TileWiredModemFull; @@ -34,7 +33,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ReloadableResourceManager; +import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -57,7 +56,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI public static InputStream getResourceFile( String domain, String subPath ) { - ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) GameInstanceUtils.getServer()).callGetResourceManager(); + ResourceManager manager = GameInstanceUtils.getServer().getResourceManager(); try { return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream(); @@ -100,7 +99,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI @Override public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath ) { - ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) GameInstanceUtils.getServer()).callGetResourceManager(); + ResourceManager manager = GameInstanceUtils.getServer().getResourceManager(); ResourceMount mount = ResourceMount.get( domain, subPath, manager ); return mount.exists( "" ) ? mount : null; } diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftTags.java b/src/main/java/dan200/computercraft/api/ComputerCraftTags.java index fc68ecc44..ab3064c8f 100644 --- a/src/main/java/dan200/computercraft/api/ComputerCraftTags.java +++ b/src/main/java/dan200/computercraft/api/ComputerCraftTags.java @@ -6,9 +6,9 @@ package dan200.computercraft.api; import dan200.computercraft.ComputerCraft; -import net.fabricmc.fabric.api.tag.TagFactory; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; @@ -19,47 +19,47 @@ public class ComputerCraftTags { public static class Items { - public static final Tag.Named COMPUTER = make( "computer" ); - public static final Tag.Named TURTLE = make( "turtle" ); - public static final Tag.Named WIRED_MODEM = make( "wired_modem" ); - public static final Tag.Named MONITOR = make( "monitor" ); + public static final TagKey COMPUTER = make( "computer" ); + public static final TagKey TURTLE = make( "turtle" ); + public static final TagKey WIRED_MODEM = make( "wired_modem" ); + public static final TagKey MONITOR = make( "monitor" ); - private static Tag.Named make( String name ) + private static TagKey make( String name ) { - return TagFactory.ITEM.create( new ResourceLocation( ComputerCraft.MOD_ID, name ) ); + return TagKey.create( Registry.ITEM_REGISTRY, new ResourceLocation( ComputerCraft.MOD_ID, name ) ); } } public static class Blocks { - public static final Tag.Named COMPUTER = make( "computer" ); - public static final Tag.Named TURTLE = make( "turtle" ); - public static final Tag.Named WIRED_MODEM = make( "wired_modem" ); - public static final Tag.Named MONITOR = make( "monitor" ); + public static final TagKey COMPUTER = make( "computer" ); + public static final TagKey TURTLE = make( "turtle" ); + public static final TagKey WIRED_MODEM = make( "wired_modem" ); + public static final TagKey MONITOR = make( "monitor" ); /** * Blocks which can be broken by any turtle tool. */ - public static final Tag.Named TURTLE_ALWAYS_BREAKABLE = make( "turtle_always_breakable" ); + public static final TagKey TURTLE_ALWAYS_BREAKABLE = make( "turtle_always_breakable" ); /** * Blocks which can be broken by the default shovel tool. */ - public static final Tag.Named TURTLE_SHOVEL_BREAKABLE = make( "turtle_shovel_harvestable" ); + public static final TagKey TURTLE_SHOVEL_BREAKABLE = make( "turtle_shovel_harvestable" ); /** * Blocks which can be broken with the default sword tool. */ - public static final Tag.Named TURTLE_SWORD_BREAKABLE = make( "turtle_sword_harvestable" ); + public static final TagKey TURTLE_SWORD_BREAKABLE = make( "turtle_sword_harvestable" ); /** * Blocks which can be broken with the default hoe tool. */ - public static final Tag.Named TURTLE_HOE_BREAKABLE = make( "turtle_hoe_harvestable" ); + public static final TagKey TURTLE_HOE_BREAKABLE = make( "turtle_hoe_harvestable" ); - private static Tag.Named make( String name ) + private static TagKey make( String name ) { - return TagFactory.BLOCK.create( new ResourceLocation( ComputerCraft.MOD_ID, name ) ); + return TagKey.create( Registry.BLOCK_REGISTRY, new ResourceLocation( ComputerCraft.MOD_ID, name ) ); } } } diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 5bcb1c935..5e82c7091 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -5,8 +5,10 @@ */ package dan200.computercraft.client.gui; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.render.RenderTypes; @@ -15,7 +17,7 @@ import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Palette; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.client.renderer.texture.OverlayTexture; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -34,14 +36,10 @@ import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMA * *
  • {@link #drawTerminal}: Draw a terminal with a cursor. This is used by the various computer GUIs to render the * whole term.
  • - *
  • {@link #drawBlocker}: When rendering a terminal using {@link RenderTypes#TERMINAL_WITHOUT_DEPTH} you need to - * render an additional "depth blocker" on top of the monitor.
  • * */ public final class FixedWidthFontRenderer { - public static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" ); - public static final int FONT_HEIGHT = 9; public static final int FONT_WIDTH = 6; public static final float WIDTH = 256.0f; @@ -49,6 +47,8 @@ public final class FixedWidthFontRenderer public static final float BACKGROUND_START = (WIDTH - 6.0f) / WIDTH; public static final float BACKGROUND_END = (WIDTH - 4.0f) / WIDTH; + public static final float Z_EPSILON = 0.001f; + private FixedWidthFontRenderer() { } @@ -63,7 +63,7 @@ public final class FixedWidthFontRenderer return 15 - Terminal.getColour( c, def ); } - private static void drawChar( Matrix4f transform, VertexConsumer buffer, float x, float y, int index, float r, float g, float b, int light ) + private static void drawChar( PoseStack 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 == ' ' ) return; @@ -74,25 +74,25 @@ public final class FixedWidthFontRenderer int xStart = 1 + column * (FONT_WIDTH + 2); int yStart = 1 + row * (FONT_HEIGHT + 2); - buffer.vertex( transform, x, y, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, yStart / WIDTH ).uv2( light ).endVertex(); - buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).uv2( light ).endVertex(); - buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).uv2( light ).endVertex(); - buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).uv2( light ).endVertex(); - buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).uv2( light ).endVertex(); - buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).uv2( light ).endVertex(); + Matrix4f matrix = transform.last().pose(); + Matrix3f normalMatrix = transform.last().normal(); + vertex( matrix, normalMatrix, buffer, x, y, Z_EPSILON, r, g, b, xStart / WIDTH, yStart / WIDTH, light ); + vertex( matrix, normalMatrix, buffer, x, y + FONT_HEIGHT, Z_EPSILON, r, g, b, xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH, light ); + vertex( matrix, normalMatrix, buffer, x + FONT_WIDTH, y + FONT_HEIGHT, Z_EPSILON, r, g, b, (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH, light ); + vertex( matrix, normalMatrix, buffer, x + FONT_WIDTH, y, Z_EPSILON, r, g, b, (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH, light ); } - private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, float r, float g, float b ) + private static void drawQuad( PoseStack transform, VertexConsumer buffer, float x, float y, float width, float height, float r, float g, float b, int light ) { - buffer.vertex( transform, x, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_START ).endVertex(); - buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_END ).endVertex(); - buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_START ).endVertex(); - buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_START ).endVertex(); - buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_END ).endVertex(); - buffer.vertex( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_END ).endVertex(); + Matrix4f matrix = transform.last().pose(); + Matrix3f normalMatrix = transform.last().normal(); + vertex( matrix, normalMatrix, buffer, x, y, 0, r, g, b, BACKGROUND_START, BACKGROUND_START, light ); + vertex( matrix, normalMatrix, buffer, x, y + height, 0, r, g, b, BACKGROUND_START, BACKGROUND_END, light ); + vertex( matrix, normalMatrix, buffer, x + width, y + height, 0, r, g, b, BACKGROUND_END, BACKGROUND_END, light ); + vertex( matrix, normalMatrix, buffer, x + width, y, 0, r, g, b, BACKGROUND_END, BACKGROUND_START, light ); } - private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex ) + private static void drawQuad( PoseStack transform, VertexConsumer buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex, int light ) { double[] colour = palette.getColour( getColour( colourIndex, Colour.BLACK ) ); float r, g, b; @@ -107,23 +107,23 @@ public final class FixedWidthFontRenderer b = (float) colour[2]; } - drawQuad( transform, buffer, x, y, width, height, r, g, b ); + drawQuad( transform, buffer, x, y, width, height, r, g, b, light ); } private static void drawBackground( - @Nonnull Matrix4f transform, @Nonnull VertexConsumer renderer, float x, float y, + @Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, - float leftMarginSize, float rightMarginSize, float height + float leftMarginSize, float rightMarginSize, float height, int light ) { if( leftMarginSize > 0 ) { - drawQuad( transform, renderer, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ) ); + drawQuad( transform, buffer, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ), light ); } if( rightMarginSize > 0 ) { - drawQuad( transform, renderer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ) ); + drawQuad( transform, buffer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ), light ); } // Batch together runs of identical background cells. @@ -136,7 +136,7 @@ public final class FixedWidthFontRenderer if( blockColour != '\0' ) { - drawQuad( transform, renderer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour ); + drawQuad( transform, buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour, light ); } blockColour = colourIndex; @@ -145,19 +145,19 @@ public final class FixedWidthFontRenderer if( blockColour != '\0' ) { - drawQuad( transform, renderer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour ); + drawQuad( transform, buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour, light ); } } public static void drawString( - @Nonnull Matrix4f transform, @Nonnull VertexConsumer renderer, float x, float y, + @Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize, int light ) { if( backgroundColour != null ) { - drawBackground( transform, renderer, x, y, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize, FONT_HEIGHT ); + drawBackground( transform, buffer, x, y, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize, FONT_HEIGHT, light ); } for( int i = 0; i < text.length(); i++ ) @@ -178,15 +178,15 @@ public final class FixedWidthFontRenderer // Draw char int index = text.charAt( i ); if( index > 255 ) index = '?'; - drawChar( transform, renderer, x + i * FONT_WIDTH, y, index, r, g, b, light ); + drawChar( transform, buffer, x + i * FONT_WIDTH, y, index, r, g, b, light ); } } public static void drawTerminalWithoutCursor( - @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, + @Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale, - float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize + float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize, int light ) { Palette palette = terminal.getPalette(); @@ -196,13 +196,13 @@ public final class FixedWidthFontRenderer drawBackground( transform, buffer, x, y - topMarginSize, terminal.getBackgroundColourLine( 0 ), palette, greyscale, - leftMarginSize, rightMarginSize, topMarginSize + leftMarginSize, rightMarginSize, topMarginSize, light ); drawBackground( transform, buffer, x, y + height * FONT_HEIGHT, terminal.getBackgroundColourLine( height - 1 ), palette, greyscale, - leftMarginSize, rightMarginSize, bottomMarginSize + leftMarginSize, rightMarginSize, bottomMarginSize, light ); // The main text @@ -217,7 +217,7 @@ public final class FixedWidthFontRenderer } public static void drawCursor( - @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, + @Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale ) { @@ -247,42 +247,44 @@ public final class FixedWidthFontRenderer } public static void drawTerminal( - @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y, + @Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale, - float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize + float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize, int light ) { - drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); + drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize, light ); drawCursor( transform, buffer, x, y, terminal, greyscale ); } - public static void drawTerminal( - @Nonnull Matrix4f transform, float x, float y, @Nonnull Terminal terminal, boolean greyscale, + // Called by WidgetTerminal + public static void drawTerminalImmediate( + @Nonnull PoseStack transform, float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize ) { MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() ); - VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ); - drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); + VertexConsumer buffer = renderer.getBuffer( RenderTypes.GUI_TERMINAL ); + drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize, FULL_BRIGHT_LIGHTMAP ); renderer.endBatch(); } - public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull MultiBufferSource renderer, float x, float y, float width, float height ) + public static void drawEmptyTerminal( @Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, float x, float y, float width, float height, int light ) { Colour colour = Colour.BLACK; - drawQuad( transform, renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() ); + drawQuad( transform, buffer, x, y, width, height, colour.getR(), colour.getG(), colour.getB(), light ); } - public static void drawEmptyTerminal( @Nonnull Matrix4f transform, float x, float y, float width, float height ) + public static void drawEmptyTerminalImmediate( @Nonnull PoseStack transform, float x, float y, float width, float height ) { MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() ); - drawEmptyTerminal( transform, renderer, x, y, width, height ); + VertexConsumer buffer = renderer.getBuffer( RenderTypes.GUI_TERMINAL ); + drawEmptyTerminal( transform, buffer, x, y, width, height, FULL_BRIGHT_LIGHTMAP ); renderer.endBatch(); } - public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull MultiBufferSource renderer, float x, float y, float width, float height ) + private static void vertex( Matrix4f poseMatrix, Matrix3f normalMatrix, VertexConsumer buffer, float x, float y, float z, float r, float g, float b, float u, float v, int light ) { - Colour colour = Colour.BLACK; - drawQuad( transform, renderer.getBuffer( RenderTypes.TERMINAL_BLOCKER ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() ); + buffer.vertex( poseMatrix, x, y, z ).color( r, g, b, 1.0f ).uv( u, v ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( light ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); } + } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index d05f7e4e1..5eb8cbc8f 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -76,7 +76,7 @@ public final class GuiComputer extends Computer public void renderBg( @Nonnull PoseStack stack, float partialTicks, int mouseX, int mouseY ) { // Draw a border around the terminal - ComputerBorderRenderer.render( + ComputerBorderRenderer.renderFromGui( ComputerBorderRenderer.getTexture( family ), terminal.x, terminal.y, getBlitOffset(), RenderTypes.FULL_BRIGHT_LIGHTMAP, terminal.getWidth(), terminal.getHeight() ); diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java index ed8e551d5..e5074a941 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java @@ -5,10 +5,10 @@ */ package dan200.computercraft.client.gui; -import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.math.Matrix4f; +import com.mojang.blaze3d.vertex.VertexConsumer; +import dan200.computercraft.client.render.RenderTypes; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.media.items.ItemPrintout; @@ -100,13 +100,14 @@ public class GuiPrintout extends AbstractContainerScreen protected void renderBg( @Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY ) { // Draw the printout - RenderSystem.setShaderColor( 1.0f, 1.0f, 1.0f, 1.0f ); - RenderSystem.enableDepthTest(); - MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() ); - Matrix4f matrix = transform.last().pose(); - drawBorder( matrix, renderer, leftPos, topPos, getBlitOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP ); - drawText( matrix, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours ); + + VertexConsumer borderBuffer = renderer.getBuffer( RenderTypes.GUI_PRINTOUT_BACKGROUND ); + drawBorder( transform, borderBuffer, leftPos, topPos, getBlitOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP ); + + VertexConsumer textBuffer = renderer.getBuffer( RenderTypes.GUI_PRINTOUT_TEXT ); + drawText( transform, textBuffer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours ); + renderer.endBatch(); } diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java index ebef85e1d..bae7fd8fd 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java @@ -6,7 +6,6 @@ package dan200.computercraft.client.gui.widgets; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix4f; import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.shared.computer.core.ClientComputer; @@ -313,15 +312,14 @@ public class WidgetTerminal extends AbstractWidget public void render( @Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks ) { if( !visible ) return; - Matrix4f matrix = transform.last().pose(); Terminal terminal = computer.getTerminal(); if( terminal != null ) { - FixedWidthFontRenderer.drawTerminal( matrix, innerX, innerY, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN ); + FixedWidthFontRenderer.drawTerminalImmediate( transform, innerX, innerY, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN ); } else { - FixedWidthFontRenderer.drawEmptyTerminal( matrix, x, y, width, height ); + FixedWidthFontRenderer.drawEmptyTerminalImmediate( transform, x, y, width, height ); } } diff --git a/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java b/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java index 225211d71..a17f50bc0 100644 --- a/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java @@ -5,13 +5,15 @@ */ package dan200.computercraft.client.render; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import javax.annotation.Nonnull; @@ -53,13 +55,13 @@ public class ComputerBorderRenderer public static final int TEX_SIZE = 256; private static final float TEX_SCALE = 1 / (float) TEX_SIZE; - private final Matrix4f transform; + private final PoseStack transform; private final VertexConsumer builder; private final int light; private final int z; private final float r, g, b; - public ComputerBorderRenderer( Matrix4f transform, VertexConsumer builder, int z, int light, float r, float g, float b ) + public ComputerBorderRenderer( PoseStack transform, VertexConsumer builder, int z, int light, float r, float g, float b ) { this.transform = transform; this.builder = builder; @@ -86,20 +88,18 @@ public class ComputerBorderRenderer } } - public static RenderType getRenderType( ResourceLocation location ) + public static void renderFromGui( ResourceLocation location, int x, int y, int z, int light, int width, int height ) { - // See note in RenderTypes about why we use text rather than anything intuitive. - return RenderType.text( location ); + PoseStack identityStack = new PoseStack(); + MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() ); + render( + identityStack, renderer.getBuffer( RenderTypes.guiComputerBorder( location ) ), + x, y, z, light, width, height, false, 1, 1, 1 + ); + renderer.endBatch(); } - public static void render( ResourceLocation location, int x, int y, int z, int light, int width, int height ) - { - MultiBufferSource.BufferSource source = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() ); - render( IDENTITY, source.getBuffer( getRenderType( location ) ), x, y, z, light, width, height, false, 1, 1, 1 ); - source.endBatch(); - } - - public static void render( Matrix4f transform, VertexConsumer buffer, int x, int y, int z, int light, int width, int height, boolean withLight, float r, float g, float b ) + public static void render( PoseStack transform, VertexConsumer buffer, int x, int y, int z, int light, int width, int height, boolean withLight, float r, float g, float b ) { new ComputerBorderRenderer( transform, buffer, z, light, r, g, b ).doRender( x, y, width, height, withLight ); } @@ -151,9 +151,11 @@ public class ComputerBorderRenderer private void renderTexture( int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight ) { - builder.vertex( transform, x, y + height, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).uv2( light ).endVertex(); - builder.vertex( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).uv2( light ).endVertex(); - builder.vertex( transform, x + width, y, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).uv2( light ).endVertex(); - builder.vertex( transform, x, y, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, v * TEX_SCALE ).uv2( light ).endVertex(); + Matrix4f poseMatrix = transform.last().pose(); + Matrix3f normalMatrix = transform.last().normal(); + builder.vertex( poseMatrix, x, y + height, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( light ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); + builder.vertex( poseMatrix, x + width, y + height, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( light ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); + builder.vertex( poseMatrix, x + width, y, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( light ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); + builder.vertex( poseMatrix, x, y, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, v * TEX_SCALE ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( light ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); } } diff --git a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java index 6806aa089..9ab59b94b 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java @@ -6,6 +6,7 @@ package dan200.computercraft.client.render; import com.mojang.blaze3d.vertex.*; +import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; import com.mojang.math.Vector3f; import dan200.computercraft.ComputerCraft; @@ -16,12 +17,13 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.util.Colour; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; -import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT; -import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH; +import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*; import static dan200.computercraft.client.render.ComputerBorderRenderer.*; +import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP; /** * Emulates map rendering for pocket computers. @@ -63,7 +65,9 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer transform.scale( 0.5f, 0.5f, 0.5f ); float scale = 0.75f / Math.max( width + BORDER * 2, height + BORDER * 2 + LIGHT_HEIGHT ); - transform.scale( scale, scale, -1.0f ); + // Avoid PoseStack#scale to preserve normal matrix, and fix the normals ourselves. + transform.last().pose().multiply( Matrix4f.createScaleMatrix( scale, scale, -1.0f ) ); + transform.last().normal().mul( -1.0f ); transform.translate( -0.5 * width, -0.5 * height, 0 ); // Render the main frame @@ -71,31 +75,32 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer ComputerFamily family = item.getFamily(); int frameColour = item.getColour( stack ); - Matrix4f matrix = transform.last().pose(); - renderFrame( matrix, renderer, family, frameColour, light, width, height ); + renderFrame( transform, renderer, family, frameColour, light, width, height ); // Render the light int lightColour = ItemPocketComputer.getLightState( stack ); if( lightColour == -1 ) lightColour = Colour.BLACK.getHex(); - renderLight( matrix, renderer, lightColour, width, height ); + renderLight( transform, renderer, lightColour, width, height ); + VertexConsumer buffer = renderer.getBuffer( RenderTypes.ITEM_POCKET_TERMINAL ); if( computer != null && terminal != null ) { FixedWidthFontRenderer.drawTerminal( - matrix, renderer.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH ), - MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN + transform, buffer, + MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN, FULL_BRIGHT_LIGHTMAP ); - FixedWidthFontRenderer.drawBlocker( transform.last().pose(), renderer, 0, 0, width, height ); } else { - FixedWidthFontRenderer.drawEmptyTerminal( matrix, 0, 0, width, height ); + FixedWidthFontRenderer.drawEmptyTerminal( + transform, buffer, + 0, 0, width, height, 0 ); } transform.popPose(); } - private static void renderFrame( Matrix4f transform, MultiBufferSource render, ComputerFamily family, int colour, int light, int width, int height ) + private static void renderFrame( PoseStack transform, MultiBufferSource renderer, ComputerFamily family, int colour, int light, int width, int height ) { ResourceLocation texture = colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ); @@ -103,20 +108,23 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer float g = ((colour >>> 8) & 0xFF) / 255.0f; float b = (colour & 0xFF) / 255.0f; - ComputerBorderRenderer.render( transform, render.getBuffer( ComputerBorderRenderer.getRenderType( texture ) ), 0, 0, 0, light, width, height, true, r, g, b ); + VertexConsumer buffer = renderer.getBuffer( RenderTypes.itemPocketBorder( texture ) ); + ComputerBorderRenderer.render( transform, buffer, 0, 0, 0, light, width, height, true, r, g, b ); } - private static void renderLight( Matrix4f transform, MultiBufferSource render, int colour, int width, int height ) + private static void renderLight( PoseStack transform, MultiBufferSource renderer, int colour, int width, int height ) { float r = ((colour >>> 16) & 0xFF) / 255.0f; float g = ((colour >>> 8) & 0xFF) / 255.0f; float b = (colour & 0xFF) / 255.0f; float z = 0.001f; - VertexConsumer buffer = render.getBuffer( RenderTypes.POSITION_COLOR ); - buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).endVertex(); - buffer.vertex( transform, width, height + LIGHT_HEIGHT + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).endVertex(); - buffer.vertex( transform, width, height + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).endVertex(); - buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).endVertex(); + VertexConsumer buffer = renderer.getBuffer( RenderTypes.ITEM_POCKET_LIGHT ); + Matrix4f poseMatrix = transform.last().pose(); + Matrix3f normalMatrix = transform.last().normal(); + buffer.vertex( poseMatrix, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_START ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( FULL_BRIGHT_LIGHTMAP ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); + buffer.vertex( poseMatrix, width, height + LIGHT_HEIGHT + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_END ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( FULL_BRIGHT_LIGHTMAP ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); + buffer.vertex( poseMatrix, width, height + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_END ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( FULL_BRIGHT_LIGHTMAP ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); + buffer.vertex( poseMatrix, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, z ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_START ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( FULL_BRIGHT_LIGHTMAP ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); } } diff --git a/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java index 8d07b890c..422370065 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java @@ -29,32 +29,38 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer { } - public boolean renderInFrame( PoseStack matrixStack, MultiBufferSource consumerProvider, ItemStack stack, int light ) + public boolean renderInFrame( PoseStack transform, MultiBufferSource renderer, ItemStack stack, int light ) { if( !(stack.getItem() instanceof ItemPrintout) ) return false; // Move a little bit forward to ensure we're not clipping with the frame - matrixStack.translate( 0.0f, 0.0f, -0.001f ); - matrixStack.mulPose( Vector3f.ZP.rotationDegrees( 180f ) ); - matrixStack.scale( 0.95f, 0.95f, -0.95f ); - matrixStack.translate( -0.5f, -0.5f, 0.0f ); + transform.translate( 0.0f, 0.0f, -0.001f ); + transform.mulPose( Vector3f.ZP.rotationDegrees( 180f ) ); + // Avoid PoseStack#scale to preserve normal matrix, and fix the normals ourselves. + transform.last().pose().multiply( Matrix4f.createScaleMatrix( 0.95f, 0.95f, -0.95f ) ); + transform.last().normal().mul( -1.0f ); - drawPrintout( matrixStack, consumerProvider, stack, light ); + //transform.last().normal().mul( -1.0f ); + transform.translate( -0.5f, -0.5f, 0.0f ); + + drawPrintout( transform, renderer, stack, light ); return true; } @Override - protected void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack, int light ) + protected void renderItem( PoseStack transform, MultiBufferSource renderer, ItemStack stack, int light ) { transform.mulPose( Vector3f.XP.rotationDegrees( 180f ) ); - transform.scale( 0.42f, 0.42f, -0.42f ); + // Avoid PoseStack#scale to preserve normal matrix, and fix the normals ourselves. + transform.last().pose().multiply( Matrix4f.createScaleMatrix( 0.42f, 0.42f, -0.42f ) ); + transform.last().normal().mul( -1.0f ); transform.translate( -0.5f, -0.48f, 0.0f ); - drawPrintout( transform, render, stack, light ); + drawPrintout( transform, renderer, stack, light ); } - private static void drawPrintout( PoseStack transform, MultiBufferSource render, ItemStack stack, int light ) + private static void drawPrintout( PoseStack transform, MultiBufferSource renderer, ItemStack stack, int light ) { int pages = ItemPrintout.getPageCount( stack ); boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK; @@ -81,11 +87,13 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer transform.scale( scale, scale, scale ); transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 ); - Matrix4f matrix = transform.last().pose(); - drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book, light ); + drawBorder( + transform, renderer.getBuffer( RenderTypes.ITEM_PRINTOUT_BACKGROUND ), + 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 ) + transform, renderer.getBuffer( RenderTypes.ITEM_PRINTOUT_TEXT ), + X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, light, 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 58bef2984..af35f2253 100644 --- a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java @@ -5,12 +5,14 @@ */ package dan200.computercraft.client.render; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Palette; -import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.texture.OverlayTexture; import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT; import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE; @@ -54,9 +56,8 @@ public final class PrintoutRenderer private PrintoutRenderer() {} - public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours ) + public static void drawText( PoseStack transform, VertexConsumer buffer, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours ) { - VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT ); for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) { FixedWidthFontRenderer.drawString( transform, buffer, @@ -67,9 +68,8 @@ public final class PrintoutRenderer } } - public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, int light, String[] text, String[] colours ) + public static void drawText( PoseStack transform, VertexConsumer buffer, int x, int y, int start, int light, String[] text, String[] colours ) { - VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT ); for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ ) { FixedWidthFontRenderer.drawString( transform, buffer, @@ -81,13 +81,11 @@ public final class PrintoutRenderer } } - public static void drawBorder( Matrix4f transform, MultiBufferSource renderer, float x, float y, float z, int page, int pages, boolean isBook, int light ) + public static void drawBorder( PoseStack transform, VertexConsumer buffer, float x, float y, float z, int page, int pages, boolean isBook, int light ) { int leftPages = page; int rightPages = pages - page - 1; - VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_BACKGROUND ); - if( isBook ) { // Border @@ -144,25 +142,29 @@ public final class PrintoutRenderer } } - private static void drawTexture( Matrix4f matrix, VertexConsumer buffer, float x, float y, float z, float u, float v, float width, float height, int light ) + private static void drawTexture( PoseStack transform, VertexConsumer buffer, float x, float y, float z, float u, float v, float width, float height, int light ) { - 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 ); + Matrix4f poseMatrix = transform.last().pose(); + Matrix3f normalMatrix = transform.last().normal(); + vertex( poseMatrix, normalMatrix, buffer, x, y + height, z, u / BG_SIZE, (v + height) / BG_SIZE, light ); + vertex( poseMatrix, normalMatrix, buffer, x + width, y + height, z, (u + width) / BG_SIZE, (v + height) / BG_SIZE, light ); + vertex( poseMatrix, normalMatrix, buffer, x + width, y, z, (u + width) / BG_SIZE, v / BG_SIZE, light ); + vertex( poseMatrix, normalMatrix, buffer, 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, int light ) + private static void drawTexture( PoseStack transform, VertexConsumer buffer, float x, float y, float z, float width, float height, float u, float v, float tWidth, float tHeight, int light ) { - 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 ); + Matrix4f poseMatrix = transform.last().pose(); + Matrix3f normalMatrix = transform.last().normal(); + vertex( poseMatrix, normalMatrix, buffer, x, y + height, z, u / BG_SIZE, (v + tHeight) / BG_SIZE, light ); + vertex( poseMatrix, normalMatrix, buffer, x + width, y + height, z, (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE, light ); + vertex( poseMatrix, normalMatrix, buffer, x + width, y, z, (u + tWidth) / BG_SIZE, v / BG_SIZE, light ); + vertex( poseMatrix, normalMatrix, buffer, x, y, z, u / BG_SIZE, v / BG_SIZE, light ); } - private static void vertex( VertexConsumer buffer, Matrix4f matrix, float x, float y, float z, float u, float v, int light ) + private static void vertex( Matrix4f poseMatrix, Matrix3f normalMatrix, VertexConsumer buffer, float x, float y, float z, float u, float v, int light ) { - buffer.vertex( matrix, x, y, z ).color( 255, 255, 255, 255 ).uv( u, v ).uv2( light ).endVertex(); + buffer.vertex( poseMatrix, x, y, z ).color( 255, 255, 255, 255 ).uv( u, v ).overlayCoords( OverlayTexture.NO_OVERLAY ).uv2( light ).normal( normalMatrix, 0f, 0f, 1f ).endVertex(); } public static float offsetAt( int page ) diff --git a/src/main/java/dan200/computercraft/client/render/RenderTypes.java b/src/main/java/dan200/computercraft/client/render/RenderTypes.java index 21d407b6e..57d1d5e32 100644 --- a/src/main/java/dan200/computercraft/client/render/RenderTypes.java +++ b/src/main/java/dan200/computercraft/client/render/RenderTypes.java @@ -7,7 +7,7 @@ package dan200.computercraft.client.render; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; -import dan200.computercraft.client.gui.FixedWidthFontRenderer; +import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.ShaderInstance; @@ -15,28 +15,41 @@ import net.minecraft.resources.ResourceLocation; import javax.annotation.Nonnull; + public class RenderTypes { + public static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" ); + public static final ResourceLocation PRINTOUT_BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printout.png" ); public static final int FULL_BRIGHT_LIGHTMAP = (0xF << 4) | (0xF << 20); - public static MonitorTextureBufferShader monitorTboShader; - public static ShaderInstance terminalShader; - - public static final RenderType TERMINAL_WITHOUT_DEPTH = Types.TERMINAL_WITHOUT_DEPTH; - public static final RenderType TERMINAL_BLOCKER = Types.TERMINAL_BLOCKER; - public static final RenderType TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH; public static final RenderType MONITOR_TBO = Types.MONITOR_TBO; - public static final RenderType PRINTOUT_TEXT = Types.PRINTOUT_TEXT; + public static final RenderType MONITOR = RenderType.textIntensity( FONT ); - /** - * This looks wrong (it should be POSITION_COLOR_TEX_LIGHTMAP surely!) but the fragment/vertex shader for that - * appear to entirely ignore the lightmap. - * - * Note that vanilla maps do the same, so this isn't unreasonable. - */ - public static final RenderType PRINTOUT_BACKGROUND = RenderType.text( new ResourceLocation( "computercraft", "textures/gui/printout.png" ) ); + public static final RenderType ITEM_POCKET_TERMINAL = RenderType.textIntensity( FONT ); + public static final RenderType ITEM_POCKET_LIGHT = RenderType.textIntensity( FONT ); + public static final RenderType ITEM_PRINTOUT_BACKGROUND = RenderType.entityCutout( PRINTOUT_BACKGROUND ); + public static final RenderType ITEM_PRINTOUT_TEXT = RenderType.entityCutout( FONT ); - public static final RenderType POSITION_COLOR = Types.POSITION_COLOR; + public static final RenderType GUI_TERMINAL = RenderType.text( FONT ); + public static final RenderType GUI_PRINTOUT_BACKGROUND = RenderType.text( PRINTOUT_BACKGROUND ); + public static final RenderType GUI_PRINTOUT_TEXT = RenderType.text( FONT ); + + public static ShaderInstance getMonitorShader() + { + return GameRenderer.getRendertypeTextIntensityShader(); + } + + public static RenderType itemPocketBorder( ResourceLocation location ) + { + return RenderType.entityCutout( location ); + } + + public static RenderType guiComputerBorder( ResourceLocation location ) + { + return RenderType.text( location ); + } + + public static MonitorTextureBufferShader monitorTboShader; @Nonnull static MonitorTextureBufferShader getMonitorTextureBufferShader() @@ -45,22 +58,12 @@ public class RenderTypes return monitorTboShader; } - @Nonnull - static ShaderInstance getTerminalShader() - { - if( terminalShader == null ) throw new NullPointerException( "MonitorTboShader has not been registered" ); - return terminalShader; - } - private static final class Types extends RenderStateShard { private static final RenderStateShard.TextureStateShard TERM_FONT_TEXTURE = new TextureStateShard( - FixedWidthFontRenderer.FONT, + FONT, false, false // blur, minimap ); - private static final VertexFormat TERM_FORMAT = DefaultVertexFormat.POSITION_COLOR_TEX; - private static final VertexFormat.Mode TERM_MODE = VertexFormat.Mode.TRIANGLES; - private static final ShaderStateShard TERM_SHADER = new ShaderStateShard( RenderTypes::getTerminalShader ); static final RenderType MONITOR_TBO = RenderType.create( "monitor_tbo", DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.TRIANGLE_STRIP, 128, @@ -68,57 +71,6 @@ public class RenderTypes RenderType.CompositeState.builder() .setTextureState( TERM_FONT_TEXTURE ) .setShaderState( new ShaderStateShard( RenderTypes::getMonitorTextureBufferShader ) ) - .setWriteMaskState( COLOR_WRITE ) - .createCompositeState( false ) - ); - - static final RenderType TERMINAL_WITHOUT_DEPTH = RenderType.create( - "terminal_without_depth", TERM_FORMAT, TERM_MODE, 1024, - false, false, // useDelegate, needsSorting - RenderType.CompositeState.builder() - .setTextureState( TERM_FONT_TEXTURE ) - .setShaderState( TERM_SHADER ) - .setWriteMaskState( COLOR_WRITE ) - .createCompositeState( false ) - ); - - static final RenderType TERMINAL_BLOCKER = RenderType.create( - "terminal_blocker", TERM_FORMAT, TERM_MODE, 256, - false, false, // useDelegate, needsSorting - RenderType.CompositeState.builder() - .setTextureState( TERM_FONT_TEXTURE ) - .setShaderState( TERM_SHADER ) - .setWriteMaskState( DEPTH_WRITE ) - .createCompositeState( false ) - ); - - static final RenderType TERMINAL_WITH_DEPTH = RenderType.create( - "terminal_with_depth", TERM_FORMAT, TERM_MODE, 1024, - false, false, // useDelegate, needsSorting - RenderType.CompositeState.builder() - .setTextureState( TERM_FONT_TEXTURE ) - .setShaderState( TERM_SHADER ) - .createCompositeState( false ) - ); - - /** - * A variant of {@link #TERMINAL_WITH_DEPTH} which uses the lightmap rather than rendering fullbright. - */ - static final RenderType PRINTOUT_TEXT = RenderType.create( - "printout_text", DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, TERM_MODE, 1024, - false, false, // useDelegate, needsSorting - RenderType.CompositeState.builder() - .setTextureState( TERM_FONT_TEXTURE ) - .setShaderState( RenderStateShard.RENDERTYPE_TEXT_SHADER ) - .setLightmapState( RenderStateShard.LIGHTMAP ) - .createCompositeState( false ) - ); - - static final RenderType POSITION_COLOR = RenderType.create( - "position_color", DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS, 128, - false, false, // useDelegate, needsSorting - RenderType.CompositeState.builder() - .setShaderState( POSITION_COLOR_SHADER ) .createCompositeState( false ) ); diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 7c71f4a0f..5cc3c97a5 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -9,8 +9,8 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.MemoryTracker; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; +import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; -import com.mojang.math.Transformation; import com.mojang.math.Vector3f; import dan200.computercraft.ComputerCraft; import dan200.computercraft.client.FrameInfo; @@ -23,7 +23,6 @@ import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.DirectionUtil; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.core.BlockPos; @@ -36,6 +35,7 @@ import javax.annotation.Nonnull; import java.nio.ByteBuffer; import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*; +import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP; public class TileEntityMonitorRenderer implements BlockEntityRenderer { @@ -43,10 +43,17 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer list, List>> list2 ) throws IOException { - list2.add( Pair.of( new ShaderInstance( - manager, - "terminal", - RenderTypes.TERMINAL_WITHOUT_DEPTH.format() - ), shader -> RenderTypes.terminalShader = shader ) ); list2.add( Pair.of( new MonitorTextureBufferShader( manager, "monitor_tbo", diff --git a/src/main/java/dan200/computercraft/fabric/mixin/MixinLanguage.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinLanguage.java index 4f79841c4..9296a91c7 100644 --- a/src/main/java/dan200/computercraft/fabric/mixin/MixinLanguage.java +++ b/src/main/java/dan200/computercraft/fabric/mixin/MixinLanguage.java @@ -15,8 +15,8 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonParseException; -import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/src/main/java/dan200/computercraft/shared/Registry.java b/src/main/java/dan200/computercraft/shared/Registry.java index 32f8f056c..509902dbc 100644 --- a/src/main/java/dan200/computercraft/shared/Registry.java +++ b/src/main/java/dan200/computercraft/shared/Registry.java @@ -49,7 +49,6 @@ import dan200.computercraft.shared.turtle.upgrades.TurtleCraftingTable; import dan200.computercraft.shared.turtle.upgrades.TurtleModem; import dan200.computercraft.shared.turtle.upgrades.TurtleSpeaker; import dan200.computercraft.shared.turtle.upgrades.TurtleTool; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.minecraft.core.BlockPos; @@ -61,13 +60,12 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.*; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.MaterialColor; import java.util.function.BiFunction; @@ -116,7 +114,7 @@ public final class Registry register( "computer_advanced", new BlockComputer<>( properties(), ComputerFamily.ADVANCED, () -> ModBlockEntities.COMPUTER_ADVANCED ) ); public static final BlockComputer COMPUTER_COMMAND = - register( "computer_command", new BlockComputer<>( FabricBlockSettings.copyOf( Blocks.STONE ).strength( -1, 6000000.0F ), ComputerFamily.COMMAND, () -> ModBlockEntities.COMPUTER_COMMAND ) ); + register( "computer_command", new BlockComputer<>( properties().strength( -1, 6000000.0F ).requiresCorrectToolForDrops().noDrops(), ComputerFamily.COMMAND, () -> ModBlockEntities.COMPUTER_COMMAND ) ); public static final BlockTurtle TURTLE_NORMAL = register( "turtle_normal", new BlockTurtle( turtleProperties(), ComputerFamily.NORMAL, () -> ModBlockEntities.TURTLE_NORMAL ) ); @@ -147,17 +145,17 @@ public final class Registry private static BlockBehaviour.Properties properties() { - return BlockBehaviour.Properties.of( Material.GLASS ).strength( 2F ).sound( SoundType.STONE ).noOcclusion(); + return BlockBehaviour.Properties.of( Material.STONE ).strength( 2F ).noOcclusion(); } private static BlockBehaviour.Properties turtleProperties() { - return FabricBlockSettings.copyOf( Blocks.STONE ).strength( 2.5f ); + return BlockBehaviour.Properties.of( Material.STONE ).strength( 2.5f ); } private static BlockBehaviour.Properties modemProperties() { - return FabricBlockSettings.copyOf( Blocks.STONE ).breakByHand( true ).strength( 1.5f ); + return BlockBehaviour.Properties.of( Material.STONE, MaterialColor.STONE ).strength( 1.5f ); } } diff --git a/src/main/java/dan200/computercraft/shared/command/CommandUtils.java b/src/main/java/dan200/computercraft/shared/command/CommandUtils.java index 98f459061..f7f5a90a6 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandUtils.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandUtils.java @@ -45,7 +45,7 @@ public final class CommandUtils } else { - return ((SharedSuggestionProvider) source).customSuggestion( (CommandContext) context, builder ); + return ((SharedSuggestionProvider) source).customSuggestion( context ); } } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index ae60d0c36..243c9eb21 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -423,7 +423,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT public IPeripheral getPeripheral( Direction side ) { if( proxy == null ) proxy = new ComputerProxy( () -> this ); - return new ComputerPeripheral( "computer", proxy ); + return new ComputerPeripheral( getPeripheralName(), proxy ); + } + + @Nonnull + protected String getPeripheralName() + { + return "computer"; } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/integration/ModMenuIntegration.java b/src/main/java/dan200/computercraft/shared/integration/ModMenuIntegration.java index 0193fe67c..dfb583e3e 100644 --- a/src/main/java/dan200/computercraft/shared/integration/ModMenuIntegration.java +++ b/src/main/java/dan200/computercraft/shared/integration/ModMenuIntegration.java @@ -7,7 +7,6 @@ package dan200.computercraft.shared.integration; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer; import dan200.computercraft.shared.util.Config; import me.shedaniel.clothconfig2.api.ConfigBuilder; @@ -33,20 +32,60 @@ public class ModMenuIntegration implements ModMenuApi Config.clientSpec.correct( Config.clientConfig ); Config.sync(); Config.save(); - ComputerCraft.log.info( "Monitor renderer: {}", ComputerCraft.monitorRenderer ); } ); ConfigCategory client = builder.getOrCreateCategory( new TextComponent( "Client" ) ); ConfigEntryBuilder entryBuilder = builder.entryBuilder(); - client.addEntry( entryBuilder.startEnumSelector( new TextComponent( "Monitor Renderer" ), MonitorRenderer.class, ComputerCraft.monitorRenderer ) + client.addEntry( entryBuilder + .startEnumSelector( + new TextComponent( "Monitor Renderer" ), + MonitorRenderer.class, + Config.clientConfig.getEnum( "monitor_renderer", MonitorRenderer.class ) + ) .setDefaultValue( MonitorRenderer.BEST ) .setSaveConsumer( renderer -> Config.clientConfig.set( "monitor_renderer", renderer ) ) - .setTooltip( Component.nullToEmpty( Config.clientConfig.getComment( "monitor_renderer" ) ) ) + .setTooltip( Component.nullToEmpty( rewrapComment( Config.clientConfig.getComment( "monitor_renderer" ) ) ) ) .build() ); return builder.build(); }; } + + private static String rewrapComment( String comment ) + { + String[] words = comment.strip().replaceAll( "[\r\n]", "" ).split( " " ); + + StringBuilder builder = new StringBuilder(); + int lineLength = 0; + for( String word : words ) + { + int wordLength = word.length(); + + if( lineLength + wordLength + 1 > 50 ) + { + builder.append( "\n" ); + lineLength = 0; + builder.append( word ); + lineLength += wordLength; + } + else + { + if( builder.length() == 0 ) + { + builder.append( word ); + lineLength += wordLength; + } + else + { + builder.append( " " ); + builder.append( word ); + lineLength += wordLength + 1; + } + } + } + + return new String( builder ); + } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/generic/data/DataHelpers.java b/src/main/java/dan200/computercraft/shared/peripheral/generic/data/DataHelpers.java index f21bb7c51..2c280fce6 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/generic/data/DataHelpers.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/generic/data/DataHelpers.java @@ -7,8 +7,6 @@ package dan200.computercraft.shared.peripheral.generic.data; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.BlockTags; -import net.minecraft.tags.ItemTags; import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.block.Block; @@ -18,6 +16,7 @@ import javax.annotation.Nullable; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; public final class DataHelpers { @@ -35,14 +34,14 @@ public final class DataHelpers @Nonnull static Map getTags( @Nonnull Block block ) { - Collection tags = BlockTags.getAllTags().getMatchingTags( block ); + Collection tags = block.builtInRegistryHolder().tags().map( tag -> tag.location() ).collect( Collectors.toList() ); return getTags( tags ); } @Nonnull static Map getTags( @Nonnull Item item ) { - Collection tags = ItemTags.getAllTags().getMatchingTags( item ); + Collection tags = item.builtInRegistryHolder().tags().map( tag -> tag.location() ).collect( Collectors.toList() ); return getTags( tags ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorRenderer.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorRenderer.java index 18e88f26d..3eac19b1d 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorRenderer.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorRenderer.java @@ -8,7 +8,6 @@ package dan200.computercraft.shared.peripheral.monitor; import dan200.computercraft.ComputerCraft; import dan200.computercraft.client.render.TileEntityMonitorRenderer; import net.fabricmc.loader.api.FabricLoader; -import org.lwjgl.opengl.GL; import javax.annotation.Nonnull; import java.util.Arrays; @@ -49,61 +48,33 @@ public enum MonitorRenderer @Nonnull public static MonitorRenderer current() { - MonitorRenderer current = ComputerCraft.monitorRenderer; - switch( current ) - { - case BEST: - return best(); - case TBO: - checkCapabilities(); - if( !textureBuffer ) - { - ComputerCraft.log.warn( "Texture buffers are not supported on your graphics card. Falling back to default." ); - ComputerCraft.monitorRenderer = BEST; - return best(); - } + if( !initialised ) initialise(); - return TBO; - default: - return current; - } + MonitorRenderer current = ComputerCraft.monitorRenderer; + if( current == BEST ) return best(); + return current; } private static MonitorRenderer best() { - if( !initialised ) + if( shaderMod ) { - checkCapabilities(); - checkForShaderMods(); - if( textureBuffer && shaderMod ) - { - ComputerCraft.log.warn( "Shader mod detected. Enabling VBO renderer for compatibility." ); - } - - initialised = true; + ComputerCraft.log.warn( "Shader mod detected. Enabling VBO monitor renderer for compatibility." ); + return ComputerCraft.monitorRenderer = VBO; } - - return textureBuffer && !shaderMod ? TBO : VBO; + return ComputerCraft.monitorRenderer = TBO; } private static boolean initialised = false; - private static boolean textureBuffer = false; - private static boolean shaderMod = false; - //TODO find out which shader mods do better with VBOs and add them here. - private static List shaderModIds = Arrays.asList( "optifabric" ); + private static boolean shaderMod; + private static final List shaderModIds = Arrays.asList( "iris", "canvas", "optifabric" ); - private static void checkCapabilities() - { - if( initialised ) return; - - textureBuffer = GL.getCapabilities().OpenGL31; - initialised = true; - } - - private static void checkForShaderMods() + private static void initialise() { shaderMod = FabricLoader.getInstance().getAllMods().stream() .map( modContainer -> modContainer.getMetadata().getId() ) - .anyMatch( id -> shaderModIds.contains( id ) ); + .anyMatch( shaderModIds::contains ); + + initialised = true; } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index f19d1fa02..e9bf0fa72 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -500,6 +500,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default return nbt; } + @Nonnull + @Override + protected String getPeripheralName() + { + return "turtle"; + } + // Privates private boolean hasPeripheralUpgradeOnSide( ComputerSide side ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java index 7b5de06d5..01b9e3064 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -27,7 +27,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; @@ -62,9 +62,9 @@ public class TurtleTool extends AbstractTurtleUpgrade final ItemStack item; final float damageMulitiplier; @Nullable - final Tag breakable; + final TagKey breakable; - public TurtleTool( ResourceLocation id, Item item, float damageMulitiplier, @Nullable Tag breakable ) + public TurtleTool( ResourceLocation id, Item item, float damageMulitiplier, @Nullable TagKey breakable ) { super( id, TurtleUpgradeType.TOOL, new ItemStack( item ) ); this.item = new ItemStack( item ); @@ -122,7 +122,7 @@ public class TurtleTool extends AbstractTurtleUpgrade return UNBREAKABLE; } - return breakable == null || breakable.contains( state.getBlock() ) || isTriviallyBreakable( world, pos, state ) + return breakable == null || state.is( breakable ) || isTriviallyBreakable( world, pos, state ) ? TurtleCommandResult.success() : INEFFECTIVE; } diff --git a/src/main/resources/computercraft.mixins.json b/src/main/resources/computercraft.mixins.json index f92f23b39..f8cc4eda1 100644 --- a/src/main/resources/computercraft.mixins.json +++ b/src/main/resources/computercraft.mixins.json @@ -1,12 +1,10 @@ { "required": true, "package": "dan200.computercraft.fabric.mixin", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_17", "mixins": [ "ConnectionAccess", "LevelResourceAccess", - "MinecraftServerAccess", - "MixinBlock", "MixinChunkMap", "MixinEntity", @@ -18,7 +16,6 @@ "client": [ "ChatComponentAccess", "ItemInHandRendererAccess", - "MixinGameRenderer", "MixinItemFrameRenderer", "MixinItemInHandRenderer", diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json new file mode 100644 index 000000000..84f9f8953 --- /dev/null +++ b/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -0,0 +1,19 @@ +{ + "replace": false, + "values": [ + "computercraft:monitor_normal", + "computercraft:monitor_advanced", + "computercraft:computer_normal", + "computercraft:computer_advanced", + "computercraft:computer_command", + "computercraft:turtle_normal", + "computercraft:turtle_advanced", + "computercraft:speaker", + "computercraft:disk_drive", + "computercraft:printer", + "computercraft:wireless_modem_normal", + "computercraft:wireless_modem_advanced", + "computercraft:wired_modem_full", + "computercraft:cable" + ] +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7a77a8133..41a8330bb 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,7 +21,7 @@ "3prm3" ], "depends": { - "minecraft": "1.18.x", + "minecraft": ">=1.18.2-rc.1 <1.19", "fabricloader": ">=0.12.9", "fabric": "*" }, diff --git a/src/main/resources/resourcepacks/overhaul b/src/main/resources/resourcepacks/overhaul index d81fdcb6d..8785fe249 160000 --- a/src/main/resources/resourcepacks/overhaul +++ b/src/main/resources/resourcepacks/overhaul @@ -1 +1 @@ -Subproject commit d81fdcb6d529c4eefbb1bd36df15b4c2bd0cecdd +Subproject commit 8785fe24967be1b8628de834fa6ba387d2ab2d7a