Skip to content

Commit

Permalink
InteractionMenu updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadecimal233 authored and C10udburst committed Nov 12, 2022
1 parent bb7c6f0 commit c4f4539
Showing 1 changed file with 49 additions and 44 deletions.
93 changes: 49 additions & 44 deletions src/main/java/anticope/rejects/modules/InteractionMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import anticope.rejects.gui.screens.InteractionScreen;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import meteordevelopment.meteorclient.gui.GuiTheme;
import meteordevelopment.meteorclient.gui.utils.CharFilter;
import meteordevelopment.meteorclient.gui.utils.StarscriptTextBoxRenderer;
import meteordevelopment.meteorclient.gui.widgets.WWidget;
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
Expand All @@ -19,21 +18,21 @@
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.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtString;

import java.util.*;
import java.util.HashMap;
import java.util.Optional;

public class InteractionMenu extends Module {

private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final SettingGroup sgStyle = settings.createGroup("Style");

private final Setting<Object2BooleanMap<EntityType<?>>> entities = sgGeneral.add(new EntityTypeListSetting.Builder()
.name("entities")
.description("Entities")
Expand All @@ -47,6 +46,12 @@ public class InteractionMenu extends Module {
.action(this::onKey)
.build()
);
public final Setting<Boolean> useCrosshairTarget = sgGeneral.add(new BoolSetting.Builder()
.name("use-crosshair-target")
.description("Use crosshair target.")
.defaultValue(false)
.build()
);

// Style
public final Setting<SettingColor> selectedDotColor = sgStyle.add(new ColorSetting.Builder()
Expand All @@ -70,33 +75,40 @@ public class InteractionMenu extends Module {
public final Setting<SettingColor> borderColor = sgStyle.add(new ColorSetting.Builder()
.name("border-color")
.description("Color of the border.")
.defaultValue(new SettingColor(0,0,0))
.defaultValue(new SettingColor(0, 0, 0))
.build()
);
public final Setting<SettingColor> textColor = sgStyle.add(new ColorSetting.Builder()
.name("text-color")
.description("Color of the text.")
.defaultValue(new SettingColor(255,255,255))
.defaultValue(new SettingColor(255, 255, 255))
.build()
);
public final HashMap<String,String> messages = new HashMap<>();

public final HashMap<String, String> messages = new HashMap<>();
private String currMsgK = "", currMsgV = "";

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() {
if (mc.currentScreen != null) return;
Optional<Entity> lookingAt = DebugRenderer.getTargetedEntity(mc.player, 20);
if (lookingAt.isPresent()) {
Entity e = lookingAt.get();
if (entities.get().getBoolean(e.getType())) {
mc.setScreen(new InteractionScreen(e, this));
if (mc.player == null || mc.currentScreen != null) return;
Entity e = null;
if (useCrosshairTarget.get()) {
e = mc.targetedEntity;
} else {
Optional<Entity> lookingAt = DebugRenderer.getTargetedEntity(mc.player, 20);
if (lookingAt.isPresent()) {
e = lookingAt.get();
}
}

if (e == null) return;
if (entities.get().getBoolean(e.getType())) {
mc.setScreen(new InteractionScreen(e, this));
}
}

@Override
Expand All @@ -114,24 +126,21 @@ private void fillTable(GuiTheme theme, WTable table) {
WMinus delete = table.add(theme.minus()).widget();
delete.action = () -> {
messages.remove(key);
fillTable(theme,table);
fillTable(theme, table);
};
table.row();
});
WTextBox textBoxK = table.add(theme.textBox(currMsgK)).minWidth(100).expandX().widget();
textBoxK.action = () -> {
currMsgK = textBoxK.get();
};
textBoxK.action = () -> currMsgK = textBoxK.get();
WTextBox textBoxV = table.add(theme.textBox(currMsgV, (text1, c) -> true, StarscriptTextBoxRenderer.class)).minWidth(100).expandX().widget();
textBoxV.action = () -> {
currMsgV = textBoxV.get();
};
textBoxV.action = () -> currMsgV = textBoxV.get();
WPlus add = table.add(theme.plus()).widget();
add.action = () -> {
if (currMsgK != "" && currMsgV != "") {
if (!currMsgK.equals("") && !currMsgV.equals("")) {
messages.put(currMsgK, currMsgV);
currMsgK = ""; currMsgV = "";
fillTable(theme,table);
currMsgK = "";
currMsgV = "";
fillTable(theme, table);
}
};
table.row();
Expand All @@ -140,25 +149,21 @@ private void fillTable(GuiTheme theme, WTable table) {
@Override
public NbtCompound toTag() {
NbtCompound tag = super.toTag();

NbtCompound messTag = new NbtCompound();
messages.keySet().forEach((key) -> {
messTag.put(key, NbtString.of(messages.get(key)));
});
messages.keySet().forEach((key) -> messTag.put(key, NbtString.of(messages.get(key))));

tag.put("messages", messTag);
return tag;
}

@Override
public Module fromTag(NbtCompound tag) {

messages.clear();
if (tag.contains("messages")) {
NbtCompound msgs = tag.getCompound("messages");
msgs.getKeys().forEach((key) -> {
messages.put(key, msgs.getString(key));
});
msgs.getKeys().forEach((key) -> messages.put(key, msgs.getString(key)));
}

return super.fromTag(tag);
Expand All @@ -179,15 +184,15 @@ 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()))
.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()))
);
}

Expand Down

0 comments on commit c4f4539

Please sign in to comment.