From 620965069d16ef378bde89f9a81d0440047934e7 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Tue, 3 Aug 2021 16:23:10 +0800 Subject: [PATCH 1/8] fix: update mc to 1.17.1, fabric to latest --- build.gradle | 16 ++++------ gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 +- src/main/java/me/shedaniel/csb/CSB.java | 2 +- src/main/java/me/shedaniel/csb/CSBConfig.java | 2 +- .../me/shedaniel/csb/CSBDefaultRenderer.java | 4 +-- .../shedaniel/csb/gui/CSBSettingsScreen.java | 32 +++++++++---------- .../mixin/MixinClientPlayNetworkHandler.java | 2 +- .../csb/mixin/MixinClientPlayerEntity.java | 2 +- .../csb/mixin/MixinWorldRenderer.java | 4 +-- 10 files changed, 32 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index 7f68b93..f21dea3 100755 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,9 @@ plugins { - id 'fabric-loom' version "0.5-SNAPSHOT" + id 'fabric-loom' version "0.9.+" } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 archivesBaseName = "CustomSelectionBox" version = "5.0.2" @@ -11,10 +11,6 @@ version = "5.0.2" minecraft { } -repositories { - maven { url "https://dl.bintray.com/shedaniel/legacy-yarn-updated" } -} - processResources { filesMatching('fabric.mod.json') { expand 'version': project.version @@ -23,7 +19,7 @@ processResources { } dependencies { - minecraft "com.mojang:minecraft:1.16.2" - mappings "me.shedaniel:legacy-yarn:1.16.2+build.9+legacy.20w09a+build.8:v2" - modCompile "net.fabricmc:fabric-loader:0.9.2+build.206" + minecraft "com.mojang:minecraft:1.17.1" + mappings "net.fabricmc:yarn:1.17.1+build.32:v2" + modImplementation "net.fabricmc:fabric-loader:0.11.6" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5c57504..8f8bc6d 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip diff --git a/settings.gradle b/settings.gradle index 683b201..5b60df3 100755 --- a/settings.gradle +++ b/settings.gradle @@ -3,7 +3,7 @@ pluginManagement { jcenter() maven { name = 'Fabric' - url = 'http://maven.fabricmc.net/' + url = 'https://maven.fabricmc.net/' } gradlePluginPortal() } diff --git a/src/main/java/me/shedaniel/csb/CSB.java b/src/main/java/me/shedaniel/csb/CSB.java index 5f1b6aa..3b7c1dd 100644 --- a/src/main/java/me/shedaniel/csb/CSB.java +++ b/src/main/java/me/shedaniel/csb/CSB.java @@ -16,7 +16,7 @@ public class CSB implements ClientModInitializer { public static final List RENDERERS = new ArrayList<>(); public static void openSettingsGUI(MinecraftClient client, Screen parent) { - client.openScreen(new CSBSettingsScreen(parent)); + client.setScreen(new CSBSettingsScreen(parent)); } @Override diff --git a/src/main/java/me/shedaniel/csb/CSBConfig.java b/src/main/java/me/shedaniel/csb/CSBConfig.java index 929363f..5727071 100644 --- a/src/main/java/me/shedaniel/csb/CSBConfig.java +++ b/src/main/java/me/shedaniel/csb/CSBConfig.java @@ -24,7 +24,7 @@ public class CSBConfig implements ClientModInitializer { public static boolean disableDepthBuffer; public static boolean adjustBoundingBoxByLinkedBlocks; public static boolean rainbow; - private static File configFile = new File(FabricLoader.getInstance().getGameDirectory(), "config" + File.separator + "CSB" + File.separator + "config.json"); + private static File configFile = new File(FabricLoader.getInstance().getGameDir().toFile(), "config" + File.separator + "CSB" + File.separator + "config.json"); private static void loadConfig() throws IOException { configFile.getParentFile().mkdirs(); diff --git a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java b/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java index de2e836..86d624f 100644 --- a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java +++ b/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java @@ -11,7 +11,7 @@ import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.EntityContext; +import net.minecraft.block.ShapeContext; import net.minecraft.util.ActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -34,7 +34,7 @@ public ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitR BlockPos blockPos = hitResult.getBlockPos(); BlockState blockState = world.getBlockState(blockPos); Vec3d cameraPos = camera.getPos(); - VoxelShape shape = blockState.getOutlineShape(world, blockPos, EntityContext.of(camera.getFocusedEntity())); + VoxelShape shape = blockState.getOutlineShape(world, blockPos, ShapeContext.of(camera.getFocusedEntity())); if (CSBConfig.isAdjustBoundingBoxByLinkedBlocks()) shape = adjustShapeByLinkedBlocks(world, blockState, blockPos, shape); drawOutlinedBoundingBox(shape, blockPos.getX() - cameraPos.getX(), blockPos.getY() - cameraPos.getY(), blockPos.getZ() - cameraPos.getZ(), getOutlineRed(), getOutlineGreen(), getOutlineBlue(), getOutlineAlpha()); diff --git a/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java b/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java index 1d627a5..f91e671 100644 --- a/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java +++ b/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java @@ -26,7 +26,7 @@ public CSBSettingsScreen(Screen parent) { public boolean keyPressed(int int_1, int int_2, int int_3) { if (int_1 == 256 && this.shouldCloseOnEsc()) { onClose(); - client.openScreen(parent); + client.setScreen(parent); return true; } return super.keyPressed(int_1, int_2, int_3); @@ -35,41 +35,41 @@ public boolean keyPressed(int int_1, int int_2, int int_3) { @Override protected void init() { this.configCache = new ConfigCache(enabled, red, green, blue, alpha, thickness, blinkAlpha, blinkSpeed, disableDepthBuffer, rainbow, adjustBoundingBoxByLinkedBlocks); - this.buttons.clear(); + this.clearChildren(); // left - addButton(new CSBSliderWidget(1, 4, this.height / 2 - 62, getRed())); - addButton(new CSBSliderWidget(2, 4, this.height / 2 - 38, getGreen())); - addButton(new CSBSliderWidget(3, 4, this.height / 2 - 14, getBlue())); - addButton(new CSBSliderWidget(4, 4, this.height / 2 + 10, getAlpha())); - addButton(new CSBSliderWidget(5, 4, this.height / 2 + 34, getThickness() / 7.0F)); + addDrawableChild(new CSBSliderWidget(1, 4, this.height / 2 - 62, getRed())); + addDrawableChild(new CSBSliderWidget(2, 4, this.height / 2 - 38, getGreen())); + addDrawableChild(new CSBSliderWidget(3, 4, this.height / 2 - 14, getBlue())); + addDrawableChild(new CSBSliderWidget(4, 4, this.height / 2 + 10, getAlpha())); + addDrawableChild(new CSBSliderWidget(5, 4, this.height / 2 + 34, getThickness() / 7.0F)); // right - addButton(new CSBSliderWidget(7, this.width - 154, this.height / 2 - 14, getBlinkAlpha())); - addButton(new CSBSliderWidget(8, this.width - 154, this.height / 2 + 10, getBlinkSpeed())); - addButton(new ButtonWidget(this.width - 154, this.height / 2 - 38, 150, 20, new LiteralText("Chroma: " + (usingRainbow() ? "ON" : "OFF")), widget -> { + addDrawableChild(new CSBSliderWidget(7, this.width - 154, this.height / 2 - 14, getBlinkAlpha())); + addDrawableChild(new CSBSliderWidget(8, this.width - 154, this.height / 2 + 10, getBlinkSpeed())); + addDrawableChild(new ButtonWidget(this.width - 154, this.height / 2 - 38, 150, 20, new LiteralText("Chroma: " + (usingRainbow() ? "ON" : "OFF")), widget -> { setIsRainbow(!usingRainbow()); widget.setMessage(new LiteralText("Chroma: " + (usingRainbow() ? "ON" : "OFF"))); })); - addButton(new ButtonWidget(this.width - 154, this.height / 2 + 34, 150, 20, new LiteralText("Link Blocks: " + (isAdjustBoundingBoxByLinkedBlocks() ? "ON" : "OFF")), widget -> { + addDrawableChild(new ButtonWidget(this.width - 154, this.height / 2 + 34, 150, 20, new LiteralText("Link Blocks: " + (isAdjustBoundingBoxByLinkedBlocks() ? "ON" : "OFF")), widget -> { setAdjustBoundingBoxByLinkedBlocks(!isAdjustBoundingBoxByLinkedBlocks()); widget.setMessage(new LiteralText("Link Blocks: " + (isAdjustBoundingBoxByLinkedBlocks() ? "ON" : "OFF"))); })); //below - addButton(new ButtonWidget(this.width / 2 - 100, this.height - 48, 95, 20, new LiteralText("Enabled: " + (isEnabled() ? "True" : "False")), widget -> { + addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 48, 95, 20, new LiteralText("Enabled: " + (isEnabled() ? "True" : "False")), widget -> { setEnabled(!isEnabled()); widget.setMessage(new LiteralText("Enabled: " + (isEnabled() ? "True" : "False"))); })); - addButton(new ButtonWidget(this.width / 2 + 5, this.height - 48, 95, 20, new LiteralText("Save"), widget -> { + addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height - 48, 95, 20, new LiteralText("Save"), widget -> { try { saveConfig(); configCache = new ConfigCache(CSBConfig.enabled, red, green, blue, alpha, thickness, blinkAlpha, blinkSpeed, disableDepthBuffer, rainbow, adjustBoundingBoxByLinkedBlocks); } catch (FileNotFoundException e) { e.printStackTrace(); } - client.openScreen(parent); + client.setScreen(parent); })); - addButton(new ButtonWidget(this.width / 2 - 100, this.height - 24, 95, 20, new LiteralText("CSB defaults"), widget -> { + addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 24, 95, 20, new LiteralText("CSB defaults"), widget -> { try { reset(false); saveConfig(); @@ -79,7 +79,7 @@ protected void init() { } openSettingsGUI(client, parent); })); - addButton(new ButtonWidget(this.width / 2 + 5, this.height - 24, 95, 20, new LiteralText("MC defaults"), widget -> { + addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height - 24, 95, 20, new LiteralText("MC defaults"), widget -> { try { reset(true); saveConfig(); diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java index 5edc249..64d00ca 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java @@ -7,7 +7,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket; -import net.minecraft.server.command.CommandSource; +import net.minecraft.command.CommandSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java index 5e3439a..7bd6fc2 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java @@ -20,7 +20,7 @@ public class MixinClientPlayerEntity { public void sendChatMessage(String message, CallbackInfo ci) { String[] split = message.toLowerCase().split(" "); if (split.length > 0 && split[0].contentEquals("/csbconfig")) { - client.openScreen(new CSBSettingsScreen(client.currentScreen instanceof ChatScreen ? null : client.currentScreen)); + client.setScreen(new CSBSettingsScreen(client.currentScreen instanceof ChatScreen ? null : client.currentScreen)); ci.cancel(); } } diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java b/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java index 5092284..ffc92bc 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java @@ -8,7 +8,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityContext; +import net.minecraft.block.ShapeContext; import net.minecraft.util.ActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -52,7 +52,7 @@ private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer ver ordinal = 0)) private void onDrawShapeOutline(WorldRenderer worldRenderer, MatrixStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos blockPos, BlockState blockState) { if (!isEnabled()) { - drawShapeOutline(matrixStack, vertexConsumer, blockState.getOutlineShape(world, blockPos, EntityContext.of(entity)), blockPos.getX() - d, blockPos.getY() - e, blockPos.getZ() - f, 0.0F, 0.0F, 0.0F, 0.4F); + drawShapeOutline(matrixStack, vertexConsumer, blockState.getOutlineShape(world, blockPos, ShapeContext.of(entity)), blockPos.getX() - d, blockPos.getY() - e, blockPos.getZ() - f, 0.0F, 0.0F, 0.0F, 0.4F); return; } render = true; From 762fdd5922cc798dd1bdbec49c6324dcf8ed2389 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Tue, 3 Aug 2021 16:54:38 +0800 Subject: [PATCH 2/8] fix: try to fix render, update mixin --- .../me/shedaniel/csb/CSBDefaultRenderer.java | 45 ++++++++++--------- src/main/resources/csb.mixins.json | 4 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java b/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java index 86d624f..10c8d2a 100644 --- a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java +++ b/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java @@ -9,6 +9,7 @@ import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Camera; import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.world.ClientWorld; import net.minecraft.block.ShapeContext; @@ -46,18 +47,18 @@ public ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitR private void drawOutlinedBoundingBox(VoxelShape voxelShapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder vertexConsumer = tessellator.getBuffer(); - RenderSystem.pushMatrix(); + RenderSystem.getModelViewStack().push(); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); RenderSystem.depthMask(false); - RenderSystem.color4f(red, green, blue, alpha); - RenderSystem.defaultAlphaFunc(); - RenderSystem.enableAlphaTest(); + RenderSystem.setShaderColor(red, green, blue, alpha); + // RenderSystem.defaultAlphaFunc(); + // RenderSystem.enableAlphaTest(); RenderSystem.disableCull(); RenderSystem.disableTexture(); RenderSystem.lineWidth(getOutlineThickness()); - vertexConsumer.begin(1, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION); voxelShapeIn.forEachEdge((k, l, m, n, o, p) -> { vertexConsumer.vertex( (float)(k + xIn), (float)(l + yIn), (float)(m + zIn)).next(); vertexConsumer.vertex( (float)(n + xIn), (float)(o + yIn), (float)(p + zIn)).next(); @@ -114,24 +115,24 @@ private void drawOutlinedBoundingBox(VoxelShape voxelShapeIn, double xIn, double // tessellator.draw(); // } RenderSystem.enableCull(); - RenderSystem.disableAlphaTest(); - RenderSystem.enableAlphaTest(); + // RenderSystem.disableAlphaTest(); + // RenderSystem.enableAlphaTest(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); - RenderSystem.popMatrix(); + RenderSystem.getModelViewStack().pop(); } private void drawBlinkingBlock(VoxelShape voxelShapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder vertexConsumer = tessellator.getBuffer(); - RenderSystem.pushMatrix(); + RenderSystem.getModelViewStack().push(); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); RenderSystem.depthMask(false); - RenderSystem.color4f(red, green, blue, alpha); - RenderSystem.defaultAlphaFunc(); - RenderSystem.enableAlphaTest(); + RenderSystem.setShaderColor(red, green, blue, alpha); + // RenderSystem.defaultAlphaFunc(); + // RenderSystem.enableAlphaTest(); RenderSystem.disableCull(); RenderSystem.disableTexture(); VoxelShape shape = voxelShapeIn.getBoundingBoxes().stream() @@ -140,14 +141,14 @@ private void drawBlinkingBlock(VoxelShape voxelShapeIn, double xIn, double yIn, .reduce(VoxelShapes::union) .orElse(VoxelShapes.empty()).simplify(); for (Box box : shape.getBoundingBoxes()) { - box(tessellator, vertexConsumer, box.x1, box.y1, box.z1, box.x2, box.y2, box.z2, xIn, yIn, zIn); + box(tessellator, vertexConsumer, box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, xIn, yIn, zIn); } RenderSystem.enableCull(); - RenderSystem.disableAlphaTest(); - RenderSystem.enableAlphaTest(); + // RenderSystem.disableAlphaTest(); + // RenderSystem.enableAlphaTest(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); - RenderSystem.popMatrix(); + RenderSystem.getModelViewStack().pop(); } private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x1, double y1, double z1, double x2, double y2, double z2, double xIn, double yIn, double zIn) { @@ -157,7 +158,7 @@ private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x // x2 += 0.005; // y2 += 0.005; // z2 += 0.005; - vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); @@ -166,7 +167,7 @@ private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x tessellator.draw(); //Down - vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); @@ -175,7 +176,7 @@ private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x tessellator.draw(); //North - vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); @@ -184,7 +185,7 @@ private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x tessellator.draw(); //South - vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); @@ -193,7 +194,7 @@ private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x tessellator.draw(); //West - vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); @@ -202,7 +203,7 @@ private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x tessellator.draw(); //East - vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); diff --git a/src/main/resources/csb.mixins.json b/src/main/resources/csb.mixins.json index 7d0cb11..68240c5 100644 --- a/src/main/resources/csb.mixins.json +++ b/src/main/resources/csb.mixins.json @@ -1,14 +1,14 @@ { "required": true, "package": "me.shedaniel.csb.mixin", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_16", "client": [ "MixinWorldRenderer", "MixinClientPlayerEntity", "MixinClientPlayNetworkHandler", "MixinChatScreen" ], - "minVersion": "0.7.11", + "minVersion": "0.8", "injectors": { "defaultRequire": 1 } From bf9aa6a6f15b2077d96eb19fa57643ea13b51a68 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Tue, 3 Aug 2021 21:22:14 +0800 Subject: [PATCH 3/8] refactor: use fabric api to register command --- build.gradle | 11 ++++++ src/main/java/me/shedaniel/csb/CSB.java | 5 +++ .../shedaniel/csb/mixin/MixinChatScreen.java | 2 +- .../mixin/MixinClientPlayNetworkHandler.java | 34 ------------------- .../csb/mixin/MixinClientPlayerEntity.java | 28 --------------- src/main/resources/csb.mixins.json | 2 -- src/main/resources/fabric.mod.json | 5 +-- 7 files changed, 18 insertions(+), 69 deletions(-) delete mode 100644 src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java delete mode 100644 src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java diff --git a/build.gradle b/build.gradle index f21dea3..355e67b 100755 --- a/build.gradle +++ b/build.gradle @@ -22,4 +22,15 @@ dependencies { minecraft "com.mojang:minecraft:1.17.1" mappings "net.fabricmc:yarn:1.17.1+build.32:v2" modImplementation "net.fabricmc:fabric-loader:0.11.6" + + // Fabric api + // Make a collection of all api modules we wish to use + Set apiModules = [ + "fabric-command-api-v1" + ] + + // Add each module as a dependency + apiModules.forEach { + include(modImplementation(fabricApi.module(it, "0.37.1+1.17"))) + } } diff --git a/src/main/java/me/shedaniel/csb/CSB.java b/src/main/java/me/shedaniel/csb/CSB.java index 3b7c1dd..086f107 100644 --- a/src/main/java/me/shedaniel/csb/CSB.java +++ b/src/main/java/me/shedaniel/csb/CSB.java @@ -4,6 +4,7 @@ import me.shedaniel.csb.gui.CSBSettingsScreen; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; @@ -27,6 +28,10 @@ public void onInitializeClient() { if (RENDERERS.isEmpty()) { throw new IllegalStateException("No default CSB renderers!"); } + ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("csbconfig").executes(context -> { + openSettingsGUI(context.getSource().getClient(), null); + return 1; + })); } public static int HSBtoRGB(float hue, float saturation, float brightness) { diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java b/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java index 9b788fb..28c8351 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java @@ -21,7 +21,7 @@ protected MixinChatScreen(Text title) { } @Inject(method = "keyPressed", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;openScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 1), + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 1), cancellable = true) public void keyPressed(int int_1, int int_2, int int_3, CallbackInfoReturnable ci) { String[] split = this.chatField.getText().trim().toLowerCase().split(" "); diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java deleted file mode 100644 index 64d00ca..0000000 --- a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -package me.shedaniel.csb.mixin; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.ClientConnection; -import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket; -import net.minecraft.command.CommandSource; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; - -@Mixin(ClientPlayNetworkHandler.class) -public class MixinClientPlayNetworkHandler { - - @Shadow private CommandDispatcher commandDispatcher; - - @Inject(method = "", at = @At("RETURN")) - private void init(MinecraftClient client, Screen screen, ClientConnection connection, GameProfile profile, CallbackInfo ci) { - commandDispatcher.register(literal("csbconfig")); - } - - @Inject(method = "onCommandTree", at = @At("RETURN")) - private void onCommandTree(CommandTreeS2CPacket packet, CallbackInfo ci) { - commandDispatcher.register(literal("csbconfig")); - } - -} diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java deleted file mode 100644 index 7bd6fc2..0000000 --- a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.shedaniel.csb.mixin; - -import me.shedaniel.csb.gui.CSBSettingsScreen; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.network.ClientPlayerEntity; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ClientPlayerEntity.class) -public class MixinClientPlayerEntity { - - @Shadow @Final protected MinecraftClient client; - - @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) - public void sendChatMessage(String message, CallbackInfo ci) { - String[] split = message.toLowerCase().split(" "); - if (split.length > 0 && split[0].contentEquals("/csbconfig")) { - client.setScreen(new CSBSettingsScreen(client.currentScreen instanceof ChatScreen ? null : client.currentScreen)); - ci.cancel(); - } - } - -} diff --git a/src/main/resources/csb.mixins.json b/src/main/resources/csb.mixins.json index 68240c5..c8ade0f 100644 --- a/src/main/resources/csb.mixins.json +++ b/src/main/resources/csb.mixins.json @@ -4,8 +4,6 @@ "compatibilityLevel": "JAVA_16", "client": [ "MixinWorldRenderer", - "MixinClientPlayerEntity", - "MixinClientPlayNetworkHandler", "MixinChatScreen" ], "minVersion": "0.8", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 684b2e3..29f651b 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -25,8 +25,5 @@ ], "authors": [ "shedaniel" - ], - "custom": { - "modmenu:clientsideOnly": true - } + ] } \ No newline at end of file From 87318a90dd28b0b1c02b1ff2edda6fdd6ca91e48 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Tue, 3 Aug 2021 21:24:45 +0800 Subject: [PATCH 4/8] fix: Config screen in mod menu --- build.gradle | 9 +++++++++ .../java/me/shedaniel/csb/CSBModMenuApiImpl.java | 12 ++++++++++++ src/main/resources/fabric.mod.json | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 src/main/java/me/shedaniel/csb/CSBModMenuApiImpl.java diff --git a/build.gradle b/build.gradle index 355e67b..0177f65 100755 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,12 @@ processResources { inputs.property "version", project.version } +repositories { + maven { + url 'https://maven.terraformersmc.com/releases/' + } +} + dependencies { minecraft "com.mojang:minecraft:1.17.1" mappings "net.fabricmc:yarn:1.17.1+build.32:v2" @@ -33,4 +39,7 @@ dependencies { apiModules.forEach { include(modImplementation(fabricApi.module(it, "0.37.1+1.17"))) } + + // Mod Menu + modCompileOnly "com.terraformersmc:modmenu:2.0.4" } diff --git a/src/main/java/me/shedaniel/csb/CSBModMenuApiImpl.java b/src/main/java/me/shedaniel/csb/CSBModMenuApiImpl.java new file mode 100644 index 0000000..ba1c9fe --- /dev/null +++ b/src/main/java/me/shedaniel/csb/CSBModMenuApiImpl.java @@ -0,0 +1,12 @@ +package me.shedaniel.csb; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; + +import me.shedaniel.csb.gui.CSBSettingsScreen; + +public class CSBModMenuApiImpl implements ModMenuApi { + public ConfigScreenFactory getModConfigScreenFactory() { + return (screen) -> new CSBSettingsScreen(screen); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 29f651b..a47d2fe 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,6 +12,9 @@ ], "csb_renderers": [ "me.shedaniel.csb.CSBDefaultRenderer" + ], + "modmenu": [ + "me.shedaniel.csb.CSBModMenuApiImpl" ] }, "contact": { From 5635c4c07c5e96e36206caa4df4ce6769ae7ecd8 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Fri, 6 Aug 2021 21:16:13 +0800 Subject: [PATCH 5/8] refactor: fix rendering, remove unnecessary codes --- src/main/java/me/shedaniel/csb/CSB.java | 140 ++++++++- .../me/shedaniel/csb/CSBDefaultRenderer.java | 273 ------------------ .../me/shedaniel/csb/api/CSBRenderer.java | 76 ----- .../java/me/shedaniel/csb/gui/CSBInfo.java | 19 -- .../csb/mixin/MixinWorldRenderer.java | 204 +++++++------ src/main/resources/fabric.mod.json | 3 - 6 files changed, 246 insertions(+), 469 deletions(-) delete mode 100644 src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java delete mode 100644 src/main/java/me/shedaniel/csb/api/CSBRenderer.java delete mode 100644 src/main/java/me/shedaniel/csb/gui/CSBInfo.java diff --git a/src/main/java/me/shedaniel/csb/CSB.java b/src/main/java/me/shedaniel/csb/CSB.java index 086f107..20f9ab5 100644 --- a/src/main/java/me/shedaniel/csb/CSB.java +++ b/src/main/java/me/shedaniel/csb/CSB.java @@ -1,33 +1,31 @@ package me.shedaniel.csb; -import me.shedaniel.csb.api.CSBRenderer; import me.shedaniel.csb.gui.CSBSettingsScreen; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormat; +import net.minecraft.client.render.VertexFormats; +import net.minecraft.block.*; +import net.minecraft.block.enums.BedPart; +import net.minecraft.block.enums.PistonType; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; public class CSB implements ClientModInitializer { - public static final List RENDERERS = new ArrayList<>(); - public static void openSettingsGUI(MinecraftClient client, Screen parent) { client.setScreen(new CSBSettingsScreen(parent)); } @Override public void onInitializeClient() { - RENDERERS.clear(); - RENDERERS.addAll(FabricLoader.getInstance().getEntrypoints("csb_renderers", CSBRenderer.class)); - RENDERERS.sort(Comparator.comparingDouble(CSBRenderer::getPriority)); - if (RENDERERS.isEmpty()) { - throw new IllegalStateException("No default CSB renderers!"); - } ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("csbconfig").executes(context -> { openSettingsGUI(context.getSource().getClient(), null); return 1; @@ -81,4 +79,118 @@ public static int HSBtoRGB(float hue, float saturation, float brightness) { return -16777216 | r << 16 | g << 8 | b; } + + public static void drawBox(Tessellator tessellator, BufferBuilder bufferBuilder, double x1, double y1, double z1, double x2, double y2, double z2, float red, float green, float blue, float alpha) { + // Up + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y1, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + tessellator.draw(); + + // Down + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y2, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y2, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y2, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next(); + tessellator.draw(); + + // North + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y2, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + tessellator.draw(); + + // South + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y1, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y2, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y2, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next(); + tessellator.draw(); + + // West + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y1, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y2, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y2, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x1, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + tessellator.draw(); + + // East + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y2, (float)z1).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y2, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y1, (float)z2).color(red, green, blue, alpha).next(); + bufferBuilder.vertex((float)x2, (float)y1, (float)z1).color(red, green, blue, alpha).next(); + tessellator.draw(); + } + + public static VoxelShape adjustShapeByLinkedBlocks(ClientWorld world, BlockState blockState, BlockPos blockPos, VoxelShape shape) { + try { + if (blockState.getBlock() instanceof ChestBlock) { + // Chests + Block block = blockState.getBlock(); + Direction facing = ChestBlock.getFacing(blockState); + BlockState anotherChestState = world.getBlockState(blockPos.offset(facing, 1)); + if (anotherChestState.getBlock() == block) + if (blockPos.offset(facing, 1).offset(ChestBlock.getFacing(anotherChestState)).equals(blockPos)) + return VoxelShapes.union(shape, anotherChestState.getOutlineShape(world, blockPos).offset(facing.getOffsetX(), facing.getOffsetY(), facing.getOffsetZ())); + } else if (blockState.getBlock() instanceof DoorBlock) { + // Doors + Block block = blockState.getBlock(); + if (world.getBlockState(blockPos.up(1)).getBlock() == block) { + BlockState otherState = world.getBlockState(blockPos.up(1)); + if (otherState.get(DoorBlock.POWERED).equals(blockState.get(DoorBlock.POWERED)) && otherState.get(DoorBlock.FACING).equals(blockState.get(DoorBlock.FACING)) && otherState.get(DoorBlock.HINGE).equals(blockState.get(DoorBlock.HINGE))) { + return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(0, 1, 0)); + } + } + if (world.getBlockState(blockPos.down(1)).getBlock() == block) { + BlockState otherState = world.getBlockState(blockPos.down(1)); + if (otherState.get(DoorBlock.POWERED).equals(blockState.get(DoorBlock.POWERED)) && otherState.get(DoorBlock.FACING).equals(blockState.get(DoorBlock.FACING)) && otherState.get(DoorBlock.HINGE).equals(blockState.get(DoorBlock.HINGE))) + return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(0, -1, 0)); + } + } else if (blockState.getBlock() instanceof BedBlock) { + // Beds + Block block = blockState.getBlock(); + Direction direction = blockState.get(HorizontalFacingBlock.FACING); + BlockState otherState = world.getBlockState(blockPos.offset(direction)); + if (blockState.get(BedBlock.PART).equals(BedPart.FOOT) && otherState.getBlock() == block) { + if (otherState.get(BedBlock.PART).equals(BedPart.HEAD)) + return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ())); + } + otherState = world.getBlockState(blockPos.offset(direction.getOpposite())); + direction = direction.getOpposite(); + if (blockState.get(BedBlock.PART).equals(BedPart.HEAD) && otherState.getBlock() == block) { + if (otherState.get(BedBlock.PART).equals(BedPart.FOOT)) + return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ())); + } + } else if (blockState.getBlock() instanceof PistonBlock && blockState.get(PistonBlock.EXTENDED)) { + // Piston Base + Block block = blockState.getBlock(); + Direction direction = blockState.get(FacingBlock.FACING); + BlockState otherState = world.getBlockState(blockPos.offset(direction)); + if (otherState.get(PistonHeadBlock.TYPE).equals(block == Blocks.PISTON ? PistonType.DEFAULT : PistonType.STICKY) && direction.equals(otherState.get(FacingBlock.FACING))) + return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ())); + } else if (blockState.getBlock() instanceof PistonHeadBlock) { + // Piston Arm + Direction direction = blockState.get(FacingBlock.FACING); + BlockState otherState = world.getBlockState(blockPos.offset(direction.getOpposite())); + if (otherState.getBlock() instanceof PistonBlock && direction == otherState.get(FacingBlock.FACING) && otherState.get(PistonBlock.EXTENDED)) + return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos.offset(direction.getOpposite())).offset(direction.getOpposite().getOffsetX(), direction.getOpposite().getOffsetY(), direction.getOpposite().getOffsetZ())); + } + } catch (Throwable ignored) { + } + return shape; + } } diff --git a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java b/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java deleted file mode 100644 index 10c8d2a..0000000 --- a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java +++ /dev/null @@ -1,273 +0,0 @@ -package me.shedaniel.csb; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import me.shedaniel.csb.api.CSBRenderer; -import net.minecraft.block.*; -import net.minecraft.block.enums.BedPart; -import net.minecraft.block.enums.PistonType; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.block.ShapeContext; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; -import org.lwjgl.opengl.GL11; - -public class CSBDefaultRenderer implements CSBRenderer { - @Override - public double getPriority() { - return 1050d; - } - - @Override - public ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitResult, float delta) { - GL11.glEnable(GL11.GL_LINE_SMOOTH); - BlockPos blockPos = hitResult.getBlockPos(); - BlockState blockState = world.getBlockState(blockPos); - Vec3d cameraPos = camera.getPos(); - VoxelShape shape = blockState.getOutlineShape(world, blockPos, ShapeContext.of(camera.getFocusedEntity())); - if (CSBConfig.isAdjustBoundingBoxByLinkedBlocks()) - shape = adjustShapeByLinkedBlocks(world, blockState, blockPos, shape); - drawOutlinedBoundingBox(shape, blockPos.getX() - cameraPos.getX(), blockPos.getY() - cameraPos.getY(), blockPos.getZ() - cameraPos.getZ(), getOutlineRed(), getOutlineGreen(), getOutlineBlue(), getOutlineAlpha()); - drawBlinkingBlock(shape, blockPos.getX() - cameraPos.getX(), blockPos.getY() - cameraPos.getY(), blockPos.getZ() - cameraPos.getZ(), getInnerRed(), getInnerGreen(), getInnerBlue(), getInnerAlpha()); - GL11.glDisable(GL11.GL_LINE_SMOOTH); - return ActionResult.SUCCESS; - } - - private void drawOutlinedBoundingBox(VoxelShape voxelShapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) { - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder vertexConsumer = tessellator.getBuffer(); - RenderSystem.getModelViewStack().push(); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); - RenderSystem.depthMask(false); - RenderSystem.setShaderColor(red, green, blue, alpha); - // RenderSystem.defaultAlphaFunc(); - // RenderSystem.enableAlphaTest(); - RenderSystem.disableCull(); - RenderSystem.disableTexture(); - RenderSystem.lineWidth(getOutlineThickness()); - vertexConsumer.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION); - voxelShapeIn.forEachEdge((k, l, m, n, o, p) -> { - vertexConsumer.vertex( (float)(k + xIn), (float)(l + yIn), (float)(m + zIn)).next(); - vertexConsumer.vertex( (float)(n + xIn), (float)(o + yIn), (float)(p + zIn)).next(); - }); - tessellator.draw(); -// for (Box box : voxelShapeIn.getBoundingBoxes()) { -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z1 - 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y1 - 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// vertexConsumer.begin(1, VertexFormats.POSITION); -// vertexConsumer.vertex((float) (box.x1 - 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// vertexConsumer.vertex((float) (box.x2 + 0.005 + xIn), (float) (box.y2 + 0.005 + yIn), (float) (box.z2 + 0.005 + zIn)).next(); -// tessellator.draw(); -// } - RenderSystem.enableCull(); - // RenderSystem.disableAlphaTest(); - // RenderSystem.enableAlphaTest(); - RenderSystem.disableBlend(); - RenderSystem.depthMask(true); - RenderSystem.getModelViewStack().pop(); - } - - private void drawBlinkingBlock(VoxelShape voxelShapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) { - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder vertexConsumer = tessellator.getBuffer(); - RenderSystem.getModelViewStack().push(); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); - RenderSystem.depthMask(false); - RenderSystem.setShaderColor(red, green, blue, alpha); - // RenderSystem.defaultAlphaFunc(); - // RenderSystem.enableAlphaTest(); - RenderSystem.disableCull(); - RenderSystem.disableTexture(); - VoxelShape shape = voxelShapeIn.getBoundingBoxes().stream() - .map(box -> box.expand(0.005, 0.005, 0.005)) - .map(VoxelShapes::cuboid) - .reduce(VoxelShapes::union) - .orElse(VoxelShapes.empty()).simplify(); - for (Box box : shape.getBoundingBoxes()) { - box(tessellator, vertexConsumer, box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, xIn, yIn, zIn); - } - RenderSystem.enableCull(); - // RenderSystem.disableAlphaTest(); - // RenderSystem.enableAlphaTest(); - RenderSystem.disableBlend(); - RenderSystem.depthMask(true); - RenderSystem.getModelViewStack().pop(); - } - - private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x1, double y1, double z1, double x2, double y2, double z2, double xIn, double yIn, double zIn) { -// x1 -= 0.005; -// y1 -= 0.005; -// z1 -= 0.005; -// x2 += 0.005; -// y2 += 0.005; -// z2 += 0.005; - vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - tessellator.draw(); - - //Down - vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); - tessellator.draw(); - - //North - vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - tessellator.draw(); - - //South - vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); - tessellator.draw(); - - //West - vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - tessellator.draw(); - - //East - vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); - vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); - tessellator.draw(); - } - - private VoxelShape adjustShapeByLinkedBlocks(ClientWorld world, BlockState blockState, BlockPos blockPos, VoxelShape shape) { - try { - if (blockState.getBlock() instanceof ChestBlock) { - // Chests - Block block = blockState.getBlock(); - Direction facing = ChestBlock.getFacing(blockState); - BlockState anotherChestState = world.getBlockState(blockPos.offset(facing, 1)); - if (anotherChestState.getBlock() == block) - if (blockPos.offset(facing, 1).offset(ChestBlock.getFacing(anotherChestState)).equals(blockPos)) - return VoxelShapes.union(shape, anotherChestState.getOutlineShape(world, blockPos).offset(facing.getOffsetX(), facing.getOffsetY(), facing.getOffsetZ())); - } else if (blockState.getBlock() instanceof DoorBlock) { - // Doors - Block block = blockState.getBlock(); - if (world.getBlockState(blockPos.up(1)).getBlock() == block) { - BlockState otherState = world.getBlockState(blockPos.up(1)); - if (otherState.get(DoorBlock.POWERED).equals(blockState.get(DoorBlock.POWERED)) && otherState.get(DoorBlock.FACING).equals(blockState.get(DoorBlock.FACING)) && otherState.get(DoorBlock.HINGE).equals(blockState.get(DoorBlock.HINGE))) { - return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(0, 1, 0)); - } - } - if (world.getBlockState(blockPos.down(1)).getBlock() == block) { - BlockState otherState = world.getBlockState(blockPos.down(1)); - if (otherState.get(DoorBlock.POWERED).equals(blockState.get(DoorBlock.POWERED)) && otherState.get(DoorBlock.FACING).equals(blockState.get(DoorBlock.FACING)) && otherState.get(DoorBlock.HINGE).equals(blockState.get(DoorBlock.HINGE))) - return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(0, -1, 0)); - } - } else if (blockState.getBlock() instanceof BedBlock) { - // Beds - Block block = blockState.getBlock(); - Direction direction = blockState.get(HorizontalFacingBlock.FACING); - BlockState otherState = world.getBlockState(blockPos.offset(direction)); - if (blockState.get(BedBlock.PART).equals(BedPart.FOOT) && otherState.getBlock() == block) { - if (otherState.get(BedBlock.PART).equals(BedPart.HEAD)) - return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ())); - } - otherState = world.getBlockState(blockPos.offset(direction.getOpposite())); - direction = direction.getOpposite(); - if (blockState.get(BedBlock.PART).equals(BedPart.HEAD) && otherState.getBlock() == block) { - if (otherState.get(BedBlock.PART).equals(BedPart.FOOT)) - return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ())); - } - } else if (blockState.getBlock() instanceof PistonBlock && blockState.get(PistonBlock.EXTENDED)) { - // Piston Base - Block block = blockState.getBlock(); - Direction direction = blockState.get(FacingBlock.FACING); - BlockState otherState = world.getBlockState(blockPos.offset(direction)); - if (otherState.get(PistonHeadBlock.TYPE).equals(block == Blocks.PISTON ? PistonType.DEFAULT : PistonType.STICKY) && direction.equals(otherState.get(FacingBlock.FACING))) - return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ())); - } else if (blockState.getBlock() instanceof PistonHeadBlock) { - // Piston Arm - Block block = blockState.getBlock(); - Direction direction = blockState.get(FacingBlock.FACING); - BlockState otherState = world.getBlockState(blockPos.offset(direction.getOpposite())); - if (otherState.getBlock() instanceof PistonBlock && direction == otherState.get(FacingBlock.FACING) && otherState.get(PistonBlock.EXTENDED)) - return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos.offset(direction.getOpposite())).offset(direction.getOpposite().getOffsetX(), direction.getOpposite().getOffsetY(), direction.getOpposite().getOffsetZ())); - } - } catch (Exception ignored) { - } - return shape; - } -} diff --git a/src/main/java/me/shedaniel/csb/api/CSBRenderer.java b/src/main/java/me/shedaniel/csb/api/CSBRenderer.java deleted file mode 100644 index 985bf60..0000000 --- a/src/main/java/me/shedaniel/csb/api/CSBRenderer.java +++ /dev/null @@ -1,76 +0,0 @@ -package me.shedaniel.csb.api; - -import me.shedaniel.csb.CSBConfig; -import me.shedaniel.csb.gui.CSBInfo; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.Camera; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; - -public interface CSBRenderer { - /** - * The priority of this renderer, smaller priorities are called first, and once it has been rendered, - * all priorities that has a bigger priority in number will be ignored. - * - * @return the priority of this renderer in double. - */ - default double getPriority() { - return 1000d; - } - - default MinecraftClient getClient() { - return MinecraftClient.getInstance(); - } - - @Deprecated - default CSBInfo getInfo() { - return (CSBInfo) getClient().worldRenderer; - } - - default float getOutlineThickness() { - return CSBConfig.getThickness() * Math.max(2.5F, (float)MinecraftClient.getInstance().getWindow().getFramebufferWidth() / 1920.0F * 2.5F); - } - - default int getOutlineColor() { - return (((int) (getOutlineAlpha() * 255)) & 255) << 24 | (((int) (getOutlineRed() * 255)) & 255) << 16 | (((int) (getOutlineGreen() * 255)) & 255) << 8 | (((int) (getOutlineBlue() * 255)) & 255); - } - - default float getOutlineRed() { - return getInfo().getOutlineRed(); - } - - default float getOutlineGreen() { - return getInfo().getOutlineGreen(); - } - - default float getOutlineBlue() { - return getInfo().getOutlineBlue(); - } - - default float getOutlineAlpha() { - return getInfo().getOutlineAlpha(); - } - - default int getInnerColor() { - return (((int) (getInnerAlpha() * 255)) & 255) << 24 | (((int) (getInnerRed() * 255)) & 255) << 16 | (((int) (getInnerGreen() * 255)) & 255) << 8 | (((int) (getInnerBlue() * 255)) & 255); - } - - default float getInnerRed() { - return getInfo().getInnerRed(); - } - - default float getInnerGreen() { - return getInfo().getInnerGreen(); - } - - default float getInnerBlue() { - return getInfo().getInnerBlue(); - } - - default float getInnerAlpha() { - return getInfo().getInnerAlpha(); - } - - ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitResult, float delta); -} diff --git a/src/main/java/me/shedaniel/csb/gui/CSBInfo.java b/src/main/java/me/shedaniel/csb/gui/CSBInfo.java deleted file mode 100644 index 97a2bdc..0000000 --- a/src/main/java/me/shedaniel/csb/gui/CSBInfo.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.shedaniel.csb.gui; - -public interface CSBInfo { - float getOutlineRed(); - - float getOutlineGreen(); - - float getOutlineBlue(); - - float getOutlineAlpha(); - - float getInnerRed(); - - float getInnerGreen(); - - float getInnerBlue(); - - float getInnerAlpha(); -} diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java b/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java index ffc92bc..ed9f75f 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java @@ -1,10 +1,11 @@ package me.shedaniel.csb.mixin; -import me.shedaniel.csb.api.CSBRenderer; -import me.shedaniel.csb.gui.CSBInfo; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.csb.CSB; +import me.shedaniel.csb.CSBConfig; import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.*; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; @@ -14,6 +15,29 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Matrix4f; import net.minecraft.util.shape.VoxelShape; +import net.minecraft.block.enums.BedPart; +import net.minecraft.block.enums.PistonType; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.BufferBuilderStorage; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.LightmapTextureManager; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexFormat; +import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.block.ShapeContext; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -25,104 +49,116 @@ import java.util.Objects; -import static me.shedaniel.csb.CSB.HSBtoRGB; -import static me.shedaniel.csb.CSB.RENDERERS; -import static me.shedaniel.csb.CSBConfig.*; - @SuppressWarnings("unused") @Mixin(WorldRenderer.class) -public abstract class MixinWorldRenderer implements CSBInfo { - - @Unique private boolean render = false; - @Unique private float r = 0f; - @Unique private float g = 0f; - @Unique private float b = 0f; - @Unique private float a = 0f; - @Unique private float blinkingAlpha = 0f; +public abstract class MixinWorldRenderer { + + @Unique private boolean csbRender = false; + @Unique private VoxelShape csbShape; + @Unique private float csbRed; + @Unique private float csbGreen; + @Unique private float csbBlue; + @Unique private float csbAlpha; @Shadow private ClientWorld world; - + @Shadow private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) { } - + @Shadow @Final private MinecraftClient client; - + @Shadow @Final private BufferBuilderStorage bufferBuilders; + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;drawBlockOutline(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/entity/Entity;DDDLnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V", ordinal = 0)) - private void onDrawShapeOutline(WorldRenderer worldRenderer, MatrixStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos blockPos, BlockState blockState) { - if (!isEnabled()) { - drawShapeOutline(matrixStack, vertexConsumer, blockState.getOutlineShape(world, blockPos, ShapeContext.of(entity)), blockPos.getX() - d, blockPos.getY() - e, blockPos.getZ() - f, 0.0F, 0.0F, 0.0F, 0.4F); - return; + private void onDrawShapeOutline(WorldRenderer worldRenderer, MatrixStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos blockPos, BlockState blockState) { + var shape = blockState.getOutlineShape(world, blockPos, ShapeContext.of(entity)); + var offsetX = blockPos.getX() - cameraX; + var offsetY = blockPos.getY() - cameraY; + var offsetZ = blockPos.getZ() - cameraZ; + + if (CSBConfig.isEnabled()) { + if (CSBConfig.rainbow) { + final double millis = System.currentTimeMillis() % 10000L / 10000.0f; + final int color = CSB.HSBtoRGB((float) millis, 0.8f, 0.8f); + csbRed = (color >> 16 & 255) / 255.0f; + csbGreen = (color >> 8 & 255) / 255.0f; + csbBlue = (color & 255) / 255.0f; + } else { + csbRed = CSBConfig.getRed(); + csbGreen = CSBConfig.getGreen(); + csbBlue = CSBConfig.getBlue(); + } + csbAlpha = CSBConfig.getAlpha(); + csbShape = shape; + if (CSBConfig.adjustBoundingBoxByLinkedBlocks) { + csbShape = CSB.adjustShapeByLinkedBlocks(world, blockState, blockPos, shape); + } + csbShape = csbShape.offset(offsetX, offsetY, offsetZ); + + MatrixStack.Entry entry = matrixStack.peek(); + csbShape.forEachEdge((k, l, m, n, o, p) -> { + float q1 = (float)(n - k); + float r1 = (float)(o - l); + float s1 = (float)(p - m); + float t = (float)Math.sqrt(q1 * q1 + r1 * r1 + s1 * s1); + q1 /= t; + r1 /= t; + s1 /= t; + vertexConsumer.vertex(entry.getModel(), (float)k, (float)l, (float)m).color(csbRed, csbGreen, csbBlue, csbAlpha).normal(entry.getNormal(), q1, r1, s1).next(); + vertexConsumer.vertex(entry.getModel(), (float)n, (float)o, (float)p).color(csbRed, csbGreen, csbBlue, csbAlpha).normal(entry.getNormal(), q1, r1, s1).next(); + }); + csbRender = true; + } else { + drawShapeOutline(matrixStack, vertexConsumer, shape, offsetX, offsetY, offsetZ, 0.0F, 0.0F, 0.0F, 0.4F); } - render = true; } - + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;renderWorldBorder(Lnet/minecraft/client/render/Camera;)V", shift = At.Shift.AFTER)) private void renderWorldBorder(MatrixStack matrices, float delta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) { - if (render) { - r = getRed(); - g = getGreen(); - b = getBlue(); - a = getAlpha(); - if (rainbow) { - final double millis = System.currentTimeMillis() % 10000L / 10000.0f; - final int color = HSBtoRGB((float) millis, 0.8f, 0.8f); - r = (color >> 16 & 255) / 255.0f; - g = (color >> 8 & 255) / 255.0f; - b = (color & 255) / 255.0f; + if (csbRender) { + var blinkingSpeed = CSBConfig.getBlinkSpeed(); + var blinkingAlpha = CSBConfig.getBlinkAlpha(); + if (blinkingSpeed > 0) { + blinkingAlpha *= (float) Math.abs(Math.sin(System.currentTimeMillis() / 100.0D * blinkingSpeed)); } - blinkingAlpha = getBlinkSpeed() > 0 ? getBlinkAlpha() * (float) Math.abs(Math.sin(System.currentTimeMillis() / 100.0D * getBlinkSpeed())) : getBlinkAlpha(); - BlockHitResult hitResult = (BlockHitResult) client.crosshairTarget; - BlockPos blockPos = hitResult.getBlockPos(); - for (CSBRenderer renderer : RENDERERS) { - ActionResult result = Objects.requireNonNull(renderer.render(world, camera, hitResult, delta)); - if (result != ActionResult.PASS) - break; - } - render = false; + final var blinkingAlpha2 = blinkingAlpha; + + RenderSystem.enableBlend(); + RenderSystem.enableDepthTest(); + RenderSystem.defaultBlendFunc(); + RenderSystem.depthMask(false); + RenderSystem.disableCull(); + RenderSystem.disableTexture(); + RenderSystem.enableBlend(); + RenderSystem.setShader(GameRenderer::getPositionColorShader); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuffer(); + + bufferBuilder.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR); + csbShape.forEachEdge((k, l, m, n, o, p) -> { + bufferBuilder.vertex((float)k, (float)l, (float)m).color(csbRed, csbGreen, csbBlue, csbAlpha).next(); + bufferBuilder.vertex((float)n, (float)o, (float)p).color(csbRed, csbGreen, csbBlue, csbAlpha).next(); + }); + tessellator.draw(); + + csbShape = csbShape.getBoundingBoxes().stream() + .map(box -> box.expand(0.002D, 0.002D, 0.002D)) + .map(VoxelShapes::cuboid) + .reduce(VoxelShapes::union) + .orElse(VoxelShapes.empty()).simplify(); + csbShape.forEachBox((k, l, m, n, o, p) -> { + CSB.drawBox(tessellator, bufferBuilder, k, l, m, n, o, p, csbRed, csbGreen, csbBlue, blinkingAlpha2); + }); + + RenderSystem.enableCull(); + RenderSystem.disableBlend(); + RenderSystem.depthMask(true); + + csbRender = false; } } - - @Override - public float getOutlineRed() { - return r; - } - - @Override - public float getOutlineGreen() { - return g; - } - - @Override - public float getOutlineBlue() { - return b; - } - - @Override - public float getOutlineAlpha() { - return a; - } - - @Override - public float getInnerRed() { - return r; - } - - @Override - public float getInnerGreen() { - return g; - } - - @Override - public float getInnerBlue() { - return b; - } - - @Override - public float getInnerAlpha() { - return blinkingAlpha; - } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a47d2fe..3dd36a0 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -10,9 +10,6 @@ "me.shedaniel.csb.CSB", "me.shedaniel.csb.CSBConfig" ], - "csb_renderers": [ - "me.shedaniel.csb.CSBDefaultRenderer" - ], "modmenu": [ "me.shedaniel.csb.CSBModMenuApiImpl" ] From 27bf25edb9ec3303d4840febe908daf3c2faaee3 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Fri, 6 Aug 2021 21:28:09 +0800 Subject: [PATCH 6/8] fix: remove the broken thickness slider --- .../java/me/shedaniel/csb/gui/CSBSettingsScreen.java | 12 ++++++------ src/main/resources/fabric.mod.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java b/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java index f91e671..3254bae 100644 --- a/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java +++ b/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java @@ -37,11 +37,11 @@ protected void init() { this.configCache = new ConfigCache(enabled, red, green, blue, alpha, thickness, blinkAlpha, blinkSpeed, disableDepthBuffer, rainbow, adjustBoundingBoxByLinkedBlocks); this.clearChildren(); // left - addDrawableChild(new CSBSliderWidget(1, 4, this.height / 2 - 62, getRed())); - addDrawableChild(new CSBSliderWidget(2, 4, this.height / 2 - 38, getGreen())); - addDrawableChild(new CSBSliderWidget(3, 4, this.height / 2 - 14, getBlue())); - addDrawableChild(new CSBSliderWidget(4, 4, this.height / 2 + 10, getAlpha())); - addDrawableChild(new CSBSliderWidget(5, 4, this.height / 2 + 34, getThickness() / 7.0F)); + addDrawableChild(new CSBSliderWidget(1, 4, this.height / 2 - 38, getRed())); + addDrawableChild(new CSBSliderWidget(2, 4, this.height / 2 - 14, getGreen())); + addDrawableChild(new CSBSliderWidget(3, 4, this.height / 2 + 10, getBlue())); + addDrawableChild(new CSBSliderWidget(4, 4, this.height / 2 + 34, getAlpha())); + // addDrawableChild(new CSBSliderWidget(5, 4, this.height / 2 + 34, getThickness() / 7.0F)); // right addDrawableChild(new CSBSliderWidget(7, this.width - 154, this.height / 2 - 14, getBlinkAlpha())); @@ -96,7 +96,7 @@ public void render(MatrixStack matrices, int par1, int par2, float par3) { if (this.client.world == null) this.renderBackgroundTexture(0); fillGradient(matrices, 0, 0, this.width, 48 - 4, -1072689136, -804253680); // top - fillGradient(matrices, 0, this.height / 2 - 67, 158, this.height / 2 + 59, -1072689136, -804253680); // left + fillGradient(matrices, 0, this.height / 2 - 43, 158, this.height / 2 + 59, -1072689136, -804253680); // left fillGradient(matrices, this.width - 158, this.height / 2 - 43, this.width, this.height / 2 + 59, -1072689136, -804253680); // right fillGradient(matrices, 0, this.height - 48 - 4, this.width, this.height, -1072689136, -804253680); // bottom diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3dd36a0..d373fc7 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "csb", - "name": "Custom Selection Box Fabric", + "name": "Custom Selection Box", "description": "Custom Selection Box shows you a clear and concise selection box that you can set to your own preferences. Sometimes it may be very unclear as to what you’re setting your sights on and which item you are trying to highlight to either edit, destroy or even place. Now the box is much clearer and completely editable to fit your needs.", "version": "${version}", "environment": "client", From 4323419501e762d4a2586d7a14805f85b9cddcd5 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Fri, 6 Aug 2021 21:42:17 +0800 Subject: [PATCH 7/8] bump version --- build.gradle | 2 +- gradle.properties | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 gradle.properties diff --git a/build.gradle b/build.gradle index 0177f65..dbc22d1 100755 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ sourceCompatibility = JavaVersion.VERSION_16 targetCompatibility = JavaVersion.VERSION_16 archivesBaseName = "CustomSelectionBox" -version = "5.0.2" +version = "5.1.0" minecraft { } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..d73eaba --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx4G \ No newline at end of file From 0db609d405472f5dcbb6f005119b2398c5494701 Mon Sep 17 00:00:00 2001 From: NKID00 Date: Tue, 24 Aug 2021 13:10:21 +0800 Subject: [PATCH 8/8] chore: update fabric to latest --- .gitignore | 18 +++++++++++++++++- build.gradle | 6 +++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 288cac5..09cd281 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ .gradle/ build/ out/ +classes/ + +# eclipse + +*.launch # idea @@ -11,7 +16,18 @@ out/ *.ipr *.iws +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# macos + +*.DS_Store + # fabric run/ -classes/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index dbc22d1..39a0011 100755 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ repositories { dependencies { minecraft "com.mojang:minecraft:1.17.1" - mappings "net.fabricmc:yarn:1.17.1+build.32:v2" + mappings "net.fabricmc:yarn:1.17.1+build.43:v2" modImplementation "net.fabricmc:fabric-loader:0.11.6" // Fabric api @@ -37,9 +37,9 @@ dependencies { // Add each module as a dependency apiModules.forEach { - include(modImplementation(fabricApi.module(it, "0.37.1+1.17"))) + include(modImplementation(fabricApi.module(it, "0.38.2+1.17"))) } // Mod Menu - modCompileOnly "com.terraformersmc:modmenu:2.0.4" + modCompileOnly "com.terraformersmc:modmenu:2.0.5" }