Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
14 678
src/client/java/dev/kodari/blockveil/BlockVeilClient.java
package dev.kodari.blockveil;
import dev.isxander.yacl3.api.ButtonOption;
import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.OptionGroup;
import dev.isxander.yacl3.api.YetAnotherConfigLib;
import dev.isxander.yacl3.api.controller.StringControllerBuilder;
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.source.BiomeAccess;
import dev.kodari.blockveil.mixin.BiomeAccessAccessor;
import org.lwjgl.glfw.GLFW;
public final class BlockVeilClient implements ClientModInitializer {
public static final String MOD_ID = "blockveil";
public static final VisibilityConfig CONFIG = new VisibilityConfig();
private static final KeyBinding.Category KEY_CATEGORY = KeyBinding.Category.create(Identifier.of(MOD_ID, "controls"));
public static KeyBinding TOGGLE_KEY;
public static KeyBinding SETTINGS_KEY;
private static volatile boolean renderActive;
@Override
public void onInitializeClient() {
CONFIG.load();
TOGGLE_KEY = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.blockveil.toggle_visibility", CONFIG.toggleKeyCode, KEY_CATEGORY));
SETTINGS_KEY = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.blockveil.open_settings", CONFIG.settingsKeyCode, KEY_CATEGORY));
ClientTickEvents.END_CLIENT_TICK.register(BlockVeilClient::tick);
}
public static boolean isXrayActive() {
return renderActive;
}
public static void refreshRendering(MinecraftClient client) {
renderActive = shouldBeActive(client);
if (client.world != null) {
client.worldRenderer.reload();
}
}
private static void tick(MinecraftClient client) {
boolean activeBeforeTick = renderActive;
renderActive = shouldBeActive(client);
if (activeBeforeTick != renderActive && client.world != null) {
client.worldRenderer.reload();
}
if (TOGGLE_KEY.wasPressed()) {
CONFIG.enabled = !CONFIG.enabled;
CONFIG.save();
refreshRendering(client);
}
if (SETTINGS_KEY.wasPressed()) {
client.setScreen(createSettingsScreen(client, null));
}
}
private static boolean shouldBeActive(MinecraftClient client) {
if (!CONFIG.enabled) {
return false;
}
String seedText = CONFIG.seed.trim();
if (seedText.isEmpty()) {
return true;
}
if (client.world == null) {
return false;
}
try {
long expectedSeed = BiomeAccess.hashSeed(Long.parseLong(seedText));
long worldSeed = ((BiomeAccessAccessor) (Object) client.world.getBiomeAccess()).blockveil$getSeed();
return expectedSeed == worldSeed;
} catch (NumberFormatException exception) {
return false;
}
}
private static Screen createSettingsScreen(MinecraftClient client, Screen parent) {
return YetAnotherConfigLib.createBuilder()
.title(net.minecraft.text.Text.literal("Block Veil Settings"))
.category(ConfigCategory.createBuilder()
.name(net.minecraft.text.Text.literal("Visibility"))
.group(OptionGroup.createBuilder()
.name(net.minecraft.text.Text.literal("World and controls"))
.option(Option.<Boolean>createBuilder()
.name(net.minecraft.text.Text.literal("Enable Block Veil"))
.description(OptionDescription.of(net.minecraft.text.Text.literal(
"Show non-selected blocks translucently. The visibility key also toggles this.")))
.binding(CONFIG.enabled, () -> CONFIG.enabled, value -> {
if (CONFIG.enabled != value) {
CONFIG.enabled = value;
CONFIG.save();
refreshRendering(client);
}
})
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.<String>createBuilder()
.name(net.minecraft.text.Text.literal("World seed (optional)"))
.description(OptionDescription.of(net.minecraft.text.Text.literal(
"Only activate in the matching world. Leave blank for any world.")))
.binding(CONFIG.seed, () -> CONFIG.seed, value -> {
if (!CONFIG.seed.equals(value)) {
CONFIG.seed = value;
CONFIG.save();
refreshRendering(client);
}
})
.controller(StringControllerBuilder::create)
.build())
.option(ButtonOption.createBuilder()
.name(net.minecraft.text.Text.literal("Choose opaque blocks and keys"))
.description(OptionDescription.of(net.minecraft.text.Text.literal(
"Select blocks that stay opaque and customize both key bindings.")))
.action((screen, buttonOption) -> client.setScreen(new BlockSelectionScreen(screen)))
.build())
.build())
.build())
.build()
.generateScreen(parent);
}
}