Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ loader_version=0.18.2
loom_version=1.14-SNAPSHOT

# Mod Properties
mod_version=9.1.2
mod_version=9.2.0
maven_group=hudder
archives_base_name=hudder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ protected void init() {
saveButton.active = error==null;
addRenderableWidget(saveButton);

globalResetButton = Button.builder(Component.translatable("ngsmcconfig.globalreset"), b->reset())
globalResetButton = Button.builder(Component.translatable("ngsmcconfig.globalreset").withColor(0xdb3b3b),
b->reset())
.bounds(width-40, 0, 40, 20)
.build();

Expand All @@ -79,7 +80,7 @@ protected void init() {
}
addRenderableWidget(globalResetButton);

errorWidget = new StringWidget(error!=null?error.plainCopy().withColor(0xFF0000):Component.literal(""), font);
errorWidget = new StringWidget(stylizeErrorComponment(error), font);
errorWidget.setPosition(65, 0);
errorWidget.setSize(300, 20);
// errorWidget.alignLeft();
Expand All @@ -94,7 +95,7 @@ protected void init() {
addRenderableWidget(container);
}
}

protected void save() {
for (var category : categories) {
for (var option : category.options()) {
Expand Down Expand Up @@ -151,15 +152,14 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
Component error = getError();

saveButton.active = error==null;
errorWidget.setMessage(error!=null?error:Component.literal(""));
errorWidget.setMessage(stylizeErrorComponment(error));

if (container!=null)
container.render(graphics, mouseX, mouseY, partialTick);
super.render(graphics, mouseX, mouseY, partialTick);
}
// @Override
// public boolean handleComponentClicked(@Nullable Style style) {
// if (style == null) return false;
// return super.handleComponentClicked(style);
// }

private Component stylizeErrorComponment(Component error) {
return error!=null?error.plainCopy().withColor(0xFF0000):Component.literal("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
}

@Override
protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {}
protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) { /* */ }

@Override
public boolean mouseClicked(MouseButtonEvent mouseButtonEvent, boolean bl) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/github/ngspace/hudder/Hudder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.github.ngspace.hudder.data_management.EffectData;
import io.github.ngspace.hudder.data_management.ResourcePackVariables;
import io.github.ngspace.hudder.data_management.api.DataVariableRegistry;
import io.github.ngspace.hudder.data_management.builtin.HudderBuiltInVariables;
import io.github.ngspace.hudder.main.HudCompilationManager;
import io.github.ngspace.hudder.main.HudderRenderer;
import io.github.ngspace.hudder.main.HudderTickEvent;
Expand Down Expand Up @@ -137,6 +138,7 @@ public class Hudder implements ClientModInitializer {
"selectedresourcepacks_unfiltered");
DataVariableRegistry.registerVariable(new EffectData(), "active_effects");
Advanced.registerKeyVariables();
HudderBuiltInVariables.registerVariables();

HudCompilationManager compman = new HudCompilationManager();
ClientTickEvents.END_CLIENT_TICK.register(compman);
Expand All @@ -147,6 +149,9 @@ public class Hudder implements ClientModInitializer {
ClientLifecycleEvents.CLIENT_STARTED.register(c->{
try {
HudFileUtils.reloadResources();
if (config.globalVariables.size()>0)
showWarningToast(Component.literal("Hudder is deprecating global variables!"),
Component.literal("Please stop using them or shit will break."));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import io.github.ngspace.hudder.compilers.utils.HudInformation;
import io.github.ngspace.hudder.compilers.utils.functionandconsumerapi.FunctionAndConsumerAPI;
import io.github.ngspace.hudder.compilers.utils.functionandconsumerapi.FunctionAndConsumerAPI.TranslatedItemStack;
import io.github.ngspace.hudder.data_management.BooleanData;
import io.github.ngspace.hudder.data_management.NumberData;
import io.github.ngspace.hudder.data_management.ObjectDataAPI;
import io.github.ngspace.hudder.data_management.StringData;
import io.github.ngspace.hudder.data_management.api.DataVariableRegistry;
import io.github.ngspace.hudder.main.HudCompilationManager;
import io.github.ngspace.hudder.utils.HudFileUtils;
import net.minecraft.client.Minecraft;
Expand All @@ -25,14 +23,14 @@ public static void registerFunction(FunctionAndConsumerAPI binder) {
//Getters

binder.registerFunction((m,c,s)->c.getVariable(s[0].asString()), "get", "getVal", "getVariable");
binder.registerFunction((m,c,s)->NumberData.getNumber (s[0].asString()), "getNumber" );
binder.registerFunction((m,c,s)->StringData.getString (s[0].asString()), "getString" );
binder.registerFunction((m,c,s)->ObjectDataAPI.getObject(s[0].asString()), "getObject" );
binder.registerFunction((m,c,s)->BooleanData.getBoolean (s[0].asString()), "getBoolean");
binder.registerFunction((m,c,s)->DataVariableRegistry.getNumber (s[0].asString()), "getNumber" );
binder.registerFunction((m,c,s)->DataVariableRegistry.getString (s[0].asString()), "getString" );
binder.registerFunction((m,c,s)->ObjectDataAPI.getObject (s[0].asString()), "getObject" );
binder.registerFunction((m,c,s)->DataVariableRegistry.getBoolean (s[0].asString()), "getBoolean");

binder.registerFunction((m,c,s)->new TranslatedItemStack(mc.player.getInventory().getItem(s[0].asInt())), "getItem");

// binder.bindFunction((m,c,s)->c.getConfig().savedVariables.get(s[0].asString()),"readVal");
binder.registerFunction((m,c,s)->c.getConfig().savedVariables.get(s[0].asString()),"readVal");

//Compile

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.ngspace.hudder.api.functionsandconsumers;

import java.io.IOException;

import io.github.ngspace.hudder.Hudder;
import io.github.ngspace.hudder.compilers.utils.functionandconsumerapi.FunctionAndConsumerAPI;
import io.github.ngspace.hudder.uielements.BuiltInTextureElement;
Expand Down Expand Up @@ -73,7 +75,14 @@ public static void registerMethods(FunctionAndConsumerAPI api) {
//Variables

api.registerConsumer((e,a,s)->a.put(s[0].asString(), s[1]), "set", "setVal", "setVariable");
// binder.bindConsumer((e,a,l,ch,s)->a.getConfig().savedVariables.put(s[0].asString(),s[1]),"saveVal");
api.registerConsumer((e,a,s)->{
try {
a.getConfig().putSavedVariable(s[0].asString(),s[1].get());
} catch (IOException ex) {
ex.printStackTrace();
throw new IllegalArgumentException(ex);
}
},"saveVal");

//Items

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import io.github.ngspace.hudder.compilers.utils.HudInformation;
import io.github.ngspace.hudder.compilers.utils.IScriptingLanguageEngine;
import io.github.ngspace.hudder.compilers.utils.functionandconsumerapi.ArrayElementManager;
import io.github.ngspace.hudder.data_management.BooleanData;
import io.github.ngspace.hudder.data_management.NumberData;
import io.github.ngspace.hudder.data_management.ObjectDataAPI;
import io.github.ngspace.hudder.data_management.StringData;
import io.github.ngspace.hudder.data_management.api.DataVariableRegistry;
import io.github.ngspace.hudder.main.HudCompilationManager;
import io.github.ngspace.hudder.main.config.HudderConfig;
import io.github.ngspace.hudder.uielements.AUIElement;
Expand Down Expand Up @@ -91,10 +89,8 @@ protected AScriptingLanguageCompiler() {

@SuppressWarnings("removal")
@Override public Object getVariable(String key) throws CompileException {
Object obj = NumberData.getNumber(key);
Object obj = DataVariableRegistry.getAny(key);
if ( obj!=null) return obj;
if ((obj=StringData.getString (key))!=null) return obj;
if ((obj=BooleanData.getBoolean(key))!=null) return obj;
if ((obj=ObjectDataAPI.getObject(key))!=null) return obj;
if ((obj=get(key))!=null) return obj;
if ((obj=Hudder.config.globalVariables.get(key))!=null) return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void defineFunctionOrMethod(String commands, String[] args, String name,
try {
state.combineWithResult(runtime.execute().toResult(), false);
} catch (CompileException e) {
throw new CompileException("Method "+type+" threw an error: \n"+e.getFailureMessage(),line,charpos);
throw new CompileException("Method "+type+" threw an error: \n"+e.getFailureMessage(),charpos);
}
});
} else {//Is function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import io.github.ngspace.hudder.Hudder;
import io.github.ngspace.hudder.compilers.utils.CompileException;
import io.github.ngspace.hudder.data_management.BooleanData;
import io.github.ngspace.hudder.data_management.NumberData;
import io.github.ngspace.hudder.data_management.ObjectDataAPI;
import io.github.ngspace.hudder.data_management.StringData;
import io.github.ngspace.hudder.data_management.api.DataVariableRegistry;

public abstract class AVarTextCompiler extends ATextCompiler {
Expand Down Expand Up @@ -33,11 +30,8 @@ public boolean isSystemVariable(String key) {
*/
@SuppressWarnings("removal")
public Object getSystemVariable(String key) {
Object obj = NumberData.getNumber(key);
Object obj = DataVariableRegistry.getAny(key);
if (obj!=null) return obj;
if ((obj=BooleanData.getBoolean(key))!=null) return obj;
if ((obj=StringData.getString(key))!=null) return obj;
if ((obj=DataVariableRegistry.getObject(key))!=null) return obj;
if ((obj=ObjectDataAPI.getObject(key))!=null) return obj;
return Hudder.config.globalVariables.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.github.ngspace.hudder.compilers.utils;

import io.github.ngspace.hudder.compilers.abstractions.ATextCompiler.CharPosition;

public class CompileException extends Exception {
public final int line;
public final int col;

public CompileException(String string) {this(string,-1,0);}
public CompileException(String string, int line, int col) {super(string);this.line = line;this.col = col;}
public CompileException(String string, CharPosition pos) {this(string, pos.line, pos.charpos);}
public CompileException(String string, int line, int col, Throwable e) {
super(string,e);
this.line = line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,22 @@ public static class TranslatedItemStack implements ValueGetter {
public int durability;
public int maxdurability;
private DataComponentMap components;
private ItemStack item;
public TranslatedItemStack(ItemStack stack) {
name = stack.getDisplayName().getString();
count = stack.getCount();
maxcount = stack.getMaxStackSize();
durability = stack.getMaxDamage()-stack.getDamageValue();
maxdurability = stack.getMaxDamage();
components = stack.getComponents();
item = stack;
}
@Override public String toString() {
return "{name:\"" + name + "\", count:" + count + ", maxcount: " + maxcount + ", durability: " + durability
+ ", maxdurability: " + maxdurability + "}";
}
@Override public Object get(String component) {
return ComponentsData.getObject(component, components);
return ComponentsData.getObject(component, components, item);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,119 +1,14 @@
package io.github.ngspace.hudder.data_management;

import io.github.ngspace.hudder.Hudder;
import io.github.ngspace.hudder.data_management.api.DataVariableRegistry;
import io.github.ngspace.hudder.main.config.HudderConfig;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.gui.screens.dialog.DialogScreen;
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import net.minecraft.client.gui.screens.inventory.CraftingScreen;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.equine.AbstractChestedHorse;
import net.minecraft.world.entity.animal.equine.AbstractHorse;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.levelgen.WorldgenRandom;

/**
* @deprecated use DataVariableRegistry.
*/
@Deprecated(since = "9.2.0", forRemoval = true)
public class BooleanData {private BooleanData(){}
@Deprecated
public static Boolean getBoolean(String key) {
Minecraft ins = Minecraft.getInstance();
HudderConfig config = Hudder.config;
LocalPlayer p = ins.player;
Camera c = ins.gameRenderer.getMainCamera();
return switch (key) {



/* Generic */
case "isslime", "is_slime": {
try {
yield WorldgenRandom.seedSlimeChunk(p.getBlockX() >> 4, p.getBlockZ() >> 4, ins.getSingleplayerServer()
.getLevel(ins.level.dimension()).getSeed(), 987234911L).nextInt(10) == 0;
} catch (Exception e) {/* For some reason adding a yield false; here causes runtime errors...*/}
yield false;
}
case "hudhidden": yield ins.options.hideGui;
case "showdebug": yield ins.getDebugOverlay().showDebugScreen();
case "f3enabled": yield ins.debugEntries.isOverlayVisible();
case "camera_detached": yield c.entity() != p;



/* GUI */
case "isguiopen": yield ins.screen!=null;
case "ischestopen": yield ins.screen instanceof ContainerScreen;
case "iscraftingtableopen": yield ins.screen instanceof CraftingScreen;
case "ischatopen": yield ins.screen instanceof ChatScreen;
case "isdialogopen": yield ins.screen instanceof DialogScreen<?>;
case "isinventoryopen": yield ins.screen instanceof InventoryScreen
|| ins.screen instanceof CreativeModeInventoryScreen;



/* Player gamemode */
case "issurvival","is_survival": yield ins.gameMode.getPlayerMode()==GameType.SURVIVAL;
case "iscreative","is_creative": yield ins.gameMode.getPlayerMode()==GameType.CREATIVE;
case "isadventure","is_adventure": yield ins.gameMode.getPlayerMode()==GameType.ADVENTURE;
case "isspectator","is_spectator": yield ins.gameMode.getPlayerMode()==GameType.SPECTATOR;



/* Player movement */
case "isflying": yield p.getAbilities().flying;
case "isgliding": yield p.isFallFlying();
case "isclimbing": yield p.onClimbable();
case "iscrawling": yield p.isVisuallyCrawling();
case "isswimming": yield p.isSwimming();
case "issneaking": yield p.isShiftKeyDown();
case "issprinting": yield p.isSprinting();



/* Player information */
case "isalive": yield p.isAlive();
case "isblocking": yield p.isBlocking();
case "isfreezing": yield p.isFreezing();
case "isglowing": yield p.isCurrentlyGlowing();
case "isfireimmune": yield p.fireImmune();
case "isonfire": yield p.isOnFire();
case "isonground": yield p.onGround();
case "isinvisible": yield p.isInvisible();
case "isdrowning": yield p.isInWater();
case "iscontrollingmount": yield p.getControlledVehicle() != null;
case "isonmount": yield p.getVehicle()!=null;



/* Mount information */
case "mount_is_saddled": yield p.getVehicle() instanceof Mob mob && mob.isSaddled();
case "mount_has_armor": yield p.getVehicle() instanceof Mob mob && mob.isWearingBodyArmor();
case "mount_is_tamed": yield p.getVehicle() instanceof AbstractHorse horse && horse.isTamed();
case "mount_has_chest": yield p.getVehicle() instanceof AbstractChestedHorse horse && horse.hasChest();



/* Mouse */
case "mouse_left": yield ins.mouseHandler.isLeftPressed();
case "mouse_middle": yield ins.mouseHandler.isMiddlePressed();
case "mouse_right": yield ins.mouseHandler.isRightPressed();



/* Hudder */
case "enabled": yield true; //Duh
case "shadow": yield config.shadow;
case "showinf3": yield config.showInF3;
case "javascriptenabled": yield true; // For compatibility
case "unsafeoperations": yield config.unsafeoperations;
case "globalvariablesenabled": yield config.globalVariablesEnabled;
case "background": yield config.background;
case "removegui": yield config.removegui;
case "limitrate": yield config.limitrate;
default: yield DataVariableRegistry.getBoolean(key);
};
return DataVariableRegistry.getBoolean(key);
}
}
Loading
Loading