custom interactions now use starscript
eg {entity.uuid}
This commit is contained in:
@@ -7,8 +7,14 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||||||
import meteordevelopment.meteorclient.MeteorClient;
|
import meteordevelopment.meteorclient.MeteorClient;
|
||||||
import meteordevelopment.meteorclient.events.meteor.KeyEvent;
|
import meteordevelopment.meteorclient.events.meteor.KeyEvent;
|
||||||
import meteordevelopment.meteorclient.systems.modules.Modules;
|
import meteordevelopment.meteorclient.systems.modules.Modules;
|
||||||
|
import meteordevelopment.meteorclient.utils.misc.MeteorStarscript;
|
||||||
import meteordevelopment.meteorclient.utils.render.PeekScreen;
|
import meteordevelopment.meteorclient.utils.render.PeekScreen;
|
||||||
import meteordevelopment.orbit.EventHandler;
|
import meteordevelopment.orbit.EventHandler;
|
||||||
|
import meteordevelopment.starscript.compiler.Compiler;
|
||||||
|
import meteordevelopment.starscript.compiler.Parser;
|
||||||
|
import meteordevelopment.starscript.utils.Error;
|
||||||
|
import meteordevelopment.starscript.utils.StarscriptError;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.ChatScreen;
|
import net.minecraft.client.gui.screen.ChatScreen;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
@@ -41,6 +47,8 @@ import java.util.function.Consumer;
|
|||||||
*/
|
*/
|
||||||
public class InteractionScreen extends Screen {
|
public class InteractionScreen extends Screen {
|
||||||
|
|
||||||
|
public static Entity interactionMenuEntity;
|
||||||
|
|
||||||
private final Entity entity;
|
private final Entity entity;
|
||||||
private String focusedString = null;
|
private String focusedString = null;
|
||||||
private int crosshairX, crosshairY, focusedDot = -1;
|
private int crosshairX, crosshairY, focusedDot = -1;
|
||||||
@@ -141,12 +149,22 @@ public class InteractionScreen extends Screen {
|
|||||||
}
|
}
|
||||||
msgs = Modules.get().get(InteractionMenu.class).messages;
|
msgs = Modules.get().get(InteractionMenu.class).messages;
|
||||||
msgs.keySet().forEach((key) -> {
|
msgs.keySet().forEach((key) -> {
|
||||||
if (msgs.get(key).contains("{username}") && !(entity instanceof PlayerEntity)) return;
|
|
||||||
if (msgs.get(key).contains("{health}") && !(entity instanceof LivingEntity)) return;
|
|
||||||
|
|
||||||
functions.put(key, (Entity e) -> {
|
functions.put(key, (Entity e) -> {
|
||||||
closeScreen();
|
closeScreen();
|
||||||
client.setScreen(new ChatScreen(replacePlaceholders(msgs.get(key), e)));
|
interactionMenuEntity = e;
|
||||||
|
var result = Parser.parse(msgs.get(key));
|
||||||
|
if (result.hasErrors()) {
|
||||||
|
for (Error error : result.errors) MeteorStarscript.printChatError(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var script = Compiler.compile(result);
|
||||||
|
try {
|
||||||
|
client.setScreen(new ChatScreen(MeteorStarscript.ss.run(script)));
|
||||||
|
} catch (StarscriptError err) {
|
||||||
|
MeteorStarscript.printChatError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -333,19 +351,6 @@ public class InteractionScreen extends Screen {
|
|||||||
drawHorizontalLine(matrix, startX + 1, startX + 1, startY + 2, 0x80FFFFFF);
|
drawHorizontalLine(matrix, startX + 1, startX + 1, startY + 2, 0x80FFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String replacePlaceholders(String in, Entity e) {
|
|
||||||
in = in.replace("{uuid}", e.getUuidAsString());
|
|
||||||
in = in.replace("{name}", e.getName().getString());
|
|
||||||
in = in.replace("{pos}", String.format("%.2f %.2f %.2f", e.getX(), e.getY(), e.getZ()));
|
|
||||||
if (e instanceof PlayerEntity) {
|
|
||||||
in = in.replace("{username}", ((PlayerEntity)e).getGameProfile().getName());
|
|
||||||
}
|
|
||||||
if (e instanceof LivingEntity) {
|
|
||||||
in = in.replace("{health}", String.format("%.2f", ((LivingEntity)e).getHealth()));
|
|
||||||
}
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class StaticListener {
|
private class StaticListener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onKey(KeyEvent event) {
|
private void onKey(KeyEvent event) {
|
||||||
|
|||||||
@@ -13,10 +13,15 @@ import meteordevelopment.meteorclient.settings.*;
|
|||||||
import meteordevelopment.meteorclient.systems.modules.Module;
|
import meteordevelopment.meteorclient.systems.modules.Module;
|
||||||
import meteordevelopment.meteorclient.utils.Utils;
|
import meteordevelopment.meteorclient.utils.Utils;
|
||||||
import meteordevelopment.meteorclient.utils.misc.Keybind;
|
import meteordevelopment.meteorclient.utils.misc.Keybind;
|
||||||
|
import meteordevelopment.meteorclient.utils.misc.MeteorStarscript;
|
||||||
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
|
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
|
||||||
|
import meteordevelopment.starscript.value.Value;
|
||||||
|
import meteordevelopment.starscript.value.ValueMap;
|
||||||
|
|
||||||
import net.minecraft.client.render.debug.DebugRenderer;
|
import net.minecraft.client.render.debug.DebugRenderer;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtString;
|
import net.minecraft.nbt.NbtString;
|
||||||
|
|
||||||
@@ -78,6 +83,7 @@ public class InteractionMenu extends Module {
|
|||||||
|
|
||||||
public InteractionMenu() {
|
public InteractionMenu() {
|
||||||
super(MeteorRejectsAddon.CATEGORY,"interaction-menu","An interaction screen when looking at an entity.");
|
super(MeteorRejectsAddon.CATEGORY,"interaction-menu","An interaction screen when looking at an entity.");
|
||||||
|
MeteorStarscript.ss.set("entity", () -> wrap(InteractionScreen.interactionMenuEntity));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onKey() {
|
public void onKey() {
|
||||||
@@ -155,4 +161,22 @@ public class InteractionMenu extends Module {
|
|||||||
|
|
||||||
return super.fromTag(tag);
|
return super.fromTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Value wrap(Entity entity) {
|
||||||
|
return Value.map(new ValueMap()
|
||||||
|
.set("_toString", Value.string(entity.getName().getString()))
|
||||||
|
.set("health", Value.number(entity instanceof LivingEntity e ? e.getHealth() : 0))
|
||||||
|
.set("pos", Value.map(new ValueMap()
|
||||||
|
.set("_toString", posString(entity.getX(), entity.getY(), entity.getZ()))
|
||||||
|
.set("x", Value.number(entity.getX()))
|
||||||
|
.set("y", Value.number(entity.getY()))
|
||||||
|
.set("z", Value.number(entity.getZ()))
|
||||||
|
))
|
||||||
|
.set("uuid", Value.string(entity.getUuidAsString()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Value posString(double x, double y, double z) {
|
||||||
|
return Value.string(String.format("X: %.0f Y: %.0f Z: %.0f", x, y, z));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user