Skip to content

Commit

Permalink
navigation buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Apr 19, 2024
1 parent 3c3fdea commit c1ef24b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 33 deletions.
30 changes: 4 additions & 26 deletions src/main/java/dev/dfonline/codeclient/CodeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import dev.dfonline.codeclient.action.Action;
import dev.dfonline.codeclient.action.None;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.config.KeyBinds;
import dev.dfonline.codeclient.dev.BuildPhaser;
import dev.dfonline.codeclient.dev.Debug.Debug;
import dev.dfonline.codeclient.dev.LastPos;
import dev.dfonline.codeclient.dev.NoClip;
import dev.dfonline.codeclient.dev.RecentChestInsert;
import dev.dfonline.codeclient.dev.menu.DevInventory.DevInventoryScreen;
import dev.dfonline.codeclient.dev.overlay.ChestPeeker;
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
import dev.dfonline.codeclient.location.Dev;
Expand All @@ -28,18 +28,15 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,14 +47,7 @@ public class CodeClient implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
public static final Gson gson = new Gson();
public static MinecraftClient MC = MinecraftClient.getInstance();
/**
* Starts the "Code Palette" screen if pressed.
*/
public static KeyBinding editBind;
/**
* If in build mode, holding this will allow you to phase through blocks.
*/
public static KeyBinding clipBind;

public static AutoJoin autoJoin = AutoJoin.NONE;

/**
Expand Down Expand Up @@ -127,14 +117,12 @@ public static void onTick() {
BuildPhaser.tick();
ChestPeeker.tick();
RecentChestInsert.tick();
KeyBinds.tick();

if (location instanceof Dev dev) {
if (MC.player == null) return;
MC.player.getAbilities().allowFlying = true;
if (NoClip.isIgnoringWalls()) MC.player.noClip = true;
if (editBind.wasPressed()) {
MC.setScreen(new DevInventoryScreen(MC.player));
}
var pos = new BlockPos(dev.getX() - 1, 49, dev.getZ());
if (dev.getSize() == null) {
// TODO wait for plugin messages, or make a fix now.
Expand Down Expand Up @@ -218,17 +206,7 @@ public void onInitialize() {
autoJoin = AutoJoin.GAME;
}

editBind = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.codeclient.codepalette",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_Y,
"category.codeclient.dev"
));
clipBind = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.codeclient.phaser",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_V,
"category.codeclient.dev"
));
KeyBinds.init();

ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
Commands.register(dispatcher);
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/dev/dfonline/codeclient/config/KeyBinds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dev.dfonline.codeclient.config;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.dev.menu.DevInventory.DevInventoryScreen;
import dev.dfonline.codeclient.location.Dev;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.glfw.GLFW;

public class KeyBinds {
/**
* Starts the "Code Palette" screen if pressed.
*/
public static KeyBinding editBind;
/**
* If in build mode, holding this will allow you to phase through blocks.
*/
public static KeyBinding clipBind;

public static KeyBinding teleportLeft;
public static KeyBinding teleportRight;
public static KeyBinding teleportForward;
public static KeyBinding teleportBackward;

public static void init() {
editBind = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.codeclient.codepalette", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_Y, "category.codeclient.dev"));
clipBind = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.codeclient.phaser", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_V, "category.codeclient.dev"));

teleportLeft = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.codeclient.tp.left", InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), "category.codeclient.navigation"));
teleportRight = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.codeclient.tp.right", InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), "category.codeclient.navigation"));
teleportForward = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.codeclient.tp.forward", InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), "category.codeclient.navigation"));
teleportBackward = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.codeclient.tp.backward", InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), "category.codeclient.navigation"));
}

public static void tick() {
var player = CodeClient.MC.player;
if (player != null) {
checkTp(teleportLeft, new Vec3d(0, 0, -2));
checkTp(teleportRight, new Vec3d(0, 0, 2));
checkTp(teleportForward, new Vec3d(3, 0, 0));
checkTp(teleportBackward, new Vec3d(-3, 0, 0));
}
if (CodeClient.location instanceof Dev dev) {
if (editBind.wasPressed()) {
CodeClient.MC.setScreen(new DevInventoryScreen(player));
}
}
}

