diff --git a/gradle.properties b/gradle.properties index 0234a14d..8ea12dae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ archives_base_name=TweakMyClient loader_version=0.13.3 # Required Libraries -# MagicLib - 0.5.25 -magiclib_version=0.5.25 \ No newline at end of file +# MagicLib - 0.5.27 +magiclib_version=0.5.27 \ No newline at end of file diff --git a/src/main/java/top/hendrixshen/tweakmyclient/config/Configs.java b/src/main/java/top/hendrixshen/tweakmyclient/config/Configs.java index 54f3ea2d..3b3f16d4 100644 --- a/src/main/java/top/hendrixshen/tweakmyclient/config/Configs.java +++ b/src/main/java/top/hendrixshen/tweakmyclient/config/Configs.java @@ -32,15 +32,22 @@ public class Configs { public static int autoDropInterval = 0; @Config(category = ConfigCategory.GENERIC) - public static boolean customBlockHitBoxOverlayFillRainbow = true; + public static boolean customBlockHitBoxOverlayFillRainbow = false; - @Numeric(maxValue = 10, minValue = 1) + @Numeric(maxValue = 100, minValue = 1) @Config(category = ConfigCategory.GENERIC) - public static int customBlockHitBoxOverlayFillRainbowSpeed = 4; + public static int customBlockHitBoxOverlayFillRainbowSpeed = 80; @Config(category = ConfigCategory.GENERIC) public static boolean customBlockHitBoxOverlayLinkedAdapter = true; + @Config(category = ConfigCategory.GENERIC) + public static boolean customBlockHitBoxOverlayOutlineRainbow = false; + + @Numeric(maxValue = 100, minValue = 1) + @Config(category = ConfigCategory.GENERIC) + public static int customBlockHitBoxOverlayOutlineRainbowSpeed = 80; + @Config(category = ConfigCategory.GENERIC) public static String customWindowTitle = "Minecraft {mc_version} with TweakMyClient {tmc_version} | Player {mc_username} | FPS: {mc_fps}"; @@ -125,10 +132,10 @@ public class Configs { // Color configs @Config(category = ConfigCategory.COLOR) - public static Color4f colorBlockOutside = Color4f.fromColor(StringUtils.getColor("#66000000", 0)); + public static Color4f colorBlockHitBoxOverlayOutline = Color4f.fromColor(StringUtils.getColor("#66000000", 0)); @Config(category = ConfigCategory.COLOR) - public static Color4f colorBlockHitBoxOverlayFill = Color4f.fromColor(StringUtils.getColor("#4CFFFF10", 0)); + public static Color4f colorBlockHitBoxOverlayFill = Color4f.fromColor(StringUtils.getColor("#2CFFFF10", 0)); @Config(category = ConfigCategory.COLOR) public static Color4f colorGuiStart = Color4f.fromColor(StringUtils.getColor("#C00F0F0F", 0)); @@ -171,7 +178,7 @@ public class Configs { @Hotkey() @Config(category = ConfigCategory.FEATURE) - public static boolean featureCustomBlockOutsideColor = false; + public static boolean featureCustomBlockHitBoxOverlayOutline = false; @Hotkey() @Config(category = ConfigCategory.FEATURE) diff --git a/src/main/java/top/hendrixshen/tweakmyclient/event/RenderHandler.java b/src/main/java/top/hendrixshen/tweakmyclient/event/RenderHandler.java index dcea1942..870ce41b 100644 --- a/src/main/java/top/hendrixshen/tweakmyclient/event/RenderHandler.java +++ b/src/main/java/top/hendrixshen/tweakmyclient/event/RenderHandler.java @@ -37,7 +37,7 @@ public void onRenderWorldLast(PoseStack poseStack, Matrix4f matrix4f) { OverlayRenderer.getInstance().renderOpenWater(minecraft); } //#endif - if (Configs.featureCustomBlockHitBoxOverlayFill) { + if (Configs.featureCustomBlockHitBoxOverlayFill || Configs.featureCustomBlockHitBoxOverlayOutline) { OverlayRenderer.getInstance().renderBlockOverlay(minecraft); } } diff --git a/src/main/java/top/hendrixshen/tweakmyclient/mixin/feature/featureCustomBlockOutsideColor/MixinLevelRenderer.java b/src/main/java/top/hendrixshen/tweakmyclient/mixin/feature/featureCustomBlockOutsideColor/MixinLevelRenderer.java index 3ca923b9..dc6da62d 100644 --- a/src/main/java/top/hendrixshen/tweakmyclient/mixin/feature/featureCustomBlockOutsideColor/MixinLevelRenderer.java +++ b/src/main/java/top/hendrixshen/tweakmyclient/mixin/feature/featureCustomBlockOutsideColor/MixinLevelRenderer.java @@ -1,15 +1,32 @@ package top.hendrixshen.tweakmyclient.mixin.feature.featureCustomBlockOutsideColor; import fi.dy.masa.malilib.util.Color4f; +import net.minecraft.client.Minecraft; +//#if MC >= 11500 +import net.minecraft.client.multiplayer.ClientLevel; +//#else +//$$ import net.minecraft.client.multiplayer.MultiPlayerLevel; +//#endif import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.shapes.VoxelShape; +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.ModifyArgs; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; +import top.hendrixshen.tweakmyclient.TweakMyClient; import top.hendrixshen.tweakmyclient.config.Configs; +import top.hendrixshen.tweakmyclient.util.MiscUtil; @Mixin(LevelRenderer.class) public abstract class MixinLevelRenderer { + @Shadow @Final private Minecraft minecraft; + @ModifyArgs( method = "renderHitOutline", at = @At( @@ -22,17 +39,48 @@ public abstract class MixinLevelRenderer { ) ) private void onDrawBlockOutline(Args args) { - if (Configs.featureCustomBlockOutsideColor) { - Color4f color = Configs.colorBlockOutside; + if (Configs.featureCustomBlockHitBoxOverlayOutline) { + Color4f color = Configs.colorBlockHitBoxOverlayOutline; + float r, g, b; + if (Configs.customBlockHitBoxOverlayOutlineRainbow) { + float k = System.currentTimeMillis() % (100 * (101 - Configs.customBlockHitBoxOverlayOutlineRainbowSpeed)) / (50F * (101 - Configs.customBlockHitBoxOverlayOutlineRainbowSpeed)); + r = 0.5F + 0.5F * (float) Math.sin(k * Math.PI); + g = 0.5F + 0.5F * (float) Math.sin((k + 2F / 3F) * Math.PI); + b = 0.5F + 0.5F * (float) Math.sin((k + 6F / 3F) * Math.PI); + } else { + r = color.r; + g = color.g; + b = color.b; + } + if (Configs.customBlockHitBoxOverlayLinkedAdapter) { + Minecraft minecraft = TweakMyClient.getMinecraftClient(); + HitResult hitResult = minecraft.hitResult; + //#if MC >= 11500 + ClientLevel clientLevel = minecraft.level; + //#else + //$$ MultiPlayerLevel clientLevel = minecraft.level; + //#endif + if (hitResult instanceof BlockHitResult && clientLevel != null) { + BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos(); + BlockState blockState = clientLevel.getBlockState(blockPos); + //#if MC >= 11500 + VoxelShape voxelShape = args.get(2); + args.set(2, MiscUtil.linkedBlockAdapter(clientLevel, blockState, blockPos, voxelShape)); + //#else + //$$ VoxelShape voxelShape = args.get(0); + //$$ args.set(0, MiscUtil.linkedBlockAdapter(clientLevel, blockState, blockPos, voxelShape)); + //#endif + } + } //#if MC >= 11500 - args.set(6, color.r); - args.set(7, color.g); - args.set(8, color.b); + args.set(6, r); + args.set(7, g); + args.set(8, b); args.set(9, color.a); //#else - //$$ args.set(4, color.r); - //$$ args.set(5, color.g); - //$$ args.set(6, color.b); + //$$ args.set(4, r); + //$$ args.set(5, g); + //$$ args.set(6, b); //$$ args.set(7, color.a); //#endif } diff --git a/src/main/java/top/hendrixshen/tweakmyclient/util/MiscUtil.java b/src/main/java/top/hendrixshen/tweakmyclient/util/MiscUtil.java new file mode 100644 index 00000000..da4d9a31 --- /dev/null +++ b/src/main/java/top/hendrixshen/tweakmyclient/util/MiscUtil.java @@ -0,0 +1,106 @@ +package top.hendrixshen.tweakmyclient.util; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.piston.PistonBaseBlock; +import net.minecraft.world.level.block.piston.PistonHeadBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BedPart; +import net.minecraft.world.level.block.state.properties.PistonType; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; +import top.hendrixshen.tweakmyclient.config.Configs; + +public class MiscUtil { + public static VoxelShape linkedBlockAdapter(ClientLevel clientLevel, BlockState blockState, BlockPos blockPos, VoxelShape shape) { + try { + if (blockState.getBlock() instanceof ChestBlock) { + Block block = blockState.getBlock(); + Direction direction = ChestBlock.getConnectedDirection(blockState); + BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction, 1)); + if (connectBlock.getBlock() == block && blockPos.relative(direction, 1).relative(ChestBlock.getConnectedDirection(connectBlock)).equals(blockPos)) { + return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); + } + } else if (blockState.getBlock() instanceof DoorBlock) { + Block block = blockState.getBlock(); + if (clientLevel.getBlockState(blockPos.above(1)).getBlock() == block) { + BlockState connectBlock = clientLevel.getBlockState(blockPos.above(1)); + if (connectBlock.getValue(DoorBlock.POWERED).equals(blockState.getValue(DoorBlock.POWERED)) + && connectBlock.getValue(DoorBlock.FACING).equals(blockState.getValue(DoorBlock.FACING)) + && connectBlock.getValue(DoorBlock.HINGE).equals(connectBlock.getValue(DoorBlock.HINGE))) { + return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(0, 1, 0)); + } + } else if (clientLevel.getBlockState(blockPos.below(1)).getBlock() == block) { + BlockState connectBlock = clientLevel.getBlockState(blockPos.below(1)); + if (connectBlock.getValue(DoorBlock.POWERED).equals(blockState.getValue(DoorBlock.POWERED)) + && connectBlock.getValue(DoorBlock.FACING).equals(blockState.getValue(DoorBlock.FACING)) + && connectBlock.getValue(DoorBlock.HINGE).equals(connectBlock.getValue(DoorBlock.HINGE))) { + return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(0, -1, 0)); + } + } + } else if (blockState.getBlock() instanceof BedBlock) { + Block block = blockState.getBlock(); + Direction direction = blockState.getValue(HorizontalDirectionalBlock.FACING); + BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction)); + if (blockState.getValue(BedBlock.PART).equals(BedPart.FOOT) + && connectBlock.getBlock() == block + && connectBlock.getValue(BedBlock.PART).equals(BedPart.HEAD)) { + return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); + } + connectBlock = clientLevel.getBlockState(blockPos.relative(direction.getOpposite())); + direction = direction.getOpposite(); + if (blockState.getValue(BedBlock.PART).equals(BedPart.HEAD) + && connectBlock.getBlock() == block + && connectBlock.getValue(BedBlock.PART).equals(BedPart.FOOT)) { + return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); + } + } else if (blockState.getBlock() instanceof PistonBaseBlock && blockState.getValue(PistonBaseBlock.EXTENDED)) { + Block block = blockState.getBlock(); + Direction direction = blockState.getValue(DirectionalBlock.FACING); + BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction)); + if (connectBlock.getValue(PistonHeadBlock.TYPE).equals(block == Blocks.PISTON ? PistonType.DEFAULT : PistonType.STICKY) + && direction.equals(connectBlock.getValue(DirectionalBlock.FACING))) { + return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); + } + } else if (blockState.getBlock() instanceof PistonHeadBlock) { + Direction direction = blockState.getValue(DirectionalBlock.FACING); + BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction.getOpposite())); + if (connectBlock.getBlock() instanceof PistonBaseBlock && direction == connectBlock.getValue(DirectionalBlock.FACING) && connectBlock.getValue(PistonBaseBlock.EXTENDED)) { + return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos.relative(direction.getOpposite())).move(direction.getOpposite().getStepX(), direction.getOpposite().getStepY(), direction.getOpposite().getStepZ())); + } + //#if MC >= 11700 + } else if (blockState.getBlock() instanceof PointedDripstoneBlock && Configs.expCustomBlockHitBoxOverlayLinkedAdapterSupportPointedDripstoneBlock) { + Direction direction = blockState.getValue(PointedDripstoneBlock.TIP_DIRECTION); + + BlockPos connectBlockPos = blockPos.above(); + while (true) { + BlockState connectBlock = clientLevel.getBlockState(connectBlockPos); + if (connectBlock.getBlock() instanceof PointedDripstoneBlock && connectBlock.getValue(PointedDripstoneBlock.TIP_DIRECTION).equals(direction)) { + shape = Shapes.or(shape, connectBlock.getShape(clientLevel, connectBlockPos).move(0, connectBlockPos.getY() - blockPos.getY(), 0)); + connectBlockPos = connectBlockPos.above(); + } else { + break; + } + } + + connectBlockPos = blockPos.below(); + while (true) { + BlockState connectBlock = clientLevel.getBlockState(connectBlockPos); + if (connectBlock.getBlock() instanceof PointedDripstoneBlock && connectBlock.getValue(PointedDripstoneBlock.TIP_DIRECTION).equals(direction)) { + shape = Shapes.or(shape, connectBlock.getShape(clientLevel, connectBlockPos).move(0, connectBlockPos.getY() - blockPos.getY(), 0)); + connectBlockPos = connectBlockPos.below(); + } else { + break; + } + } + + return shape; + //#endif + } + } catch (Exception ignore) { + } + return shape; + } +} diff --git a/src/main/java/top/hendrixshen/tweakmyclient/util/render/OverlayRenderer.java b/src/main/java/top/hendrixshen/tweakmyclient/util/render/OverlayRenderer.java index fd88ef12..65aa95a2 100644 --- a/src/main/java/top/hendrixshen/tweakmyclient/util/render/OverlayRenderer.java +++ b/src/main/java/top/hendrixshen/tweakmyclient/util/render/OverlayRenderer.java @@ -7,28 +7,22 @@ import net.minecraft.client.player.LocalPlayer; //#endif import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.world.entity.Entity; //#if MC >= 11600 import net.minecraft.world.entity.projectile.FishingHook; //#endif -import net.minecraft.world.level.block.*; -import net.minecraft.world.level.block.piston.PistonBaseBlock; -import net.minecraft.world.level.block.piston.PistonHeadBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BedPart; -import net.minecraft.world.level.block.state.properties.PistonType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import org.lwjgl.opengl.GL11; import top.hendrixshen.tweakmyclient.config.Configs; //#if MC >= 11600 import top.hendrixshen.tweakmyclient.fakeInterface.IFishingHookEntity; //#endif +import top.hendrixshen.tweakmyclient.util.MiscUtil; public class OverlayRenderer { private static final OverlayRenderer INSTANCE = new OverlayRenderer(); @@ -70,108 +64,36 @@ public void renderBlockOverlay(Minecraft minecraft) { BlockState blockState = clientLevel.getBlockState(blockPos); VoxelShape voxelShape = blockState.getShape(clientLevel, blockHitResult.getBlockPos(), CollisionContext.of(cameraEntity)); if (Configs.customBlockHitBoxOverlayLinkedAdapter) { - voxelShape = linkedBlockAdapter(clientLevel, blockState, blockPos, voxelShape); + voxelShape = MiscUtil.linkedBlockAdapter(clientLevel, blockState, blockPos, voxelShape); } - float k = System.currentTimeMillis() % (500 * Configs.customBlockHitBoxOverlayFillRainbowSpeed) / (250F * Configs.customBlockHitBoxOverlayFillRainbowSpeed); + if (Configs.featureCustomBlockHitBoxOverlayFill) { + float k = System.currentTimeMillis() % (100 * (101 - Configs.customBlockHitBoxOverlayFillRainbowSpeed)) / (50F * (101 - Configs.customBlockHitBoxOverlayFillRainbowSpeed)); - RenderUtil.renderShapeOverlay(voxelShape, blockPos.getX() - vec3.x(), blockPos.getY() - vec3.y(), blockPos.getZ() - vec3.z(), - Configs.customBlockHitBoxOverlayFillRainbow ? new Color4f( - 0.5F + 0.5F * (float) Math.sin(k * Math.PI), - 0.5F + 0.5F * (float) Math.sin((k + 4F / 3F) * Math.PI), - 0.5F + 0.5F * (float) Math.sin((k + 8F / 3F) * Math.PI), - Configs.colorBlockHitBoxOverlayFill.a - ) : Configs.colorBlockHitBoxOverlayFill); - } - } - - private VoxelShape linkedBlockAdapter(ClientLevel clientLevel, BlockState blockState, BlockPos blockPos, VoxelShape shape) { - try { - if (blockState.getBlock() instanceof ChestBlock) { - Block block = blockState.getBlock(); - Direction direction = ChestBlock.getConnectedDirection(blockState); - BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction, 1)); - if (connectBlock.getBlock() == block && blockPos.relative(direction, 1).relative(ChestBlock.getConnectedDirection(connectBlock)).equals(blockPos)) { - return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); - } - } else if (blockState.getBlock() instanceof DoorBlock) { - Block block = blockState.getBlock(); - if (clientLevel.getBlockState(blockPos.above(1)).getBlock() == block) { - BlockState connectBlock = clientLevel.getBlockState(blockPos.above(1)); - if (connectBlock.getValue(DoorBlock.POWERED).equals(blockState.getValue(DoorBlock.POWERED)) - && connectBlock.getValue(DoorBlock.FACING).equals(blockState.getValue(DoorBlock.FACING)) - && connectBlock.getValue(DoorBlock.HINGE).equals(connectBlock.getValue(DoorBlock.HINGE))) { - return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(0, 1, 0)); - } - } else if (clientLevel.getBlockState(blockPos.below(1)).getBlock() == block) { - BlockState connectBlock = clientLevel.getBlockState(blockPos.below(1)); - if (connectBlock.getValue(DoorBlock.POWERED).equals(blockState.getValue(DoorBlock.POWERED)) - && connectBlock.getValue(DoorBlock.FACING).equals(blockState.getValue(DoorBlock.FACING)) - && connectBlock.getValue(DoorBlock.HINGE).equals(connectBlock.getValue(DoorBlock.HINGE))) { - return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(0, -1, 0)); - } - } - } else if (blockState.getBlock() instanceof BedBlock) { - Block block = blockState.getBlock(); - Direction direction = blockState.getValue(HorizontalDirectionalBlock.FACING); - BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction)); - if (blockState.getValue(BedBlock.PART).equals(BedPart.FOOT) - && connectBlock.getBlock() == block - && connectBlock.getValue(BedBlock.PART).equals(BedPart.HEAD)) { - return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); - } - connectBlock = clientLevel.getBlockState(blockPos.relative(direction.getOpposite())); - direction = direction.getOpposite(); - if (blockState.getValue(BedBlock.PART).equals(BedPart.HEAD) - && connectBlock.getBlock() == block - && connectBlock.getValue(BedBlock.PART).equals(BedPart.FOOT)) { - return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); - } - } else if (blockState.getBlock() instanceof PistonBaseBlock && blockState.getValue(PistonBaseBlock.EXTENDED)) { - Block block = blockState.getBlock(); - Direction direction = blockState.getValue(DirectionalBlock.FACING); - BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction)); - if (connectBlock.getValue(PistonHeadBlock.TYPE).equals(block == Blocks.PISTON ? PistonType.DEFAULT : PistonType.STICKY) - && direction.equals(connectBlock.getValue(DirectionalBlock.FACING))) { - return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos).move(direction.getStepX(), direction.getStepY(), direction.getStepZ())); - } - } else if (blockState.getBlock() instanceof PistonHeadBlock) { - Direction direction = blockState.getValue(DirectionalBlock.FACING); - BlockState connectBlock = clientLevel.getBlockState(blockPos.relative(direction.getOpposite())); - if (connectBlock.getBlock() instanceof PistonBaseBlock && direction == connectBlock.getValue(DirectionalBlock.FACING) && connectBlock.getValue(PistonBaseBlock.EXTENDED)) { - return Shapes.or(shape, connectBlock.getShape(clientLevel, blockPos.relative(direction.getOpposite())).move(direction.getOpposite().getStepX(), direction.getOpposite().getStepY(), direction.getOpposite().getStepZ())); - } - //#if MC >= 11700 - } else if (blockState.getBlock() instanceof PointedDripstoneBlock && Configs.expCustomBlockHitBoxOverlayLinkedAdapterSupportPointedDripstoneBlock) { - Direction direction = blockState.getValue(PointedDripstoneBlock.TIP_DIRECTION); - - BlockPos connectBlockPos = blockPos.above(); - while (true) { - BlockState connectBlock = clientLevel.getBlockState(connectBlockPos); - if (connectBlock.getBlock() instanceof PointedDripstoneBlock && connectBlock.getValue(PointedDripstoneBlock.TIP_DIRECTION).equals(direction)) { - shape = Shapes.or(shape, connectBlock.getShape(clientLevel, connectBlockPos).move(0, connectBlockPos.getY() - blockPos.getY(), 0)); - connectBlockPos = connectBlockPos.above(); - } else { - break; - } - } + RenderUtil.renderShapeOverlay(voxelShape, 0.005F, blockPos.getX() - vec3.x(), blockPos.getY() - vec3.y(), blockPos.getZ() - vec3.z(), + Configs.customBlockHitBoxOverlayFillRainbow ? new Color4f( + 0.5F + 0.5F * (float) Math.sin(k * Math.PI), + 0.5F + 0.5F * (float) Math.sin((k + 4F / 3F) * Math.PI), + 0.5F + 0.5F * (float) Math.sin((k + 8F / 3F) * Math.PI), + Configs.colorBlockHitBoxOverlayFill.a + ) : Configs.colorBlockHitBoxOverlayFill); + } - connectBlockPos = blockPos.below(); - while (true) { - BlockState connectBlock = clientLevel.getBlockState(connectBlockPos); - if (connectBlock.getBlock() instanceof PointedDripstoneBlock && connectBlock.getValue(PointedDripstoneBlock.TIP_DIRECTION).equals(direction)) { - shape = Shapes.or(shape, connectBlock.getShape(clientLevel, connectBlockPos).move(0, connectBlockPos.getY() - blockPos.getY(), 0)); - connectBlockPos = connectBlockPos.below(); - } else { - break; - } - } + /* + if (Configs.featureCustomBlockHitBoxOverlayOutline) { + float k = System.currentTimeMillis() % (100 * (101 - Configs.customBlockHitBoxOverlayOutlineRainbowSpeed)) / (50F * (101 - Configs.customBlockHitBoxOverlayOutlineRainbowSpeed)); - return shape; - //#endif + RenderUtil.renderShapeOutline(voxelShape, (float) 0, + Configs.customBlockHitBoxOverlayOutlineWidth * 2, + blockPos.getX() - vec3.x(), blockPos.getY() - vec3.y(), blockPos.getZ() - vec3.z(), + Configs.customBlockHitBoxOverlayOutlineRainbow ? new Color4f( + 0.5F + 0.5F * (float) Math.sin(k * Math.PI), + 0.5F + 0.5F * (float) Math.sin((k + 2F / 3F) * Math.PI), + 0.5F + 0.5F * (float) Math.sin((k + 6F / 3F) * Math.PI), + Configs.colorBlockHitBoxOverlayOutline.a + ) : Configs.colorBlockHitBoxOverlayOutline); } - } catch (Exception ignore) { + */ } - return shape; } } diff --git a/src/main/java/top/hendrixshen/tweakmyclient/util/render/RenderUtil.java b/src/main/java/top/hendrixshen/tweakmyclient/util/render/RenderUtil.java index b550096a..51c3b43e 100644 --- a/src/main/java/top/hendrixshen/tweakmyclient/util/render/RenderUtil.java +++ b/src/main/java/top/hendrixshen/tweakmyclient/util/render/RenderUtil.java @@ -56,57 +56,42 @@ private static void drawBoundingBoxEdges(double minX, double minY, double minZ, //$$ bufferbuilder.begin(GL11.GL_LINES, DefaultVertexFormat.POSITION_COLOR); //#endif - drawBoundingBoxLinesX(bufferbuilder, minX, minY, minZ, maxX, maxY, maxZ, colorX); - drawBoundingBoxLinesY(bufferbuilder, minX, minY, minZ, maxX, maxY, maxZ, colorY); - drawBoundingBoxLinesZ(bufferbuilder, minX, minY, minZ, maxX, maxY, maxZ, colorZ); + RenderUtils.drawBoxAllEdgesBatchedLines(minX, minY, minZ, maxX, maxY, maxZ, colorX, bufferbuilder); tesselator.end(); } + //#endif + public static void renderShapeOverlay(VoxelShape voxelShape, float expand, double x, double y, double z, Color4f color4f) { + //#if MC < 11700 + //$$ RenderSystem.disableTexture(); + //#endif + RenderSystem.enableBlend(); + RenderSystem.disableCull(); + //#if MC >= 11700 + RenderSystem.setShader(GameRenderer::getPositionColorShader); + //#endif + Tesselator tesselator = Tesselator.getInstance(); + BufferBuilder buffer = tesselator.getBuilder(); + buffer.begin(VertexFormatCompatApi.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - private static void drawBoundingBoxLinesX(BufferBuilder buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, Color4f color) { - buffer.vertex(minX, minY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, minY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(minX, maxY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, maxY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(minX, minY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, minY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(minX, maxY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, maxY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - } - - private static void drawBoundingBoxLinesY(BufferBuilder buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, Color4f color) { - buffer.vertex(minX, minY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(minX, maxY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(maxX, minY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, maxY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(minX, minY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(minX, maxY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(maxX, minY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, maxY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - } - - private static void drawBoundingBoxLinesZ(BufferBuilder buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, Color4f color) { - buffer.vertex(minX, minY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(minX, minY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(maxX, minY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, minY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); - - buffer.vertex(minX, maxY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(minX, maxY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); + VoxelShape optimizedVoxelShape = voxelShape.toAabbs().stream() + .map(box -> box.inflate(expand, expand, expand)) + .map(Shapes::create) + .reduce(Shapes::or) + .orElse(Shapes.empty()).optimize(); + optimizedVoxelShape.forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> + RenderUtils.drawBoxAllSidesBatchedQuads(minX + x, minY + y, minZ + z, + maxX + x, maxY + y, maxZ + z, color4f, buffer)); - buffer.vertex(maxX, maxY, minZ).color(color.r, color.g, color.b, color.a).endVertex(); - buffer.vertex(maxX, maxY, maxZ).color(color.r, color.g, color.b, color.a).endVertex(); + tesselator.end(); + RenderSystem.enableCull(); + RenderSystem.disableBlend(); + //#if MC < 11700 + //$$ RenderSystem.enableTexture(); + //#endif } - //#endif - public static void renderShapeOverlay(VoxelShape voxelShape, double x, double y, double z, Color4f color4f) { + public static void renderShapeOutline(VoxelShape voxelShape, float expand, float lineWidth, double x, double y, double z, Color4f color4f) { //#if MC < 11700 //$$ RenderSystem.disableTexture(); //#endif @@ -117,20 +102,28 @@ public static void renderShapeOverlay(VoxelShape voxelShape, double x, double y, //#endif Tesselator tesselator = Tesselator.getInstance(); BufferBuilder buffer = tesselator.getBuilder(); - buffer.begin(VertexFormatCompatApi.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); + //#if MC >= 11700 + buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); + //#else + //$$ buffer.begin(GL11.GL_LINES, DefaultVertexFormat.POSITION_COLOR); + //#endif + + RenderSystem.lineWidth(lineWidth); VoxelShape optimizedVoxelShape = voxelShape.toAabbs().stream() - .map(box -> box.inflate(0.005, 0.005, 0.005)) + .map(box -> box.inflate(expand, expand, expand)) .map(Shapes::create) .reduce(Shapes::or) .orElse(Shapes.empty()).optimize(); - for (AABB aabb : optimizedVoxelShape.toAabbs()) { - RenderUtils.drawBoxAllSidesBatchedQuads(aabb.minX + x, aabb.minY + y, aabb.minZ + z, - aabb.maxX + x, aabb.maxY + y, aabb.maxZ + z, color4f, buffer); - } + optimizedVoxelShape.forAllEdges((minX, minY, minZ, maxX, maxY, maxZ) -> { + buffer.vertex(minX + x, minY + y, minZ + z).color(color4f.r, color4f.g, color4f.b, color4f.a).endVertex(); + buffer.vertex(maxX + x, minY + y, minZ + z).color(color4f.r, color4f.g, color4f.b, color4f.a).endVertex(); + }); + tesselator.end(); RenderSystem.enableCull(); RenderSystem.disableBlend(); + //#if MC < 11700 //$$ RenderSystem.enableTexture(); //#endif diff --git a/src/main/resources/assets/tweakmyclient/lang/en_us.json b/src/main/resources/assets/tweakmyclient/lang/en_us.json index 1cc3e87e..521bc084 100644 --- a/src/main/resources/assets/tweakmyclient/lang/en_us.json +++ b/src/main/resources/assets/tweakmyclient/lang/en_us.json @@ -12,8 +12,8 @@ "tweakmyclient.config.color.colorBlockHitBoxOverlayFill.name": "colorBlockHitBoxOverlayFill", "tweakmyclient.config.color.colorBlockHitBoxOverlayFill.comment": "Custom the overlay fill color of the block hit box.", - "tweakmyclient.config.color.colorBlockOutside.name": "colorBlockOutside", - "tweakmyclient.config.color.colorBlockOutside.comment": "Custom block outside color.", + "tweakmyclient.config.color.colorBlockHitBoxOverlayOutline.name": "colorBlockHitBoxOverlayOutline", + "tweakmyclient.config.color.colorBlockHitBoxOverlayOutline.comment": "Custom the overlay outline color of the block hit box.", "tweakmyclient.config.color.colorGuiStart.name": "colorGuiStart", "tweakmyclient.config.color.colorGuiStart.comment": "Custom gui gradient start color.", "tweakmyclient.config.color.colorGuiStop.name": "colorGuiStop", @@ -78,10 +78,10 @@ "tweakmyclient.config.feature.featureAutoReconnect.comment": "Automatically reconnects when you disconnect from the server.\nAdaptive AuthMe, OAuth, ReAuth and In-Game Account Switcher session validation.", "tweakmyclient.config.feature.featureAutoRespawn.name": "featureAutoRespawn", "tweakmyclient.config.feature.featureAutoRespawn.comment": "Automatically respawns you whenever you die.", - "tweakmyclient.config.feature.featureCustomBlockOutsideColor.name": "featureCustomBlockOutsideColor", - "tweakmyclient.config.feature.featureCustomBlockOutsideColor.comment": "Enable block outside color override.", "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayFill.name": "featureCustomBlockHitBoxOverlayFill", "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayFill.comment": "Enable overlay fills for pointing to block hit boxes.", + "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayOutline.name": "featureCustomBlockHitBoxOverlayOutline", + "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayOutline.comment": "Enable overlay outline for pointing to block hit boxes.", "tweakmyclient.config.feature.featureCustomGuiBackgroundColor.name": "featureCustomGuiBackgroundColor", "tweakmyclient.config.feature.featureCustomGuiBackgroundColor.comment": "Enable gui background color override.", "tweakmyclient.config.feature.featureCustomSidebarBackgroundColor.name": "featureCustomSidebarBackgroundColor", @@ -106,11 +106,15 @@ "tweakmyclient.config.generic.autoReconnectTimer.name": "autoReconnectTimer", "tweakmyclient.config.generic.autoReconnectTimer.comment": "How many seconds to wait for auto reconnection.", "tweakmyclient.config.generic.customBlockHitBoxOverlayFillRainbow.name": "customBlockHitBoxOverlayFillRainbow", - "tweakmyclient.config.generic.customBlockHitBoxOverlayFillRainbow.comment": "featureCustomBlockHitBoxOverlayFill will enable the rainbow colour change, using the alpha provided by colorBlockHitBoxOverlayFill.", + "tweakmyclient.config.generic.customBlockHitBoxOverlayFillRainbow.comment": "featureCustomBlockHitBoxOverlayFill will enable the rainbow color change, using the alpha provided by colorBlockHitBoxOverlayFill.", "tweakmyclient.config.generic.customBlockHitBoxOverlayFillRainbowSpeed.name": "customBlockHitBoxOverlayFillRainbowSpeed", - "tweakmyclient.config.generic.customBlockHitBoxOverlayFillRainbowSpeed.comment": "customBlockHitBoxOverlayFillRainbow rolling speed.", + "tweakmyclient.config.generic.customBlockHitBoxOverlayFillRainbowSpeed.comment": "The customBlockHitBoxOverlayFillRainbow rolling speed.", "tweakmyclient.config.generic.customBlockHitBoxOverlayLinkedAdapter.name": "customBlockHitBoxOverlayLinkedAdapter", "tweakmyclient.config.generic.customBlockHitBoxOverlayLinkedAdapter.comment": "Enable customBlockHitBoxOverlay optimisation of the linking block.", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbow.name": "customBlockHitBoxOverlayOutlineRainbow", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbow.comment": "featureCustomBlockHitBoxOverlayOutline will enable the rainbow color change, using the alpha provided by colorBlockHitBoxOverlayOutline.", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbowSpeed.name": "customBlockHitBoxOverlayOutlineRainbowSpeed", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbowSpeed.comment": "The customBlockHitBoxOverlayOutlineRainbow rolling speed.", "tweakmyclient.config.generic.customWindowTitle.name": "customWindowTitle", "tweakmyclient.config.generic.customWindowTitle.comment": "Modify current window title.\nThe available placeholders are as follows:\n{fabric_loader_asm_version}\n{fabric_loader_version}\n{fabric_mod_ver:}\n{mc_fps}\n{mc_protocol_version}\n{mc_username}\n{mc_version}\n{tmc_version}\n{tmc_version_type}", "tweakmyclient.config.generic.customWindowTitleWithActivity.name": "customWindowTitleWithActivity", diff --git a/src/main/resources/assets/tweakmyclient/lang/zh_cn.json b/src/main/resources/assets/tweakmyclient/lang/zh_cn.json index 259edff7..b7294fab 100644 --- a/src/main/resources/assets/tweakmyclient/lang/zh_cn.json +++ b/src/main/resources/assets/tweakmyclient/lang/zh_cn.json @@ -12,8 +12,8 @@ "tweakmyclient.config.color.colorBlockHitBoxOverlayFill.name": "方块碰撞箱覆盖填充颜色", "tweakmyclient.config.color.colorBlockHitBoxOverlayFill.comment": "自定义方块碰撞箱的覆盖层填充颜色.", - "tweakmyclient.config.color.colorBlockOutside.name": "方块轮廓颜色", - "tweakmyclient.config.color.colorBlockOutside.comment": "自定义方块轮廓颜色.", + "tweakmyclient.config.color.colorBlockHitBoxOverlayOutline.name": "方块碰撞箱覆盖轮廓颜色.", + "tweakmyclient.config.color.colorBlockHitBoxOverlayOutline.comment": "自定义方块碰撞箱的覆盖层轮廓颜色.", "tweakmyclient.config.color.colorGuiStart.name": "界面渐变背景起始颜色", "tweakmyclient.config.color.colorGuiStart.comment": "自定义界面渐变起始颜色.", "tweakmyclient.config.color.colorGuiStop.name": "界面渐变背景终止颜色", @@ -78,10 +78,10 @@ "tweakmyclient.config.feature.featureAutoReconnect.comment": "从服务器断开连接时自动重新连接服务器.\n适配 AuthMe, OAuth, ReAuth 和 In-Game Account Switcher 会话验证", "tweakmyclient.config.feature.featureAutoRespawn.name": "自动重生", "tweakmyclient.config.feature.featureAutoRespawn.comment": "死亡时自动重生.", - "tweakmyclient.config.feature.featureCustomBlockOutsideColor.name": "自定义方块轮廓", - "tweakmyclient.config.feature.featureCustomBlockOutsideColor.comment": "启用方块轮廓颜色覆写.", "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayFill.name": "自定义方块碰撞箱覆盖填充", "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayFill.comment": "启用指向方块碰撞箱的覆盖层填充.", + "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayOutline.name": "自定义方块碰撞箱覆盖轮廓", + "tweakmyclient.config.feature.featureCustomBlockHitBoxOverlayOutline.comment": "启用指向方块碰撞箱的覆盖层轮廓.", "tweakmyclient.config.feature.featureCustomGuiBackgroundColor.name": "自定义界面背景颜色", "tweakmyclient.config.feature.featureCustomGuiBackgroundColor.comment": "启用计分板界面背景色覆写.", "tweakmyclient.config.feature.featureCustomSidebarBackgroundColor.name": "自定义计分板背景颜色", @@ -111,6 +111,10 @@ "tweakmyclient.config.generic.customBlockHitBoxOverlayFillRainbowSpeed.comment": "自定义方块碰撞箱覆盖填充彩虹色滚动速度.", "tweakmyclient.config.generic.customBlockHitBoxOverlayLinkedAdapter.name": "自定义方块碰撞箱覆盖连接体方块适配", "tweakmyclient.config.generic.customBlockHitBoxOverlayLinkedAdapter.comment": "启用 自定义方块碰撞箱覆盖 对连接体方块的优化.", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbow.name": "自定义方块碰撞箱覆盖描边彩虹色", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbow.comment": "自定义方块碰撞箱覆盖轮廓 将启用彩虹变色, 使用 方块碰撞箱覆盖轮廓颜色 提供的透明度.", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbowSpeed.name": "自定义方块碰撞箱覆盖轮廓彩虹速率", + "tweakmyclient.config.generic.customBlockHitBoxOverlayOutlineRainbowSpeed.comment": "自定义方块碰撞箱覆盖轮廓彩虹色滚动速度.", "tweakmyclient.config.generic.customWindowTitle.name": "自定义窗口标题", "tweakmyclient.config.generic.customWindowTitle.comment": "修改当前窗口标题.\n可用的占位符如下:\n{fabric_loader_asm_version}\n{fabric_loader_version}\n{fabric_mod_ver:}\n{mc_fps}\n{mc_protocol_version}\n{mc_username}\n{mc_version}\n{tmc_version}\n{tmc_version_type}", "tweakmyclient.config.generic.customWindowTitleWithActivity.name": "自定义带当前活动的窗口标题",