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 7f68b93..39a0011 100755 --- a/build.gradle +++ b/build.gradle @@ -1,20 +1,16 @@ 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" +version = "5.1.0" minecraft { } -repositories { - maven { url "https://dl.bintray.com/shedaniel/legacy-yarn-updated" } -} - processResources { filesMatching('fabric.mod.json') { expand 'version': project.version @@ -22,8 +18,28 @@ processResources { inputs.property "version", project.version } +repositories { + maven { + url 'https://maven.terraformersmc.com/releases/' + } +} + 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.43: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.38.2+1.17"))) + } + + // Mod Menu + modCompileOnly "com.terraformersmc:modmenu:2.0.5" } 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 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..20f9ab5 100644 --- a/src/main/java/me/shedaniel/csb/CSB.java +++ b/src/main/java/me/shedaniel/csb/CSB.java @@ -1,32 +1,35 @@ 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.openScreen(new CSBSettingsScreen(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; + })); } public static int HSBtoRGB(float hue, float saturation, float brightness) { @@ -76,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/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 deleted file mode 100644 index de2e836..0000000 --- a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java +++ /dev/null @@ -1,272 +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.VertexFormats; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.EntityContext; -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, EntityContext.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.pushMatrix(); - 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.disableCull(); - RenderSystem.disableTexture(); - RenderSystem.lineWidth(getOutlineThickness()); - vertexConsumer.begin(1, 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.popMatrix(); - } - - 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.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.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.x1, box.y1, box.z1, box.x2, box.y2, box.z2, xIn, yIn, zIn); - } - RenderSystem.enableCull(); - RenderSystem.disableAlphaTest(); - RenderSystem.enableAlphaTest(); - RenderSystem.disableBlend(); - RenderSystem.depthMask(true); - RenderSystem.popMatrix(); - } - - 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(7, 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(7, 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(7, 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(7, 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(7, 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(7, 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/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/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/gui/CSBSettingsScreen.java b/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java index 1d627a5..3254bae 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 - 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 - 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(); @@ -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/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 5edc249..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.server.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 5e3439a..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.openScreen(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..ed9f75f 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java @@ -1,19 +1,43 @@ 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; -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; 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, EntityContext.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; - } - 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; + if (csbRender) { + var blinkingSpeed = CSBConfig.getBlinkSpeed(); + var blinkingAlpha = CSBConfig.getBlinkAlpha(); + if (blinkingSpeed > 0) { + blinkingAlpha *= (float) Math.abs(Math.sin(System.currentTimeMillis() / 100.0D * blinkingSpeed)); } - 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/csb.mixins.json b/src/main/resources/csb.mixins.json index 7d0cb11..c8ade0f 100644 --- a/src/main/resources/csb.mixins.json +++ b/src/main/resources/csb.mixins.json @@ -1,14 +1,12 @@ { "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 } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 684b2e3..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", @@ -10,8 +10,8 @@ "me.shedaniel.csb.CSB", "me.shedaniel.csb.CSBConfig" ], - "csb_renderers": [ - "me.shedaniel.csb.CSBDefaultRenderer" + "modmenu": [ + "me.shedaniel.csb.CSBModMenuApiImpl" ] }, "contact": { @@ -25,8 +25,5 @@ ], "authors": [ "shedaniel" - ], - "custom": { - "modmenu:clientsideOnly": true - } + ] } \ No newline at end of file