private static void checkTp(KeyBinding keyBinding, Vec3d offset) {
var player = CodeClient.MC.player;
if (player == null) return;
if (keyBinding.wasPressed() && CodeClient.location instanceof Dev dev && dev.isInDev(player.getPos())) {
var target = player.getPos().add(offset);
if (dev.isInDev(target)) player.setPosition(target);
}
}
}
11 changes: 6 additions & 5 deletions src/main/java/dev/dfonline/codeclient/dev/BuildPhaser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.dfonline.codeclient.ChatType;
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.config.KeyBinds;
import dev.dfonline.codeclient.hypercube.item.Location;
import dev.dfonline.codeclient.location.Build;
import dev.dfonline.codeclient.location.Dev;
Expand Down Expand Up @@ -45,11 +46,11 @@ public static void tick() {

if (CodeClient.location instanceof Dev plot) {
if (plot.getX() == null) {
if (CodeClient.clipBind.wasPressed())
if (KeyBinds.clipBind.wasPressed())
Utility.sendMessage(Text.translatable("codeclient.phaser.plot_origin"));
}
// CodeClient.LOGGER.info("dev and X");
if (!clipping && CodeClient.clipBind.isPressed() && plot.getX() != null) startClipping();
if (!clipping && KeyBinds.clipBind.isPressed() && plot.getX() != null) startClipping();
if (clipping) {
var player = CodeClient.MC.player;
player.setPos(
Expand All @@ -60,14 +61,14 @@ public static void tick() {
allowPacket = true;
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(lastPos.x, lastPos.y, lastPos.z, false));
CodeClient.MC.player.getAbilities().flying = true;
if (!CodeClient.clipBind.isPressed()) finishClipping();
if (!KeyBinds.clipBind.isPressed()) finishClipping();
}
} else if (clipping || waitForTP) {
disableClipping();
}

if (CodeClient.location instanceof Build) {
if (CodeClient.clipBind.isPressed() && !dontSpamBuildWarn) {
if (KeyBinds.clipBind.isPressed() && !dontSpamBuildWarn) {
dontSpamBuildWarn = true;
Utility.sendMessage(Text.translatable("codeclient.phaser.dev_mode1",
Text.translatable("codeclient.phaser.dev_mode2")
Expand All @@ -77,7 +78,7 @@ public static void tick() {
).formatted(Formatting.AQUA, Formatting.UNDERLINE)),
ChatType.FAIL);
}
if (dontSpamBuildWarn && !CodeClient.clipBind.isPressed()) dontSpamBuildWarn = false;
if (dontSpamBuildWarn && !KeyBinds.clipBind.isPressed()) dontSpamBuildWarn = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.config.KeyBinds;
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
import dev.dfonline.codeclient.hypercube.actiondump.Searchable;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -349,7 +350,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return true;
}
if (searchBox.active) {
if (CodeClient.MC.options.chatKey.matchesKey(keyCode, scanCode) || CodeClient.editBind.matchesKey(keyCode, scanCode)) {
if (CodeClient.MC.options.chatKey.matchesKey(keyCode, scanCode) || KeyBinds.editBind.matchesKey(keyCode, scanCode)) {
if (keyCode == GLFW.GLFW_KEY_Y) setSelectedTab(SEARCH.getIndex());
searchBox.setFocused(true);
searchBox.setCursorToEnd(false);
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/assets/codeclient/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"category.codeclient.dev": "CodeClient",

"key.codeclient.codepalette": "Code Palette",
"key.codeclient.phaser": "Phaser",

"category.codeclient.navigation": "Code Navigation",
"key.codeclient.tp.left": "Teleport Left",
"key.codeclient.tp.right": "Teleport Right",
"key.codeclient.tp.forward": "Teleport Forwards",
"key.codeclient.tp.backward": "Teleport Backwards",

"codeclient.parse_db": "Could not parse ActionDump. Go to %s to find out how to fix this.",

"codeclient.phaser.plot_origin": "CodeClient doesn't know the plot origin.",
Expand Down

0 comments on commit c1ef24b

Please sign in to comment.