Files
src
build.gradle
gradle.properties
settings.gradle
Code
15 2,188
src/main/java/com/kodari/sideways/SidewaysClient.java
package com.kodari.sideways;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
public class SidewaysClient implements ClientModInitializer {
private static final KeyBinding REPORT_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.send_report", GLFW.GLFW_KEY_K, "category.sideways")
);
private static final KeyBinding WALKER_TOGGLE_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.toggle_walker", GLFW.GLFW_KEY_J, "category.sideways")
);
private static final KeyBinding SCREENSHOT_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.send_screenshot", GLFW.GLFW_KEY_F8, "category.sideways")
);
private static final KeyBinding BROKEN_BLOCKS_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.show_broken_blocks", GLFW.GLFW_KEY_H, "category.sideways")
);
private static final KeyBinding COORDINATE_ALERT_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.open_coordinate_alert", GLFW.GLFW_KEY_O, "category.sideways")
);
private static final KeyBinding CLICK_GUI_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.open_click_gui", GLFW.GLFW_KEY_RIGHT_SHIFT, "category.sideways")
);
private static final KeyBinding CAMERA_LEFT_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.camera_left", GLFW.GLFW_KEY_LEFT, "category.sideways")
);
private static final KeyBinding CAMERA_RIGHT_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.camera_right", GLFW.GLFW_KEY_RIGHT, "category.sideways")
);
private static final KeyBinding CAMERA_UP_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.camera_up", GLFW.GLFW_KEY_UP, "category.sideways")
);
private static final KeyBinding CAMERA_DOWN_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.sideways.camera_down", GLFW.GLFW_KEY_DOWN, "category.sideways")
);
private static final Path LIFETIME_CROPS_PATH = Path.of("config", "sideways-lifetime-crops.properties");
private static final Path CROP_HUD_SETTINGS_PATH = Path.of("config", "sideways-crop-hud.properties");
private static boolean movingLeft = true;
private static boolean walkerEnabled = false;
private static boolean walkerHoldForwardEnabled = false;
private static boolean holdWadEnabled = false;
private static int speedHudX = -1;
private static int speedHudY = 8;
private static boolean hasSpeedPosition;
private static double speedPositionX;
private static double speedPositionY;
private static double speedPositionZ;
private static double playerSpeed;
private static boolean wasColliding;
private static double walkerStartX;
private static double walkerStartZ;
private static boolean yMinus50AlertSent;
private static long blocksBroken;
private static long cropsBroken;
private static int cropHudX = 8;
private static int cropHudY = 8;
private static float cropHudScale = 1.0F;
private static final Map<String, Long> blocksByType = new LinkedHashMap<>();
private static final Map<String, Long> cropsByType = new LinkedHashMap<>();
private static final Map<String, Long> lifetimeCropsByType = new LinkedHashMap<>();
@Override
public void onInitializeClient() {
DiscordWebhook.load();
CoordinateAlertScreen.load();
loadLifetimeCropCounts();
loadCropHudSettings();
GifHud.loadSettings();
ClientTickEvents.START_CLIENT_TICK.register(SidewaysClient::tick);
ClientTickEvents.END_CLIENT_TICK.register(SidewaysClient::checkWalkerWallCollision);
HudRenderCallback.EVENT.register(SidewaysClient::renderCropHud);
HudRenderCallback.EVENT.register(SidewaysClient::renderSpeedHud);
HudRenderCallback.EVENT.register(SidewaysClient::renderFeatureIndicators);
HudRenderCallback.EVENT.register(GifHud::render);
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) ->
dispatcher.register(ClientCommandManager.literal("gif")
.executes(context -> {
GifHud.clear();
context.getSource().sendFeedback(Text.literal("GIF overlay cleared."));
return 1;
})
.then(ClientCommandManager.argument("url", StringArgumentType.greedyString())
.executes(context -> {
String url = StringArgumentType.getString(context, "url");
if (url.equalsIgnoreCase("clear") || url.equalsIgnoreCase("off")) {
GifHud.clear();
context.getSource().sendFeedback(Text.literal("GIF overlay cleared."));
} else {
GifHud.show(url);
context.getSource().sendFeedback(Text.literal("Loading GIF. Use /gif size <pixels> and /gif position <x> <y> to adjust it."));
}
return 1;
}))
.then(ClientCommandManager.literal("size")
.then(ClientCommandManager.argument("pixels", IntegerArgumentType.integer(16, 1024))
.executes(context -> {
int pixels = IntegerArgumentType.getInteger(context, "pixels");
GifHud.setMaxSize(pixels);
context.getSource().sendFeedback(Text.literal("GIF maximum dimension set to " + pixels + " pixels."));
return 1;
})))
.then(ClientCommandManager.literal("position")
.then(ClientCommandManager.argument("x", IntegerArgumentType.integer(0))
.then(ClientCommandManager.argument("y", IntegerArgumentType.integer(0))
.executes(context -> {
int x = IntegerArgumentType.getInteger(context, "x");
int y = IntegerArgumentType.getInteger(context, "y");
GifHud.setPosition(x, y);
context.getSource().sendFeedback(Text.literal("GIF position set to " + x + ", " + y + " pixels from the top-left."));
return 1;
}))))
.then(ClientCommandManager.literal("center")
.executes(context -> {
GifHud.center();
context.getSource().sendFeedback(Text.literal("GIF centered."));
return 1;
}))));
ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) -> {
if (message.getString().contains("Grim Reaper found you a Jade Crystal!")) {
DiscordWebhook.notifyJadeCrystalFound();
}
});
ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
if (message.getString().contains("Grim Reaper found you a Jade Crystal!")) {
DiscordWebhook.notifyJadeCrystalFound();
}
});
}
private static void tick(MinecraftClient client) {
updatePlayerSpeed(client);
if (client.player != null) {
walkerStartX = client.player.getX();
walkerStartZ = client.player.getZ();
}
while (WALKER_TOGGLE_KEY.wasPressed()) {
toggleWalker();
}
while (REPORT_KEY.wasPressed()) {
DiscordWebhook.notifyBreakStats(cropsBroken, Map.copyOf(cropsByType));
}
while (SCREENSHOT_KEY.wasPressed()) {
DiscordWebhook.sendScreenshot(client.getFramebuffer());
}
while (BROKEN_BLOCKS_KEY.wasPressed()) {
long lifetimeCropsBroken = lifetimeCropsByType.values().stream().mapToLong(Long::longValue).sum();
client.setScreen(new BrokenBlocksScreen(cropsBroken, Map.copyOf(cropsByType),
lifetimeCropsBroken, Map.copyOf(lifetimeCropsByType)));
}
while (COORDINATE_ALERT_KEY.wasPressed()) {
client.setScreen(new CoordinateAlertScreen());
}
while (CLICK_GUI_KEY.wasPressed()) {
if (client.currentScreen instanceof FeatureClickScreen) {
client.setScreen(null);
} else {
client.setScreen(new FeatureClickScreen());
}
}
if (client.player == null) {
releaseMovement(client);
wasColliding = false;
return;
}
CoordinateAlertScreen.tick(client);
if (client.player.getY() > -50.0) {
yMinus50AlertSent = false;