Skip to content
Open
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
11 changes: 5 additions & 6 deletions src/main/java/io/github/ngspace/hudder/Hudder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import io.github.ngspace.hudder.compilers.utils.Compilers;
import io.github.ngspace.hudder.compilers.utils.functionandconsumerapi.FunctionAndConsumerAPI;
import io.github.ngspace.hudder.data_management.Advanced;
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 @@ -133,10 +131,8 @@ public class Hudder implements ClientModInitializer {
HudderBuiltInFunctions.registerFunction(FunctionAndConsumerAPI.getInstance());
ClientTickEvents.START_CLIENT_TICK.register(new HudderTickEvent());

DataVariableRegistry.registerVariable(new ResourcePackVariables(), "selectedresourcepacks",
"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 +143,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 as they'll stop working in a future release."));
} 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()),"readValue");

//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);
}
},"writeValue");

//Items

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

import java.util.ArrayList;
import java.util.Arrays;

import io.github.ngspace.hudder.Hudder;
Expand Down Expand Up @@ -38,7 +39,6 @@ public class HudderV2Compiler extends AV2Compiler {

boolean quotesafe = false;
boolean backslashsafe = false;
boolean condSafe = false;
boolean safeappend = false;
int savedind = 0;

Expand All @@ -64,7 +64,6 @@ public class HudderV2Compiler extends AV2Compiler {
switch (c) {
case '%':
compileState = CONDITION_STATE;
builder = new String[] {};
runtime.addRuntimeElement(new StringV2RuntimeElement(elemBuilder.toString(), false));
elemBuilder.setLength(0);
savedind = ind;
Expand All @@ -82,6 +81,8 @@ public class HudderV2Compiler extends AV2Compiler {
elemBuilder.setLength(0);
builder = new String[] {};
savedind = ind;
quotesafe = false;
backslashsafe = false;
break;
case '#':
compileState = HASHTAG_STATE;
Expand Down Expand Up @@ -129,33 +130,44 @@ public class HudderV2Compiler extends AV2Compiler {
break;
}
case CONDITION_STATE: {
if (c=='\\') {
if (condSafe) {elemBuilder.append('\\');condSafe = false;}
else condSafe = true;
continue;
}
if (quotesafe&&c!='"') {elemBuilder.append(c);continue;}
if (condSafe&&c=='"') {elemBuilder.append('\\');elemBuilder.append(c);condSafe=false;continue;}
if (condSafe) {elemBuilder.append(c);condSafe=false;continue;}
switch (c) {
case '%':
compileState = TEXT_STATE;
builder = addToArray(builder,elemBuilder.toString().trim());
StringBuilder conditionOrValue = new StringBuilder();
ArrayList<String> conds = new ArrayList<String>();

boolean quotes = false;
boolean escaped = false;

for (;ind<text.length();ind++) {
c = text.charAt(ind);

if (quotes) {
conditionOrValue.append(c);
if (c=='\\') {
escaped = true;
continue;
}
if (c=='"'&&!escaped) quotes = false;
escaped = false;
continue;
}

if (c=='"') quotes = true;

if (c==',') {
conds.add(conditionOrValue.toString());
conditionOrValue.setLength(0);
} else if (c=='%') {
var pos = getPosition(charPosition, savedind, text);
runtime.addRuntimeElement(new ConditionV2RuntimeElement(builder, this, info, runtime,
pos.line, pos.charpos,filename));
elemBuilder.setLength(0);
break;
case '"':
quotesafe = !quotesafe;
elemBuilder.append(c);
break;
case ',':
builder = addToArray(builder,elemBuilder.toString().trim());
elemBuilder.setLength(0);
Hudder.log(conds.get(0));
conds.add(conditionOrValue.toString());
runtime.addRuntimeElement(new ConditionV2RuntimeElement(
conds.toArray(new String[conds.size()]), this, info,
runtime, pos.line, pos.charpos,filename));
compileState = TEXT_STATE;
break;
default: elemBuilder.append(c);break;
}
} else {
conditionOrValue.append(c);
}
}

break;
}
Expand Down Expand Up @@ -287,7 +299,9 @@ public class HudderV2Compiler extends AV2Compiler {

runtime.addRuntimeElement(new StringV2RuntimeElement(elemBuilder.toString(), false));

if (compileState!=0) throw new CompileException(getCompilerErrorMessage(compileState));
if (compileState!=0) {
throw new CompileException(getCompilerErrorMessage(compileState));
}

return runtime;
}
Expand All @@ -313,10 +327,4 @@ public String getCompilerErrorMessage(int compileState) {
});
return strb.toString();
}

private static <T> T[] addToArray(T[] arr, T t) {
T[] newarr = Arrays.copyOf(arr, arr.length+1);
newarr[arr.length] = t;
return newarr;
}
}
}
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 @@ -11,6 +11,7 @@
import io.github.ngspace.hudder.utils.ObjectWrapper;
import io.github.ngspace.hudder.utils.ValueGetter;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.ItemStack;

/**
Expand Down Expand Up @@ -101,21 +102,25 @@ public static class TranslatedItemStack implements ValueGetter {
public int maxcount;
public int durability;
public int maxdurability;
public String identifier;
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();
identifier = BuiltInRegistries.ITEM.wrapAsHolder(stack.getItem()).getRegisteredName();
item = stack;
}
@Override public String toString() {
return "{name:\"" + name + "\", count:" + count + ", maxcount: " + maxcount + ", durability: " + durability
+ ", maxdurability: " + maxdurability + "}";
+ ", maxdurability: " + maxdurability + ", identifier: " + identifier + "}";
}
@Override public Object get(String component) {
return ComponentsData.getObject(component, components);
return ComponentsData.getObject(component, components, item);
}
}
}
Loading
Loading