xray works better

This commit is contained in:
Christoph J. Scherr 2023-11-11 15:07:11 +01:00
parent e7542418f3
commit 8b17944b74
3 changed files with 98 additions and 70 deletions

View File

@ -4,6 +4,7 @@ import de.cscherr.mcpht.config.MCPHTConfig;
import me.shedaniel.autoconfig.AutoConfig;
import net.fabricmc.api.ClientModInitializer;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import net.minecraft.client.MinecraftClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,9 +17,11 @@ public class MCPHTClient implements ClientModInitializer {
public static MCPHTConfig CONFIG;
public static XRay XRAY;
public static Pattern networkPacketFilter;
public static MinecraftClient MC;
@Override
public void onInitializeClient() {
MC = MinecraftClient.getInstance();
AutoConfig.register(MCPHTConfig.class, JanksonConfigSerializer::new);
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
CONFIG = AutoConfig.getConfigHolder(MCPHTConfig.class).getConfig();
@ -34,7 +37,7 @@ public class MCPHTClient implements ClientModInitializer {
});
CONFIG.onLoad();
XRAY = new XRay();
XRAY.load();
XRAY.init();
LOGGER.info("Init client!");
}
}

View File

@ -1,9 +1,14 @@
package de.cscherr.mcpht;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.block.Block;
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;
@ -11,78 +16,93 @@ import java.util.List;
public class XRay {
public boolean enable = true;
public ArrayList<Block> whitelistBlocks;
public ArrayList<Block> 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,
Blocks.ANCIENT_DEBRIS,
// 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,
Blocks.SPAWNER,
// 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
)
);
public ArrayList<Fluid> whitelistFluids;
private static KeyBinding toggleKey;
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,
Blocks.ANCIENT_DEBRIS,
// 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,
Blocks.SPAWNER,
// 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
)
);
public void init() {
toggleKey = KeyBindingHelper.registerKeyBinding( new KeyBinding(
"key.mcpht.toggleXray", // Translation of name
InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard)
GLFW.GLFW_KEY_R, // The keycode of the key (default?)
"category.mcpht.rendering" // Translation key for the keybinding category
));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
// NOTE: IDK why we need a while here
while (toggleKey.wasPressed()) {
MCPHTClient.LOGGER.info(String.format("toggle XRay: %s", MCPHTClient.XRAY.enable));
MCPHTClient.XRAY.enable = !MCPHTClient.XRAY.enable;
MCPHTClient.MC.worldRenderer.reload();
}
});
}
public boolean showRenderBlock(BlockState state) {
return whitelistBlocks.contains(state.getBlock());
}
}
}

View File

@ -3,6 +3,8 @@ 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;
@ -10,12 +12,15 @@ 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.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)
private static void shouldDrawSide(BlockState state,
BlockView world,