Skip to content

Commit

Permalink
feat: 添加指南针功能
Browse files Browse the repository at this point in the history
close #9
  • Loading branch information
SuperSkidder committed Jul 5, 2024
1 parent 5840dda commit fffb68d
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package top.fpsmaster.features.impl.interfaces

import net.minecraft.client.gui.ScaledResolution
import top.fpsmaster.event.Subscribe
import top.fpsmaster.event.events.EventRender2D
import top.fpsmaster.features.manager.Category
import top.fpsmaster.features.manager.Module
import top.fpsmaster.ui.Compass
import top.fpsmaster.utils.Utility

class DirectionDisplay : Module("DirectionDisplay", Category.Interface) {
val compass = Compass(325f, 325f, 1f, 2, true)

@Subscribe
fun onRender(e: EventRender2D){
val scaledResolution = ScaledResolution(Utility.mc)
compass.draw(scaledResolution)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ModuleManager {
modules.add(ModsList())
modules.add(ClientCommand())
modules.add(MiniMap())
modules.add(DirectionDisplay())

if (ProviderManager.constants.getVersion() == "1.12.2") {
modules.add(HideIndicator())
Expand Down
4 changes: 4 additions & 0 deletions shared/java/top/fpsmaster/font/FontManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.fpsmaster.font;

import top.fpsmaster.font.impl.StringCache;
import top.fpsmaster.font.impl.UFontRenderer;

import java.util.HashMap;
Expand All @@ -12,15 +13,18 @@ public class FontManager {
public UFontRenderer s20;
public UFontRenderer s22;
public UFontRenderer s24;
public UFontRenderer s28;
public UFontRenderer s36;
public UFontRenderer s40;

public void load(){
s14 = new UFontRenderer("harmony_bold",14);
s16 = new UFontRenderer("harmony_bold",16);
s18 = new UFontRenderer("harmony_bold",18);
s20 = new UFontRenderer("harmony_bold",20);
s22 = new UFontRenderer("harmony_bold",22);
s24 = new UFontRenderer("harmony_bold",24);
s28 = new UFontRenderer("harmony_bold",28);
s36 = new UFontRenderer("harmony_bold",36);
s40 = new UFontRenderer("harmony_bold",40);
}
Expand Down
191 changes: 191 additions & 0 deletions shared/java/top/fpsmaster/ui/Compass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package top.fpsmaster.ui;

import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;
import top.fpsmaster.FPSMaster;
import top.fpsmaster.utils.render.Render2DUtils;

import java.awt.*;
import java.util.List;

public class Compass {

public static List<Degree> degrees = Lists.newArrayList();
public float innerWidth;
public float outerWidth;
public boolean shadow;
public float scale;
public int accuracy;

public Compass(float i, float o, float s, int a, boolean sh) {
innerWidth = i;
outerWidth = o;
scale = s;
accuracy = a;
shadow = sh;

degrees.add(new Degree("N", 1));
degrees.add(new Degree("195", 2));
degrees.add(new Degree("210", 2));
degrees.add(new Degree("NE", 3));
degrees.add(new Degree("240", 2));
degrees.add(new Degree("255", 2));
degrees.add(new Degree("E", 1));
degrees.add(new Degree("285", 2));
degrees.add(new Degree("300", 2));
degrees.add(new Degree("SE", 3));
degrees.add(new Degree("330", 2));
degrees.add(new Degree("345", 2));
degrees.add(new Degree("S", 1));
degrees.add(new Degree("15", 2));
degrees.add(new Degree("30", 2));
degrees.add(new Degree("SW", 3));
degrees.add(new Degree("60", 2));
degrees.add(new Degree("75", 2));
degrees.add(new Degree("W", 1));
degrees.add(new Degree("105", 2));
degrees.add(new Degree("120", 2));
degrees.add(new Degree("NW", 3));
degrees.add(new Degree("150", 2));
degrees.add(new Degree("165", 2));
}

public void draw(ScaledResolution sr) {
preRender(sr);
float center = sr.getScaledWidth() / 2f;

int count = 0;
float yaaahhrewindTime = (Minecraft.getMinecraft().thePlayer.rotationYaw % 360) * 2 + 360 * 3;
GL11.glPushMatrix();
GL11.glEnable(3089);
Render2DUtils.doGlScissor(sr.getScaledWidth() / 2f - 100, 25, 200, 25);

try {
for (Degree d : degrees) {
float location = center + (count * 30) - yaaahhrewindTime;
float completeLocation = d.type == 1 ? (location - FPSMaster.fontManager.s28.getStringWidth(d.text) / 2f)
: d.type == 2 ? (location - FPSMaster.fontManager.s28.getStringWidth(d.text) / 2f)
: (location - FPSMaster.fontManager.s22.getStringWidth(d.text) / 2f);

int opacity = opacity(sr, completeLocation);

if (d.type == 1 && opacity != 16777215) {
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s28.drawString(d.text, completeLocation, -75 + 100, opacity(sr, completeLocation));
}

if (d.type == 2 && opacity != 16777215) {
GlStateManager.color(1, 1, 1, 1);
Gui.drawRect((int) (location - 0.5), -75 + 100 + 4, (int) (location + 0.5), -75 + 105 + 4,
opacity(sr, completeLocation));
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s14.drawString(d.text, completeLocation, -75 + 105 + 3.5f + 4, opacity(sr, completeLocation));
}

if (d.type == 3 && opacity != 16777215) {
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s22.drawString(d.text, completeLocation,
-75 + 100 + FPSMaster.fontManager.s28.getHeight() / 2 - FPSMaster.fontManager.s22.getHeight() / 2,
opacity(sr, completeLocation));
}

count++;
}

for (Degree d : degrees) {

float location = center + (count * 30) - yaaahhrewindTime;
float completeLocation = d.type == 1 ? (location - FPSMaster.fontManager.s28.getStringWidth(d.text) / 2f)
: d.type == 2 ? (location - FPSMaster.fontManager.s14.getStringWidth(d.text) / 2f)
: (location - FPSMaster.fontManager.s22.getStringWidth(d.text) / 2f);


if (d.type == 1) {
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s28.drawString(d.text, completeLocation, -75 + 100, opacity(sr, completeLocation));
}

if (d.type == 2) {
GlStateManager.color(1, 1, 1, 1);
Gui.drawRect((int) (location - 0.5), -75 + 100 + 4, (int) (location + 0.5), -75 + 105 + 4,
opacity(sr, completeLocation));
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s14.drawString(d.text, completeLocation, -75 + 105 + 3.5f + 4, opacity(sr, completeLocation));
}

if (d.type == 3) {
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s22.drawString(d.text, completeLocation,
-75 + 100 + FPSMaster.fontManager.s28.getHeight() / 2 - FPSMaster.fontManager.s22.getHeight() / 2,
opacity(sr, completeLocation));
}

count++;
}
for (Degree d : degrees) {

float location = center + (count * 30) - yaaahhrewindTime;
float completeLocation = d.type == 1 ? (location - FPSMaster.fontManager.s28.getStringWidth(d.text) / 2f)
: d.type == 2 ? (location - FPSMaster.fontManager.s14.getStringWidth(d.text) / 2f)
: (location - FPSMaster.fontManager.s22.getStringWidth(d.text) / 2f);

if (d.type == 1) {
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s28.drawString(d.text, completeLocation, -75 + 100, opacity(sr, completeLocation));
}

if (d.type == 2) {
GlStateManager.color(1, 1, 1, 1);
Gui.drawRect((int) (location - 0.5), -75 + 100 + 4, (int) (location + 0.5), -75 + 105 + 4,
opacity(sr, completeLocation));
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s14.drawString(d.text, completeLocation, -75 + 105 + 3.5f + 4, opacity(sr, completeLocation));
}

if (d.type == 3) {
GlStateManager.color(1, 1, 1, 1);
FPSMaster.fontManager.s22.drawString(d.text, completeLocation,
-75 + 100 + FPSMaster.fontManager.s28.getHeight() / 2 - FPSMaster.fontManager.s22.getHeight() / 2,
opacity(sr, completeLocation));
}

count++;
}

} catch (Exception e){
e.printStackTrace();
}

GL11.glDisable(3089);
GL11.glPopMatrix();
}

public static void preRender(ScaledResolution sr) {
GlStateManager.disableAlpha();
GlStateManager.enableBlend();

}

public static int opacity(ScaledResolution sr, float offset) {
int op = 0;
float offs = 255 - Math.abs(sr.getScaledWidth() / 2f - offset) * 1.8f;
Color c = new Color(255, 255, 255, (int) Math.min(Math.max(0, offs), 255));
return c.getRGB();
}

public static class Degree {
public String text;
public int type;

public Degree(String s, int t) {
text = s;
type = t;
}

}

}
3 changes: 3 additions & 0 deletions shared/resources/assets/minecraft/client/lang/zh_cn.lang
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ dragonwings.color=颜色
dragonwings.scale=大小
dragonwings.chroma=彩色

directiondisplay=方向显示
directiondisplay.desc=显示一个指南针

# 类别
category.optimize=优化
category.render=视觉
Expand Down

0 comments on commit fffb68d

Please sign in to comment.