Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5775c4bdb | ||
|
|
d3901dc1be | ||
|
|
1302de1d55 | ||
|
|
f247027343 | ||
|
|
16e6b40a80 | ||
|
|
6e2c25d269 | ||
|
|
3ab5a6cd94 | ||
|
|
38923722ea | ||
|
|
ca01b19c4b | ||
|
|
301484fed6 | ||
|
|
b4f75da102 | ||
|
|
599fb54335 | ||
|
|
fa9c868feb | ||
|
|
fcb7dc420f | ||
|
|
c44bb88faa | ||
|
|
7121fe1201 | ||
|
|
b7f75fea1e | ||
|
|
5cefa75b2f | ||
|
|
b711aec620 | ||
|
|
d748a036db | ||
|
|
40b5ee7aaf | ||
|
|
a8abbd511f | ||
|
|
b9b426377c | ||
|
|
1060fa18a0 | ||
|
|
71ffeb7d94 | ||
|
|
f129955367 |
+1
-2
@@ -3,7 +3,6 @@ org.gradle.jvmargs=-Xmx1G
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.21.11
|
||||
yarn_mappings=1.21.11+build.4
|
||||
loader_version=0.18.4
|
||||
loom_version=1.14-SNAPSHOT
|
||||
# Mod Properties
|
||||
@@ -15,4 +14,4 @@ archives_base_name=oyvey
|
||||
# check this on https://modmuss50.me/fabric.html
|
||||
fabric_version=0.141.1+1.21.11
|
||||
catformat_version=2.1.0
|
||||
buildconfig_version=5.3.5
|
||||
buildconfig_version=5.3.5
|
||||
|
||||
@@ -3,4 +3,7 @@ package me.alpha432.oyvey.event.impl.entity.player;
|
||||
import me.alpha432.oyvey.event.Event;
|
||||
|
||||
public class TickEvent extends Event {
|
||||
public static class Post extends TickEvent { }
|
||||
|
||||
public static class Pre extends TickEvent { }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package me.alpha432.oyvey.event.impl.entity.player;
|
||||
|
||||
import me.alpha432.oyvey.event.Event;
|
||||
|
||||
public class TravelEvent extends Event {
|
||||
public static class Post extends TravelEvent { }
|
||||
|
||||
public static class Pre extends TravelEvent { }
|
||||
}
|
||||
@@ -45,8 +45,10 @@ public class EventBus {
|
||||
Class<?> eventType = params[0];
|
||||
|
||||
Listener listener = Listener.of(host, subscribe.priority(), method);
|
||||
List<Listener> registry = listeners.computeIfAbsent(eventType,
|
||||
k -> new CopyOnWriteArrayList<>());
|
||||
List<Listener> registry = listeners.computeIfAbsent(
|
||||
eventType,
|
||||
k -> new CopyOnWriteArrayList<>()
|
||||
);
|
||||
|
||||
register(registry, listener);
|
||||
}
|
||||
@@ -58,10 +60,15 @@ public class EventBus {
|
||||
|
||||
private void register(List<Listener> registry, Listener target) {
|
||||
int i = 0;
|
||||
|
||||
for (Listener listener : registry) {
|
||||
if (target.priority() > listener.priority()) {
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
if (target.priority() > listener.priority()) break;
|
||||
}
|
||||
|
||||
registry.add(i, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package me.alpha432.oyvey.features.commands;
|
||||
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class ArgumentSuggestions {
|
||||
public static CompletableFuture<Suggestions> suggest(Stream<String> stream, SuggestionsBuilder builder) {
|
||||
return suggest(stream.toList(), x -> x, builder);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Suggestions> suggest(Iterable<String> iterable, SuggestionsBuilder builder) {
|
||||
return suggest(iterable, x -> x, builder);
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<Suggestions> suggest(Iterable<T> iterable, Function<T, String> map, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemainingLowerCase();
|
||||
for (T t : iterable) {
|
||||
String target = map.apply(t).toLowerCase(Locale.ROOT);
|
||||
if (target.equals(remaining)) {
|
||||
builder.suggest(target);
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
|
||||
for (T t : iterable) {
|
||||
String target = map.apply(t).toLowerCase(Locale.ROOT);
|
||||
if (target.contains(remaining)) builder.suggest(target);
|
||||
}
|
||||
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,12 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import me.alpha432.oyvey.features.Feature;
|
||||
import me.alpha432.oyvey.manager.CommandManager;
|
||||
import me.alpha432.oyvey.util.TextUtil;
|
||||
import me.alpha432.oyvey.util.player.ChatUtil;
|
||||
import me.alpha432.oyvey.util.chat.ChatUtil;
|
||||
import me.alpha432.oyvey.util.chat.Signature;
|
||||
|
||||
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
import static me.alpha432.oyvey.features.commands.MessageIdentifiers.*;
|
||||
import static me.alpha432.oyvey.features.commands.MessageSignatures.FAIL;
|
||||
import static me.alpha432.oyvey.features.commands.MessageSignatures.SUCCESS;
|
||||
|
||||
public abstract class Command extends Feature {
|
||||
public static final int NO_OP = -1;
|
||||
@@ -59,12 +61,12 @@ public abstract class Command extends Feature {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void sendMessage(String message, String identifier) {
|
||||
public static void sendMessage(String message, Signature identifier) {
|
||||
if (message == null) return;
|
||||
ChatUtil.sendMessage(TextUtil.text(message), identifier);
|
||||
}
|
||||
|
||||
public static void sendMessage(String message, String identifier, Object... format) {
|
||||
public static void sendMessage(String message, Signature identifier, Object... format) {
|
||||
if (message == null) return;
|
||||
ChatUtil.sendMessage(TextUtil.text(message, format), identifier);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package me.alpha432.oyvey.features.commands;
|
||||
|
||||
public class MessageIdentifiers {
|
||||
public static final String GENERAL = "general";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String FAIL = "fail";
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.alpha432.oyvey.features.commands;
|
||||
|
||||
import me.alpha432.oyvey.util.chat.Signature;
|
||||
import me.alpha432.oyvey.util.chat.SimpleSignature;
|
||||
|
||||
public class MessageSignatures {
|
||||
public static final Signature GENERAL = SimpleSignature.fromLong(-1L);
|
||||
public static final Signature SUCCESS = SimpleSignature.fromLong(0L);
|
||||
public static final Signature FAIL = SimpleSignature.fromLong(1L);
|
||||
}
|
||||
@@ -2,10 +2,16 @@ package me.alpha432.oyvey.features.commands;
|
||||
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import me.alpha432.oyvey.OyVey;
|
||||
import me.alpha432.oyvey.features.commands.argument.ColorArgumentType;
|
||||
import me.alpha432.oyvey.features.modules.Module;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
import me.alpha432.oyvey.manager.CommandManager;
|
||||
import me.alpha432.oyvey.util.chat.ChatUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@@ -29,6 +35,7 @@ public class ModuleCommand extends Command {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void createArgumentBuilder(LiteralArgumentBuilder<CommandManager> builder) {
|
||||
registerDefault(builder);
|
||||
for (Setting<?> setting : module.getSettings()) {
|
||||
Class<?> type = setting.getDefaultValue().getClass();
|
||||
|
||||
@@ -46,6 +53,29 @@ public class ModuleCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerDefault(LiteralArgumentBuilder<CommandManager> builder) {
|
||||
builder.executes(ctx -> {
|
||||
var message = Component.empty();
|
||||
|
||||
message.append("[ ");
|
||||
message.append(Component.literal(module.getName())
|
||||
.withStyle(s -> s.withColor(module.isToggled() ? ChatFormatting.GREEN : ChatFormatting.RED))
|
||||
.withStyle(s -> s.withClickEvent(suggestCommand("toggle " + module.getName())))
|
||||
);
|
||||
message.append(" ]");
|
||||
|
||||
for (Setting<?> setting : module.getSettings()) {
|
||||
message.append("\n");
|
||||
message.append(Component.literal(setting.getName() + ": ").withStyle(ChatFormatting.GRAY));
|
||||
message.append(Component.literal(setting.getValueAsString()).withStyle(s -> styledValue(setting, s)));
|
||||
}
|
||||
|
||||
ChatUtil.sendMessage(message, MessageSignatures.SUCCESS);
|
||||
|
||||
return success();
|
||||
});
|
||||
}
|
||||
|
||||
private void registerColorArgument(LiteralArgumentBuilder<CommandManager> builder,
|
||||
Setting<Color> setting) {
|
||||
builder.then(literal(setting.getName().toLowerCase())
|
||||
@@ -110,6 +140,19 @@ public class ModuleCommand extends Command {
|
||||
return success("Set %s.%s to %s", module.getName(), setting.getName(), setting.getValue());
|
||||
}
|
||||
|
||||
private static ClickEvent suggestCommand(String command) {
|
||||
return new ClickEvent.SuggestCommand(OyVey.commandManager.getCommandPrefix() + command);
|
||||
}
|
||||
|
||||
private static Style styledValue(Setting<?> setting, Style style) {
|
||||
return switch (setting.getValue()) {
|
||||
case Boolean value -> style.withColor(value ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
case Color value -> style.withColor(value.getRGB());
|
||||
case Enum<?> ignored -> style.withColor(ChatFormatting.YELLOW);
|
||||
default -> style.withColor(ChatFormatting.WHITE);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShown() {
|
||||
return false;
|
||||
|
||||
@@ -4,13 +4,20 @@ import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import me.alpha432.oyvey.features.commands.CommandExceptions;
|
||||
import net.minecraft.ChatFormatting;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ColorArgumentType implements ArgumentType<Color> {
|
||||
import static me.alpha432.oyvey.features.commands.ArgumentSuggestions.suggest;
|
||||
|
||||
public final class ColorArgumentType implements ArgumentType<Color> {
|
||||
private static final List<String> EXAMPLES = List.of("hsb:55,100,100", "255,0,255", "0,255,255,80");
|
||||
private static final String[] RGBA_VALUES = {"Red", "Green", "Blue", "Alpha"};
|
||||
|
||||
@@ -21,7 +28,16 @@ public class ColorArgumentType implements ArgumentType<Color> {
|
||||
|
||||
// if input begins with "#" its a hex color
|
||||
if (value.startsWith("#")) {
|
||||
return new Color(Integer.parseInt(value.substring(1), 16));
|
||||
int color;
|
||||
if (value.length() == 4) {
|
||||
char[] c = value.toCharArray();
|
||||
String hex = "" + c[1] + c[1] + c[2] + c[2] + c[3] + c[3];
|
||||
color = Integer.parseInt(hex, 16);
|
||||
} else {
|
||||
color = Integer.parseInt(value.substring(1), 16);
|
||||
}
|
||||
|
||||
return new Color(color);
|
||||
}
|
||||
|
||||
if (value.startsWith("hsb:")) {
|
||||
@@ -50,6 +66,11 @@ public class ColorArgumentType implements ArgumentType<Color> {
|
||||
(float) brightness / 100.0f);
|
||||
}
|
||||
|
||||
ChatFormatting format = parseFormatting(value);
|
||||
if (format != null) {
|
||||
return new Color(format.getColor(), false);
|
||||
}
|
||||
|
||||
int[] elements = parseColorElements(reader, value);
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
int element = elements[i];
|
||||
@@ -65,6 +86,29 @@ public class ColorArgumentType implements ArgumentType<Color> {
|
||||
elements.length == 4 ? elements[3] : 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String input = builder.getRemainingLowerCase();
|
||||
if (input.isEmpty()) {
|
||||
builder.suggest("#");
|
||||
builder.suggest("hsb:");
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
if (input.startsWith("#")) {
|
||||
builder.suggest(input);
|
||||
} else if (input.startsWith("h")) {
|
||||
if (input.startsWith("hsb:")) builder.suggest(input);
|
||||
else builder.suggest("hsb:");
|
||||
} else if (!Character.isDigit(input.charAt(0))){
|
||||
return suggest(Arrays.stream(ChatFormatting.values())
|
||||
.filter(ChatFormatting::isColor)
|
||||
.map(ChatFormatting::getName), builder);
|
||||
}
|
||||
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private int[] parseColorElements(StringReader reader, String value) throws CommandSyntaxException {
|
||||
String[] parts = value.split(",");
|
||||
if (parts.length < 3) {
|
||||
@@ -79,6 +123,16 @@ public class ColorArgumentType implements ArgumentType<Color> {
|
||||
return elements;
|
||||
}
|
||||
|
||||
private ChatFormatting parseFormatting(String value) {
|
||||
for (ChatFormatting format : ChatFormatting.values()) {
|
||||
if (!format.isColor()) continue;
|
||||
if (value.equalsIgnoreCase(format.getName())) {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getExamples() {
|
||||
return EXAMPLES;
|
||||
|
||||
+4
-11
@@ -13,7 +13,9 @@ import me.alpha432.oyvey.features.commands.CommandExceptions;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CommandArgumentType implements ArgumentType<Command>, CommandExceptionType {
|
||||
import static me.alpha432.oyvey.features.commands.ArgumentSuggestions.suggest;
|
||||
|
||||
public final class CommandArgumentType implements ArgumentType<Command>, CommandExceptionType {
|
||||
@Override
|
||||
public Command parse(StringReader reader) throws CommandSyntaxException {
|
||||
String value = reader.readString().toLowerCase();
|
||||
@@ -29,16 +31,7 @@ public class CommandArgumentType implements ArgumentType<Command>, CommandExcept
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String input = builder.getRemainingLowerCase();
|
||||
|
||||
for (String alias : OyVey.commandManager.getCommandAliases()) {
|
||||
String name = alias.toLowerCase();
|
||||
if (name.contains(input)) {
|
||||
builder.suggest(name);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.buildFuture();
|
||||
return suggest(OyVey.commandManager.getCommandAliases(), builder);
|
||||
}
|
||||
|
||||
public static Command getCommand(CommandContext<?> ctx, String name) {
|
||||
|
||||
@@ -12,7 +12,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class EnumArgumentType<T extends Enum<?>> implements ArgumentType<T> {
|
||||
import static me.alpha432.oyvey.features.commands.ArgumentSuggestions.suggest;
|
||||
|
||||
public final class EnumArgumentType<T extends Enum<?>> implements ArgumentType<T> {
|
||||
private final Map<String, T> enumNameMap = new HashMap<>();
|
||||
private final T defaultValue;
|
||||
|
||||
@@ -42,14 +44,7 @@ public class EnumArgumentType<T extends Enum<?>> implements ArgumentType<T> {
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String input = builder.getRemainingLowerCase();
|
||||
for (String key : enumNameMap.keySet()) {
|
||||
String name = key.toLowerCase();
|
||||
if (name.contains(input)) {
|
||||
builder.suggest(name);
|
||||
}
|
||||
}
|
||||
return builder.buildFuture();
|
||||
return suggest(enumNameMap.keySet(), builder);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.alpha432.oyvey.features.commands.argument;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public record GreedyArgumentType<T>(ArgumentType<T> parent, Class<T> type) implements ArgumentType<T[]> {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T[] parse(StringReader reader) throws CommandSyntaxException {
|
||||
String input = reader.getRemaining();
|
||||
reader.setCursor(reader.getTotalLength());
|
||||
String[] split = input.split(" ");
|
||||
T[] values = (T[]) Array.newInstance(type, split.length);
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
values[i] = parent.parse(new StringReader(split[i]));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String[] s = builder.getRemaining().split(" ", -1);
|
||||
if (s.length == 0) {
|
||||
return parent.listSuggestions(context, builder);
|
||||
}
|
||||
|
||||
int st = builder.getStart() + builder.getRemaining().length() - s[s.length - 1].length();
|
||||
return parent.listSuggestions(context, new SuggestionsBuilder(builder.getInput(), st));
|
||||
}
|
||||
|
||||
public static <T> GreedyArgumentType<T> greedy(ArgumentType<T> parent, Class<T> type) {
|
||||
return new GreedyArgumentType<>(parent, type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package me.alpha432.oyvey.features.commands.argument;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import me.alpha432.oyvey.features.commands.CommandExceptions;
|
||||
import me.alpha432.oyvey.features.settings.Bind;
|
||||
import me.alpha432.oyvey.util.KeyboardUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static me.alpha432.oyvey.features.commands.ArgumentSuggestions.suggest;
|
||||
|
||||
public final class KeybindArgumentType implements ArgumentType<Bind> {
|
||||
private static final List<String> EXAMPLES = List.of("A", "RIGHT_SHIFT", "MOUSE0");
|
||||
|
||||
@Override
|
||||
public Bind parse(StringReader reader) throws CommandSyntaxException {
|
||||
String input = reader.readString();
|
||||
Bind bind = KeyboardUtil.getBind(input);
|
||||
if (bind == null) {
|
||||
throw CommandExceptions.invalidArgument("Invalid key name").createWithContext(reader);
|
||||
}
|
||||
return bind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
return suggest(KeyboardUtil.iterateKeys(), builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getExamples() {
|
||||
return EXAMPLES;
|
||||
}
|
||||
|
||||
public static KeybindArgumentType keybind() {
|
||||
return new KeybindArgumentType();
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,14 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import me.alpha432.oyvey.OyVey;
|
||||
import me.alpha432.oyvey.features.Feature;
|
||||
import me.alpha432.oyvey.features.commands.CommandExceptions;
|
||||
import me.alpha432.oyvey.features.modules.Module;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static me.alpha432.oyvey.features.commands.ArgumentSuggestions.suggest;
|
||||
|
||||
public record ModuleArgumentType(boolean fullName) implements ArgumentType<Module> {
|
||||
@Override
|
||||
public Module parse(StringReader reader) throws CommandSyntaxException {
|
||||
@@ -28,17 +31,7 @@ public record ModuleArgumentType(boolean fullName) implements ArgumentType<Modul
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String input = builder.getRemainingLowerCase();
|
||||
|
||||
for (Module module : OyVey.moduleManager.getModules()) {
|
||||
String name = module.getName().toLowerCase();
|
||||
String displayName = module.getDisplayName().toLowerCase();
|
||||
if (name.contains(input) || displayName.contains(input)) {
|
||||
builder.suggest(name);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.buildFuture();
|
||||
return suggest(OyVey.moduleManager.getModules(), Feature::getName, builder);
|
||||
}
|
||||
|
||||
public static ModuleArgumentType module() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import me.alpha432.oyvey.features.settings.Bind;
|
||||
import me.alpha432.oyvey.manager.CommandManager;
|
||||
import me.alpha432.oyvey.util.KeyboardUtil;
|
||||
|
||||
import static me.alpha432.oyvey.features.commands.argument.ModuleArgumentType.getModule;
|
||||
import static me.alpha432.oyvey.features.commands.argument.KeybindArgumentType.keybind;
|
||||
import static me.alpha432.oyvey.features.commands.argument.ModuleArgumentType.module;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
|
||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_UNKNOWN;
|
||||
@@ -25,11 +25,20 @@ public class BindCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void createArgumentBuilder(LiteralArgumentBuilder<CommandManager> builder) {
|
||||
builder.then(argument("module", module(true))
|
||||
.executes((ctx) -> {
|
||||
module = getModule(ctx, "module");
|
||||
return success("Press any key...");
|
||||
}));
|
||||
builder.then(argument("module", module(true)).then(
|
||||
argument("keybind", keybind()).executes(ctx -> {
|
||||
Module module = ctx.getArgument("module", Module.class);
|
||||
Bind bind = ctx.getArgument("keybind", Bind.class);
|
||||
module.bind.setValue(bind);
|
||||
return success("Bind for {green} %s {} set to {green} %s",
|
||||
module.getName(),
|
||||
KeyboardUtil.getKeyName(bind)
|
||||
);
|
||||
})
|
||||
).executes((ctx) -> {
|
||||
module = ctx.getArgument("module", Module.class);
|
||||
return success("Press any key...");
|
||||
}));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -40,14 +49,16 @@ public class BindCommand extends Command {
|
||||
|
||||
if (event.getKey() == GLFW_KEY_ESCAPE) {
|
||||
module = null;
|
||||
sendMessage("Operation canceled.", "fail");
|
||||
fail("Operation canceled.");
|
||||
return;
|
||||
}
|
||||
|
||||
sendMessage("Bind for {green} %s {} set to {green} %s",
|
||||
module.bind.setValue(Bind.keyboard(event.getKey()));
|
||||
success("Bind for {green} %s {} set to {green} %s",
|
||||
module.getName(),
|
||||
KeyboardUtil.getKeyName(event.getKey()));
|
||||
module.bind.setValue(new Bind(event.getKey()));
|
||||
KeyboardUtil.getKeyName(module.getBind())
|
||||
);
|
||||
|
||||
module = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,27 @@ import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import me.alpha432.oyvey.OyVey;
|
||||
import me.alpha432.oyvey.features.commands.Command;
|
||||
import me.alpha432.oyvey.manager.CommandManager;
|
||||
import me.alpha432.oyvey.util.chat.ChatUtil;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.ComponentUtils;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static me.alpha432.oyvey.features.commands.MessageSignatures.GENERAL;
|
||||
import static me.alpha432.oyvey.features.commands.argument.CommandArgumentType.command;
|
||||
import static me.alpha432.oyvey.features.commands.argument.CommandArgumentType.getCommand;
|
||||
import static me.alpha432.oyvey.features.commands.argument.NumberArgumentType.get;
|
||||
import static me.alpha432.oyvey.features.commands.argument.NumberArgumentType.number;
|
||||
import static me.alpha432.oyvey.util.TextUtil.text;
|
||||
import static me.alpha432.oyvey.util.chat.ChatUtil.prefix;
|
||||
import static me.alpha432.oyvey.util.chat.ChatUtil.withPrefix;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
private static final int ITEMS_PER_PAGE = 5;
|
||||
@@ -28,28 +38,36 @@ public class HelpCommand extends Command {
|
||||
@Override
|
||||
public void createArgumentBuilder(LiteralArgumentBuilder<CommandManager> builder) {
|
||||
builder.then(argument("page", number(Integer.class))
|
||||
.executes((ctx) -> helpCommands(ctx, get(Integer.class, ctx, "page")))
|
||||
.executes((ctx) -> helpCommands(ctx, get(Integer.class, ctx, "page"))))
|
||||
.then(argument("command_name", command())
|
||||
.executes(this::helpSpecific))
|
||||
.executes((ctx) -> helpCommands(ctx, 1)));
|
||||
.executes((ctx) -> helpCommands(ctx, 1));
|
||||
}
|
||||
|
||||
private int helpSpecific(CommandContext<CommandManager> ctx) {
|
||||
Command command = getCommand(ctx, "command_name");
|
||||
sendMessage("Usages for %s:", command.getName());
|
||||
|
||||
MutableComponent text = Component.empty();
|
||||
text.append(withPrefix("Usages for %s:\n", command.getName()));
|
||||
|
||||
ParseResults<CommandManager> results = ctx.getSource().getDispatcher()
|
||||
.parse(command.getName(), ctx.getSource());
|
||||
|
||||
if (results.getContext().getNodes().isEmpty()) {
|
||||
return success("No usages available");
|
||||
}
|
||||
text.append(withPrefix("No usages available"));
|
||||
} else {
|
||||
Map<CommandNode<CommandManager>, String> smartUsages = ctx.getSource().getDispatcher().getSmartUsage(
|
||||
Iterables.getLast(results.getContext().getNodes()).getNode(), ctx.getSource());
|
||||
List<Component> usages = new ArrayList<>();
|
||||
|
||||
Map<CommandNode<CommandManager>, String> smartUsages = ctx.getSource().getDispatcher().getSmartUsage(
|
||||
Iterables.getLast(results.getContext().getNodes()).getNode(), ctx.getSource());
|
||||
for (String usage : smartUsages.values()) {
|
||||
sendMessage(".%s %s", results.getReader().getString(), usage);
|
||||
for (String usage : smartUsages.values()) {
|
||||
usages.add(text(" {gray}.%s %s", command.getName(), usage));
|
||||
}
|
||||
|
||||
text.append(ComponentUtils.formatList(usages, Component.literal("\n")));
|
||||
}
|
||||
|
||||
ChatUtil.sendClientSideMessage(text, GENERAL);
|
||||
return success();
|
||||
}
|
||||
|
||||
@@ -66,18 +84,38 @@ public class HelpCommand extends Command {
|
||||
List<Command> paginated = commands.subList((pageIndex - 1) * ITEMS_PER_PAGE,
|
||||
Math.min(commands.size(), pageIndex * ITEMS_PER_PAGE));
|
||||
|
||||
sendMessage("Commands (%s):", "general", commands.size());
|
||||
MutableComponent text = Component.empty();
|
||||
text.append(withPrefix("Commands (%s): \n", commands.size()));
|
||||
|
||||
for (Command command : paginated) {
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (String alias : command.getAliases()) {
|
||||
joiner.add(alias);
|
||||
}
|
||||
|
||||
sendMessage("{dark_gray} %s: {reset}\n %s", "general",
|
||||
joiner, command.getDescription());
|
||||
String aliases = String.join(", ", command.getAliases());
|
||||
String description = command.getDescription();
|
||||
text.append(withPrefix("{dark_gray} %s: {reset}\n %s\n", aliases, description));
|
||||
}
|
||||
|
||||
return success("Page %s/%s", pageIndex, pages);
|
||||
text.append(buildPages(pageIndex, pages));
|
||||
|
||||
ChatUtil.sendClientSideMessage(text, GENERAL);
|
||||
return success();
|
||||
}
|
||||
|
||||
private static Component buildPages(int index, int pages) {
|
||||
String command = OyVey.commandManager.getCommandPrefix() + "help ";
|
||||
MutableComponent text = prefix();
|
||||
boolean hasPages = pages > 1;
|
||||
|
||||
if (hasPages && index != 1)
|
||||
text.append(suggest(Component.literal(" <"), command + (index - 1)));
|
||||
|
||||
text.append(text(" Page %d/%d", index, pages));
|
||||
|
||||
if (hasPages && index != pages)
|
||||
text.append(suggest(Component.literal(" > "), command + (index + 1)));
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private static Component suggest(MutableComponent component, String command) {
|
||||
return component.withStyle(s -> s.withClickEvent(new ClickEvent.SuggestCommand(command.formatted())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.alpha432.oyvey.features.gui.OyVeyGui;
|
||||
import me.alpha432.oyvey.features.modules.client.ClickGuiModule;
|
||||
import me.alpha432.oyvey.features.settings.Bind;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
import me.alpha432.oyvey.util.KeyboardUtil;
|
||||
import me.alpha432.oyvey.util.render.RenderUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
@@ -30,8 +31,7 @@ public class BindButton
|
||||
if (this.isListening) {
|
||||
drawString("Press a Key...", this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), -1);
|
||||
} else {
|
||||
String str = this.setting.getValue().toString().toUpperCase();
|
||||
str = str.replace("KEY.KEYBOARD", "").replace(".", " ");
|
||||
String str = KeyboardUtil.getKeyName(setting.getValue());
|
||||
drawString(this.setting.getName() + " " + ChatFormatting.GRAY + str, this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import me.alpha432.oyvey.event.impl.render.Render2DEvent;
|
||||
import me.alpha432.oyvey.event.impl.render.Render3DEvent;
|
||||
import me.alpha432.oyvey.features.Feature;
|
||||
import me.alpha432.oyvey.features.commands.Command;
|
||||
import me.alpha432.oyvey.features.commands.MessageSignatures;
|
||||
import me.alpha432.oyvey.features.settings.Bind;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
import me.alpha432.oyvey.manager.ConfigManager;
|
||||
@@ -88,11 +89,13 @@ public class Module extends Feature implements Jsonable, Toggleable {
|
||||
Module module = OyVey.moduleManager.getModuleByDisplayName(name);
|
||||
Module originalModule = OyVey.moduleManager.getModuleByName(name);
|
||||
if (module == null && originalModule == null) {
|
||||
Command.sendMessage(this.getDisplayName() + ", name: " + this.getName() + ", has been renamed to: " + name, "general");
|
||||
Command.sendMessage("%, name: %s, has been renamed to: %s", MessageSignatures.GENERAL,
|
||||
getDisplayName(), getName(), name);
|
||||
this.displayName.setValue(name);
|
||||
return;
|
||||
}
|
||||
Command.sendMessage("{red} A module of this name already exists.", "general");
|
||||
|
||||
Command.sendMessage("{red} A module of this name already exists.", MessageSignatures.GENERAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,16 +11,18 @@ import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import static me.alpha432.oyvey.features.commands.MessageSignatures.GENERAL;
|
||||
|
||||
public class ClickGuiModule extends Module {
|
||||
private static ClickGuiModule INSTANCE;
|
||||
|
||||
public Setting<String> prefix = str("Prefix", ".");
|
||||
public Setting<Color> color = color("Color", 0, 0, 255, 180);
|
||||
public Setting<Color> topColor = color("TopColor", 0, 0, 150, 240);
|
||||
public Setting<Boolean> rainbow = bool("Rainbow", false);
|
||||
public Setting<Integer> rainbowHue = num("Delay", 240, 0, 600);
|
||||
public Setting<Float> rainbowBrightness = num("Brightness", 150.0f, 1.0f, 255.0f);
|
||||
public Setting<Float> rainbowSaturation = num("Saturation", 150.0f, 1.0f, 255.0f);
|
||||
public final Setting<String> prefix = str("Prefix", ".");
|
||||
public final Setting<Color> color = color("Color", 0, 0, 255, 180);
|
||||
public final Setting<Color> topColor = color("TopColor", 0, 0, 150, 240);
|
||||
public final Setting<Boolean> rainbow = bool("Rainbow", false);
|
||||
public final Setting<Integer> rainbowHue = num("Delay", 240, 0, 600);
|
||||
public final Setting<Float> rainbowBrightness = num("Brightness", 150.0f, 1.0f, 255.0f);
|
||||
public final Setting<Float> rainbowSaturation = num("Saturation", 150.0f, 1.0f, 255.0f);
|
||||
|
||||
public ClickGuiModule() {
|
||||
super("ClickGui", "Opens the ClickGui", Module.Category.CLIENT);
|
||||
@@ -36,7 +38,7 @@ public class ClickGuiModule extends Module {
|
||||
if (event.getType() == ClientEvent.Type.SETTING_UPDATE && event.getSetting().getFeature().equals(this)) {
|
||||
if (event.getSetting().equals(this.prefix)) {
|
||||
OyVey.commandManager.setCommandPrefix(this.prefix.getPlannedValue());
|
||||
Command.sendMessage("Prefix set to {global} %s", OyVey.commandManager.getCommandPrefix());
|
||||
Command.sendMessage("Prefix set to {global} %s", GENERAL, OyVey.commandManager.getCommandPrefix());
|
||||
}
|
||||
if (event.getSetting().equals(this.color)) {
|
||||
OyVey.colorManager.setColor(this.color.getPlannedValue());
|
||||
|
||||
@@ -5,12 +5,14 @@ import me.alpha432.oyvey.event.system.Subscribe;
|
||||
import me.alpha432.oyvey.features.modules.Module;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
import me.alpha432.oyvey.util.TextUtil;
|
||||
import me.alpha432.oyvey.util.player.ChatUtil;
|
||||
import me.alpha432.oyvey.util.chat.ChatUtil;
|
||||
|
||||
import static me.alpha432.oyvey.util.chat.SimpleSignature.from;
|
||||
|
||||
public class NotificationsModule extends Module {
|
||||
private static final String MODULE_FORMAT = "Toggled %s %s %s";
|
||||
private static final String MODULE_FORMAT = "{gray} %s %s%s";
|
||||
|
||||
public Setting<Boolean> moduleToggle = bool("Module Toggle", true);
|
||||
public final Setting<Boolean> moduleToggle = bool("ModuleToggle", true);
|
||||
|
||||
public NotificationsModule() {
|
||||
super("Notifications", "Displays notifications for various client events", Category.CLIENT);
|
||||
@@ -28,6 +30,6 @@ public class NotificationsModule extends Module {
|
||||
ChatUtil.sendMessage(TextUtil.text(MODULE_FORMAT,
|
||||
event.getFeature().getName(),
|
||||
moduleState ? "{green}" : "{red}",
|
||||
moduleState ? "on" : "off"), event.getFeature().getName());
|
||||
moduleState ? "on" : "off"), from(event.getFeature().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.alpha432.oyvey.features.modules.combat;
|
||||
|
||||
import me.alpha432.oyvey.OyVey;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TickEvent;
|
||||
import me.alpha432.oyvey.event.system.Subscribe;
|
||||
import me.alpha432.oyvey.features.modules.Module;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
import me.alpha432.oyvey.util.models.Angles;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class KillAuraModule extends Module {
|
||||
private final Setting<Float> delay = num("Delay", 1f, 0f, 1f);
|
||||
private final Setting<Float> range = num("Range", 3f, 1f, 6f);
|
||||
private final Setting<Boolean> onlyWeapon = bool("OnlyWeapon", false);
|
||||
private final Setting<Boolean> sync = bool("MovementSync", false);
|
||||
|
||||
public KillAuraModule() {
|
||||
super("KillAura", "Attacks nearby players.", Category.COMBAT);
|
||||
}
|
||||
|
||||
@Subscribe public void onPreTick(TickEvent.Pre event) {
|
||||
if (isOnCooldown())
|
||||
return;
|
||||
|
||||
if (onlyWeapon.getValue() && !isHoldingWeapon())
|
||||
return;
|
||||
|
||||
Player target = findPlayerTarget();
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
Angles angles = Angles.entity(target);
|
||||
int priority = 0;
|
||||
|
||||
if (sync.getValue()) {
|
||||
OyVey.rotationManager.sync(angles, priority, () -> attack(target));
|
||||
} else {
|
||||
OyVey.rotationManager.motion(angles, priority, () -> attack(target));
|
||||
}
|
||||
}
|
||||
|
||||
private void attack(Entity entity) {
|
||||
mc.gameMode.attack(mc.player, entity);
|
||||
mc.player.swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
private boolean isOnCooldown() {
|
||||
float attackDelay = sync.getValue() ? 1 : 0;
|
||||
return mc.player.getAttackStrengthScale(attackDelay) < delay.getValue();
|
||||
}
|
||||
|
||||
private boolean isHoldingWeapon() {
|
||||
ItemStack stack = mc.player.getMainHandItem();
|
||||
return stack.is(ItemTags.SWORDS) || stack.is(ItemTags.AXES) || stack.is(ItemTags.SPEARS)
|
||||
|| stack.is(Items.MACE) || stack.is(Items.TRIDENT);
|
||||
}
|
||||
|
||||
private Player findPlayerTarget() {
|
||||
Player target = null;
|
||||
float min = range.getValue();
|
||||
for (Player entity : mc.level.players()) {
|
||||
float dist = entity.distanceTo(mc.player);
|
||||
if (entity == mc.player || dist > min) continue;
|
||||
if (OyVey.friendManager.isFriend(entity)) continue;
|
||||
target = entity;
|
||||
min = dist;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import me.alpha432.oyvey.features.modules.client.HudModule;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
|
||||
public class CoordinatesHudModule extends HudModule {
|
||||
public Setting<Boolean> nether = bool("Nether", false);
|
||||
public final Setting<Boolean> nether = bool("Nether", false);
|
||||
|
||||
public CoordinatesHudModule() {
|
||||
super("Coordinates", "Display coordinates", 150, 20);
|
||||
|
||||
@@ -7,8 +7,8 @@ import me.alpha432.oyvey.util.BuildConfig;
|
||||
import me.alpha432.oyvey.util.TextUtil;
|
||||
|
||||
public class WatermarkHudModule extends HudModule {
|
||||
public Setting<String> text = str("Text", BuildConfig.NAME);
|
||||
public Setting<Boolean> fullVersion = new Setting<>("FullVersion", false);
|
||||
public final Setting<String> text = str("Text", BuildConfig.NAME);
|
||||
public final Setting<Boolean> fullVersion = new Setting<>("FullVersion", false);
|
||||
|
||||
public WatermarkHudModule() {
|
||||
super("Watermark", "Display watermark", 100, 10);
|
||||
|
||||
@@ -7,6 +7,8 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import static me.alpha432.oyvey.util.chat.SimpleSignature.from;
|
||||
|
||||
public class MCFModule extends Module {
|
||||
private boolean pressed;
|
||||
|
||||
@@ -32,10 +34,10 @@ public class MCFModule extends Module {
|
||||
if (OyVey.friendManager.isFriend(name)) {
|
||||
OyVey.friendManager.removeFriend(name);
|
||||
|
||||
Command.sendMessage("{red} %s has been unfriended.", name);
|
||||
Command.sendMessage("{red} %s has been unfriended.", from(getName()), name);
|
||||
} else {
|
||||
OyVey.friendManager.addFriend(name);
|
||||
Command.sendMessage("{aqua} %s has been friended.", name);
|
||||
Command.sendMessage("{aqua} %s has been friended.", from(getName()), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ public class NoFallModule extends Module {
|
||||
public void onTick() {
|
||||
if (!mc.player.onGround() && OyVey.positionManager.getFallDistance() > 3) {
|
||||
boolean bl = mc.player.horizontalCollision;
|
||||
ServerboundMovePlayerPacket.PosRot pakcet = new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY() + 0.000000001, mc.player.getZ(),
|
||||
ServerboundMovePlayerPacket.PosRot packet = new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY() + 0.000000001, mc.player.getZ(),
|
||||
mc.player.getYRot(), mc.player.getXRot(), false, bl);
|
||||
mc.player.connection.send(pakcet);
|
||||
mc.player.connection.send(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import java.awt.*;
|
||||
|
||||
public class BlockHighlightModule extends Module {
|
||||
public Setting<Color> color = color("Color", 255, 0, 0, 255);
|
||||
public Setting<Float> lineWidth = num("LineWidth", 1.0f, 0.1f, 5.0f);
|
||||
public final Setting<Color> color = color("Color", 255, 0, 0, 255);
|
||||
public final Setting<Float> lineWidth = num("LineWidth", 1.0f, 0.1f, 5.0f);
|
||||
|
||||
public BlockHighlightModule() {
|
||||
super("BlockHighlight", "Draws box at the block that you are looking at", Category.RENDER);
|
||||
@@ -26,9 +26,9 @@ public class BlockHighlightModule extends Module {
|
||||
if (mc.hitResult instanceof BlockHitResult result) {
|
||||
VoxelShape shape = mc.level.getBlockState(result.getBlockPos()).getShape(mc.level, result.getBlockPos());
|
||||
if (shape.isEmpty() || result.getType() == HitResult.Type.MISS) return;
|
||||
AABB box = shape.bounds();
|
||||
box = box.move(result.getBlockPos());
|
||||
RenderUtil.drawBox(event.getMatrix(), box, color.getValue(), lineWidth.getValue());
|
||||
AABB aabb = shape.bounds();
|
||||
aabb = aabb.move(result.getBlockPos());
|
||||
RenderUtil.drawBox(event.getMatrix(), aabb, color.getValue(), lineWidth.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,14 @@ public class Bind implements Util {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public static Bind keyboard(int key) {
|
||||
return new Bind(key);
|
||||
}
|
||||
|
||||
public static Bind mouse(int key) {
|
||||
return new Bind(-key - 2);
|
||||
}
|
||||
|
||||
public static Bind none() {
|
||||
return new Bind(-1);
|
||||
}
|
||||
@@ -31,10 +39,14 @@ public class Bind implements Util {
|
||||
return this.key == -1;
|
||||
}
|
||||
|
||||
public boolean isMouse() {
|
||||
return key < -1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.isEmpty()) return "None";
|
||||
if (this.key < -1) return "Mouse " + (-this.key - 1);
|
||||
return this.capitalise(InputConstants.getKey(new KeyEvent(this.key, 0, 0)).getName());
|
||||
return this.capitalise(InputConstants.getKey(new KeyEvent(this.key, 0, 0)).getName().replace("key.keyboard.", ""));
|
||||
}
|
||||
|
||||
public boolean isDown() {
|
||||
@@ -67,7 +79,7 @@ public class Bind implements Util {
|
||||
}
|
||||
int key = -1;
|
||||
try {
|
||||
key = InputConstants.getKey(s.toUpperCase()).getValue();
|
||||
key = InputConstants.getKey("key.keyboard" + s).getValue();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (key == 0) return Bind.none();
|
||||
|
||||
@@ -4,6 +4,7 @@ import me.alpha432.oyvey.event.impl.ClientEvent;
|
||||
import me.alpha432.oyvey.features.Feature;
|
||||
import org.joml.Vector2f;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -255,6 +256,9 @@ public class Setting<T> {
|
||||
}
|
||||
|
||||
public String getValueAsString() {
|
||||
if (value instanceof Color color) {
|
||||
return "%d, %d, %d".formatted(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
return this.value.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
import static me.alpha432.oyvey.features.commands.Command.SINGLE_FAILURE;
|
||||
import static me.alpha432.oyvey.features.commands.MessageIdentifiers.GENERAL;
|
||||
import static me.alpha432.oyvey.features.commands.MessageSignatures.GENERAL;
|
||||
import static me.alpha432.oyvey.features.commands.MessageSignatures.SUCCESS;
|
||||
|
||||
public class CommandManager extends Feature implements Jsonable {
|
||||
private static final Logger LOGGER = LogManager.getLogger("Commands");
|
||||
@@ -48,10 +48,8 @@ public class CommandManager extends Feature implements Jsonable {
|
||||
try {
|
||||
int result = dispatcher.execute(message.substring(commandPrefix.length()).trim(), this);
|
||||
|
||||
if (result == SINGLE_SUCCESS) {
|
||||
Command.sendMessage("{green} Command executed successfully", GENERAL);
|
||||
} else if (result == SINGLE_FAILURE) {
|
||||
Command.sendMessage("{red} Failed to execute command", GENERAL);
|
||||
if (result == SINGLE_FAILURE) {
|
||||
Command.sendMessage("{red} Failed to execute command", SUCCESS);
|
||||
}
|
||||
} catch (CommandSyntaxException e) {
|
||||
LOGGER.error("Failed to execute command", e);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class EventManager extends Feature {
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onTick(TickEvent event) {
|
||||
public void onTick(TickEvent.Post event) {
|
||||
if (nullCheck())
|
||||
return;
|
||||
OyVey.moduleManager.onTick();
|
||||
@@ -40,21 +40,6 @@ public class EventManager extends Feature {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onUpdateWalkingPlayer(UpdateWalkingPlayerEvent event) {
|
||||
if (nullCheck())
|
||||
return;
|
||||
if (event.getStage() == Stage.PRE) {
|
||||
OyVey.speedManager.update();
|
||||
OyVey.rotationManager.updateRotations();
|
||||
OyVey.positionManager.updatePosition();
|
||||
}
|
||||
if (event.getStage() == Stage.POST) {
|
||||
OyVey.rotationManager.restoreRotations();
|
||||
OyVey.positionManager.restorePosition();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPacketReceive(PacketEvent.Receive event) {
|
||||
OyVey.serverManager.onPacketReceived();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class HoleManager extends Feature {
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onTick(TickEvent event) {
|
||||
private void onTick(TickEvent.Pre event) {
|
||||
holes.clear();
|
||||
for (int x = -RANGE; x < RANGE; x++) {
|
||||
for (int y = -RANGE; y < RANGE; y++) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import me.alpha432.oyvey.features.modules.Module;
|
||||
import me.alpha432.oyvey.features.modules.client.ClickGuiModule;
|
||||
import me.alpha432.oyvey.features.modules.client.HudEditorModule;
|
||||
import me.alpha432.oyvey.features.modules.client.NotificationsModule;
|
||||
import me.alpha432.oyvey.features.modules.combat.KillAuraModule;
|
||||
import me.alpha432.oyvey.features.modules.combat.CriticalsModule;
|
||||
import me.alpha432.oyvey.features.modules.combat.KeyPearlModule;
|
||||
import me.alpha432.oyvey.features.modules.hud.CoordinatesHudModule;
|
||||
@@ -51,6 +52,7 @@ public class ModuleManager implements Jsonable, Util {
|
||||
register(new BlockHighlightModule());
|
||||
register(new NoFallModule());
|
||||
register(new KeyPearlModule());
|
||||
register(new KillAuraModule());
|
||||
|
||||
LOGGER.info("Registered {} modules", modules.size());
|
||||
|
||||
|
||||
@@ -1,75 +1,162 @@
|
||||
package me.alpha432.oyvey.manager;
|
||||
|
||||
import me.alpha432.oyvey.util.MathUtil;
|
||||
import me.alpha432.oyvey.event.Stage;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TickEvent;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TravelEvent;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.UpdateWalkingPlayerEvent;
|
||||
import me.alpha432.oyvey.event.system.Subscribe;
|
||||
import me.alpha432.oyvey.util.models.Angles;
|
||||
import me.alpha432.oyvey.util.traits.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class RotationManager implements Util {
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private final List<Callback> callbacks = new ArrayList<>();
|
||||
|
||||
public void updateRotations() {
|
||||
this.yaw = mc.player.getYRot();
|
||||
this.pitch = mc.player.getXRot();
|
||||
private boolean updateRender;
|
||||
private Angles renderSnapshot, renderSnapshot0;
|
||||
|
||||
private Angles snapshot;
|
||||
private Angles travelSnapshot;
|
||||
|
||||
public RotationManager() {
|
||||
EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public void restoreRotations() {
|
||||
mc.player.setYRot(yaw);
|
||||
mc.player.yHeadRot = yaw;
|
||||
mc.player.setXRot(pitch);
|
||||
@Subscribe(priority = 1000)
|
||||
public void onTickPre(TickEvent.Pre event) {
|
||||
executeCallbacks(callback -> callback.type() == Type.SYNC);
|
||||
}
|
||||
|
||||
public void setPlayerRotations(float yaw, float pitch) {
|
||||
mc.player.setYRot(yaw);
|
||||
mc.player.yHeadRot = yaw;
|
||||
mc.player.setXRot(pitch);
|
||||
@Subscribe
|
||||
public void onTravelPre(TravelEvent.Pre event) {
|
||||
if (callbacks.isEmpty())
|
||||
return;
|
||||
|
||||
Callback highest = callbacks.stream().max(Comparator.comparing(Callback::priority)).orElseThrow();
|
||||
if (highest.type() == Type.SYNC) {
|
||||
travelSnapshot = new Angles(mc.player.getYRot(), mc.player.getXRot());
|
||||
mc.player.setYRot(highest.angles().yRot());
|
||||
mc.player.setXRot(highest.angles().xRot());
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerYaw(float yaw) {
|
||||
mc.player.setYRot(yaw);
|
||||
mc.player.yHeadRot = yaw;
|
||||
@Subscribe
|
||||
public void onTravelPost(TravelEvent.Post event) {
|
||||
if (travelSnapshot != null) {
|
||||
mc.player.setYRot(travelSnapshot.yRot());
|
||||
mc.player.setXRot(travelSnapshot.xRot());
|
||||
travelSnapshot = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void lookAtPos(BlockPos pos) {
|
||||
float[] angle = MathUtil.calcAngle(mc.player.getEyePosition(), new Vec3((float) pos.getX() + 0.5f, (float) pos.getY() + 0.5f, (float) pos.getZ() + 0.5f));
|
||||
this.setPlayerRotations(angle[0], angle[1]);
|
||||
@Subscribe
|
||||
public void onUpdateWalking(UpdateWalkingPlayerEvent event) {
|
||||
if (event.getStage() == Stage.PRE) {
|
||||
if (callbacks.isEmpty()) {
|
||||
updateRenderSnapshot(new Angles(mc.player.getYRot(), mc.player.getXRot()), false);
|
||||
return;
|
||||
}
|
||||
Callback highest = callbacks.stream().max(Comparator.comparing(Callback::priority)).orElseThrow();
|
||||
|
||||
updateRenderSnapshot(highest.angles(), true);
|
||||
|
||||
snapshot = new Angles(mc.player.getYRot(), mc.player.getXRot());
|
||||
mc.player.setYRot(highest.angles().yRot());
|
||||
mc.player.setXRot(highest.angles().xRot());
|
||||
} else if (snapshot != null) {
|
||||
executeCallbacks(callback -> callback.type() == Type.MOTION);
|
||||
|
||||
mc.player.setYRot(snapshot.yRot());
|
||||
mc.player.setXRot(snapshot.xRot());
|
||||
snapshot = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void lookAtVec3d(Vec3 vec3d) {
|
||||
float[] angle = MathUtil.calcAngle(mc.player.getEyePosition(), new Vec3(vec3d.x, vec3d.y, vec3d.z));
|
||||
this.setPlayerRotations(angle[0], angle[1]);
|
||||
public void sync(Angles angles, Runnable runnable) {
|
||||
sync(angles, 0, runnable);
|
||||
}
|
||||
|
||||
public void lookAtVec3d(double x, double y, double z) {
|
||||
Vec3 vec3d = new Vec3(x, y, z);
|
||||
this.lookAtVec3d(vec3d);
|
||||
public void sync(Angles angles, int priority, Runnable runnable) {
|
||||
request(Type.SYNC, angles, priority, runnable);
|
||||
}
|
||||
|
||||
public void lookAtEntity(Entity entity) {
|
||||
float[] angle = MathUtil.calcAngle(mc.player.getEyePosition(), entity.getEyePosition());
|
||||
this.setPlayerRotations(angle[0], angle[1]);
|
||||
public void motion(Angles angles, Runnable runnable) {
|
||||
motion(angles, 0, runnable);
|
||||
}
|
||||
|
||||
public void setPlayerPitch(float pitch) {
|
||||
mc.player.setXRot(pitch);
|
||||
public void motion(Angles angles, int priority, Runnable runnable) {
|
||||
request(Type.MOTION, angles, priority, runnable);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.yaw;
|
||||
public void silent(Angles angles, Runnable runnable) {
|
||||
request(Type.SILENT, angles, 0, runnable);
|
||||
}
|
||||
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
public Angles getLerpRenderSnapshot(float lerp) {
|
||||
if (!updateRender) return null;
|
||||
return new Angles(
|
||||
Mth.lerp(lerp, renderSnapshot0.yRot(), renderSnapshot.yRot()),
|
||||
Mth.lerp(lerp, renderSnapshot0.xRot(), renderSnapshot.xRot())
|
||||
);
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.pitch;
|
||||
public void sendDuplicate(float yaw, float pitch) {
|
||||
mc.player.positionReminder = 20;
|
||||
mc.player.yRotLast = yaw;
|
||||
mc.player.xRotLast = pitch;
|
||||
mc.player.connection.send(new ServerboundMovePlayerPacket.PosRot(
|
||||
mc.player.getX(), mc.player.getY(), mc.player.getZ(),
|
||||
yaw, pitch,
|
||||
mc.player.onGround(), mc.player.horizontalCollision
|
||||
));
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
private void request(Type type, Angles angles, int priority, Runnable runnable) {
|
||||
Callback callback = new Callback(type, angles, priority, runnable);
|
||||
if (type == Type.SILENT) {
|
||||
sendDuplicate(angles.yRot(), angles.xRot());
|
||||
callback.execute();
|
||||
} else {
|
||||
callbacks.add(callback);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeCallbacks(Predicate<Callback> filter) {
|
||||
callbacks.removeIf(callback -> {
|
||||
if (filter.test(callback)) {
|
||||
callback.execute();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateRenderSnapshot(Angles angles, boolean update) {
|
||||
this.renderSnapshot0 = this.renderSnapshot;
|
||||
this.renderSnapshot = angles;
|
||||
this.updateRender = update;
|
||||
|
||||
if (renderSnapshot0 == null || renderSnapshot == null)
|
||||
return;
|
||||
|
||||
if (Mth.abs(renderSnapshot.yRot() - renderSnapshot0.yRot()) > 320) {
|
||||
this.renderSnapshot0 = this.renderSnapshot;
|
||||
}
|
||||
}
|
||||
|
||||
record Callback(Type type, Angles angles, int priority, Runnable action) {
|
||||
public void execute() {
|
||||
if (action != null) action.run();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
MOTION,
|
||||
SYNC,
|
||||
SILENT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.alpha432.oyvey.mixin.entity;
|
||||
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TravelEvent;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS;
|
||||
import static me.alpha432.oyvey.util.traits.Util.isLocalPlayer;
|
||||
|
||||
@Mixin(AbstractClientPlayer.class)
|
||||
public class MixinAbstractClientPlayer {
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void travelPreHook(CallbackInfo ci) {
|
||||
if (isLocalPlayer(this)) {
|
||||
EVENT_BUS.post(new TravelEvent.Pre());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("TAIL"))
|
||||
private void travelPostHook(CallbackInfo ci) {
|
||||
if (isLocalPlayer(this)) {
|
||||
EVENT_BUS.post(new TravelEvent.Post());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,14 @@ import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS;
|
||||
|
||||
@Mixin(LocalPlayer.class)
|
||||
public class MixinClientPlayerEntity {
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void tickPreHook(CallbackInfo ci) {
|
||||
EVENT_BUS.post(new TickEvent.Pre());
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("TAIL"))
|
||||
private void tickHook(CallbackInfo ci) {
|
||||
EVENT_BUS.post(new TickEvent());
|
||||
EVENT_BUS.post(new TickEvent.Post());
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/AbstractClientPlayer;tick()V", shift = At.Shift.AFTER))
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.alpha432.oyvey.mixin.render;
|
||||
|
||||
import me.alpha432.oyvey.OyVey;
|
||||
import me.alpha432.oyvey.util.models.Angles;
|
||||
import net.minecraft.client.renderer.entity.player.AvatarRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.AvatarRenderState;
|
||||
import net.minecraft.world.entity.Avatar;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static me.alpha432.oyvey.util.traits.Util.mc;
|
||||
|
||||
@Mixin(AvatarRenderer.class)
|
||||
public class MixinAvatarRenderer {
|
||||
@Inject(method = "extractRenderState(Lnet/minecraft/world/entity/Avatar;Lnet/minecraft/client/renderer/entity/state/AvatarRenderState;F)V", at = @At("TAIL"))
|
||||
private <T extends Avatar> void extractRenderStateHook(T avatar, AvatarRenderState state, float f, CallbackInfo ci) {
|
||||
if (mc.player != avatar) return;
|
||||
Angles lerped = OyVey.rotationManager.getLerpRenderSnapshot(f);
|
||||
if (lerped == null) return;
|
||||
state.xRot = lerped.xRot();
|
||||
state.yRot = 0;
|
||||
state.bodyRot = lerped.yRot();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import me.alpha432.oyvey.ducks.render.IChatComponent;
|
||||
import net.minecraft.client.GuiMessage;
|
||||
import net.minecraft.client.gui.components.ChatComponent;
|
||||
import net.minecraft.network.chat.MessageSignature;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -11,13 +11,16 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS;
|
||||
import static me.alpha432.oyvey.util.traits.Util.mc;
|
||||
|
||||
@Mixin(Gui.class)
|
||||
public class MixinGui {
|
||||
|
||||
@Inject(method = "render", at = @At("RETURN"))
|
||||
public void render(GuiGraphics context, DeltaTracker tickCounter, CallbackInfo ci) {
|
||||
if (Minecraft.getInstance().gui.getDebugOverlay().showDebugScreen()) return;
|
||||
boolean debugOpen = mc.debugEntries.isOverlayVisible();
|
||||
|
||||
if (debugOpen) return;
|
||||
|
||||
Render2DEvent event = new Render2DEvent(context, tickCounter.getGameTimeDeltaPartialTick(true));
|
||||
EVENT_BUS.post(event);
|
||||
|
||||
@@ -1,11 +1,57 @@
|
||||
package me.alpha432.oyvey.util;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import me.alpha432.oyvey.features.settings.Bind;
|
||||
import net.minecraft.client.input.KeyEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class KeyboardUtil {
|
||||
public static String getKeyName(int key) {
|
||||
String str = new Bind(key).toString().toUpperCase();
|
||||
str = str.replace("KEY.KEYBOARD", "").replace(".", " ");
|
||||
return str;
|
||||
public static String getKeyName(int key, boolean mouse) {
|
||||
return getKeyName(mouse ? Bind.mouse(key) : Bind.keyboard(key));
|
||||
}
|
||||
|
||||
public static String getKeyName(Bind bind) {
|
||||
if (bind.isEmpty()) return "NONE";
|
||||
if (bind.isMouse()) return "MOUSE" + (-bind.getKey() - 1);
|
||||
return getKeyName(InputConstants.getKey(new KeyEvent(bind.getKey(), 0, 0)));
|
||||
}
|
||||
|
||||
public static String getKeyName(InputConstants.Key key) {
|
||||
return key.getName()
|
||||
.replace("key.mouse.", "")
|
||||
.replace("key.keyboard.", "")
|
||||
.replace(".", "_")
|
||||
.toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public static Bind getBind(String name) {
|
||||
String lowercaseName = name.toLowerCase(Locale.ROOT).replace("_", ".");
|
||||
if (name.startsWith("mouse")) {
|
||||
try {
|
||||
return new Bind(-Integer.parseInt(name.substring(5)) - 1);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
InputConstants.Key key = InputConstants.getKey("key.keyboard." + lowercaseName);
|
||||
return new Bind(key.getValue());
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterable<String> iterateKeys() {
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (InputConstants.Key key : InputConstants.Type.KEYSYM.map.values())
|
||||
keys.add(getKeyName(key));
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
keys.add("MOUSE" + i);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,4 +204,12 @@ public class MathUtil
|
||||
double dist = Math.sqrt(difX * difX + difZ * difZ);
|
||||
return new float[]{(float) Mth.wrapDegrees(Math.toDegrees(Math.atan2(difZ, difX)) - 90.0), (float) Mth.wrapDegrees(Math.toDegrees(Math.atan2(difY, dist)))};
|
||||
}
|
||||
|
||||
public static Vec3 clamp(Vec3 vec3d, AABB aabb) {
|
||||
return new Vec3(
|
||||
clamp(vec3d.x, aabb.minX, aabb.maxX),
|
||||
clamp(vec3d.y, aabb.minY, aabb.maxY),
|
||||
clamp(vec3d.z, aabb.minZ, aabb.maxZ)
|
||||
);
|
||||
}
|
||||
}
|
||||
+29
-20
@@ -1,35 +1,51 @@
|
||||
package me.alpha432.oyvey.util.player;
|
||||
package me.alpha432.oyvey.util.chat;
|
||||
|
||||
import me.alpha432.oyvey.OyVey;
|
||||
import me.alpha432.oyvey.ducks.render.IChatComponent;
|
||||
import me.alpha432.oyvey.features.commands.Command;
|
||||
import me.alpha432.oyvey.util.TextUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.GuiMessage;
|
||||
import net.minecraft.client.GuiMessageTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MessageSignature;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static me.alpha432.oyvey.util.traits.Util.mc;
|
||||
|
||||
public class ChatUtil {
|
||||
public static void sendMessage(Component message, String identifier) {
|
||||
sendClientSideMessage(Component.empty()
|
||||
.setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))
|
||||
.append("<")
|
||||
.append(getClientNameComponent())
|
||||
.append(">")
|
||||
.append(" ")
|
||||
.append(message), identifier);
|
||||
public static MutableComponent prefix() {
|
||||
return withPrefix((Component) null);
|
||||
}
|
||||
|
||||
public static void sendClientSideMessage(Component message, String identifier) {
|
||||
public static MutableComponent withPrefix(String string) {
|
||||
return withPrefix(string, new Object[0]);
|
||||
}
|
||||
|
||||
public static MutableComponent withPrefix(String string, Object... o) {
|
||||
return withPrefix(TextUtil.text(string, o));
|
||||
}
|
||||
|
||||
public static MutableComponent withPrefix(Component component) {
|
||||
MutableComponent text = Component.empty()
|
||||
.setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))
|
||||
.append(Component.literal("<"))
|
||||
.append(getClientNameComponent())
|
||||
.append(Component.literal(">"));
|
||||
if (component != null) text.append(" ").append(component);
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void sendMessage(Component message, Signature identifier) {
|
||||
sendClientSideMessage(withPrefix(message), identifier);
|
||||
}
|
||||
|
||||
public static void sendClientSideMessage(Component message, Signature sig) {
|
||||
if (Command.nullCheck()) return;
|
||||
|
||||
IChatComponent chat = (IChatComponent) mc.gui.getChat();
|
||||
MessageSignature signature = new MessageSignature(get256Bytes(identifier));
|
||||
MessageSignature signature = new MessageSignature(sig.getByteSignature());
|
||||
chat.oyvey$removeMessage(signature);
|
||||
chat.oyvey$addMessage(new GuiMessage(mc.gui.getGuiTicks(), message, signature, getMessageTag()));
|
||||
}
|
||||
@@ -41,11 +57,4 @@ public class ChatUtil {
|
||||
private static GuiMessageTag getMessageTag() {
|
||||
return new GuiMessageTag(OyVey.colorManager.getColorAsInt(), null, null, null);
|
||||
}
|
||||
|
||||
private static byte[] get256Bytes(String identifier) {
|
||||
byte[] bytes = new byte[256];
|
||||
byte[] identifierBytes = identifier.getBytes(StandardCharsets.UTF_8);
|
||||
System.arraycopy(identifierBytes, 0, bytes, 0, Math.min(bytes.length, identifierBytes.length));
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.alpha432.oyvey.util.chat;
|
||||
|
||||
public interface Signature {
|
||||
byte[] getByteSignature();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.alpha432.oyvey.util.chat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class SimpleSignature implements Signature {
|
||||
private static final MessageDigest MESSAGE_DIGEST;
|
||||
|
||||
private final byte[] signature;
|
||||
|
||||
SimpleSignature(byte[] signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public static SimpleSignature from(String content) {
|
||||
byte[] sig = allocateBuf()
|
||||
.put((byte) 1)
|
||||
.put(sha256(content))
|
||||
.array();
|
||||
return new SimpleSignature(sig);
|
||||
}
|
||||
|
||||
public static SimpleSignature fromInt(int id) {
|
||||
byte[] sig = allocateBuf()
|
||||
.put((byte) 2)
|
||||
.putInt(id)
|
||||
.array();
|
||||
return new SimpleSignature(sig);
|
||||
}
|
||||
|
||||
public static SimpleSignature fromLong(long id) {
|
||||
byte[] sig = allocateBuf()
|
||||
.put((byte) 3)
|
||||
.putLong(id)
|
||||
.array();
|
||||
return new SimpleSignature(sig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getByteSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
private static byte[] sha256(String content) {
|
||||
return MESSAGE_DIGEST.digest(content.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static ByteBuffer allocateBuf() {
|
||||
return ByteBuffer.allocate(256);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
MESSAGE_DIGEST = MessageDigest.getInstance("SHA-512");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package me.alpha432.oyvey.util.models;
|
||||
|
||||
import me.alpha432.oyvey.util.MathUtil;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import static me.alpha432.oyvey.util.traits.Util.mc;
|
||||
|
||||
public record Angles(float yRot, float xRot) {
|
||||
public Angles(float[] rot) {
|
||||
this(rot[0], rot[1]);
|
||||
}
|
||||
|
||||
public static Angles pos(Vec3 pos) {
|
||||
return new Angles(MathUtil.calcAngle(mc.player.getEyePosition(), pos));
|
||||
}
|
||||
|
||||
public static Angles entity(Entity entity) {
|
||||
return pos(MathUtil.clamp(mc.player.getEyePosition(), entity.getBoundingBox()));
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,8 @@ import net.minecraft.client.Minecraft;
|
||||
public interface Util {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
EventBus EVENT_BUS = new EventBus();
|
||||
|
||||
static boolean isLocalPlayer(Object o) {
|
||||
return o == mc.player;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,9 @@ accessible field net/minecraft/network/protocol/game/ServerboundInteractPacket e
|
||||
accessible method net/minecraft/network/protocol/game/ServerboundInteractPacket$Action getType ()Lnet/minecraft/network/protocol/game/ServerboundInteractPacket$ActionType;
|
||||
accessible class net/minecraft/network/protocol/game/ServerboundInteractPacket$ActionType
|
||||
accessible field net/minecraft/network/protocol/game/ServerboundInteractPacket action Lnet/minecraft/network/protocol/game/ServerboundInteractPacket$Action;
|
||||
accessible method net/minecraft/client/multiplayer/MultiPlayerGameMode ensureHasSentCarriedItem ()V
|
||||
accessible method net/minecraft/client/multiplayer/MultiPlayerGameMode ensureHasSentCarriedItem ()V
|
||||
accessible field com/mojang/blaze3d/platform/InputConstants$Type map Lit/unimi/dsi/fastutil/ints/Int2ObjectMap;
|
||||
|
||||
accessible field net/minecraft/client/player/LocalPlayer positionReminder I
|
||||
accessible field net/minecraft/client/player/LocalPlayer yRotLast F
|
||||
accessible field net/minecraft/client/player/LocalPlayer xRotLast F
|
||||
@@ -7,13 +7,15 @@
|
||||
"network.MixinConnection"
|
||||
],
|
||||
"client": [
|
||||
"entity.MixinAbstractClientPlayer",
|
||||
"entity.MixinClientPlayerEntity",
|
||||
"input.MixinKeyboardHandler",
|
||||
"input.MixinMouseHandler",
|
||||
"network.MixinClientPacketListener",
|
||||
"render.MixinAvatarRenderer",
|
||||
"render.MixinChatComponent",
|
||||
"render.MixinLevelRenderer",
|
||||
"render.MixinDeltaTrackerTimer",
|
||||
"render.MixinLevelRenderer",
|
||||
"render.gui.MixinCommandSuggestions",
|
||||
"render.gui.MixinGui"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user