some xray stuff

This commit is contained in:
Christoph J. Scherr 2023-11-11 00:50:04 +01:00
parent 21eca17e31
commit 1f625f795c
6 changed files with 160 additions and 27 deletions

View File

@ -14,6 +14,7 @@ public class MCPHTClient implements ClientModInitializer {
public static final String VERSION_NUMBER = "0.0.1"; public static final String VERSION_NUMBER = "0.0.1";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static MCPHTConfig CONFIG; public static MCPHTConfig CONFIG;
public static XRay XRAY;
public static Pattern networkPacketFilter; public static Pattern networkPacketFilter;
@Override @Override
@ -32,6 +33,8 @@ public class MCPHTClient implements ClientModInitializer {
return null; return null;
}); });
CONFIG.onLoad(); CONFIG.onLoad();
XRAY = new XRay();
XRAY.load();
LOGGER.info("Init client!"); LOGGER.info("Init client!");
} }
} }

View File

@ -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<Block> whitelistBlocks;
public ArrayList<Fluid> whitelistFluids;
public void load() {
whitelistBlocks = new ArrayList<Block>(
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
)
);
}
}

View File

@ -5,39 +5,26 @@ import de.cscherr.mcpht.mixin.client.NetworkPacketLogMixin;
import me.shedaniel.autoconfig.ConfigData; import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config; import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry; 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; import java.util.regex.Pattern;
@Config(name = "mcphtconf") @Config(name = "mcphtconf")
public class MCPHTConfig implements ConfigData { public class MCPHTConfig implements ConfigData {
@ConfigEntry.Category("Networking")
@ConfigEntry.Gui.CollapsibleObject
public NetworkLoggingScheme networkLogging = new NetworkLoggingScheme();
public void onSave() { public void onSave() {
MCPHTClient.LOGGER.info("saving and processing configs"); MCPHTClient.LOGGER.info("saving and processing configs");
MCPHTClient.networkPacketFilter = compileFilter(); MCPHTClient.networkPacketFilter = compileFilter();
logSettings(); logSettings();
} }
public void onLoad() { public void onLoad() {
MCPHTClient.LOGGER.info("loading configs"); MCPHTClient.LOGGER.info("loading configs");
MCPHTClient.networkPacketFilter = compileFilter(); MCPHTClient.networkPacketFilter = compileFilter();
logSettings(); 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() { public void logSettings() {
MCPHTClient.LOGGER.info(String.format("CONFIG: \n" + MCPHTClient.LOGGER.info(String.format("CONFIG: \n" +
"NetworkLogging\n" + "NetworkLogging\n" +
@ -45,23 +32,43 @@ public class MCPHTConfig implements ConfigData {
" TX: %b\n" + " TX: %b\n" +
" verbosity: %s\n" + " verbosity: %s\n" +
" regex: '%s'\n" + " regex: '%s'\n" +
" filter: %s", " filter: %s\n" +
"Rendering\n" +
" enabled: %b",
MCPHTClient.CONFIG.networkLogging.RX, MCPHTClient.CONFIG.networkLogging.RX,
MCPHTClient.CONFIG.networkLogging.TX, MCPHTClient.CONFIG.networkLogging.TX,
MCPHTClient.CONFIG.networkLogging.verbosity, MCPHTClient.CONFIG.networkLogging.verbosity,
MCPHTClient.CONFIG.networkLogging.regex, 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 static class NetworkLoggingScheme {
public boolean RX = false; public boolean RX = false;
public boolean TX = false; public boolean TX = false;
public NetworkPacketVerbosity verbosity = NetworkPacketVerbosity.NAME; public NetworkPacketVerbosity verbosity = NetworkPacketVerbosity.NAME;
public String regex = ".*"; public String regex = ".*";
public enum NetworkPacketVerbosity { public enum NetworkPacketVerbosity {
ALL, NAME 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;
}
} }

View File

@ -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;" + // blockPos
")Z", // ci
cancellable = true)
private static void shouldDrawSide(BlockState state, BlockView reader, BlockPos pos, Direction face,
BlockPos blockPos, CallbackInfoReturnable<Boolean> ci) {
if (MCPHTClient.CONFIG.xRay.enable) {
if (MCPHTClient.XRAY.whitelistBlocks.contains(state.getBlock())) {
ci.setReturnValue(true);
} else {
ci.setReturnValue(false);
}
}
}
}

View File

@ -3,7 +3,8 @@
"package": "de.cscherr.mcpht.mixin.client", "package": "de.cscherr.mcpht.mixin.client",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"client": [ "client": [
"NetworkPacketLogMixin" "NetworkPacketLogMixin",
"BlockMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

View File

@ -3,5 +3,11 @@
"text.autoconfig.mcphtconf.option.networkLogging.RX": "RX", "text.autoconfig.mcphtconf.option.networkLogging.RX": "RX",
"text.autoconfig.mcphtconf.option.networkLogging.TX": "TX", "text.autoconfig.mcphtconf.option.networkLogging.TX": "TX",
"text.autoconfig.mcphtconf.option.networkLogging.regex": "Regex Filter", "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"
} }