Files
src
build.gradle
gradle.properties
settings.gradle
Code
12 453
src/main/java/com/astro/client/AstroClient.java
package com.astro.client;
import com.astro.client.gui.AstroScreen;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.glfw.GLFW;
public final class AstroClient implements ClientModInitializer {
public static boolean freecamEnabled;
public static boolean storageEspEnabled;
private static boolean menuKeyDown;
private static Vec3d freecamPosition;
private static Vec3d playerAnchor;
@Override
public void onInitializeClient() {
}
public static void clientTick(MinecraftClient client) {
boolean pressed = GLFW.glfwGetKey(client.getWindow().getHandle(), GLFW.GLFW_KEY_RIGHT_SHIFT) == GLFW.GLFW_PRESS;
if (pressed && !menuKeyDown && client.currentScreen == null) {
client.setScreen(new AstroScreen());
}
menuKeyDown = pressed;
if (freecamEnabled && client.player == null) {
freecamEnabled = false;
freecamPosition = null;
playerAnchor = null;
}
}
public static void toggleFreecam(MinecraftClient client) {
if (freecamEnabled) {
freecamEnabled = false;
freecamPosition = null;
playerAnchor = null;
return;
}
if (client.player == null) {
return;
}
playerAnchor = client.player.getPos();
freecamPosition = client.player.getEyePos();
freecamEnabled = true;
}
public static void tickFreecam(ClientPlayerEntity player) {
if (!freecamEnabled || player != MinecraftClient.getInstance().player || playerAnchor == null || freecamPosition == null) {
return;
}
MinecraftClient client = MinecraftClient.getInstance();
player.setPosition(playerAnchor.x, playerAnchor.y, playerAnchor.z);
player.setVelocity(Vec3d.ZERO);
if (client.currentScreen != null) {
return;
}
Vec3d look = player.getRotationVec(1.0F);
Vec3d forward = look.multiply(1.0, 0.0, 1.0).normalize();
Vec3d right = new Vec3d(forward.z, 0.0, -forward.x);
Vec3d movement = Vec3d.ZERO;
if (client.options.forwardKey.isPressed()) movement = movement.add(look);
if (client.options.backKey.isPressed()) movement = movement.subtract(look);
if (client.options.rightKey.isPressed()) movement = movement.add(right);
if (client.options.leftKey.isPressed()) movement = movement.subtract(right);
if (client.options.jumpKey.isPressed()) movement = movement.add(0.0, 1.0, 0.0);
if (client.options.sneakKey.isPressed()) movement = movement.add(0.0, -1.0, 0.0);
if (movement.lengthSquared() > 0.0) {
double speed = client.options.sprintKey.isPressed() ? 1.5 : 0.45;
freecamPosition = freecamPosition.add(movement.normalize().multiply(speed));
}
}
public static Vec3d getFreecamPosition() {
return freecamPosition;
}
}