xray works better
This commit is contained in:
parent
e7542418f3
commit
8b17944b74
|
@ -4,6 +4,7 @@ import de.cscherr.mcpht.config.MCPHTConfig;
|
||||||
import me.shedaniel.autoconfig.AutoConfig;
|
import me.shedaniel.autoconfig.AutoConfig;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
|
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -16,9 +17,11 @@ public class MCPHTClient implements ClientModInitializer {
|
||||||
public static MCPHTConfig CONFIG;
|
public static MCPHTConfig CONFIG;
|
||||||
public static XRay XRAY;
|
public static XRay XRAY;
|
||||||
public static Pattern networkPacketFilter;
|
public static Pattern networkPacketFilter;
|
||||||
|
public static MinecraftClient MC;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
|
MC = MinecraftClient.getInstance();
|
||||||
AutoConfig.register(MCPHTConfig.class, JanksonConfigSerializer::new);
|
AutoConfig.register(MCPHTConfig.class, JanksonConfigSerializer::new);
|
||||||
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
||||||
CONFIG = AutoConfig.getConfigHolder(MCPHTConfig.class).getConfig();
|
CONFIG = AutoConfig.getConfigHolder(MCPHTConfig.class).getConfig();
|
||||||
|
@ -34,7 +37,7 @@ public class MCPHTClient implements ClientModInitializer {
|
||||||
});
|
});
|
||||||
CONFIG.onLoad();
|
CONFIG.onLoad();
|
||||||
XRAY = new XRay();
|
XRAY = new XRay();
|
||||||
XRAY.load();
|
XRAY.init();
|
||||||
LOGGER.info("Init client!");
|
LOGGER.info("Init client!");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,14 @@
|
||||||
package de.cscherr.mcpht;
|
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.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.client.option.KeyBinding;
|
||||||
|
import net.minecraft.client.util.InputUtil;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -11,77 +16,92 @@ import java.util.List;
|
||||||
|
|
||||||
public class XRay {
|
public class XRay {
|
||||||
public boolean enable = true;
|
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;
|
public ArrayList<Fluid> whitelistFluids;
|
||||||
|
private static KeyBinding toggleKey;
|
||||||
|
|
||||||
public void load() {
|
public void init() {
|
||||||
whitelistBlocks = new ArrayList<Block>(
|
toggleKey = KeyBindingHelper.registerKeyBinding( new KeyBinding(
|
||||||
List.of(
|
"key.mcpht.toggleXray", // Translation of name
|
||||||
// Ores
|
InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard)
|
||||||
Blocks.COAL_ORE,
|
GLFW.GLFW_KEY_R, // The keycode of the key (default?)
|
||||||
Blocks.COPPER_ORE,
|
"category.mcpht.rendering" // Translation key for the keybinding category
|
||||||
Blocks.IRON_ORE,
|
));
|
||||||
Blocks.GOLD_ORE,
|
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||||
Blocks.LAPIS_ORE,
|
// NOTE: IDK why we need a while here
|
||||||
Blocks.DIAMOND_ORE,
|
while (toggleKey.wasPressed()) {
|
||||||
Blocks.EMERALD_ORE,
|
MCPHTClient.LOGGER.info(String.format("toggle XRay: %s", MCPHTClient.XRAY.enable));
|
||||||
Blocks.REDSTONE_ORE,
|
MCPHTClient.XRAY.enable = !MCPHTClient.XRAY.enable;
|
||||||
Blocks.ANCIENT_DEBRIS,
|
MCPHTClient.MC.worldRenderer.reload();
|
||||||
|
}
|
||||||
// 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 boolean showRenderBlock(BlockState state) {
|
public boolean showRenderBlock(BlockState state) {
|
||||||
return whitelistBlocks.contains(state.getBlock());
|
return whitelistBlocks.contains(state.getBlock());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package de.cscherr.mcpht.mixin.client;
|
||||||
import de.cscherr.mcpht.MCPHTClient;
|
import de.cscherr.mcpht.MCPHTClient;
|
||||||
import de.cscherr.mcpht.XRay;
|
import de.cscherr.mcpht.XRay;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(Block.class)
|
@Mixin(Block.class)
|
||||||
public abstract class BlockMixin {
|
public abstract class BlockMixin {
|
||||||
|
@Shadow @Final private static Logger LOGGER;
|
||||||
|
|
||||||
@Inject(method = "shouldDrawSide", at = @At("RETURN"), cancellable = true)
|
@Inject(method = "shouldDrawSide", at = @At("RETURN"), cancellable = true)
|
||||||
private static void shouldDrawSide(BlockState state,
|
private static void shouldDrawSide(BlockState state,
|
||||||
BlockView world,
|
BlockView world,
|
||||||
|
|
Loading…
Reference in New Issue