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,11 +16,7 @@ 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>(
|
||||||
public ArrayList<Fluid> whitelistFluids;
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
whitelistBlocks = new ArrayList<Block>(
|
|
||||||
List.of(
|
List.of(
|
||||||
// Ores
|
// Ores
|
||||||
Blocks.COAL_ORE,
|
Blocks.COAL_ORE,
|
||||||
|
@ -81,7 +82,26 @@ public class XRay {
|
||||||
Blocks.RED_SHULKER_BOX
|
Blocks.RED_SHULKER_BOX
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
public ArrayList<Fluid> whitelistFluids;
|
||||||
|
private static KeyBinding toggleKey;
|
||||||
|
|
||||||
|
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) {
|
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