mirror of
https://github.com/squeek502/Squake.git
synced 2025-08-04 02:07:37 -04:00
51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
package squeek.quakemovement;
|
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
|
|
|
import me.shedaniel.autoconfig.AutoConfig;
|
|
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
|
|
import net.fabricmc.api.ModInitializer;
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.client.util.math.MatrixStack;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.util.math.MathHelper;
|
|
import squeek.quakemovement.ModConfig.SpeedometerPosition;
|
|
|
|
public class ModQuakeMovement implements ModInitializer {
|
|
public static final ModConfig CONFIG;
|
|
|
|
static {
|
|
AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
|
|
CONFIG = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
|
|
}
|
|
|
|
@Override
|
|
public void onInitialize() {
|
|
//Cause this class to be loaded so the config loads on startup
|
|
}
|
|
|
|
public static void drawSpeedometer(MatrixStack matrixStack)
|
|
{
|
|
MinecraftClient mc = MinecraftClient.getInstance();
|
|
PlayerEntity player = mc.player;
|
|
double deltaX = player.getX() - player.prevX;
|
|
double deltaZ = player.getZ() - player.prevZ;
|
|
double speed = MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ);
|
|
String speedString = String.format("%.02f", speed);
|
|
int x;
|
|
int y;
|
|
if (CONFIG.getSpeedometerPosition() == SpeedometerPosition.BOTTOM_LEFT || CONFIG.getSpeedometerPosition() == SpeedometerPosition.TOP_LEFT) {
|
|
x = 10;
|
|
} else {
|
|
x = mc.getWindow().getScaledWidth() - mc.textRenderer.getWidth(speedString) - 10;
|
|
}
|
|
if (CONFIG.getSpeedometerPosition() == SpeedometerPosition.TOP_RIGHT || CONFIG.getSpeedometerPosition() == SpeedometerPosition.TOP_LEFT) {
|
|
y = 10;
|
|
} else {
|
|
y = mc.getWindow().getScaledHeight() - mc.textRenderer.fontHeight - 10;
|
|
}
|
|
GlStateManager.pushMatrix();
|
|
mc.textRenderer.drawWithShadow(matrixStack, speedString, x, y, 0xFFDDDDDD);
|
|
GlStateManager.popMatrix();
|
|
}
|
|
} |