Skip to content

Commit

Permalink
New features & bug fixes.
Browse files Browse the repository at this point in the history
- Move `featureCustomBlockOutsideColor` to `featureCustomBlockHitBoxOverlayOutline`
- Fix a crash when the game is not installed with any auth mods
  • Loading branch information
Hendrix-Shen committed May 21, 2022
1 parent c60d5a5 commit 42f33f6
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 180 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ archives_base_name=TweakMyClient
loader_version=0.13.3

# Required Libraries
# MagicLib - 0.5.25
magiclib_version=0.5.25
# MagicLib - 0.5.27
magiclib_version=0.5.27
19 changes: 13 additions & 6 deletions src/main/java/top/hendrixshen/tweakmyclient/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
}
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/top/hendrixshen/tweakmyclient/util/MiscUtil.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 42f33f6

Please sign in to comment.