From a0c41b1540af98cd680ae6072a174f744196600a Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sat, 11 Nov 2023 19:23:47 +0100 Subject: [PATCH] i hope this works enough to play with --- .../java/de/cscherr/mcpht/MCPHTClient.java | 1 - src/client/java/de/cscherr/mcpht/XRay.java | 9 ++++--- .../de/cscherr/mcpht/config/MCPHTConfig.java | 24 ++++++++--------- .../{BlockMixin.java => MixinBlock.java} | 24 ++++++++--------- .../client/MixinBlockOcclusionCache.java | 23 ++++++++++++++++ .../client/MixinLightmapTextureManager.java | 26 +++++++++++++++++++ .../mixin/client/MixinMinecraftClient.java | 19 ++++++++++++++ ...gMixin.java => MixinNetworkPacketLog.java} | 5 +--- src/client/resources/mcpht.client.mixins.json | 23 +++++++++------- src/client/resources/mcpht.sodium.mixins.json | 16 ++++++++++++ .../resources/assets/mcpht/lang/en_us.json | 6 ++++- src/main/resources/fabric.mod.json | 4 +++ 12 files changed, 134 insertions(+), 46 deletions(-) rename src/client/java/de/cscherr/mcpht/mixin/client/{BlockMixin.java => MixinBlock.java} (66%) create mode 100644 src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java create mode 100644 src/client/java/de/cscherr/mcpht/mixin/client/MixinLightmapTextureManager.java create mode 100644 src/client/java/de/cscherr/mcpht/mixin/client/MixinMinecraftClient.java rename src/client/java/de/cscherr/mcpht/mixin/client/{NetworkPacketLogMixin.java => MixinNetworkPacketLog.java} (96%) create mode 100644 src/client/resources/mcpht.sodium.mixins.json diff --git a/src/client/java/de/cscherr/mcpht/MCPHTClient.java b/src/client/java/de/cscherr/mcpht/MCPHTClient.java index 90b561b..09d2259 100644 --- a/src/client/java/de/cscherr/mcpht/MCPHTClient.java +++ b/src/client/java/de/cscherr/mcpht/MCPHTClient.java @@ -12,7 +12,6 @@ import java.util.regex.Pattern; public class MCPHTClient implements ClientModInitializer { public static final String MOD_ID = "mcpht"; - public static final String VERSION_NUMBER = "0.0.1"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static MCPHTConfig CONFIG; public static XRay XRAY; diff --git a/src/client/java/de/cscherr/mcpht/XRay.java b/src/client/java/de/cscherr/mcpht/XRay.java index bb02344..aa05221 100644 --- a/src/client/java/de/cscherr/mcpht/XRay.java +++ b/src/client/java/de/cscherr/mcpht/XRay.java @@ -7,16 +7,14 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; -import net.minecraft.fluid.Fluid; import org.lwjgl.glfw.GLFW; import java.util.ArrayList; -import java.util.Collection; import java.util.List; public class XRay { public boolean enable = true; - public ArrayList whitelistBlocks = new ArrayList( + public ArrayList whitelistBlocks = new ArrayList<>( List.of( // Ores Blocks.COAL_ORE, @@ -82,7 +80,6 @@ public class XRay { Blocks.RED_SHULKER_BOX ) ); - public ArrayList whitelistFluids; private static KeyBinding toggleKey; public void init() { @@ -105,4 +102,8 @@ public class XRay { public boolean showRenderBlock(BlockState state) { return whitelistBlocks.contains(state.getBlock()); } + + public boolean getEnable() { + return enable && MCPHTClient.CONFIG.xRay.enable; + } } \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java b/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java index d8912fd..70953a0 100644 --- a/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java +++ b/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java @@ -1,14 +1,10 @@ package de.cscherr.mcpht.config; import de.cscherr.mcpht.MCPHTClient; -import de.cscherr.mcpht.mixin.client.NetworkPacketLogMixin; import me.shedaniel.autoconfig.ConfigData; import me.shedaniel.autoconfig.annotation.Config; import me.shedaniel.autoconfig.annotation.ConfigEntry; -import net.minecraft.block.Block; -import net.minecraft.block.RedstoneBlock; -import java.util.ArrayList; import java.util.regex.Pattern; @Config(name = "mcphtconf") @@ -26,15 +22,16 @@ public class MCPHTConfig implements ConfigData { logSettings(); } public void logSettings() { - MCPHTClient.LOGGER.info(String.format("CONFIG: \n" + - "NetworkLogging\n" + - " RX: %b\n" + - " TX: %b\n" + - " verbosity: %s\n" + - " regex: '%s'\n" + - " filter: %s\n" + - "Rendering\n" + - " enabled: %b", + MCPHTClient.LOGGER.info(String.format(""" + CONFIG:\s + NetworkLogging + RX: %b + TX: %b + verbosity: %s + regex: '%s' + filter: %s + Rendering + enabled: %b""", MCPHTClient.CONFIG.networkLogging.RX, MCPHTClient.CONFIG.networkLogging.TX, MCPHTClient.CONFIG.networkLogging.verbosity, @@ -70,5 +67,6 @@ public class MCPHTConfig implements ConfigData { // TODO: toggle with hotkey public static class XRayScheme { public boolean enable = false; + public boolean overwriteBrightness; } } diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/BlockMixin.java b/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlock.java similarity index 66% rename from src/client/java/de/cscherr/mcpht/mixin/client/BlockMixin.java rename to src/client/java/de/cscherr/mcpht/mixin/client/MixinBlock.java index b937201..cee3a27 100644 --- a/src/client/java/de/cscherr/mcpht/mixin/client/BlockMixin.java +++ b/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlock.java @@ -1,27 +1,25 @@ package de.cscherr.mcpht.mixin.client; import de.cscherr.mcpht.MCPHTClient; -import de.cscherr.mcpht.XRay; -import net.minecraft.util.Identifier; -import org.slf4j.Logger; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.BlockView; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Block.class) -public abstract class BlockMixin { - @Shadow @Final private static Logger LOGGER; - - @Inject(method = "shouldDrawSide", at = @At("RETURN"), cancellable = true) +public abstract class MixinBlock { + @Inject(at = @At("RETURN"), method = "shouldDrawSide(" + "Lnet/minecraft/block/BlockState;" + // state + "Lnet/minecraft/world/BlockView;" + // reader + "Lnet/minecraft/util/math/BlockPos;" + // pos + "Lnet/minecraft/util/math/Direction;" + // face + "Lnet/minecraft/util/math/BlockPos;" + // blockPos + ")Z", // ci + cancellable = true) private static void shouldDrawSide(BlockState state, BlockView world, BlockPos pos, @@ -29,8 +27,8 @@ public abstract class BlockMixin { BlockPos otherPos, CallbackInfoReturnable cir ) { - if (MCPHTClient.XRAY.enable && MCPHTClient.CONFIG.xRay.enable) { + if (MCPHTClient.XRAY.getEnable()) { cir.setReturnValue(MCPHTClient.XRAY.showRenderBlock(state)); } } -} +} \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java b/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java new file mode 100644 index 0000000..f4a6fd4 --- /dev/null +++ b/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java @@ -0,0 +1,23 @@ +package de.cscherr.mcpht.mixin.client; + +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockView; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Pseudo +@Mixin(targets = "me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache") +/** + * Fix for sodium, so that it doesn't break xray. + */ +public class MixinBlockOcclusionCache { + @Inject(at = @At("HEAD"), method = "shouldDrawSide", cancellable = true, remap = false) + private void shouldDrawSide(BlockState state, BlockView reader, BlockPos pos, Direction face, + CallbackInfoReturnable ci) { + } +} \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/MixinLightmapTextureManager.java b/src/client/java/de/cscherr/mcpht/mixin/client/MixinLightmapTextureManager.java new file mode 100644 index 0000000..d5c2be7 --- /dev/null +++ b/src/client/java/de/cscherr/mcpht/mixin/client/MixinLightmapTextureManager.java @@ -0,0 +1,26 @@ +package de.cscherr.mcpht.mixin.client; + +import de.cscherr.mcpht.MCPHTClient; +import net.minecraft.client.option.GameOptions; +import net.minecraft.client.option.SimpleOption; +import net.minecraft.text.Text; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(net.minecraft.client.render.LightmapTextureManager.class) +public class MixinLightmapTextureManager { + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/GameOptions;getGamma()Lnet/minecraft/client/option/SimpleOption;", opcode = Opcodes.INVOKEVIRTUAL), method = "update(F)V") + private SimpleOption getFieldValue(GameOptions options) { + // full brightness if xray is on with overwriteBrightness + if (MCPHTClient.CONFIG.xRay.overwriteBrightness && MCPHTClient.XRAY.getEnable()) { + return new SimpleOption<>("options.gamma", SimpleOption.emptyTooltip(), (optionText, value) -> Text.empty(), SimpleOption.DoubleSliderCallbacks.INSTANCE.withModifier( + d -> (double) 20f, d -> 1 + ), 0.5, value -> { + }); + } else { + return options.getGamma(); + } + } +} diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/MixinMinecraftClient.java b/src/client/java/de/cscherr/mcpht/mixin/client/MixinMinecraftClient.java new file mode 100644 index 0000000..7c3e238 --- /dev/null +++ b/src/client/java/de/cscherr/mcpht/mixin/client/MixinMinecraftClient.java @@ -0,0 +1,19 @@ +package de.cscherr.mcpht.mixin.client; + +import de.cscherr.mcpht.MCPHTClient; +import net.minecraft.client.MinecraftClient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(MinecraftClient.class) +public class MixinMinecraftClient { + @Inject(at = @At(value = "HEAD"), method = "isAmbientOcclusionEnabled()Z", cancellable = true) + private static void isAmbientOcclusionEnabled(CallbackInfoReturnable ci) { + if (MCPHTClient.XRAY.getEnable() && MCPHTClient.CONFIG.xRay.overwriteBrightness) { + ci.setReturnValue(false); + ci.cancel(); + } + } +} \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/NetworkPacketLogMixin.java b/src/client/java/de/cscherr/mcpht/mixin/client/MixinNetworkPacketLog.java similarity index 96% rename from src/client/java/de/cscherr/mcpht/mixin/client/NetworkPacketLogMixin.java rename to src/client/java/de/cscherr/mcpht/mixin/client/MixinNetworkPacketLog.java index 53af2a2..f6620f2 100644 --- a/src/client/java/de/cscherr/mcpht/mixin/client/NetworkPacketLogMixin.java +++ b/src/client/java/de/cscherr/mcpht/mixin/client/MixinNetworkPacketLog.java @@ -1,7 +1,6 @@ package de.cscherr.mcpht.mixin.client; import de.cscherr.mcpht.MCPHTClient; -import de.cscherr.mcpht.config.MCPHTConfig; import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import org.slf4j.Logger; @@ -15,10 +14,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.jetbrains.annotations.Nullable; -import java.util.regex.Pattern; - @Mixin(ClientConnection.class) -public class NetworkPacketLogMixin { +public class MixinNetworkPacketLog { private static boolean filterPacket(Packet packet) { return MCPHTClient.networkPacketFilter.matcher(packet.getClass().getSimpleName()).find(); } diff --git a/src/client/resources/mcpht.client.mixins.json b/src/client/resources/mcpht.client.mixins.json index 80f54b4..e745139 100644 --- a/src/client/resources/mcpht.client.mixins.json +++ b/src/client/resources/mcpht.client.mixins.json @@ -1,12 +1,15 @@ { - "required": true, - "package": "de.cscherr.mcpht.mixin.client", - "compatibilityLevel": "JAVA_17", - "client": [ - "NetworkPacketLogMixin", - "BlockMixin" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "package": "de.cscherr.mcpht.mixin.client", + "compatibilityLevel": "JAVA_17", + "client": [ + "MixinBlock", + "MixinNetworkPacketLog", + "MixinBlockOcclusionCache", + "MixinLightmapTextureManager", + "MixinMinecraftClient" + ], + "injectors": { + "defaultRequire": 1 + } } \ No newline at end of file diff --git a/src/client/resources/mcpht.sodium.mixins.json b/src/client/resources/mcpht.sodium.mixins.json new file mode 100644 index 0000000..5f36411 --- /dev/null +++ b/src/client/resources/mcpht.sodium.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "de.cscherr.mcpht.mixin.client", + "compatibilityLevel": "JAVA_8", + "mixins": [], + "client": [ + "MixinBlock", + "MixinBlockOcclusionCache", + "MixinMinecraftClient", + "MixinLightmapTextureManager" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/mcpht/lang/en_us.json b/src/main/resources/assets/mcpht/lang/en_us.json index 2e74985..9cf3833 100644 --- a/src/main/resources/assets/mcpht/lang/en_us.json +++ b/src/main/resources/assets/mcpht/lang/en_us.json @@ -7,7 +7,11 @@ "text.autoconfig.mcphtconf.option.xRay": "XRay", "text.autoconfig.mcphtconf.option.xRay.enable": "enable", + "text.autoconfig.mcphtconf.option.xRay.overwriteBrightness": "overwrite Brightness", "text.autoconfig.mcphtconf.category.Networking": "Networking", - "text.autoconfig.mcphtconf.category.Rendering": "Rendering" + "text.autoconfig.mcphtconf.category.Rendering": "Rendering", + + "key.mcpht.toggleXray": "XRay toggle", + "category.mcpht.rendering": "MCPHT-Rendering" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b79686e..61f94c9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -35,6 +35,10 @@ { "config": "mcpht.client.mixins.json", "environment": "client" + }, + { + "config": "mcpht.sodium.mixins.json", + "environment": "client" } ], "depends": {