Skip to content

Commit

Permalink
enchant ai, add yaw i.
Browse files Browse the repository at this point in the history
  • Loading branch information
OutsiderH committed Feb 17, 2024
1 parent 806f795 commit 88b834d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.outsiderh.doabarrelrollwithhud.renderer.AttitudeIndicator;
import com.github.outsiderh.doabarrelrollwithhud.renderer.Renderer;
import com.github.outsiderh.doabarrelrollwithhud.renderer.SpeedIndicator;
import com.github.outsiderh.doabarrelrollwithhud.renderer.YawIndicator;
import com.github.outsiderh.doabarrelrollwithhud.utils.FlightComputer;

import me.shedaniel.autoconfig.AutoConfig;
Expand All @@ -21,7 +22,12 @@
public class DoABarrelRollWithHud implements ClientModInitializer {
public static final String modId = "doabarrelrollwithhud";
public static final Logger loggerSource = LoggerFactory.getLogger(modId);
public static final List<Renderer> renderers = List.of(new SpeedIndicator(), new AltitudeIndicator(), new AttitudeIndicator());
public static final List<Renderer> renderers = List.of(
new SpeedIndicator(),
new AltitudeIndicator(),
new AttitudeIndicator(),
new YawIndicator()
);
public static final FlightComputer fc = new FlightComputer();
public static ModConfig config;
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,59 @@
package com.github.outsiderh.doabarrelrollwithhud.renderer;

import static com.github.outsiderh.doabarrelrollwithhud.DoABarrelRollWithHud.fc;

import com.github.outsiderh.doabarrelrollwithhud.utils.Vector2Int;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;

public class AttitudeIndicator extends Renderer {
private final int groundColor = 0xFFB87325;
private final int skyColor = 0xFF47A6CC;
@Override
public void render(MinecraftClient client, MatrixStack mat) {
int halfSize = (hudEnd.x - hudBegin.x) / 4;
Vector2Int aiBegin = hudCenter.copy().subAndGet(halfSize);
Vector2Int aiEnd = hudCenter.copy().addAndGet(halfSize);
int horizonLength = (int)((float)(aiEnd.x - aiBegin.x) * 0.75f);
float horizonGap = (float)(Math.sqrt((double)(halfSize * halfSize)) / 3f);
enableScissor(aiBegin.x, aiBegin.y, aiEnd.x, aiEnd.y);
mat.push();
rotate(mat, -fc.roll);
float pitch = -fc.pitch;
float mod = pitch % 10f;
for (int n = (int)(pitch - (pitch < 0 ? mod + 10f : mod)), p = hudCenter.y + (int)((pitch < 0 ? 10f + mod : mod) * 5), c = 0; c < 3; n -= 10, p += 50, ++c) {
drawHorizontalLine(mat, hudCenter.x - 75, hudCenter.x + 75, p, color);
for (int n = (int)(pitch - (pitch < 0 ? mod + 10f : mod)), p = hudCenter.y + (int)((pitch < 0 ? 10f + mod : mod) * (horizonGap / 10f)), c = 0; c < 3; n -= 10, p += horizonGap, ++c) {
int numToShow = Math.abs(n);
if (numToShow > 90) {
numToShow = 180 - numToShow;
}
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(hudCenter.x - 75, p), TextAlign.Right);
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(hudCenter.x + 75, p), TextAlign.Left);
int length = horizonLength / (numToShow == 0 ? 2 : 4);
int posL = hudCenter.x - length;
int posR = hudCenter.x + length;
int color = n < 0 ? groundColor : n > 0 ? skyColor : Renderer.color;
drawHorizontalLine(mat, posL, posR, p, color);
drawVerticalLine(mat, posL, p, p + 3, color);
drawVerticalLine(mat, posR, p, p + 3, color);
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(posL, p), TextAlign.Right);
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(posR + 2, p), TextAlign.Left);
}
for (int n = (int)(pitch + (pitch < 0 ? -mod : 10f - mod)), p = hudCenter.y - (int)((pitch < 0 ? -mod : 10 - mod) * 5), c = 0; c < 3; n += 10, p -= 50, ++c) {
drawHorizontalLine(mat, hudCenter.x - 75, hudCenter.x + 75, p, color);
for (int n = (int)(pitch + (pitch < 0 ? -mod : 10f - mod)), p = hudCenter.y - (int)((pitch < 0 ? -mod : 10 - mod) * (horizonGap / 10)), c = 0; c < 3; n += 10, p -= horizonGap, ++c) {
int numToShow = Math.abs(n);
if (numToShow > 90) {
numToShow = 180 - numToShow;
}
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(hudCenter.x - 75, p), TextAlign.Right);
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(hudCenter.x + 75, p), TextAlign.Left);
int length = horizonLength / (numToShow == 0 ? 2 : 4);
int posL = hudCenter.x - length;
int posR = hudCenter.x + length;
int color = n < 0 ? groundColor : n > 0 ? skyColor : Renderer.color;
drawHorizontalLine(mat, posL, posR, p, color);
drawVerticalLine(mat, posL, p, p + 3, color);
drawVerticalLine(mat, posR, p, p + 3, color);
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(posL, p), TextAlign.Right);
drawText(client.textRenderer, mat, String.valueOf(numToShow), color, new Vector2Int(posR + 2, p), TextAlign.Left);
}
mat.pop();
disableScissor();
drawDot(mat, color, hudCenter);
drawHorizontalLine(mat, hudCenter.x - 1, hudCenter.x - 9, hudCenter.y, color);
drawHorizontalLine(mat, hudCenter.x + 1, hudCenter.x + 9, hudCenter.y, color);
drawHorizontalLine(mat, hudCenter.x - 2, hudCenter.x - 4, hudCenter.y, color);
drawHorizontalLine(mat, hudCenter.x + 2, hudCenter.x + 4, hudCenter.y, color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected int boxedHeight(TextRenderer tr) {
return tr.fontHeight + 2;
}
protected void drawDot(MatrixStack mat, int color, Vector2Int pos) {
fill(mat, pos.x, pos.y, pos.x, pos.y, color);
fill(mat, pos.x, pos.y, pos.x + 1, pos.y + 1, color);
}
protected void drawText(TextRenderer tr, MatrixStack mat, String text, int color, Vector2Int pos, TextAlign align) {
switch (align) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.github.outsiderh.doabarrelrollwithhud.renderer;

import static com.github.outsiderh.doabarrelrollwithhud.DoABarrelRollWithHud.fc;

import com.github.outsiderh.doabarrelrollwithhud.utils.Vector2Int;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;

public class YawIndicator extends Renderer {
@Override
public void render(MinecraftClient client, MatrixStack mat) {

int leftEdge = hudCenter.x - 100;
int rightEdge = hudCenter.x + 100;
drawHorizontalLine(mat, leftEdge, rightEdge, hudBegin.y, color);
drawText(client.textRenderer, mat, String.format("%.0f", fc.yaw), color, new Vector2Int(hudCenter.x, hudBegin.y), TextAlign.Down);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void eval(MinecraftClient client) {
altitude = (float)client.player.getPos().y;
radarEnable = altitude <= 520;
if (radarEnable) {
radarAltitude = 1;
radarAltitude = 0;
Mutable curCheck = client.player.getBlockPos().mutableCopy();
while (curCheck.getY() > -65 && client.world.isAir(curCheck)) {
curCheck.setY(curCheck.getY() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public void div(int val) {
x /= val;
y /= val;
}
public Vector2Int addAndGet(int val) {
x += val;
y += val;
return this;
}
public Vector2Int subAndGet(int val) {
x -= val;
y -= val;
return this;
}
public Vector2Int subAndGet(Vector2Int val) {
x -= val.x;
y -= val.y;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"text.autoconfig": "z"
"text.autoconfig.doabarrelrollwithhud.title": "设置",
"text.autoconfig.doabarrelrollwithhud.option.speedUnit": "速度单位"
}

0 comments on commit 88b834d

Please sign in to comment.