Skip to content

Commit

Permalink
version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
NGSpace committed Mar 28, 2024
1 parent 3940a10 commit f406efa
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 128 deletions.
4 changes: 3 additions & 1 deletion src/main/java/io/github/ngspace/hudder/Hudder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public class Hudder implements ModInitializer {
public static String LastFailMessage = "";
ConfigInfo config = ConfigManager.getConfig();
public static MinecraftClient ins = null;
public static long onesecdelay = 0;

@Override
public void onInitialize() {
ins = MinecraftClient.getInstance();

String[] defaultfiles = {"hand","armor","hud","tutorial"};
String[] defaultfiles = {"hand","armor","hud","tutorial","basic"};
for (String file : defaultfiles) {
File dest = new File(ConfigInfo.FOLDER + file);
if (dest.exists()) continue;
Expand Down Expand Up @@ -94,6 +95,7 @@ public void onInitialize() {
// reset the key
boolean valid = wk.reset();
if (!valid) {
wk = null;
LOGGER.error("Unable to watch for changes in File!");
showErrorToast(ins);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Arrays;

import io.github.ngspace.hudder.Hudder;
import io.github.ngspace.hudder.config.ConfigInfo;
import io.github.ngspace.hudder.meta.Element;
import io.github.ngspace.hudder.meta.Meta;
Expand Down Expand Up @@ -76,10 +75,10 @@ public class DefaultCompiler extends TextCompiler {
safeappend = true;
break;
case '&':
resultBuilder.append('§');
resultBuilder.append('\u00A7');//§ \u00A7
break;
case '#': compileState = ADVANCED_CONDITION_STATE;break;
// case '@': compileState = WHILE_STATE;break;
// case '@': compileState = WHILE_STATE;break;
default:
resultBuilder.append(c);
break;
Expand Down
226 changes: 113 additions & 113 deletions src/main/java/io/github/ngspace/hudder/compilers/JavaScriptCompiler.java
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
package io.github.ngspace.hudder.compilers;

import static io.github.ngspace.hudder.Hudder.player;
//import static io.github.ngspace.hudder.Hudder.player;
//
//import java.util.LinkedList;
//import java.util.function.BiConsumer;
//import java.util.function.Function;
//
//import javax.script.ScriptContext;
//import javax.script.ScriptEngineManager;
//import javax.script.ScriptException;
//
//import org.openjdk.nashorn.api.scripting.NashornScriptEngine;
//import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory;
//
//import io.github.ngspace.hudder.Hudder;
//import io.github.ngspace.hudder.config.ConfigInfo;
//import io.github.ngspace.hudder.meta.Element;
//import io.github.ngspace.hudder.meta.ItemElement;

import java.util.LinkedList;
import java.util.function.BiConsumer;
import java.util.function.Function;

import javax.script.ScriptContext;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.openjdk.nashorn.api.scripting.NashornScriptEngine;
import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory;

import io.github.ngspace.hudder.Hudder;
import io.github.ngspace.hudder.config.ConfigInfo;
import io.github.ngspace.hudder.meta.Element;
import io.github.ngspace.hudder.meta.ItemElement;

public class JavaScriptCompiler extends AVarTextCompiler {

public static final String PRESCRIPT = """
var TLScale = 1;
var BLScale = 1;
var TRScale = 1;
var BRScale = 1;
function topleft() {
return "";
}
function bottomleft() {
return "";
}
function topright() {
return "";
}
function bottomright() {
return "";
}
function createelements() {}
""";

@FunctionalInterface
interface Function5<A, B, C, D, E, R> {
public R apply(A one, B two, C three, D four, E five);
}
@FunctionalInterface
interface Function2<A1, A2, R> {
public R apply(A1 one, A2 two);
}
@FunctionalInterface
interface Consumer4<A, B, C, D> {
public A accept(A one, B two, C three, D four);
}

@Override public Object getVariable(String key) throws CompileException {
return getPureVariable(key);
}

public int slotelement(int s, int x, int y, int scale) {
new Exception("slotElement").printStackTrace();
elms.add(new ItemElement(x,y,player.getInventory().getStack(s),scale, true));
return 0;
}

LinkedList<Element> elms = new LinkedList<Element>();

@SuppressWarnings({ "unchecked", "unused" })
@Override
public CompileResult compile(ConfigInfo info, String text) throws CompileException {
try {
elms.clear();
ScriptEngineManager m = new ScriptEngineManager();
NashornScriptEngine engine = (NashornScriptEngine) m.getEngineByName("nashorn");
new NashornScriptEngineFactory().getScriptEngine(className -> false);
ScriptContext context = engine.getContext();

if (engine==null) throw new CompileException("Unable to load JavaScriptEngine!");

engine.put("getVal", (Function<String, Object>)t -> {
try {return getVariable(t);} catch (CompileException e) {e.printStackTrace();}
return null;
});
engine.put("setVal", (BiConsumer<String,Object>)this::put);
engine.put("slotElement", ((Consumer4<Integer,Integer,Integer,Integer>)this::slotelement));
Consumer4<Integer,Integer,Integer,Integer> slot3 = (s,x,y,scale) -> {
Hudder.LOGGER.info("r");
elms.add(new ItemElement(x,y,player.getInventory().getStack(s),scale, true));
return 0;
};
engine.put("slotElement3", slot3);
context.setAttribute("slotElement3", slot3, ScriptContext.ENGINE_SCOPE);
// read script file
engine.eval(PRESCRIPT);
engine.eval(text);
Hudder.LOGGER.info(engine.get("slotElement3").toString());
Hudder.LOGGER.info(((Consumer4<Integer,Integer,Integer,Integer>)engine.get("slotElement3")).toString());
((Consumer4<Integer,Integer,Integer,Integer>)engine.get("slotElement3")).accept(1, 1, 1, 1);

//engine.invokeFunction("slotElement3", 1,1,1,1);

String TL = String.valueOf(engine.invokeFunction("topleft", info));
String BL = String.valueOf(engine.invokeFunction("bottomleft", info));
String TR = String.valueOf(engine.invokeFunction("topright", info));
String BR = String.valueOf(engine.invokeFunction("bottomright", info));

return new CompileResult(TL, 1, BL, 1, TR, 1, BR, 1, new Element[0]); //This one works.
} catch (ScriptException | NoSuchMethodException e) {
e.printStackTrace();
throw new CompileException(e.getLocalizedMessage());
} catch (CompileException e) {
throw e; //Double it and give it to the next person
}
}
public class JavaScriptCompiler {private JavaScriptCompiler() {}// extends AVarTextCompiler {
//
// public static final String PRESCRIPT = """
//var TLScale = 1;
//var BLScale = 1;
//var TRScale = 1;
//var BRScale = 1;
//
//function topleft() {
// return "";
//}
//function bottomleft() {
// return "";
//}
//function topright() {
// return "";
//}
//function bottomright() {
// return "";
//}
//function createelements() {}
//
//""";
//
// @FunctionalInterface
// interface Function5<A, B, C, D, E, R> {
// public R apply(A one, B two, C three, D four, E five);
// }
// @FunctionalInterface
// interface Function2<A1, A2, R> {
// public R apply(A1 one, A2 two);
// }
// @FunctionalInterface
// interface Consumer4<A, B, C, D> {
// public A accept(A one, B two, C three, D four);
// }
//
// @Override public Object getVariable(String key) throws CompileException {
// return getPureVariable(key);
// }
//
// public int slotelement(int s, int x, int y, int scale) {
// new Exception("slotElement").printStackTrace();
// elms.add(new ItemElement(x,y,player.getInventory().getStack(s),scale, true));
// return 0;
// }
//
// LinkedList<Element> elms = new LinkedList<Element>();
//
// @SuppressWarnings({ "unchecked", "unused" })
// @Override
// public CompileResult compile(ConfigInfo info, String text) throws CompileException {
// try {
// elms.clear();
// ScriptEngineManager m = new ScriptEngineManager();
// NashornScriptEngine engine = (NashornScriptEngine) m.getEngineByName("nashorn");
// new NashornScriptEngineFactory().getScriptEngine(className -> false);
// ScriptContext context = engine.getContext();
//
// if (engine==null) throw new CompileException("Unable to load JavaScriptEngine!");
//
// engine.put("getVal", (Function<String, Object>)t -> {
// try {return getVariable(t);} catch (CompileException e) {e.printStackTrace();}
// return null;
// });
// engine.put("setVal", (BiConsumer<String,Object>)this::put);
// engine.put("slotElement", ((Consumer4<Integer,Integer,Integer,Integer>)this::slotelement));
// Consumer4<Integer,Integer,Integer,Integer> slot3 = (s,x,y,scale) -> {
// Hudder.LOGGER.info("r");
// elms.add(new ItemElement(x,y,player.getInventory().getStack(s),scale, true));
// return 0;
// };
// engine.put("slotElement3", slot3);
// context.setAttribute("slotElement3", slot3, ScriptContext.ENGINE_SCOPE);
// // read script file
// engine.eval(PRESCRIPT);
// engine.eval(text);
// Hudder.LOGGER.info(engine.get("slotElement3").toString());
// Hudder.LOGGER.info(((Consumer4<Integer,Integer,Integer,Integer>)engine.get("slotElement3")).toString());
// ((Consumer4<Integer,Integer,Integer,Integer>)engine.get("slotElement3")).accept(1, 1, 1, 1);
//
// //engine.invokeFunction("slotElement3", 1,1,1,1);
//
// String TL = String.valueOf(engine.invokeFunction("topleft", info));
// String BL = String.valueOf(engine.invokeFunction("bottomleft", info));
// String TR = String.valueOf(engine.invokeFunction("topright", info));
// String BR = String.valueOf(engine.invokeFunction("bottomright", info));
//
// return new CompileResult(TL, 1, BL, 1, TR, 1, BR, 1, new Element[0]); //This one works.
// } catch (ScriptException | NoSuchMethodException e) {
// e.printStackTrace();
// throw new CompileException(e.getLocalizedMessage());
// } catch (CompileException e) {
// throw e; //Double it and give it to the next person
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;

public class ConfigMenu implements ConfigScreenFactory<Screen> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.ngspace.hudder.data_management;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.MinecraftClient;

public class Advanced {private Advanced() {}
public static double gpuUsage = 0;
private static final List<Integer> list = new ArrayList<>();

public static int getFPS(MinecraftClient ins) {
int fps = ins.getCurrentFps();
list.add(fps);
if (list.size() > 800) list.remove(0);
return fps;
}
public static int getMinimumFPS() {
int max = list.get(0);
for (int i:list) if (i<max) max=i;
return max;
}
public static int getMaximumFPS() {
int max = 0;
for (int i:list) if (i>max) max=i;
return max;
}
public static int getAverageFPS() {
int sum = 0;
for (int fps : list) sum += fps;
return sum / list.size();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.world.LightType;
import net.minecraft.world.World;
import static io.github.ngspace.hudder.data_management.Advanced.*;

public class NumberData {private NumberData() {}
static double MB = 1024d*1024d;
Expand All @@ -24,14 +25,18 @@ public static Double getNumber(String key) throws CompileException {
PlayerEntity p = ins.player;
WorldRenderer wr = ins.worldRenderer;
World world = ins.world;
int fps = getFPS(ins);
return switch(key) {

/* Performance */
case "fps": yield (double) ins.getCurrentFps();
case "fps": yield (double) fps;
case "avgfps","avg_fps": yield (double) getAverageFPS();
case "minfps","min_fps": yield (double) getMinimumFPS();
case "maxfps","max_fps": yield (double) getMaximumFPS();
case "ping": yield (double) ins.getNetworkHandler().getPlayerListEntry(p.getName().getString()).getLatency();
case "tps": yield (double) getTPS(ins);
case "gpu_d": yield DataStorage.gpuUsage;
case "gpu": yield (double) ((int)DataStorage.gpuUsage);
case "gpu_d": yield Advanced.gpuUsage;
case "gpu": yield (double) ((int)Advanced.gpuUsage);
case "cpu": throw new CompileException("due to my lack of skills and mental abilites cpu is unavaliable");

/* Memory */
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/io/github/ngspace/hudder/meta/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Collections;
import java.util.List;

import io.github.ngspace.hudder.Hudder;
import io.github.ngspace.hudder.compilers.CompileException;
import io.github.ngspace.hudder.compilers.CompileResult;
import io.github.ngspace.hudder.config.ConfigManager;
Expand Down Expand Up @@ -38,7 +37,6 @@ public void addString(String txt, boolean cleanup) throws CompileException {
private void addString(String txt, String pos, boolean cleanup) throws CompileException {
String text = txt;
if (cleanup) {
// Hudder.LOGGER.info(cleanup + txt);
int buffer = ConfigManager.getConfig().metaBuffer;
if (buffer<10) {
for (int i = 0; i<buffer;i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public MetaCompiler() {
methods.put("fullnumber",s);
var decimalMethods = new DecimalMethod();
methods.put("decimalpoint", decimalMethods);
methods.put("float", decimalMethods);
var stringMethods = new StringMethods();
methods.put("concat", stringMethods);
methods.put("multiplystring", stringMethods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import io.github.ngspace.hudder.config.ConfigManager;
import io.github.ngspace.hudder.data_management.DataStorage;
import io.github.ngspace.hudder.data_management.Advanced;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;

Expand All @@ -19,7 +19,7 @@ public abstract class MinecraftClientInjections {
@Inject(method = "render", at = @At(value = "INVOKE",
target = "Ljava/lang/String;format(Ljava/util/Locale;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;"))
public void getGpuUsage(boolean tick, CallbackInfo ci) {
DataStorage.gpuUsage = gpuUtilizationPercentage > 100 ? 100 : gpuUtilizationPercentage;
Advanced.gpuUsage = gpuUtilizationPercentage > 100 ? 100 : gpuUtilizationPercentage;
}

@Redirect(method = "render", at = @At(value = "INVOKE",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/hudder/basic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
&r{FPS} (max. {maxfps} avg. {avgfps} min. {minfps}) {usedram_percentage}\% of {maxram}MB
X: {x}, Y: {y}, Z: {z};run, hand;
Loading

0 comments on commit f406efa

Please sign in to comment.