diff --git a/src/client/java/de/cscherr/mcpht/MCPHTClient.java b/src/client/java/de/cscherr/mcpht/MCPHTClient.java index 04b1655..f64a557 100644 --- a/src/client/java/de/cscherr/mcpht/MCPHTClient.java +++ b/src/client/java/de/cscherr/mcpht/MCPHTClient.java @@ -14,6 +14,7 @@ public class MCPHTClient implements ClientModInitializer { 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; public static Pattern networkPacketFilter; @Override @@ -32,6 +33,8 @@ public class MCPHTClient implements ClientModInitializer { return null; }); CONFIG.onLoad(); + XRAY = new XRay(); + XRAY.load(); LOGGER.info("Init client!"); } } \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/XRay.java b/src/client/java/de/cscherr/mcpht/XRay.java new file mode 100644 index 0000000..7b4fd60 --- /dev/null +++ b/src/client/java/de/cscherr/mcpht/XRay.java @@ -0,0 +1,82 @@ +package de.cscherr.mcpht; + +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.fluid.Fluid; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class XRay { + public boolean enable = false; + public ArrayList whitelistBlocks; + public ArrayList whitelistFluids; + + public void load() { + whitelistBlocks = new ArrayList( + List.of( + // Ores + Blocks.COAL_ORE, + Blocks.COPPER_ORE, + Blocks.IRON_ORE, + Blocks.GOLD_ORE, + Blocks.LAPIS_ORE, + Blocks.DIAMOND_ORE, + Blocks.EMERALD_ORE, + Blocks.REDSTONE_ORE, + + // Deepslate Ores + Blocks.DEEPSLATE_COAL_ORE, + Blocks.DEEPSLATE_COPPER_ORE, + Blocks.DEEPSLATE_IRON_ORE, + Blocks.DEEPSLATE_GOLD_ORE, + Blocks.DEEPSLATE_LAPIS_ORE, + Blocks.DEEPSLATE_DIAMOND_ORE, + Blocks.DEEPSLATE_EMERALD_ORE, + Blocks.DEEPSLATE_REDSTONE_ORE, + + // Resource Blocks + Blocks.COAL_BLOCK, + Blocks.COPPER_BLOCK, + Blocks.IRON_BLOCK, + Blocks.GOLD_BLOCK, + Blocks.LAPIS_BLOCK, + Blocks.DIAMOND_BLOCK, + Blocks.REDSTONE_BLOCK, + + // Crafting stuff + Blocks.CHEST, + Blocks.ENDER_CHEST, + Blocks.TRAPPED_CHEST, + Blocks.ENCHANTING_TABLE, + Blocks.FURNACE, + Blocks.BLAST_FURNACE, + Blocks.ANVIL, + Blocks.HOPPER, + Blocks.BEACON, + + // Danger + Blocks.TNT, + + // Shulker Boxes + // FIXME: Add the ones I forgot + Blocks.SHULKER_BOX, + Blocks.GREEN_SHULKER_BOX, + Blocks.YELLOW_SHULKER_BOX, + Blocks.BLACK_SHULKER_BOX, + Blocks.BLUE_SHULKER_BOX, + Blocks.BROWN_SHULKER_BOX, + Blocks.CYAN_SHULKER_BOX, + Blocks.GRAY_SHULKER_BOX, + Blocks.LIGHT_BLUE_SHULKER_BOX, + Blocks.LIGHT_GRAY_SHULKER_BOX, + Blocks.LIME_SHULKER_BOX, + Blocks.ORANGE_SHULKER_BOX, + Blocks.PINK_SHULKER_BOX, + Blocks.WHITE_SHULKER_BOX, + Blocks.RED_SHULKER_BOX + ) + ); + } +} diff --git a/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java b/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java index 2920c3c..d8912fd 100644 --- a/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java +++ b/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java @@ -5,63 +5,70 @@ 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") public class MCPHTConfig implements ConfigData { - @ConfigEntry.Category("Networking") - @ConfigEntry.Gui.CollapsibleObject - public NetworkLoggingScheme networkLogging = new NetworkLoggingScheme(); - public void onSave() { MCPHTClient.LOGGER.info("saving and processing configs"); MCPHTClient.networkPacketFilter = compileFilter(); logSettings(); } - public void onLoad() { MCPHTClient.LOGGER.info("loading configs"); MCPHTClient.networkPacketFilter = compileFilter(); logSettings(); } - - private Pattern compileFilter() { - try { - return Pattern.compile(this.networkLogging.regex); - } - catch (Exception e) { - MCPHTClient.LOGGER.warn(String.format("Invalid regex: %s", this.networkLogging.regex)); - return Pattern.compile(".*"); // just accept all on error - } - } - 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", + "NetworkLogging\n" + + " RX: %b\n" + + " TX: %b\n" + + " verbosity: %s\n" + + " regex: '%s'\n" + + " filter: %s\n" + + "Rendering\n" + + " enabled: %b", MCPHTClient.CONFIG.networkLogging.RX, MCPHTClient.CONFIG.networkLogging.TX, MCPHTClient.CONFIG.networkLogging.verbosity, MCPHTClient.CONFIG.networkLogging.regex, - MCPHTClient.networkPacketFilter + MCPHTClient.networkPacketFilter, + + MCPHTClient.CONFIG.xRay.enable )); } - + private Pattern compileFilter() { + try { + return Pattern.compile(this.networkLogging.regex); + } catch (Exception e) { + MCPHTClient.LOGGER.warn(String.format("Invalid regex: %s", this.networkLogging.regex)); + return Pattern.compile(".*"); // just accept all on error + } + } public static class NetworkLoggingScheme { public boolean RX = false; public boolean TX = false; public NetworkPacketVerbosity verbosity = NetworkPacketVerbosity.NAME; public String regex = ".*"; - public enum NetworkPacketVerbosity { ALL, NAME } } + @ConfigEntry.Category("Networking") + @ConfigEntry.Gui.CollapsibleObject + public NetworkLoggingScheme networkLogging = new NetworkLoggingScheme(); + @ConfigEntry.Category("Rendering") + @ConfigEntry.Gui.CollapsibleObject + public XRayScheme xRay = new XRayScheme(); + // TODO: toggle with hotkey + public static class XRayScheme { + public boolean enable = false; + } } diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/BlockMixin.java b/src/client/java/de/cscherr/mcpht/mixin/client/BlockMixin.java new file mode 100644 index 0000000..4069690 --- /dev/null +++ b/src/client/java/de/cscherr/mcpht/mixin/client/BlockMixin.java @@ -0,0 +1,34 @@ +package de.cscherr.mcpht.mixin.client; + +import de.cscherr.mcpht.MCPHTClient; +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.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = Block.class) +public abstract class BlockMixin { + @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;" + // blockPosaaa + ")Z", // ci + cancellable = true) + private static void shouldDrawSide(BlockState state, BlockView reader, BlockPos pos, Direction face, + BlockPos blockPos, CallbackInfoReturnable ci) { + if (MCPHTClient.CONFIG.xRay.enable) { + if (MCPHTClient.XRAY.whitelistBlocks.contains(state.getBlock())) { + ci.setReturnValue(true); + } else { + ci.setReturnValue(false); + } + } + } +} diff --git a/src/client/resources/mcpht.client.mixins.json b/src/client/resources/mcpht.client.mixins.json index b3096c7..80f54b4 100644 --- a/src/client/resources/mcpht.client.mixins.json +++ b/src/client/resources/mcpht.client.mixins.json @@ -3,7 +3,8 @@ "package": "de.cscherr.mcpht.mixin.client", "compatibilityLevel": "JAVA_17", "client": [ - "NetworkPacketLogMixin" + "NetworkPacketLogMixin", + "BlockMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/assets/mcpht/lang/en_us.json b/src/main/resources/assets/mcpht/lang/en_us.json index 46866a5..2e74985 100644 --- a/src/main/resources/assets/mcpht/lang/en_us.json +++ b/src/main/resources/assets/mcpht/lang/en_us.json @@ -3,5 +3,11 @@ "text.autoconfig.mcphtconf.option.networkLogging.RX": "RX", "text.autoconfig.mcphtconf.option.networkLogging.TX": "TX", "text.autoconfig.mcphtconf.option.networkLogging.regex": "Regex Filter", - "text.autoconfig.mcphtconf.option.networkLogging.verbosity": "Log verbosity" + "text.autoconfig.mcphtconf.option.networkLogging.verbosity": "Log verbosity", + + "text.autoconfig.mcphtconf.option.xRay": "XRay", + "text.autoconfig.mcphtconf.option.xRay.enable": "enable", + + "text.autoconfig.mcphtconf.category.Networking": "Networking", + "text.autoconfig.mcphtconf.category.Rendering": "Rendering" } \ No newline at end of file