diff --git a/src/main/java/best/azura/eventbus/core/Event.java b/src/main/java/best/azura/eventbus/core/Event.java deleted file mode 100644 index fdb4414..0000000 --- a/src/main/java/best/azura/eventbus/core/Event.java +++ /dev/null @@ -1,9 +0,0 @@ -package best.azura.eventbus.core; - -import dev.blend.event.api.EventBus; - -public interface Event{ - default void call() { - EventBus.INSTANCE.post(this); - } -} \ No newline at end of file diff --git a/src/main/java/best/azura/eventbus/core/EventPriority.java b/src/main/java/best/azura/eventbus/core/EventPriority.java deleted file mode 100644 index a062d74..0000000 --- a/src/main/java/best/azura/eventbus/core/EventPriority.java +++ /dev/null @@ -1,9 +0,0 @@ -package best.azura.eventbus.core; - -public final class EventPriority { - public static final int LOWEST = 4; - public static final int LOWER = 3; - public static final int DEFAULT = 2; - public static final int HIGHER = 1; - public static final int HIGHEST = 0; -} diff --git a/src/main/java/best/azura/eventbus/events/CancellableEvent.java b/src/main/java/best/azura/eventbus/events/CancellableEvent.java deleted file mode 100644 index cf52348..0000000 --- a/src/main/java/best/azura/eventbus/events/CancellableEvent.java +++ /dev/null @@ -1,13 +0,0 @@ -package best.azura.eventbus.events; - -import best.azura.eventbus.core.Event; - -public abstract class CancellableEvent implements Event { - private boolean cancelled; - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - public boolean isCancelled() { - return cancelled; - } -} \ No newline at end of file diff --git a/src/main/java/best/azura/eventbus/handler/EventExecutable.java b/src/main/java/best/azura/eventbus/handler/EventExecutable.java deleted file mode 100644 index 4e00ff0..0000000 --- a/src/main/java/best/azura/eventbus/handler/EventExecutable.java +++ /dev/null @@ -1,68 +0,0 @@ -package best.azura.eventbus.handler; - -import best.azura.eventbus.core.Event; -import best.azura.eventbus.core.EventPriority; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -public final class EventExecutable { - - // Parental object - private final Object parent; - - // MethodHandler instance for registered methods - private MethodHandler method; - - // ListenerHandler instance for registered listeners - private ListenerHandler listener; - - private final int priority; - - public EventExecutable(final Method method, final Object parent, final int eventPriority) { - this(method, null, parent, eventPriority); - } - - public EventExecutable(final Field field, final Object parent, final int eventPriority) { - this(null, field, parent, eventPriority); - } - - public EventExecutable(final Class clazz, final Listener listener, final Object parent, final int eventPriority) { - this((Method) null, null, parent, eventPriority); - this.listener = new ListenerHandler<>(clazz, listener); - } - - public EventExecutable(final Method method, final Field field, final Object parent, final int priority) { - this.parent = parent; - this.priority = priority; - //Registering a listener if the field isn't null - if (field != null) { - try { - field.setAccessible(true); - this.listener = new ListenerHandler<>(field.getGenericType(), (Listener) field.get(parent)); - } catch (Exception e) { - this.listener = null; - e.printStackTrace(); - } - } else { - this.listener = null; - } - //Registering the method if it isn't null - if (method != null && method.getParameterCount() == 1) { - this.method = new MethodHandler(method, parent); - } - } - - public Object getParent() { - return parent; - } - - public int getPriority() { - return priority; - } - - public void call(final Event event) { - if (listener != null) listener.call(event); - if (method != null) method.call(event); - } -} \ No newline at end of file diff --git a/src/main/java/best/azura/eventbus/handler/EventHandler.java b/src/main/java/best/azura/eventbus/handler/EventHandler.java deleted file mode 100644 index fa690d6..0000000 --- a/src/main/java/best/azura/eventbus/handler/EventHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -package best.azura.eventbus.handler; - -import best.azura.eventbus.core.EventPriority; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ElementType.FIELD, ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -public @interface EventHandler { - int value() default EventPriority.DEFAULT; -} \ No newline at end of file diff --git a/src/main/java/best/azura/eventbus/handler/Listener.java b/src/main/java/best/azura/eventbus/handler/Listener.java deleted file mode 100644 index 23dbecb..0000000 --- a/src/main/java/best/azura/eventbus/handler/Listener.java +++ /dev/null @@ -1,17 +0,0 @@ -package best.azura.eventbus.handler; - -import best.azura.eventbus.core.Event; - -/** - * @author Solastis - * DATE:19.12.21 - */ -public interface Listener { - - /** - * Method for calling an event - * - * @param event event that should be called - */ - void call(final T event); -} diff --git a/src/main/java/best/azura/eventbus/handler/ListenerHandler.java b/src/main/java/best/azura/eventbus/handler/ListenerHandler.java deleted file mode 100644 index 792192f..0000000 --- a/src/main/java/best/azura/eventbus/handler/ListenerHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -package best.azura.eventbus.handler; - -import best.azura.eventbus.core.Event; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -public final class ListenerHandler { - private final Type type; - private final Listener listener; - private final Class typeClass; - - public ListenerHandler(Type type, Listener listener) { - this.type = type; - this.listener = listener; - if (type instanceof Class) - this.typeClass = (Class) type; - else if (type instanceof ParameterizedType) - this.typeClass = (Class) ((ParameterizedType) this.type).getActualTypeArguments()[0]; - else throw new IllegalArgumentException("Type must be a class or a parameterized type"); - } - - @SuppressWarnings("unchecked") - public void call(final Event event) { - if (!this.typeClass.equals(event.getClass()) && - !this.typeClass.equals(Event.class)) return; - - this.listener.call((T) event); - } - - public Class getTypeClass() { - return typeClass; - } - - public Type getType() { - return type; - } -} \ No newline at end of file diff --git a/src/main/java/best/azura/eventbus/handler/MethodHandler.java b/src/main/java/best/azura/eventbus/handler/MethodHandler.java deleted file mode 100644 index 4d10db4..0000000 --- a/src/main/java/best/azura/eventbus/handler/MethodHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -package best.azura.eventbus.handler; - -import best.azura.eventbus.core.Event; - -import java.lang.reflect.Method; - -public final class MethodHandler { - private final Object parent; - private Method method; - - public MethodHandler(Method method, Object parent) { - this.method = method; - this.parent = parent; - if (!this.isValid(this.method)) { - this.method = null; - return; - } - this.method.setAccessible(true); - } - - private boolean isValid(Method method) { - if (method.getParameterCount() == 0) return false; - - Class parameterTypes = method.getParameterTypes()[0]; - Class[] interfaces = parameterTypes.getInterfaces(); - Class superclass = parameterTypes.getSuperclass(); - - if (interfaces.length != 0) - return this.isValid(interfaces[0]); - if (this.isValid(parameterTypes) || this.isValid(superclass)) - return true; - return this.isValid(superclass.getInterfaces()[0]); - } - - private boolean isValid(Class clazz) { - return clazz.equals(Event.class); - } - - - public void call(final Event event) { - if (this.method == null) return; - try { - this.method.invoke(parent, event); - } catch (Exception ignored) {} - } - -} \ No newline at end of file diff --git a/src/main/java/dev/blend/interfaces/KeybindingAccessor.java b/src/main/java/dev/blend/interfaces/KeybindingAccessor.java deleted file mode 100644 index d851cd1..0000000 --- a/src/main/java/dev/blend/interfaces/KeybindingAccessor.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.blend.interfaces; - -import net.minecraft.client.util.InputUtil; - -public interface KeybindingAccessor { - InputUtil.Key getBoundKey(); -} diff --git a/src/main/java/dev/blend/mixin/client/KeyboardMixin.java b/src/main/java/dev/blend/mixin/client/KeyboardMixin.java deleted file mode 100644 index 5612d5a..0000000 --- a/src/main/java/dev/blend/mixin/client/KeyboardMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package dev.blend.mixin.client; - -import dev.blend.event.impl.KeyEvent; -import net.minecraft.client.Keyboard; -import net.minecraft.client.MinecraftClient; -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; - -@Mixin(Keyboard.class) -public class KeyboardMixin { - - @Inject( - method = "onKey", - at = @At( - value = "HEAD" - ) - ) - private void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) { - if ( - MinecraftClient.getInstance().getWindow().getHandle() == window - && MinecraftClient.getInstance().player != null - && MinecraftClient.getInstance().world != null - && MinecraftClient.getInstance().currentScreen == null - ) { - new KeyEvent(window, key, scancode, action, modifiers).call(); - } - } - -} diff --git a/src/main/java/dev/blend/mixin/client/MinecraftClientMixin.java b/src/main/java/dev/blend/mixin/client/MinecraftClientMixin.java deleted file mode 100644 index 9cf22b0..0000000 --- a/src/main/java/dev/blend/mixin/client/MinecraftClientMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -package dev.blend.mixin.client; - -import dev.blend.handler.impl.ThemeHandler; -import dev.blend.util.render.DrawUtil; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.RunArgs; -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; - -@Mixin(MinecraftClient.class) -public class MinecraftClientMixin { - - @Inject( - method = "", - at = @At( - value = "NEW", - target = "(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/render/item/HeldItemRenderer;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/client/render/BufferBuilderStorage;)Lnet/minecraft/client/render/GameRenderer;" - ) - ) - private void createNanoVGContext(RunArgs args, CallbackInfo ci) { - DrawUtil.initialize(); - } - - @Inject( - method = "render", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/gl/Framebuffer;beginWrite(Z)V" - ) - ) - private void preRender(CallbackInfo ci) { - ThemeHandler.INSTANCE.update(); - } - -} diff --git a/src/main/java/dev/blend/mixin/client/gui/screen/ChatScreenMixin.java b/src/main/java/dev/blend/mixin/client/gui/screen/ChatScreenMixin.java deleted file mode 100644 index 5afd8e9..0000000 --- a/src/main/java/dev/blend/mixin/client/gui/screen/ChatScreenMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package dev.blend.mixin.client.gui.screen; - -import dev.blend.event.impl.ChatSendEvent; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ChatScreen; -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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ChatScreen.class) -public class ChatScreenMixin { - - @Inject( - method = "keyPressed", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/gui/screen/ChatScreen;sendMessage(Ljava/lang/String;Z)V" - ) - ) - private void setScreenToNullBeforeTriggeringEventSoICanToggleClickGUIAndNotHaveItClosedByThis(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable cir) { - MinecraftClient.getInstance().setScreen(null); - } - - @Inject( - method = "sendMessage", - at = @At( - value = "HEAD" - ), - cancellable = true - ) - private void onChatSend(String chatText, boolean addToHistory, CallbackInfo ci) { - final ChatSendEvent event = new ChatSendEvent(chatText); - event.call(); - if (event.isCancelled()) { - ci.cancel(); - } - } - -} diff --git a/src/main/java/dev/blend/mixin/client/network/ClientPlayerEntityMixin.java b/src/main/java/dev/blend/mixin/client/network/ClientPlayerEntityMixin.java deleted file mode 100644 index b328d40..0000000 --- a/src/main/java/dev/blend/mixin/client/network/ClientPlayerEntityMixin.java +++ /dev/null @@ -1,102 +0,0 @@ -package dev.blend.mixin.client.network; - -import com.mojang.authlib.GameProfile; -import dev.blend.event.api.EventBus; -import dev.blend.event.impl.PostMotionEvent; -import dev.blend.event.impl.PreMotionEvent; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; -import net.minecraft.util.math.MathHelper; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ClientPlayerEntity.class) -public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity { - - public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) { - super(world, profile); - } - - @Shadow - protected abstract void sendSprintingPacket(); - @Shadow - protected abstract boolean isCamera(); - - @Shadow private double lastX; - @Shadow private double lastBaseY; - @Shadow private double lastZ; - @Shadow private float lastYaw; - @Shadow private float lastPitch; - @Shadow private int ticksSinceLastPositionPacketSent; - - @Shadow private boolean lastOnGround; - - @Shadow @Final public ClientPlayNetworkHandler networkHandler; - - @Shadow private boolean lastHorizontalCollision; - - @Shadow @Final protected MinecraftClient client; - - @Shadow private boolean autoJumpEnabled; - - @Shadow public abstract float getYaw(float tickDelta); - - @Inject( - method = "sendMovementPackets", - at = @At( - value = "HEAD" - ), - cancellable = true - ) - private void iLikePublicStaticVoidMainStringArgs(CallbackInfo ci) { - ci.cancel(); // cancel the method already - this.sendSprintingPacket(); - if (this.isCamera()) { - final PreMotionEvent event = new PreMotionEvent(this.getX(), this.getY(), this.getZ(), this.getYaw(), this.getPitch(), this.isOnGround()); - event.call(); - double d = event.getX() - this.lastX; - double e = event.getY() - this.lastBaseY; - double f = event.getZ() - this.lastZ; - double g = (double)(event.getYaw() - this.lastYaw); - double h = (double)(event.getPitch() - this.lastPitch); - ++this.ticksSinceLastPositionPacketSent; - boolean bl = MathHelper.squaredMagnitude(d, e, f) > MathHelper.square(2.0E-4) || this.ticksSinceLastPositionPacketSent >= 20; - boolean bl2 = g != (double)0.0F || h != (double)0.0F; - if (bl && bl2) { - this.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(event.getX(), event.getY(), event.getZ(), event.getYaw(), event.getPitch(), event.getOnGround(), this.horizontalCollision)); - } else if (bl) { - this.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(event.getX(), event.getY(), event.getZ(), event.getOnGround(), this.horizontalCollision)); - } else if (bl2) { - this.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(event.getYaw(), event.getPitch(), event.getOnGround(), this.horizontalCollision)); - } else if (this.lastOnGround != event.getOnGround() || this.lastHorizontalCollision != this.horizontalCollision) { - this.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(event.getOnGround(), this.horizontalCollision)); - } - - if (bl) { - this.lastX = event.getX(); - this.lastBaseY = event.getY(); - this.lastZ = event.getZ(); - this.ticksSinceLastPositionPacketSent = 0; - } - - if (bl2) { - this.lastYaw = event.getYaw(); - this.lastPitch = event.getPitch(); - } - - this.lastOnGround = event.getOnGround(); - this.lastHorizontalCollision = this.horizontalCollision; - this.autoJumpEnabled = (Boolean)this.client.options.getAutoJump().getValue(); - EventBus.INSTANCE.post(new PostMotionEvent()); - } - } - -} diff --git a/src/main/java/dev/blend/mixin/client/option/KeybindingMixin.java b/src/main/java/dev/blend/mixin/client/option/KeybindingMixin.java deleted file mode 100644 index aa156e1..0000000 --- a/src/main/java/dev/blend/mixin/client/option/KeybindingMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.blend.mixin.client.option; - -import dev.blend.interfaces.KeybindingAccessor; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(KeyBinding.class) -public class KeybindingMixin implements KeybindingAccessor { - - @Shadow - private InputUtil.Key boundKey; - - @Override - public InputUtil.Key getBoundKey() { - return boundKey; - } -} diff --git a/src/main/kotlin/dev/blend/Client.kt b/src/main/kotlin/dev/blend/Client.kt deleted file mode 100644 index 740a308..0000000 --- a/src/main/kotlin/dev/blend/Client.kt +++ /dev/null @@ -1,31 +0,0 @@ -package dev.blend - -import dev.blend.command.api.CommandManager -import dev.blend.config.ConfigManager -import dev.blend.handler.api.HandlerManager -import dev.blend.module.api.ModuleManager -import org.slf4j.LoggerFactory - -object Client { - - val name = "Blend" - val version = "5.0.0" - val logger = LoggerFactory.getLogger(name) - - fun initialize() { - val initTime = System.currentTimeMillis() - - ModuleManager.initialize() - CommandManager.initialize() - HandlerManager.initialize() - ConfigManager.initialize() - - Runtime.getRuntime().addShutdownHook(Thread(this::shutdown, "Shutdown")) - logger.info("Initialized $name in ${System.currentTimeMillis() - initTime}ms") - } - - private fun shutdown() { - - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/Initializer.kt b/src/main/kotlin/dev/blend/Initializer.kt deleted file mode 100644 index 1e82806..0000000 --- a/src/main/kotlin/dev/blend/Initializer.kt +++ /dev/null @@ -1,11 +0,0 @@ -package dev.blend - -import net.fabricmc.api.ModInitializer - -class Initializer : ModInitializer { - - override fun onInitialize() { - Client.initialize() - } - -} diff --git a/src/main/kotlin/dev/blend/command/Command.kt b/src/main/kotlin/dev/blend/command/Command.kt deleted file mode 100644 index 72f3384..0000000 --- a/src/main/kotlin/dev/blend/command/Command.kt +++ /dev/null @@ -1,29 +0,0 @@ -package dev.blend.command - -import dev.blend.command.api.CommandInfo -import dev.blend.util.player.ChatUtil.format -import dev.blend.util.player.ChatUtil.info - -abstract class Command { - - val commandInfo: CommandInfo - val name get() = commandInfo.names.first() - - init { - if (this::class.java.isAnnotationPresent(CommandInfo::class.java)) { - commandInfo = this::class.java.getAnnotation(CommandInfo::class.java) - } else { - throw IllegalStateException("@CommandInfo not found on ${this::class.java.simpleName}") - } - } - - abstract fun execute(args: List) - - protected fun usage() { - info("Usage of ${format("@$name!")}:") - commandInfo.syntax.forEach { syntax -> - info(format(syntax), false) - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/command/api/CommandInfo.kt b/src/main/kotlin/dev/blend/command/api/CommandInfo.kt deleted file mode 100644 index f85511e..0000000 --- a/src/main/kotlin/dev/blend/command/api/CommandInfo.kt +++ /dev/null @@ -1,9 +0,0 @@ -package dev.blend.command.api - -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -annotation class CommandInfo( - val names: Array, - val description: String, - val syntax: Array -) diff --git a/src/main/kotlin/dev/blend/command/api/CommandManager.kt b/src/main/kotlin/dev/blend/command/api/CommandManager.kt deleted file mode 100644 index b4a5627..0000000 --- a/src/main/kotlin/dev/blend/command/api/CommandManager.kt +++ /dev/null @@ -1,26 +0,0 @@ -package dev.blend.command.api - -import dev.blend.command.Command -import dev.blend.command.impl.ConfigCommand -import dev.blend.command.impl.HelpCommand -import dev.blend.command.impl.ListCommand -import dev.blend.command.impl.UsageCommand -import dev.blend.util.interfaces.IManager - -object CommandManager: IManager { - - val commands = mutableListOf() - - override fun initialize() { - commands.addAll(arrayOf( - HelpCommand(), - ListCommand(), - ConfigCommand(), - UsageCommand, - )) - commands.sortBy { - it.name - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/command/impl/ConfigCommand.kt b/src/main/kotlin/dev/blend/command/impl/ConfigCommand.kt deleted file mode 100644 index 9296d3e..0000000 --- a/src/main/kotlin/dev/blend/command/impl/ConfigCommand.kt +++ /dev/null @@ -1,64 +0,0 @@ -package dev.blend.command.impl - -import dev.blend.Client -import dev.blend.command.Command -import dev.blend.command.api.CommandInfo -import dev.blend.config.ConfigManager -import dev.blend.util.player.ChatUtil -import java.awt.Desktop - -@CommandInfo( - names = ["config", "profile", "configs", "profiles", "c", "f"], - description = "Save the current configuration to a file.", - syntax = [".config @save! _name", ".config @load! _name", ".config @folder!", ".config @list!"], -) -class ConfigCommand: Command() { - override fun execute(args: List) { - with(ChatUtil) { - if (args.size > 1) { - val argument = args[1].lowercase() - // save, load - if (args.size > 2) { - val file = args[2].lowercase().replace(".json", "") - when (argument) { - "load" -> { - if (ConfigManager.load(file)) { - info("Loaded config ${format("@$file!")} successfully.") - } else { - error("Failed to load config ${format("%$file!")}.") - } - } - "save" -> { - if (ConfigManager.save(file)) { - info("Saved config ${format("@$file!")} successfully.") - } else { - warn("Failed to save config ${format("%$file!")}.") - } - } - else -> { - usage() - } - } - } else { - when (argument) { - "folder" -> { - try { - Desktop.getDesktop().open(ConfigManager.configDir) - info("Opened config folder.") - } catch (hi: Exception) { - error("Error opening config directory ${format("%:(")}") - } - } - "list" -> { - ConfigManager.listConfigs() - } - else -> usage() - } - } - - } else { - usage() - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/command/impl/HelpCommand.kt b/src/main/kotlin/dev/blend/command/impl/HelpCommand.kt deleted file mode 100644 index 4641fbb..0000000 --- a/src/main/kotlin/dev/blend/command/impl/HelpCommand.kt +++ /dev/null @@ -1,24 +0,0 @@ -package dev.blend.command.impl - -import dev.blend.command.Command -import dev.blend.command.api.CommandInfo -import dev.blend.util.player.ChatUtil - -@CommandInfo( - names = ["help", "wtf", "h"], - description = "Helps users with chat commands.", - syntax = [".help", ".help @{command}"] -) -class HelpCommand: Command() { - override fun execute(args: List) { - with(ChatUtil) { - if (args.size > 1) { - UsageCommand.execute(args) - } else { - info("Help: ") - info("${format("@.list!")} for a list of all available commands.", false) - info("${format("@.usage!")} for proper usage of a command.", false) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/command/impl/ListCommand.kt b/src/main/kotlin/dev/blend/command/impl/ListCommand.kt deleted file mode 100644 index d9261ae..0000000 --- a/src/main/kotlin/dev/blend/command/impl/ListCommand.kt +++ /dev/null @@ -1,22 +0,0 @@ -package dev.blend.command.impl - -import dev.blend.command.Command -import dev.blend.command.api.CommandInfo -import dev.blend.command.api.CommandManager -import dev.blend.util.player.ChatUtil - -@CommandInfo( - names = ["list", "l"], - description = "Lists all available commands.", - syntax = [".list"] -) -class ListCommand: Command() { - override fun execute(args: List) { - with(ChatUtil) { - info("List of all available commands: ") - CommandManager.commands.forEach { command -> - info("${aquafy(command.name)}: ${command.commandInfo.description}", false) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/command/impl/UsageCommand.kt b/src/main/kotlin/dev/blend/command/impl/UsageCommand.kt deleted file mode 100644 index d18fb36..0000000 --- a/src/main/kotlin/dev/blend/command/impl/UsageCommand.kt +++ /dev/null @@ -1,34 +0,0 @@ -package dev.blend.command.impl - -import dev.blend.command.Command -import dev.blend.command.api.CommandInfo -import dev.blend.command.api.CommandManager -import dev.blend.util.player.ChatUtil - -@CommandInfo( - names = ["usage", "how", "?"], - description = "Displays the proper usage of a command.", - syntax = [".usage @{command}!"] -) -object UsageCommand: Command() { - override fun execute(args: List) { - with(ChatUtil) { - if (args.size > 1) { - val commandName = args[1] - CommandManager.commands - .forEach { command -> - command.commandInfo.names.forEach { name -> - if (name.equals(commandName, ignoreCase = true)) { - info("Usage of ${format("@${commandName}!")}:") - command.commandInfo.syntax.forEach { syntax -> - info(format(syntax), false) - } - } - } - } - } else { - error(this@UsageCommand.commandInfo.syntax.first()) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/config/ConfigManager.kt b/src/main/kotlin/dev/blend/config/ConfigManager.kt deleted file mode 100644 index 92f6a88..0000000 --- a/src/main/kotlin/dev/blend/config/ConfigManager.kt +++ /dev/null @@ -1,90 +0,0 @@ -package dev.blend.config - -import com.google.gson.GsonBuilder -import com.google.gson.JsonArray -import com.google.gson.JsonObject -import dev.blend.Client -import dev.blend.module.api.ModuleManager -import dev.blend.util.IAccessor -import dev.blend.util.interfaces.IManager -import dev.blend.util.player.ChatUtil -import org.lwjgl.util.tinyfd.TinyFileDialogs -import java.io.File -import java.io.FileReader -import java.io.FileWriter - -object ConfigManager: IAccessor, IManager { - - val configDir get() = File(clientDir, "configs") - val gson = GsonBuilder() - .setPrettyPrinting() - .create() - - override fun initialize() { - clientDir.mkdir() - configDir.mkdir() - load() - } - - fun save(name: String = "default"): Boolean { - try { - val config = File(configDir, "$name.json") - if (!config.exists()) { - config.createNewFile() - } - FileWriter(config).use { - val root = JsonObject() - root.addProperty("name", Client.name.lowercase()) - root.addProperty("version", Client.version.lowercase()) - val modules = JsonArray() - ModuleManager.modules.forEach { module -> - modules.add(module.getJsonObject()) - } - root.add("modules", modules) - it.write(gson.toJson(root)) - } - return true - } catch (e: Exception) { - Client.logger.error("Failed to save config \"${name}\"", e) - return false - } - } - - fun load(name: String = "default"): Boolean { - val config = File(configDir, "$name.json") - try { - FileReader(config).use { reader -> - val root = gson.fromJson(reader, JsonObject::class.java) - val configVersion = root.get("version").asString.substring(2).toDouble() - if (configVersion > Client.version.substring(2).toDouble()) { - with(ChatUtil) { - warn("Config ${aquafy(name)} saved on a newer version, Please update your client.") - } - } - val modules = root.getAsJsonArray("modules") - modules.forEach { obj -> - val moduleName = obj.asJsonObject?.get("name")?.asString - ModuleManager.getModule(moduleName!!)?.useJsonObject(obj.asJsonObject) - } - } - return true - } catch (e: Exception) { - Client.logger.error("Failed to load config \"${name}\"", e) - } - return false - } - - fun listConfigs() { - try { - ChatUtil.info("List of available configs:") - configDir.listFiles()?.forEach { file -> - if (file.isFile) { - ChatUtil.info(file.name.replace(".json", ""), false) - } - } - } catch (_: Exception) { - ChatUtil.error("Error listing configs.") - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/event/api/EventBus.kt b/src/main/kotlin/dev/blend/event/api/EventBus.kt deleted file mode 100644 index a4c2fd8..0000000 --- a/src/main/kotlin/dev/blend/event/api/EventBus.kt +++ /dev/null @@ -1,62 +0,0 @@ -package dev.blend.event.api - -import best.azura.eventbus.core.Event -import best.azura.eventbus.handler.EventExecutable -import best.azura.eventbus.handler.EventHandler -import best.azura.eventbus.handler.Listener -import java.util.concurrent.CopyOnWriteArrayList - -object EventBus { - - private val executables = CopyOnWriteArrayList() - - fun subscribe(any: Any) { - if (subscribed(any)) - return - any::class.java.declaredMethods.forEach { method -> - if (method.isAnnotationPresent(EventHandler::class.java) && method.parameterCount > 0) { - executables.add( - EventExecutable( - method, - any, - method.getDeclaredAnnotation(EventHandler::class.java).value - ) - ) - } - } - any::class.java.declaredFields.forEach { field -> - if (field.isAnnotationPresent(EventHandler::class.java) && Listener::class.java.isAssignableFrom(field.type)) { - executables.add( - EventExecutable( - field, - any, - field.getDeclaredAnnotation(EventHandler::class.java).value - ) - ) - } - } - executables.sortBy { - it.priority - } - } - fun unsubscribe(any: Any) { - if (!subscribed(any)) - return - executables.removeIf { - it.parent == any - } - } - - fun post(event: E): E { - executables.forEach { it.call(event) } - return event - } - - fun subscribed(any: Any): Boolean { - return executables.stream().anyMatch { - it.parent.equals(any) - } - } - - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/event/impl/InputEvents.kt b/src/main/kotlin/dev/blend/event/impl/InputEvents.kt deleted file mode 100644 index 153f4d6..0000000 --- a/src/main/kotlin/dev/blend/event/impl/InputEvents.kt +++ /dev/null @@ -1,16 +0,0 @@ -package dev.blend.event.impl - -import best.azura.eventbus.core.Event -import best.azura.eventbus.events.CancellableEvent - -class KeyEvent( - val window: Long, - val key: Int, - val scanCode: Int, - val action: Int, - val modifiers: Int -): Event - -class ChatSendEvent( - val message: String -): CancellableEvent() \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/event/impl/PostMotionEvent.kt b/src/main/kotlin/dev/blend/event/impl/PostMotionEvent.kt deleted file mode 100644 index 44fa720..0000000 --- a/src/main/kotlin/dev/blend/event/impl/PostMotionEvent.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.blend.event.impl - -import best.azura.eventbus.core.Event - -class PostMotionEvent: Event \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/event/impl/PreMotionEvent.kt b/src/main/kotlin/dev/blend/event/impl/PreMotionEvent.kt deleted file mode 100644 index 980d86c..0000000 --- a/src/main/kotlin/dev/blend/event/impl/PreMotionEvent.kt +++ /dev/null @@ -1,12 +0,0 @@ -package dev.blend.event.impl - -import best.azura.eventbus.core.Event - -class PreMotionEvent( - var x: Double, - var y: Double, - var z: Double, - var yaw: Float, - var pitch: Float, - var onGround: Boolean, -): Event \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/handler/Handler.kt b/src/main/kotlin/dev/blend/handler/Handler.kt deleted file mode 100644 index dbfd5af..0000000 --- a/src/main/kotlin/dev/blend/handler/Handler.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.blend.handler - -import dev.blend.event.api.EventBus -import dev.blend.util.IAccessor - -interface Handler: IAccessor { - fun register() { - EventBus.subscribe(this) - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/handler/api/HandlerManager.kt b/src/main/kotlin/dev/blend/handler/api/HandlerManager.kt deleted file mode 100644 index c18cdad..0000000 --- a/src/main/kotlin/dev/blend/handler/api/HandlerManager.kt +++ /dev/null @@ -1,22 +0,0 @@ -package dev.blend.handler.api - -import dev.blend.handler.Handler -import dev.blend.handler.impl.* -import dev.blend.util.interfaces.IManager - -object HandlerManager: IManager { - - val handlers = mutableListOf() - - override fun initialize() { - handlers.addAll(arrayOf( - KeyPressHandler(), - ChatMessageHandler(), - ThemeHandler - )) - handlers.forEach { - it.register() - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/handler/impl/ChatMessageHandler.kt b/src/main/kotlin/dev/blend/handler/impl/ChatMessageHandler.kt deleted file mode 100644 index 79f0ffd..0000000 --- a/src/main/kotlin/dev/blend/handler/impl/ChatMessageHandler.kt +++ /dev/null @@ -1,42 +0,0 @@ -package dev.blend.handler.impl - -import best.azura.eventbus.handler.EventHandler -import best.azura.eventbus.handler.Listener -import dev.blend.command.api.CommandManager -import dev.blend.event.impl.ChatSendEvent -import dev.blend.handler.Handler -import dev.blend.util.player.ChatUtil - -class ChatMessageHandler: Handler { - - var errorCounter = 0 - - @EventHandler - val chatEventListener = Listener { event -> - val message = event.message - if (message.isNotEmpty() && message.startsWith(".") && message.length > 1 && !message.startsWith("..")) { - event.isCancelled = true - mc.inGameHud.chatHud.addToMessageHistory(message); - val messages = message - .substring(1) - .split(" ") - CommandManager.commands.forEach { command -> - command.commandInfo.names.forEach { commandAlias -> - if (messages.first().equals(commandAlias, true)) { - command.execute(messages) - return@Listener - } - } - } - errorCounter++ - with(ChatUtil) { - error("Failed to find command ${aquafy(messages.first())}.") - if (errorCounter > 1) { - info("Try ${aquafy(".help")}.", false) - errorCounter = 0 - } - } - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/handler/impl/KeyPressHandler.kt b/src/main/kotlin/dev/blend/handler/impl/KeyPressHandler.kt deleted file mode 100644 index 34852ec..0000000 --- a/src/main/kotlin/dev/blend/handler/impl/KeyPressHandler.kt +++ /dev/null @@ -1,23 +0,0 @@ -package dev.blend.handler.impl - -import best.azura.eventbus.handler.EventHandler -import best.azura.eventbus.handler.Listener -import dev.blend.event.impl.KeyEvent -import dev.blend.handler.Handler -import dev.blend.module.api.ModuleManager -import org.lwjgl.glfw.GLFW - -class KeyPressHandler: Handler { - - @EventHandler - val keyEventListener: Listener = Listener { event -> - if (event.action == GLFW.GLFW_PRESS) { - ModuleManager.modules.filter { - it.key == event.key - }.forEach { - it.toggle() - } - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/handler/impl/ThemeHandler.kt b/src/main/kotlin/dev/blend/handler/impl/ThemeHandler.kt deleted file mode 100644 index 0334775..0000000 --- a/src/main/kotlin/dev/blend/handler/impl/ThemeHandler.kt +++ /dev/null @@ -1,63 +0,0 @@ -package dev.blend.handler.impl - -import dev.blend.handler.Handler -import dev.blend.module.impl.client.ThemeModule -import dev.blend.util.animations.CubicOutAnimation -import dev.blend.util.animations.SineInAnimation -import dev.blend.util.animations.SineOutAnimation -import dev.blend.util.render.ColorUtil -import java.awt.Color - -object ThemeHandler: Handler { - - private val background = SineOutAnimation(500) - private val text = SineInAnimation(500) - private val foreground = SineInAnimation(500) - val gray = Color(120, 120, 120) - val theme get() = ThemeModule.theme.get() - - fun update() { - background.animate( - if (theme.equals("light", true)) { - 255.0 - } else { - 0.0 - } - ) - text.animate( - if (theme.equals("light", true)) { - 0.0 - } else { - 255.0 - } - ) - foreground.animate( - if (theme.equals("light", true)) { - 50.0 - } else { - 200.0 - } - ) - } - - @JvmStatic - fun getPrimary(): Color { - return ThemeModule.accent.get() - } - @JvmStatic - fun getBackground(): Color { - return ColorUtil.mixColors(getBaseColor(), getPrimary(), 0.05) - } - @JvmStatic - fun getTextColor(): Color { - return Color(text.get().toInt(), text.get().toInt(), text.get().toInt()) - } - @JvmStatic - fun getContrast(): Color { - return Color(foreground.get().toInt(), foreground.get().toInt(), foreground.get().toInt()) - } - fun getBaseColor(): Color { - return Color(background.get().toInt(), background.get().toInt(), background.get().toInt()) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/module/Module.kt b/src/main/kotlin/dev/blend/module/Module.kt deleted file mode 100644 index 094f3f0..0000000 --- a/src/main/kotlin/dev/blend/module/Module.kt +++ /dev/null @@ -1,71 +0,0 @@ -package dev.blend.module - -import com.google.gson.JsonArray -import com.google.gson.JsonElement -import com.google.gson.JsonObject -import dev.blend.event.api.EventBus -import dev.blend.module.api.ModuleInfo -import dev.blend.util.IAccessor -import dev.blend.value.api.ValueHolder -import org.lwjgl.glfw.GLFW - -abstract class Module: IAccessor, ValueHolder() { - - val moduleInfo: ModuleInfo - var key = GLFW.GLFW_KEY_UNKNOWN - val name: String - private var enabled = false - - init { - if (this::class.java.isAnnotationPresent(ModuleInfo::class.java)) { - moduleInfo = this::class.java.getAnnotation(ModuleInfo::class.java) - } else { - throw IllegalStateException("@ModuleInfo not found on ${this::class.java.simpleName}") - } - name = moduleInfo.names.first() - } - - open fun onEnable() {} - open fun onDisable() {} - - fun toggle() { - set(!enabled) - } - fun set(enabled: Boolean) { - if (this.enabled != enabled) { - this.enabled = enabled - if (this.enabled) { - onEnable() - EventBus.subscribe(this) - } else { - EventBus.unsubscribe(this) - onDisable() - } - } - } - fun get(): Boolean { - return enabled - } - - fun getJsonObject(): JsonObject { - val obj = JsonObject() - val values = JsonArray() - obj.addProperty("name", name) - obj.addProperty("state", enabled) - obj.addProperty("key", key) - this.values.forEach { value -> - values.add(value.getJsonObject()) - } - obj.add("values", values) - return obj - } - - fun useJsonObject(obj: JsonObject) { - set(obj.get("state").asBoolean) - key = obj.get("key").asInt - obj.getAsJsonArray("values").forEach { value -> - getValue(value.asJsonObject.get("name").asString.lowercase())?.useJsonObject(value.asJsonObject) - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/module/api/Category.kt b/src/main/kotlin/dev/blend/module/api/Category.kt deleted file mode 100644 index c891324..0000000 --- a/src/main/kotlin/dev/blend/module/api/Category.kt +++ /dev/null @@ -1,11 +0,0 @@ -package dev.blend.module.api - -enum class Category { - COMBAT, - MOVEMENT, - PLAYER, - VISUAL, - CLIENT, - OTHER; - val properName get() = name.uppercase()[0] + name.lowercase().substring(1) -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/module/api/ModuleInfo.kt b/src/main/kotlin/dev/blend/module/api/ModuleInfo.kt deleted file mode 100644 index 4ea095b..0000000 --- a/src/main/kotlin/dev/blend/module/api/ModuleInfo.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.blend.module.api - -import org.lwjgl.glfw.GLFW - -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -annotation class ModuleInfo( - val names: Array, - val description: String, - val category: Category, - val enabled: Boolean = false, - val key: Int = GLFW.GLFW_KEY_UNKNOWN -) diff --git a/src/main/kotlin/dev/blend/module/api/ModuleManager.kt b/src/main/kotlin/dev/blend/module/api/ModuleManager.kt deleted file mode 100644 index 458c999..0000000 --- a/src/main/kotlin/dev/blend/module/api/ModuleManager.kt +++ /dev/null @@ -1,36 +0,0 @@ -package dev.blend.module.api - -import dev.blend.module.Module -import dev.blend.module.impl.client.ClickGUIModule -import dev.blend.module.impl.client.ThemeModule -import dev.blend.module.impl.movement.SprintModule -import dev.blend.util.interfaces.IManager - -object ModuleManager: IManager { - - val modules = mutableListOf() - - override fun initialize() { - modules.addAll(arrayOf( - ClickGUIModule, - ThemeModule, - SprintModule - )) - modules.sortBy { - it.name - } - modules.forEach { - it.set(it.moduleInfo.enabled) - } - modules.forEach { - it.key = it.moduleInfo.key - } - } - - fun getModule(name: String): Module? { - return modules.find { module -> - module.name.equals(name, true) - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/module/impl/client/ClickGUIModule.kt b/src/main/kotlin/dev/blend/module/impl/client/ClickGUIModule.kt deleted file mode 100644 index 6190127..0000000 --- a/src/main/kotlin/dev/blend/module/impl/client/ClickGUIModule.kt +++ /dev/null @@ -1,28 +0,0 @@ -package dev.blend.module.impl.client - -import dev.blend.module.Module -import dev.blend.module.api.Category -import dev.blend.module.api.ModuleInfo -import dev.blend.ui.dropdown.DropdownClickGUI -import dev.blend.value.impl.ModeValue -import org.lwjgl.glfw.GLFW - -@ModuleInfo( - names = ["ClickGUI", "GUI"], - description = "Displays a GUI for the user to edit the client's features in.", - category = Category.CLIENT, - key = GLFW.GLFW_KEY_RIGHT_SHIFT -) -object ClickGUIModule: Module() { - - val style = ModeValue("Style", this, arrayOf("Dropdown")) - - override fun onEnable() { - mc.setScreen(DropdownClickGUI) - } - - override fun onDisable() { - mc.setScreen(null) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/module/impl/client/ThemeModule.kt b/src/main/kotlin/dev/blend/module/impl/client/ThemeModule.kt deleted file mode 100644 index 80e3e6d..0000000 --- a/src/main/kotlin/dev/blend/module/impl/client/ThemeModule.kt +++ /dev/null @@ -1,28 +0,0 @@ -package dev.blend.module.impl.client - -import dev.blend.module.Module -import dev.blend.module.api.Category -import dev.blend.module.api.ModuleInfo -import dev.blend.value.impl.ColorValue -import dev.blend.value.impl.ModeValue -import dev.blend.value.impl.NumberValue -import java.awt.Color - -@ModuleInfo( - names = ["Theme", "Colors"], - description = "Customize the client's look and feel", - category = Category.CLIENT -) -object ThemeModule: Module() { - - val accent = ColorValue("Accent", this, Color(0, 160, 255)) - val secondary = ColorValue("Secondary", this, Color(160, 0, 255)) - val theme = ModeValue("Theme", this, arrayOf("Dark", "Light")) - val font = ModeValue("Font", this, arrayOf("Regular", "Ubuntu")) - val gradientSpeed = NumberValue("Speed", this, 500.0, 200.0, 2000.0, 100.0) - - override fun onEnable() { - this.set(false) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/module/impl/movement/SprintModule.kt b/src/main/kotlin/dev/blend/module/impl/movement/SprintModule.kt deleted file mode 100644 index f82711d..0000000 --- a/src/main/kotlin/dev/blend/module/impl/movement/SprintModule.kt +++ /dev/null @@ -1,35 +0,0 @@ -package dev.blend.module.impl.movement - -import best.azura.eventbus.handler.EventHandler -import best.azura.eventbus.handler.Listener -import dev.blend.event.impl.PreMotionEvent -import dev.blend.interfaces.KeybindingAccessor -import dev.blend.module.Module -import dev.blend.module.api.Category -import dev.blend.module.api.ModuleInfo -import dev.blend.value.impl.BooleanValue -import net.minecraft.client.util.InputUtil - -@ModuleInfo( - names = ["Sprint"], - description = "Makes the player sprint.", - category = Category.MOVEMENT, - enabled = true -) -object SprintModule: Module() { - - private val allDirections = BooleanValue("All directions", this, false) - - override fun onDisable() { - mc.options.sprintKey.isPressed = InputUtil.isKeyPressed( - mc.window.handle, - (mc.options.sprintKey as KeybindingAccessor).boundKey.code - ) - } - - @EventHandler - val preMotion: Listener = Listener { - mc.options.sprintKey.isPressed = true - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/AbstractUIComponent.kt b/src/main/kotlin/dev/blend/ui/AbstractUIComponent.kt deleted file mode 100644 index 847e19e..0000000 --- a/src/main/kotlin/dev/blend/ui/AbstractUIComponent.kt +++ /dev/null @@ -1,17 +0,0 @@ -package dev.blend.ui - -import dev.blend.util.interfaces.IScreen - -abstract class AbstractUIComponent( - var x: Double = 0.0, - var y: Double = 0.0, - var width: Double = 0.0, - var height: Double = 0.0, -): IScreen { - fun isOver(mouseX: Number, mouseY: Number): Boolean { - return mouseX.toDouble() > x && mouseX.toDouble() < x + width && mouseY.toDouble() > y && mouseY.toDouble() < y + height - } - fun isOver(x: Number, y: Number, width: Number, height: Number, mouseX: Number, mouseY: Number): Boolean { - return mouseX.toDouble() > x.toDouble() && mouseX.toDouble() < x.toDouble() + width.toDouble() && mouseY.toDouble() > y.toDouble() && mouseY.toDouble() < y.toDouble() + height.toDouble() - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/DropdownClickGUI.kt b/src/main/kotlin/dev/blend/ui/dropdown/DropdownClickGUI.kt deleted file mode 100644 index d1e103b..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/DropdownClickGUI.kt +++ /dev/null @@ -1,85 +0,0 @@ -package dev.blend.ui.dropdown - -import dev.blend.Client -import dev.blend.module.api.Category -import dev.blend.module.impl.client.ClickGUIModule -import dev.blend.ui.dropdown.components.CategoryComponent -import dev.blend.util.render.DrawUtil -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.screen.Screen -import net.minecraft.text.Text - -object DropdownClickGUI: Screen(Text.of("Dropdown Click GUI")) { - - private val components = mutableListOf() - - init { - var x = 20.0 - Category.entries.forEach { - val component = CategoryComponent(it) - component.x = x - component.y = 20.0 - components.add(component) - x += component.width + 10.0 - } - } - - override fun init() { - components.forEach{ - it.init() - } - } - - override fun render(context: DrawContext?, mouseX: Int, mouseY: Int, delta: Float) { - DrawUtil.begin() - components.forEach { - it.render(mouseX, mouseY) - } - DrawUtil.end() - } - - override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean { - components.forEach { - if (it.isOver(mouseX, mouseY)) { - if (it.click(mouseX, mouseY, button)) { - return true - } - } - } - return super.mouseClicked(mouseX, mouseY, button) - } - - override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean { - components.forEach { - if (it.release(mouseX, mouseY, button)) { - return true - } - } - return super.mouseReleased(mouseX, mouseY, button) - } - - override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { - components.forEach { - if (it.key(keyCode, scanCode, modifiers)) { - return true - } - } - return super.keyPressed(keyCode, scanCode, modifiers) - } - - override fun close() { - components.forEach{ - it.close() - } - ClickGUIModule.set(false) - } - - override fun shouldPause(): Boolean { - return false - } - - override fun shouldCloseOnEsc(): Boolean { - return true - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/AbstractValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/AbstractValueComponent.kt deleted file mode 100644 index f78320e..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/AbstractValueComponent.kt +++ /dev/null @@ -1,19 +0,0 @@ -package dev.blend.ui.dropdown.components - -import dev.blend.ui.AbstractUIComponent -import dev.blend.value.Value - -abstract class AbstractValueComponent( - val parent: ModuleComponent, - open val value: Value<*>, - width: Double = 0.0, - height: Double = 0.0, -): AbstractUIComponent( - width = width, - height = height -) { - val padding = 5.0 - open fun isExpanding(): Boolean { - return false - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/CategoryComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/CategoryComponent.kt deleted file mode 100644 index 318b2f3..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/CategoryComponent.kt +++ /dev/null @@ -1,124 +0,0 @@ -package dev.blend.ui.dropdown.components - -import dev.blend.handler.impl.ThemeHandler -import dev.blend.module.api.Category -import dev.blend.module.api.ModuleManager -import dev.blend.ui.AbstractUIComponent -import dev.blend.util.animations.* -import dev.blend.util.render.Alignment -import dev.blend.util.render.DrawUtil -import org.lwjgl.glfw.GLFW - -class CategoryComponent( - private val category: Category -): AbstractUIComponent( - width = 100.0, - height = 20.0 -) { - - val components = mutableListOf() - private val expandAnimation = SineOutAnimation() - private val expandToggleAnimation = SineOutAnimation() - private val initialHeight = height; - private var expanded = true - - init { - ModuleManager.modules.filter { - it.moduleInfo.category == category - }.forEach { - components.add(ModuleComponent(this, it)) - } - } - - override fun init() { - components.forEach { - it.init() - } - } - - override fun render(mouseX: Int, mouseY: Int) { - DrawUtil.save() - DrawUtil.scissor(x, y, width, height) - DrawUtil.roundedRect(x, y, width, height, 5, ThemeHandler.getBackground()) - DrawUtil.drawString(category.properName, x + (width / 2), y + (initialHeight / 2), 12, ThemeHandler.getTextColor(), Alignment.CENTER) - - var veryRealHeight = initialHeight - components.forEach { - it.x = x - it.y = y + veryRealHeight - it.width = width - it.render(mouseX, mouseY) - veryRealHeight += - if (it.isExpanding()) { - it.expandAnimation.get() - } else { - it.height - } - } - DrawUtil.resetScissor() - DrawUtil.restore() - if (canAnimateExpansion()) { - this.height = expandAnimation.get() - } else { - expandAnimation.set(veryRealHeight) - this.height = veryRealHeight - } - expandAnimation.animate( - if (expanded) veryRealHeight else initialHeight - ) - expandToggleAnimation.animate(if (expanded) 1.0 else 0.0) - } - - override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - if (isOver(x, y, width, initialHeight, mouseX, mouseY)) { - if (mouseButton == GLFW.GLFW_MOUSE_BUTTON_LEFT) { - return true - } else if (mouseButton == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { - expanded = !expanded - return true - } - } - if (expanded) { - components.forEach { - if (it.isOver(mouseX, mouseY)) { - if (it.click(mouseX, mouseY, mouseButton)) { - return true - } - } - } - } - return false - } - - override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - components.forEach { - if (it.release(mouseX, mouseY, mouseButton)) { - return true - } - } - return false - } - - override fun key(key: Int, scancode: Int, modifiers: Int): Boolean { - components.forEach { - if (it.key(key, scancode, modifiers)) { - return true - } - } - return false - } - - override fun close() { - components.forEach { - it.close() - } - } - - fun canAnimateExpansion(): Boolean { - return !components.any { it.isExpanding() } - } - fun isExpanding(): Boolean { - return !expandAnimation.finished - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt deleted file mode 100644 index a694124..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt +++ /dev/null @@ -1,142 +0,0 @@ -package dev.blend.ui.dropdown.components - -import dev.blend.handler.impl.ThemeHandler -import dev.blend.module.Module -import dev.blend.ui.AbstractUIComponent -import dev.blend.ui.dropdown.components.values.BooleanValueComponent -import dev.blend.ui.dropdown.components.values.ColorValueComponent -import dev.blend.ui.dropdown.components.values.ModeValueComponent -import dev.blend.ui.dropdown.components.values.NumberValueComponent -import dev.blend.util.animations.SineOutAnimation -import dev.blend.util.render.Alignment -import dev.blend.util.render.ColorUtil -import dev.blend.util.render.DrawUtil -import dev.blend.value.impl.BooleanValue -import dev.blend.value.impl.ColorValue -import dev.blend.value.impl.ModeValue -import dev.blend.value.impl.NumberValue -import org.lwjgl.glfw.GLFW - -class ModuleComponent( - private val parent: CategoryComponent, - private val module: Module -): AbstractUIComponent( - width = parent.width, - height = parent.height -) { - - val components = mutableListOf() - val expandAnimation = SineOutAnimation() - private val toggleAnimation = SineOutAnimation() - private val lastElementAnimation = SineOutAnimation() - private val expandToggleAnimation = SineOutAnimation() - private val initialHeight = height - private var expanded = false - private var last = false - - init { - module.values.forEach { - when (it) { - is BooleanValue -> components.add(BooleanValueComponent(this, it)) - is NumberValue -> components.add(NumberValueComponent(this, it)) - is ColorValue -> components.add(ColorValueComponent(this, it)) - is ModeValue -> components.add(ModeValueComponent(this, it)) - else -> throw IllegalArgumentException("There is no component defined for ${it::class.simpleName} in Dropdown ClickGUI") - } - } - } - - override fun init() { - components.forEach { - it.init() - } - } - - override fun render(mouseX: Int, mouseY: Int) { - DrawUtil.save() - DrawUtil.intersectScissor(x, y, width, height) - DrawUtil.roundedRect(x, y, width, initialHeight, doubleArrayOf(0.0, 0.0, lastElementAnimation.get(), lastElementAnimation.get()), ColorUtil.applyOpacity(ThemeHandler.getPrimary(), toggleAnimation.get())) - DrawUtil.drawString(module.name, x + (width / 2), y + (initialHeight / 2), 12, ThemeHandler.getTextColor(), Alignment.CENTER) - - var veryRealHeight = initialHeight - components.forEach { - it.x = x - it.y = y + veryRealHeight - it.width = width - if (it.value.visibility()) { - it.render(mouseX, mouseY) - veryRealHeight += - if (it.isExpanding() && (it is ColorValueComponent)) { - it.expandAnimation.get() - } else { - it.height - } - } - } - DrawUtil.restore() - - if (canAnimateExpansion()) { - this.height = expandAnimation.get() - } else { - expandAnimation.set(veryRealHeight) - this.height = veryRealHeight - } - last = parent.components.last() == this && !expanded - expandAnimation.animate( - if (expanded) veryRealHeight else initialHeight - ) - expandToggleAnimation.animate(if (expanded) 1.0 else 0.0) - toggleAnimation.animate(if (module.get()) 0.75 else 0.0) - lastElementAnimation.animate(if (last) 5.0 else 0.0) - } - - override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - if (isOver(x, y, width, initialHeight, mouseX, mouseY)) { - if (mouseButton == GLFW.GLFW_MOUSE_BUTTON_LEFT) { - module.toggle() - } else { - expanded = !expanded - } - } - components.filter { - expanded && it.value.visibility() && it.isOver(mouseX, mouseY) - }.forEach { - if (it.click(mouseX, mouseY, mouseButton)) { - return true - } - } - return false - } - - override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - components.forEach { - if (it.release(mouseX, mouseY, mouseButton)) { - return true - } - } - return false - } - - override fun key(key: Int, scancode: Int, modifiers: Int): Boolean { - components.forEach { - if (it.key(key, scancode, modifiers)) { - return true - } - } - return false - } - - override fun close() { - components.forEach { - it.close() - } - } - - private fun canAnimateExpansion(): Boolean { - return !components.any { it.isExpanding() } - } - fun isExpanding(): Boolean { - return !expandAnimation.finished - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/values/BooleanValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/values/BooleanValueComponent.kt deleted file mode 100644 index 9fd49c6..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/values/BooleanValueComponent.kt +++ /dev/null @@ -1,61 +0,0 @@ -package dev.blend.ui.dropdown.components.values - -import dev.blend.handler.impl.ThemeHandler -import dev.blend.ui.dropdown.components.AbstractValueComponent -import dev.blend.ui.dropdown.components.ModuleComponent -import dev.blend.util.animations.* -import dev.blend.util.render.Alignment -import dev.blend.util.render.ColorUtil -import dev.blend.util.render.DrawUtil -import dev.blend.value.impl.BooleanValue - -class BooleanValueComponent( - parent: ModuleComponent, - override val value: BooleanValue -): AbstractValueComponent( - parent, value, height = 20.0 -) { - - private val toggleAnimation = SineOutAnimation() - private val toggleDependentAnimation = SineOutAnimation() - - override fun init() { - - } - - override fun render(mouseX: Int, mouseY: Int) { - val pillHeight = 8.0 - val pillWidth = 16.0 - val pillX = ((x + width) - padding) - val pillY = y + (height / 2.0) - val indicatorRadius = 6.0 - val indicatorOffset = 1.0 - val indicatorX = (pillX - (pillWidth - indicatorRadius + (indicatorOffset * 2.0))) + (pillWidth - (indicatorRadius + (indicatorOffset * 2.0))) * toggleAnimation.get() - - val pillColor = ColorUtil.mixColors(ThemeHandler.gray, ThemeHandler.getPrimary(), toggleAnimation.get()) - with(DrawUtil) { - drawString(value.name, x + padding, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) - roundedRect(pillX, pillY, pillWidth, pillHeight, pillHeight / 2.0, pillColor, Alignment.CENTER_RIGHT) - roundedRect(indicatorX, pillY, indicatorRadius + ((indicatorRadius / 3.0) * toggleDependentAnimation.get()), indicatorRadius, indicatorRadius / 2.0, ThemeHandler.getTextColor(), Alignment.CENTER) - } - toggleAnimation.animate(if (value.get()) 1.0 else 0.0) - toggleDependentAnimation.animate(if (toggleAnimation.finished) 0.0 else 1.0) - } - - override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - value.toggle() - return true - } - - override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - return false - } - - override fun key(key: Int, scancode: Int, modifiers: Int): Boolean { - return false - } - - override fun close() { - - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ColorValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/values/ColorValueComponent.kt deleted file mode 100644 index c3e7e55..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ColorValueComponent.kt +++ /dev/null @@ -1,156 +0,0 @@ -package dev.blend.ui.dropdown.components.values - -import dev.blend.handler.impl.ThemeHandler -import dev.blend.ui.dropdown.components.AbstractValueComponent -import dev.blend.ui.dropdown.components.ModuleComponent -import dev.blend.util.animations.LinearAnimation -import dev.blend.util.animations.SineOutAnimation -import dev.blend.util.render.* -import dev.blend.value.impl.ColorValue -import java.awt.Color -import kotlin.math.* - -class ColorValueComponent( - parent: ModuleComponent, - override val value: ColorValue -): AbstractValueComponent( - parent, value, height = 20.0 -) { - - val expandAnimation = SineOutAnimation() - private val hueAnimation = LinearAnimation(100) - private val pickerHoldAnimation = SineOutAnimation() - private val initialHeight = height - private var expanded = false - private var pickerHeld = false - private var hueSliderHeld = false - - override fun init() { - - } - - override fun render(mouseX: Int, mouseY: Int) { - var height = initialHeight - val pickerX = x + padding - val pickerY = y + initialHeight + padding - val pickerWidth = width - (padding * 2.0) - val pickerHeight = pickerWidth - (initialHeight + padding) - val relativeMouseX = (mouseX - pickerX) / ((pickerX + pickerWidth) - pickerX) - val relativePickerY = (mouseY - pickerY) / ((pickerY + pickerHeight) - pickerY) - if (pickerHeld) { - value.saturation = max(0.0, min(relativeMouseX, 1.0)).toFloat() - value.brightness = max(0.0, min((1.0 - relativePickerY), 1.0)).toFloat() - } - if (hueSliderHeld) { - value.hue = max(0.0, min(relativeMouseX, 1.0)).toFloat() - } - val pickerSelectorColor = ColorUtil.mixColors(Color.WHITE, value.get(), pickerHoldAnimation.get()) - val hueSelectorColor = ColorUtil.mixColors(Color.WHITE, Color.getHSBColor(value.hue, 1.0f, 1.0f), hueAnimation.get()) - with(DrawUtil) { - save() - intersectScissor(x, y, width, this@ColorValueComponent.height) - drawString(value.name, x + 5.0, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) - - roundedRect(x + (width - padding), y + (height / 2.0), 20.0, height - (padding * 2.0), 2.0, value.get(), Alignment.CENTER_RIGHT) - roundedRect(x + (width - padding), y + (height / 2.0), 20.0, height - (padding * 2.0), 2.0, 1.0, ThemeHandler.getContrast(), Alignment.CENTER_RIGHT) - - height += padding - height += pickerHeight - roundedRect( - pickerX, pickerY, - pickerWidth, pickerHeight, 2.0, - Gradient( - Color.WHITE, - Color.getHSBColor(value.hue, 1.0f, 1.0f), - Point(pickerX, pickerY), - Point(x + padding + pickerWidth, pickerY) - ) - ) - roundedRect( - pickerX, pickerY, - pickerWidth, pickerHeight, 2.0, - Gradient( - Color(255, 255, 255, 0), - Color.BLACK, - Point(pickerX, pickerY), - Point(pickerX, pickerY + pickerHeight) - ) - ) - roundedRect(pickerX + (value.saturation.toDouble() * pickerWidth), pickerY + (1.0 - value.brightness.toDouble()) * pickerHeight, padding + (2.0 * pickerHoldAnimation.get()), padding + (2.0 * pickerHoldAnimation.get()), 2.0, Color.WHITE, Alignment.CENTER) - roundedRect(pickerX + (value.saturation.toDouble() * pickerWidth), pickerY + (1.0 - value.brightness.toDouble()) * pickerHeight, 3.0, 3.0, 3.0, pickerSelectorColor, Alignment.CENTER) - - height += initialHeight - rainbowBar( - pickerX, pickerY + pickerHeight + padding, - pickerWidth, initialHeight - (padding * 2.0), 2.0 - ) - roundedRect(pickerX + (value.hue.toDouble() * pickerWidth), (pickerY + pickerHeight + padding) + ((initialHeight - (padding * 2.0)) / 2.0), padding + (2.0 * hueAnimation.get()), padding + (2.0 * hueAnimation.get()), 2.0, Color.WHITE, Alignment.CENTER) - roundedRect(pickerX + (value.hue.toDouble() * pickerWidth), (pickerY + pickerHeight + padding) + ((initialHeight - (padding * 2.0)) / 2.0), 3.0, 3.0, 3.0, hueSelectorColor, Alignment.CENTER) - - restore() - } - this.height = expandAnimation.get() - expandAnimation.animate( - if (expanded) { - height - } else { - initialHeight - } - ) - pickerHoldAnimation.animate( - if (pickerHeld) { - 1.0 - } else { - 0.0 - } - ) - hueAnimation.animate( - if (hueSliderHeld) { - 1.0 - } else { - 0.0 - } - ) - } - - override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - val pickerX = x + padding - val pickerY = y + initialHeight - val pickerWidth = width - (padding * 2.0) - val pickerHeight = pickerWidth - (initialHeight + padding) - if (isOver(x, y, width, initialHeight, mouseX, mouseY)) { - expanded = !expanded - return true - } - if (isOver(pickerX, pickerY, pickerWidth, pickerHeight, mouseX, mouseY)) { - pickerHeld = true - return true - } - if (isOver(pickerX, pickerY + pickerHeight + padding, pickerWidth, initialHeight - (padding), mouseX, mouseY)) { - hueSliderHeld = true - return true - } - return false - } - - override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - if (pickerHeld) - pickerHeld = false - if (hueSliderHeld) - hueSliderHeld = false - return false - } - - override fun key(key: Int, scancode: Int, modifiers: Int): Boolean { - return false - } - - override fun close() { - - } - - override fun isExpanding(): Boolean { - return !expandAnimation.finished - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ModeValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/values/ModeValueComponent.kt deleted file mode 100644 index 82b01d1..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ModeValueComponent.kt +++ /dev/null @@ -1,68 +0,0 @@ -package dev.blend.ui.dropdown.components.values - -import dev.blend.handler.impl.ThemeHandler -import dev.blend.ui.dropdown.components.AbstractValueComponent -import dev.blend.ui.dropdown.components.ModuleComponent -import dev.blend.util.animations.SineOutAnimation -import dev.blend.util.render.Alignment -import dev.blend.util.render.ColorUtil -import dev.blend.util.render.DrawUtil -import dev.blend.value.impl.ModeValue -import org.lwjgl.glfw.GLFW - -class ModeValueComponent( - parent: ModuleComponent, - override val value: ModeValue -): AbstractValueComponent( - parent, value, height = 20.0 -) { - - private val expandToggleAnimation = SineOutAnimation(100) - private var clicked = false - private var button = -1 - - override fun init() { - - } - - override fun render(mouseX: Int, mouseY: Int) { - val e = ColorUtil.applyOpacity(ThemeHandler.getTextColor(), expandToggleAnimation.get()) - with(DrawUtil) { - drawString(value.name + ": ", x + padding, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) - drawString(value.get(), (x + width) - padding, y + (height / 2.0), 8, e, Alignment.CENTER_RIGHT) - } - expandToggleAnimation.animate(if (clicked) 0.5 else 1.0) - if (clicked && expandToggleAnimation.finished) { - when (button) { - GLFW.GLFW_MOUSE_BUTTON_LEFT -> value.next() - GLFW.GLFW_MOUSE_BUTTON_RIGHT -> value.previous() - else -> {} - } - } - if (expandToggleAnimation.finished) { - clicked = false - } - } - - override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - if (isOver(x, y, width, height, mouseX, mouseY) && value.modes.size > 1) { - button = mouseButton - clicked = true - return true - } - return false - } - - override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - return false - } - - override fun key(key: Int, scancode: Int, modifiers: Int): Boolean { - return false - } - - override fun close() { - - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/values/NumberValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/values/NumberValueComponent.kt deleted file mode 100644 index 35452fd..0000000 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/values/NumberValueComponent.kt +++ /dev/null @@ -1,75 +0,0 @@ -package dev.blend.ui.dropdown.components.values - -import dev.blend.handler.impl.ThemeHandler -import dev.blend.ui.dropdown.components.AbstractValueComponent -import dev.blend.ui.dropdown.components.ModuleComponent -import dev.blend.util.animations.* -import dev.blend.util.render.Alignment -import dev.blend.util.render.ColorUtil -import dev.blend.util.render.DrawUtil -import dev.blend.value.impl.NumberValue - -class NumberValueComponent( - parent: ModuleComponent, - override val value: NumberValue -): AbstractValueComponent( - parent, value, height = 30.0 -) { - - private val dragAnimation = LinearAnimation(100) - private val dragDependentAnimation = SineOutAnimation() - private val selectAnimation = SineOutAnimation() - private var held = false - - override fun init() { - - } - - override fun render(mouseX: Int, mouseY: Int) { - val sliderW = width - (padding * 2.0) - val sliderH = 2.0 - val sliderX = x + padding - val sliderY = (y + height) - (padding * 2.0) - val dragIndicator = 6.0 + (selectAnimation.get() * 2.0) - val holdIndicator = 4.0 - // (value - min) / (max - min) - // (15 - 10) / (20 - 10) = 0.5 - val relativeValue = (value.get().toDouble() - value.min.toDouble()) / (value.max.toDouble() - value.min.toDouble()) - val relativeMouseX = (mouseX - sliderX) / ((sliderX + sliderW) - sliderX) - if (held) { - value.set(value.min.toDouble() + relativeMouseX * (value.max.toDouble() - value.min.toDouble())) - } - - val heldColor = ColorUtil.mixColors(ThemeHandler.getTextColor(), ThemeHandler.getPrimary(), selectAnimation.get()) - with(DrawUtil) { - drawString(value.name, x + padding, y + padding, 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) - drawString(value.toString(), (x + width) - padding, y + padding, 8, heldColor, Alignment.CENTER_RIGHT) - roundedRect(sliderX, sliderY, sliderW, sliderH, sliderH / 2.0, ThemeHandler.getContrast(), Alignment.CENTER_LEFT) - roundedRect(sliderX, sliderY, dragAnimation.get(), sliderH, sliderH / 2.0, ThemeHandler.getPrimary(), Alignment.CENTER_LEFT) - roundedRect(sliderX + dragAnimation.get(), sliderY, dragIndicator + (dragDependentAnimation.get() * 3.0), dragIndicator, dragIndicator / 2.0, ThemeHandler.getTextColor(), Alignment.CENTER) - roundedRect(sliderX + dragAnimation.get() , sliderY, holdIndicator + (dragDependentAnimation.get() * 3.0), holdIndicator, holdIndicator / 2.0, heldColor, Alignment.CENTER) - } - dragAnimation.animate(relativeValue * sliderW) - dragDependentAnimation.animate(if (dragAnimation.finished) 0.0 else 1.0) - selectAnimation.animate(if (held) 1.0 else 0.0) - } - - override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - held = true - return false - } - - override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { - held = false - return false - } - - override fun key(key: Int, scancode: Int, modifiers: Int): Boolean { - return false - } - - override fun close() { - - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/IAccessor.kt b/src/main/kotlin/dev/blend/util/IAccessor.kt deleted file mode 100644 index 03c8deb..0000000 --- a/src/main/kotlin/dev/blend/util/IAccessor.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.blend.util - -import dev.blend.Client -import net.minecraft.client.MinecraftClient -import java.io.File - -interface IAccessor { - val mc get() = MinecraftClient.getInstance()!! - val clientDir get() = File(mc.runDirectory!!, Client.name) -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/animations/AbstractAnimation.kt b/src/main/kotlin/dev/blend/util/animations/AbstractAnimation.kt deleted file mode 100644 index cffac50..0000000 --- a/src/main/kotlin/dev/blend/util/animations/AbstractAnimation.kt +++ /dev/null @@ -1,58 +0,0 @@ -package dev.blend.util.animations - -abstract class AbstractAnimation( - private val function: (Double) -> Double, - var duration: Number, -) { - private var currentTime = 0L - private var startTime = 0L - private var initialValue = 0.0 - private var targetValue = 1.0 - private var currentValue = 0.0 - var finished = false - - init { - startTime = System.currentTimeMillis() - } - - fun animate(targetValue: Double) { - currentTime = System.currentTimeMillis() - if (this.targetValue != targetValue) { - this.targetValue = targetValue - reset() - } else { - finished = (currentTime - duration.toDouble()) > startTime - if (finished) { - currentValue = targetValue - return - } - } - val result = function(progress()) - currentValue = - if (currentValue > targetValue) { - initialValue - (initialValue - targetValue) * result - } else { - initialValue + (targetValue - initialValue) * result - } - } - - - fun progress(): Double { - // No, this isn't a redundant cast. - return ((System.currentTimeMillis() - startTime).toDouble() / duration.toDouble()).toDouble() - } - - fun reset() { - this.startTime = System.currentTimeMillis() - this.initialValue = currentValue - this.finished = false - } - - fun get(): Double { - return currentValue - } - fun set(value: Double) { - currentValue = value - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/animations/Animations.kt b/src/main/kotlin/dev/blend/util/animations/Animations.kt deleted file mode 100644 index e6b92d8..0000000 --- a/src/main/kotlin/dev/blend/util/animations/Animations.kt +++ /dev/null @@ -1,17 +0,0 @@ -package dev.blend.util.animations - -import kotlin.math.* - -/** - * All easing functions are referred from https://easings.net - */ - -class LinearAnimation(duration: Number = 200.0): AbstractAnimation( { a -> a }, duration) - -class SineInAnimation(duration: Number = 200.0): AbstractAnimation( { x -> 1 - cos((x * PI) / 2) }, duration) -class SineOutAnimation(duration: Number = 200.0): AbstractAnimation( { x -> sin((x * PI) / 2) }, duration) -class SineInOutAnimation(duration: Number = 200.0): AbstractAnimation( { x -> -(cos(PI * x) - 1) / 2 }, duration) - -class CubicOutAnimation(duration: Number = 200.0): AbstractAnimation( { x -> 1 - (1 - x).pow(3.0) }, duration) - -class ExpoOutAnimation(duration: Number = 200.0): AbstractAnimation( { x -> if (x == 1.0) 1.0 else 1.0 - 2.0.pow(-10.0 * x) }, duration) diff --git a/src/main/kotlin/dev/blend/util/interfaces/IManager.kt b/src/main/kotlin/dev/blend/util/interfaces/IManager.kt deleted file mode 100644 index 7b8573a..0000000 --- a/src/main/kotlin/dev/blend/util/interfaces/IManager.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.blend.util.interfaces - -interface IManager { - fun initialize() -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/interfaces/IScreen.kt b/src/main/kotlin/dev/blend/util/interfaces/IScreen.kt deleted file mode 100644 index cfccc10..0000000 --- a/src/main/kotlin/dev/blend/util/interfaces/IScreen.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.blend.util.interfaces - -interface IScreen { - fun init() - fun render(mouseX: Int, mouseY: Int) - fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean - fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean - fun key(key: Int, scancode: Int, modifiers: Int): Boolean - fun close() -} diff --git a/src/main/kotlin/dev/blend/util/misc/MiscUtil.kt b/src/main/kotlin/dev/blend/util/misc/MiscUtil.kt deleted file mode 100644 index d9ea39a..0000000 --- a/src/main/kotlin/dev/blend/util/misc/MiscUtil.kt +++ /dev/null @@ -1,46 +0,0 @@ -package dev.blend.util.misc - -import dev.blend.Client -import dev.blend.util.IAccessor -import kotlinx.io.IOException -import org.lwjgl.BufferUtils -import org.lwjgl.system.MemoryUtil -import java.nio.ByteBuffer -import java.nio.channels.Channels -import java.nio.channels.ReadableByteChannel - -object MiscUtil: IAccessor { - - @JvmStatic - fun isOver(x: Number, y: Number, width: Number, height: Number, mouseX: Number, mouseY: Number): Boolean { - return mouseX.toDouble() > x.toDouble() && mouseX.toDouble() < x.toDouble() + width.toDouble() && mouseY.toDouble() > y.toDouble() && mouseY.toDouble() < y.toDouble() + height.toDouble() - } - - @JvmStatic - @Throws(IOException::class) - fun getResourceAsByteBuffer(resource: String, bufferSize: Int = 1024): ByteBuffer { - val source = Client::class.java.getResourceAsStream("/assets/blend/$resource") - checkNotNull(source) - val rbc: ReadableByteChannel = Channels.newChannel(source) - var buffer = BufferUtils.createByteBuffer(bufferSize) - while (true) { - val bytes = rbc.read(buffer) - if (bytes == -1) { - break - } - if (buffer.remaining() == 0) { - buffer = resizeBuffer(buffer, buffer.capacity() * 3 / 2) - } - } - buffer.flip() - return MemoryUtil.memSlice(buffer) - } - - private fun resizeBuffer(buffer: ByteBuffer, newCapacity: Int): ByteBuffer { - val newBuffer = BufferUtils.createByteBuffer(newCapacity) - buffer.flip() - newBuffer.put(buffer) - return newBuffer - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/player/ChatUtil.kt b/src/main/kotlin/dev/blend/util/player/ChatUtil.kt deleted file mode 100644 index 67733c0..0000000 --- a/src/main/kotlin/dev/blend/util/player/ChatUtil.kt +++ /dev/null @@ -1,49 +0,0 @@ -package dev.blend.util.player - -import dev.blend.Client -import dev.blend.util.IAccessor -import net.minecraft.text.Text -import net.minecraft.util.Formatting - -object ChatUtil: IAccessor { - - @JvmStatic - fun info(message: String, prefix: Boolean = true) { - val text = Text.empty() - if (prefix) - text.append("${Formatting.AQUA}${Client.name} ") - text.append("${Formatting.GREEN} » ") - text.append("${Formatting.RESET}$message") - mc.inGameHud.chatHud.addMessage(text) - } - @JvmStatic - fun warn(message: String, prefix: Boolean = true) { - val text = Text.empty() - if (prefix) - text.append("${Formatting.AQUA}${Client.name} ") - text.append("${Formatting.GOLD} » ") - text.append("${Formatting.RESET}$message") - mc.inGameHud.chatHud.addMessage(text) - } - @JvmStatic - fun error(message: String, prefix: Boolean = true) { - val text = Text.empty() - if (prefix) - text.append("${Formatting.AQUA}${Client.name} ") - text.append("${Formatting.RED} » ") - text.append("${Formatting.RESET}$message") - mc.inGameHud.chatHud.addMessage(text) - } - fun aquafy(message: String): String { - return "${Formatting.AQUA}${message}${Formatting.RESET}" - } - fun format(message: String): String { - return message - .replace("@", Formatting.AQUA.toString()) - .replace("*", Formatting.BOLD.toString()) - .replace("_", Formatting.ITALIC.toString()) - .replace("!", Formatting.RESET.toString()) - .replace("%", Formatting.RED.toString()) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/render/Alignment.kt b/src/main/kotlin/dev/blend/util/render/Alignment.kt deleted file mode 100644 index 831b715..0000000 --- a/src/main/kotlin/dev/blend/util/render/Alignment.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.blend.util.render - -enum class Alignment { - TOP_LEFT, - TOP_CENTER, - TOP_RIGHT, - CENTER_LEFT, - CENTER, - CENTER_RIGHT, - BOTTOM_LEFT, - BOTTOM_CENTER, - BOTTOM_RIGHT -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/render/ColorUtil.kt b/src/main/kotlin/dev/blend/util/render/ColorUtil.kt deleted file mode 100644 index ab0ceac..0000000 --- a/src/main/kotlin/dev/blend/util/render/ColorUtil.kt +++ /dev/null @@ -1,24 +0,0 @@ -package dev.blend.util.render - -import java.awt.Color - -object ColorUtil { - - @JvmStatic - fun mixColors(primary: Color, secondary: Color, factor: Double): Color { - val otherFactor = 1.0 - factor - val redFactor = (primary.red * otherFactor + secondary.red * factor).toInt() - val greenFactor = (primary.green * otherFactor + secondary.green * factor).toInt() - val blueFactor = (primary.blue * otherFactor + secondary.blue * factor).toInt() - return Color(redFactor, greenFactor, blueFactor) - } - @JvmStatic - fun applyOpacity(color: Color, opacity: Double): Color { - return Color(color.red, color.green, color.blue, ((opacity / 1.0) * 255.0).toInt()) - } - @JvmStatic - fun setOpacity(color: Color, opacity: Int): Color { - return Color(color.red, color.green, color.blue, opacity) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/render/DrawUtil.kt b/src/main/kotlin/dev/blend/util/render/DrawUtil.kt deleted file mode 100644 index 39e65b6..0000000 --- a/src/main/kotlin/dev/blend/util/render/DrawUtil.kt +++ /dev/null @@ -1,368 +0,0 @@ -package dev.blend.util.render - -import com.mojang.blaze3d.platform.GlStateManager -import com.mojang.blaze3d.systems.RenderSystem -import dev.blend.util.IAccessor -import dev.blend.util.misc.MiscUtil -import kotlinx.io.IOException -import org.lwjgl.nanovg.NVGColor -import org.lwjgl.nanovg.NVGPaint -import org.lwjgl.nanovg.NanoVG.* -import org.lwjgl.nanovg.NanoVGGL3 -import org.lwjgl.opengl.GL11 -import org.lwjgl.system.MemoryStack -import java.awt.Color -import java.lang.IllegalArgumentException -import java.nio.ByteBuffer - -object DrawUtil: IAccessor { - - var context = -1L - private lateinit var regularFont: ByteBuffer - - @JvmStatic - fun initialize() { - context = NanoVGGL3.nvgCreate(NanoVGGL3.NVG_ANTIALIAS or NanoVGGL3.NVG_STENCIL_STROKES) - if (context == -1L) { - throw IllegalStateException("NanoVG Context could not be created.") - } - ResourceManager.init() - } - - @JvmStatic - fun begin() { - preRender() - nvgBeginFrame(context, mc.window.width.toFloat(), mc.window.height.toFloat(), 1.0f) - save() - scale() - } - @JvmStatic - fun end() { - restore() - nvgEndFrame(context) - postRender() - } - - @JvmStatic - fun save() = nvgSave(context) - @JvmStatic - fun restore() = nvgRestore(context) - - @JvmStatic - fun scale() = scale(mc.window.scaleFactor) - @JvmStatic - fun scale(scaleFactor: Number) = scale(scaleFactor, scaleFactor) - @JvmStatic - fun scale(xScaleFactor: Number, yScaleFactor: Number) = nvgScale(context, xScaleFactor.toFloat(), yScaleFactor.toFloat()) - - @JvmStatic - fun translate(xTranslate: Number, yTranslate: Number) = nvgTranslate(context, xTranslate.toFloat(), yTranslate.toFloat()) - @JvmStatic - fun resetTranslate() = nvgResetTransform(context) - - @JvmStatic - fun scissor(x: Number, y: Number, width: Number, height: Number) = nvgScissor(context, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat()) - @JvmStatic - fun resetScissor() = nvgResetScissor(context) - @JvmStatic - fun intersectScissor(x: Number, y:Number, width:Number, height: Number) = nvgIntersectScissor(context, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat()) - @JvmStatic - fun beginPath() = nvgBeginPath(context) - @JvmStatic - fun pathWindingCCW() = nvgPathWinding(context, NVG_CCW) - @JvmStatic - fun fill() = nvgFill(context) - @JvmStatic - fun nvgRoundedRect(x: Number, y: Number, width: Number, height: Number, radius: Number) = nvgRoundedRect(context, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), radius.toFloat()) - - // Shapes. - @JvmStatic - fun rect(x: Number, y: Number, width: Number, height: Number, color: Color, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGColor.calloc().use { nvgColor -> - nvgRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat()) - nvgRGBAf(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f, nvgColor) - nvgFillColor(context, nvgColor) - nvgFill(context) - } - nvgClosePath(context) - } - @JvmStatic - fun rect(x: Number, y: Number, width: Number, height: Number, stroke: Number, color: Color, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGColor.calloc().use { nvgColor -> - nvgRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat()) - nvgRGBAf(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f, nvgColor) - nvgStrokeWidth(context, stroke.toFloat()) - nvgStrokeColor(context, nvgColor) - nvgStroke(context) - } - nvgClosePath(context) - } - @JvmStatic - fun rect(x: Number, y: Number, width: Number, height: Number, gradient: Gradient, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGPaint.calloc().use { nvgPaint -> - nvgRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat()) - NVGColor.calloc().use { primary -> - NVGColor.calloc().use { secondary -> - nvgRGBAf(gradient.primary.red / 255f, gradient.primary.green / 255f, gradient.primary.blue / 255f, gradient.primary.alpha / 255f, primary) - nvgRGBAf(gradient.secondary.red / 255f, gradient.secondary.green / 255f, gradient.secondary.blue / 255f, gradient.secondary.alpha / 255f, secondary) - nvgLinearGradient(context, gradient.origin.x.toFloat(), gradient.origin.y.toFloat(), gradient.end.x.toFloat(), gradient.end.y.toFloat(), primary, secondary, nvgPaint) - } - } - nvgFillPaint(context, nvgPaint) - nvgFill(context) - } - nvgClosePath(context) - } - @JvmStatic - fun rect(x: Number, y: Number, width: Number, height: Number, stroke: Number, gradient: Gradient, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGPaint.calloc().use { nvgPaint -> - nvgRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat()) - NVGColor.calloc().use { primary -> - NVGColor.calloc().use { secondary -> - nvgRGBAf(gradient.primary.red / 255f, gradient.primary.green / 255f, gradient.primary.blue / 255f, gradient.primary.alpha / 255f, primary) - nvgRGBAf(gradient.secondary.red / 255f, gradient.secondary.green / 255f, gradient.secondary.blue / 255f, gradient.secondary.alpha / 255f, secondary) - nvgLinearGradient(context, gradient.origin.x.toFloat(), gradient.origin.y.toFloat(), gradient.end.x.toFloat(), gradient.end.y.toFloat(), primary, secondary, nvgPaint) - } - } - nvgStrokeWidth(context, stroke.toFloat()) - nvgStrokePaint(context, nvgPaint) - nvgStroke(context) - } - nvgClosePath(context) - } - - @JvmStatic - fun roundedRect(x: Number, y: Number, width: Number, height: Number, radius: Number, color: Color, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGColor.calloc().use { nvgColor -> - nvgRoundedRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat(), radius.toFloat()) - nvgRGBAf(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f, nvgColor) - nvgFillColor(context, nvgColor) - nvgFill(context) - } - nvgClosePath(context) - } - @JvmStatic - fun roundedRect(x: Number, y: Number, width: Number, height: Number, radius: Number, gradient: Gradient, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGPaint.calloc().use { nvgPaint -> - nvgRoundedRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat(), radius.toFloat()) - NVGColor.calloc().use { primary -> - NVGColor.calloc().use { secondary -> - nvgRGBAf(gradient.primary.red / 255f, gradient.primary.green / 255f, gradient.primary.blue / 255f, gradient.primary.alpha / 255f, primary) - nvgRGBAf(gradient.secondary.red / 255f, gradient.secondary.green / 255f, gradient.secondary.blue / 255f, gradient.secondary.alpha / 255f, secondary) - nvgLinearGradient(context, gradient.origin.x.toFloat(), gradient.origin.y.toFloat(), gradient.end.x.toFloat(), gradient.end.y.toFloat(), primary, secondary, nvgPaint) - } - } - nvgFillPaint(context, nvgPaint) - nvgFill(context) - } - nvgClosePath(context) - } - @JvmStatic - fun roundedRect(x: Number, y: Number, width: Number, height: Number, radius: Number, stroke: Number, color: Color, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGColor.calloc().use { nvgColor -> - nvgRoundedRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat(), radius.toFloat()) - nvgRGBAf(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f, nvgColor) - nvgStrokeWidth(context, stroke.toFloat()) - nvgStrokeColor(context, nvgColor) - nvgStroke(context) - } - nvgClosePath(context) - } - @JvmStatic - fun roundedRect(x: Number, y: Number, width: Number, height: Number, radius: Number, stroke: Number, gradient: Gradient, alignment: Alignment = Alignment.TOP_LEFT) { - nvgBeginPath(context) - NVGPaint.calloc().use { nvgPaint -> - nvgRoundedRect(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat(), radius.toFloat()) - NVGColor.calloc().use { primary -> - NVGColor.calloc().use { secondary -> - nvgRGBAf(gradient.primary.red / 255f, gradient.primary.green / 255f, gradient.primary.blue / 255f, gradient.primary.alpha / 255f, primary) - nvgRGBAf(gradient.secondary.red / 255f, gradient.secondary.green / 255f, gradient.secondary.blue / 255f, gradient.secondary.alpha / 255f, secondary) - nvgLinearGradient(context, gradient.origin.x.toFloat(), gradient.origin.y.toFloat(), gradient.end.x.toFloat(), gradient.end.y.toFloat(), primary, secondary, nvgPaint) - } - } - nvgStrokeWidth(context, stroke.toFloat()) - nvgStrokePaint(context, nvgPaint) - nvgStroke(context) - } - nvgClosePath(context) - } - @JvmStatic - fun roundedRect(x: Number, y: Number, width: Number, height: Number, radius: DoubleArray, color: Color, alignment: Alignment = Alignment.TOP_LEFT) { - if (radius.size != 4) { - throw IllegalArgumentException("DoubleArray of size 4 required. only ${radius.size} found.") - } - nvgBeginPath(context) - NVGColor.calloc().use { nvgColor -> - nvgRoundedRectVarying(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat(), radius[0].toFloat(), radius[1].toFloat(), radius[2].toFloat(), radius[3].toFloat()) - nvgRGBAf(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f, nvgColor) - nvgFillColor(context, nvgColor) - nvgFill(context) - } - nvgClosePath(context) - } - @JvmStatic - fun roundedRect(x: Number, y: Number, width: Number, height: Number, radius: DoubleArray, gradient: Gradient, alignment: Alignment = Alignment.TOP_LEFT) { - if (radius.size != 4) { - throw IllegalArgumentException("DoubleArray of size 4 required. only ${radius.size} found.") - } - nvgBeginPath(context) - NVGPaint.calloc().use { nvgPaint -> - nvgRoundedRectVarying(context, alignX(x, width, alignment), alignY(y, height, alignment), width.toFloat(), height.toFloat(), radius[0].toFloat(), radius[1].toFloat(), radius[2].toFloat(), radius[3].toFloat()) - NVGColor.calloc().use { primary -> - NVGColor.calloc().use { secondary -> - nvgRGBAf(gradient.primary.red / 255f, gradient.primary.green / 255f, gradient.primary.blue / 255f, gradient.primary.alpha / 255f, primary) - nvgRGBAf(gradient.secondary.red / 255f, gradient.secondary.green / 255f, gradient.secondary.blue / 255f, gradient.secondary.alpha / 255f, secondary) - nvgLinearGradient(context, gradient.origin.x.toFloat(), gradient.origin.y.toFloat(), gradient.end.x.toFloat(), gradient.end.y.toFloat(), primary, secondary, nvgPaint) - } - } - nvgFillPaint(context, nvgPaint) - nvgFill(context) - } - nvgClosePath(context) - } - - // Font Rendering - @JvmStatic - fun drawString(text: String, x: Number, y: Number, size: Number, color: Color, alignment: Alignment = Alignment.TOP_LEFT, font: FontResource = ResourceManager.FontResources.regular) { - nvgBeginPath(context) - NVGColor.calloc().use { nvgColor -> - nvgRGBAf(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f, nvgColor) - nvgFillColor(context, nvgColor) - nvgFontFace(context, font.identifier) - nvgFontSize(context, size.toFloat()) - nvgTextAlign(context, getAlignFlags(alignment)) - nvgText(context, x.toFloat(), y.toFloat(), text) - } - nvgClosePath(context) - } - @JvmStatic - fun drawString(text: String, x: Number, y: Number, size: Number, gradient: Gradient, alignment: Alignment = Alignment.TOP_LEFT, font: FontResource = ResourceManager.FontResources.regular) { - nvgBeginPath(context) - NVGPaint.calloc().use { nvgPaint -> - NVGColor.calloc().use { primary -> - NVGColor.calloc().use { secondary -> - nvgRGBAf(gradient.primary.red / 255f, gradient.primary.green / 255f, gradient.primary.blue / 255f, gradient.primary.alpha / 255f, primary) - nvgRGBAf(gradient.secondary.red / 255f, gradient.secondary.green / 255f, gradient.secondary.blue / 255f, gradient.secondary.alpha / 255f, secondary) - nvgLinearGradient(context, gradient.origin.x.toFloat(), gradient.origin.y.toFloat(), gradient.end.x.toFloat(), gradient.end.y.toFloat(), primary, secondary, nvgPaint) - } - } - nvgFillPaint(context, nvgPaint) - nvgFontFace(context, font.identifier) - nvgFontSize(context, size.toFloat()) - nvgTextAlign(context, getAlignFlags(alignment)) - nvgText(context, x.toFloat(), y.toFloat(), text) - } - nvgClosePath(context) - } - @JvmStatic - fun getStringWidth(text: String, size: Number, font: FontResource = ResourceManager.FontResources.regular): Double { - var width: Float - nvgFontFace(context, font.identifier) - nvgFontSize(context, size.toFloat()) - MemoryStack.stackPush().use { - val bounds = floatArrayOf(0.0f, 0.0f, 0.0f, 0.0f) - nvgTextBounds(context, 0.0f, 0.0f, text, bounds) - width = bounds[2] - bounds[0] - } - return width.toDouble() - } - - // custom shit - - /** - * Q: How bad is this code? - * A: yes. - */ - @JvmStatic - fun rainbowBar(x: Number, y: Number, width: Number, height: Number, radius: Number, alignment: Alignment = Alignment.TOP_LEFT) { - val yay = width.toDouble() / 10.0 - var x = x.toDouble() - for (hue in 0..9) { - roundedRect( - x, y, yay, height, - doubleArrayOf( - if (hue == 0) { - radius.toDouble() - } else { - 0.0 - }, - if (hue == 9) { - radius.toDouble() - } else { - 0.0 - }, - if (hue == 9) { - radius.toDouble() - } else { - 0.0 - }, - if (hue == 0) { - radius.toDouble() - } else { - 0.0 - } - ), - Gradient( - Color.getHSBColor(hue / 10.0f, 1.0f, 1.0f), - Color.getHSBColor((hue / 10.0f) + 0.1f, 1.0f, 1.0f), - Point(x, y), - Point(x + yay, y) - ), - alignment - ) - x += yay - } - } - - private fun preRender() { - RenderSystem.enableBlend() - RenderSystem.defaultBlendFunc() -// RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE) -// RenderSystem.disableDepthTest() -// RenderSystem.depthFunc(GL11.GL_LESS) -// RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT) - } - private fun postRender() { - RenderSystem.disableCull() - RenderSystem.disableDepthTest() - RenderSystem.enableBlend() -// RenderSystem.defaultBlendFunc() -// RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA) - RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE) - } - private fun alignX(x: Number, width: Number, alignment: Alignment): Float { - return when (alignment) { - Alignment.TOP_RIGHT, Alignment.CENTER_RIGHT, Alignment.BOTTOM_RIGHT -> x.toDouble() - width.toDouble() - Alignment.TOP_CENTER, Alignment.CENTER, Alignment.BOTTOM_CENTER -> x.toDouble() - (width.toDouble() / 2.0) - else -> x - }.toFloat() - } - private fun alignY(y: Number, height: Number, alignment: Alignment): Float { - return when (alignment) { - Alignment.BOTTOM_LEFT, Alignment.BOTTOM_CENTER, Alignment.BOTTOM_RIGHT -> y.toDouble() - height.toDouble() - Alignment.CENTER_LEFT, Alignment.CENTER, Alignment.CENTER_RIGHT -> y.toDouble() - (height.toDouble() / 2.0) - else -> y - }.toFloat() - } - private fun getAlignFlags(alignment: Alignment): Int { - val x = when (alignment) { - Alignment.TOP_CENTER, Alignment.CENTER, Alignment.BOTTOM_CENTER -> NVG_ALIGN_CENTER - Alignment.TOP_RIGHT, Alignment.CENTER_RIGHT, Alignment.BOTTOM_RIGHT -> NVG_ALIGN_RIGHT - else -> NVG_ALIGN_LEFT - } - val y = when (alignment) { - Alignment.CENTER_LEFT, Alignment.CENTER, Alignment.CENTER_RIGHT -> NVG_ALIGN_MIDDLE - Alignment.BOTTOM_LEFT, Alignment.BOTTOM_CENTER, Alignment.BOTTOM_RIGHT -> NVG_ALIGN_BOTTOM - else -> NVG_ALIGN_TOP - } - return x or y - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/render/Gradient.kt b/src/main/kotlin/dev/blend/util/render/Gradient.kt deleted file mode 100644 index 7e7ecc0..0000000 --- a/src/main/kotlin/dev/blend/util/render/Gradient.kt +++ /dev/null @@ -1,14 +0,0 @@ -package dev.blend.util.render - -import dev.blend.util.IAccessor -import net.minecraft.client.MinecraftClient -import java.awt.Color - -class Gradient( - val primary: Color, - val secondary: Color, - var origin: Point = Point(0, 0), - var end: Point = Point(MinecraftClient.getInstance().window.width, MinecraftClient.getInstance().window.height) -): IAccessor - -class Point(val x: Number, val y: Number) diff --git a/src/main/kotlin/dev/blend/util/render/ResourceManager.kt b/src/main/kotlin/dev/blend/util/render/ResourceManager.kt deleted file mode 100644 index d360437..0000000 --- a/src/main/kotlin/dev/blend/util/render/ResourceManager.kt +++ /dev/null @@ -1,19 +0,0 @@ -package dev.blend.util.render - -object ResourceManager { - - @JvmStatic - fun init() { - FontResources.init() - } - - object FontResources { - lateinit var regular: FontResource - lateinit var ubuntu: FontResource - fun init() { - regular = FontResource("regular") - ubuntu = FontResource("ubuntu") - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/util/render/Resources.kt b/src/main/kotlin/dev/blend/util/render/Resources.kt deleted file mode 100644 index edfe109..0000000 --- a/src/main/kotlin/dev/blend/util/render/Resources.kt +++ /dev/null @@ -1,18 +0,0 @@ -package dev.blend.util.render - -import dev.blend.util.misc.MiscUtil -import org.lwjgl.nanovg.NanoVG -import java.nio.ByteBuffer - -class FontResource( - fontName: String -) { - private val resource: ByteBuffer - val identifier: String = fontName - .replace(' ', '_') - .replace('-', '_') - init { - resource = MiscUtil.getResourceAsByteBuffer("fonts/$identifier.ttf") - NanoVG.nvgCreateFontMem(DrawUtil.context, fontName, resource, false) - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/value/Value.kt b/src/main/kotlin/dev/blend/value/Value.kt deleted file mode 100644 index 468676c..0000000 --- a/src/main/kotlin/dev/blend/value/Value.kt +++ /dev/null @@ -1,29 +0,0 @@ -package dev.blend.value - -import com.google.gson.JsonObject -import dev.blend.value.api.ValueHolder - -abstract class Value( - val name: String, - val parent: ValueHolder, - private val defaultValue: T, - var visibility: () -> Boolean, -): ValueHolder() { - protected var value: T = defaultValue - - init { - parent.values.add(this) - } - - open fun get(): T { - return value - } - open fun set(value: T) { - this.value = value - } - fun reset() { - set(defaultValue) - } - abstract fun getJsonObject(): JsonObject - abstract fun useJsonObject(jsonObject: JsonObject) -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/value/api/ValueHolder.kt b/src/main/kotlin/dev/blend/value/api/ValueHolder.kt deleted file mode 100644 index 8cc5629..0000000 --- a/src/main/kotlin/dev/blend/value/api/ValueHolder.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.blend.value.api - -import dev.blend.value.Value - -abstract class ValueHolder { - val values = mutableListOf>() - fun getValue(name: String): Value<*>? { - return values.find { it.name.equals(name, true) } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/value/impl/BooleanValue.kt b/src/main/kotlin/dev/blend/value/impl/BooleanValue.kt deleted file mode 100644 index 33940dd..0000000 --- a/src/main/kotlin/dev/blend/value/impl/BooleanValue.kt +++ /dev/null @@ -1,30 +0,0 @@ -package dev.blend.value.impl - -import com.google.gson.JsonObject -import dev.blend.value.Value -import dev.blend.value.api.ValueHolder - -class BooleanValue( - name: String, - parent: ValueHolder, - defaultValue: Boolean, - visibility: () -> Boolean = { true }, -): Value( - name, - parent, - defaultValue, - visibility -) { - fun toggle() { - set(!value) - } - override fun getJsonObject(): JsonObject { - val obj = JsonObject() - obj.addProperty("name", name) - obj.addProperty("value", value) - return obj - } - override fun useJsonObject(jsonObject: JsonObject) { - set(jsonObject.get("value").asBoolean) - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/value/impl/ColorValue.kt b/src/main/kotlin/dev/blend/value/impl/ColorValue.kt deleted file mode 100644 index 6c93ed6..0000000 --- a/src/main/kotlin/dev/blend/value/impl/ColorValue.kt +++ /dev/null @@ -1,57 +0,0 @@ -package dev.blend.value.impl - -import com.google.gson.JsonObject -import dev.blend.value.Value -import dev.blend.value.api.ValueHolder -import java.awt.Color - -class ColorValue( - name: String, - parent: ValueHolder, - defaultValue: Color, - visibility: () -> Boolean = { true }, -): Value( - name, parent, defaultValue, visibility -) { - var hue: Float = 0.0f - var saturation: Float = 0.0f - var brightness: Float = 1.0f - - init { - set(defaultValue) - } - - fun set(hsb: FloatArray) { - set(hsb[0], hsb[1], hsb[2]) - } - - fun set(hue: Float, saturation: Float, brightness: Float) { - this.hue = hue - this.saturation = saturation - this.brightness = brightness - } - - override fun get(): Color { - return Color.getHSBColor(hue, saturation, brightness) - } - override fun set(value: Color) { - val hsb = floatArrayOf(1f, 1f, 1f) - set(Color.RGBtoHSB(value.red, value.green, value.blue, hsb)) - } - override fun getJsonObject(): JsonObject { - val obj = JsonObject() - obj.addProperty("name", name) - obj.addProperty("hue", hue) - obj.addProperty("saturation", saturation) - obj.addProperty("brightness", brightness) - return obj - } - - override fun useJsonObject(jsonObject: JsonObject) { - set(floatArrayOf( - jsonObject.get("hue").asFloat, - jsonObject.get("saturation").asFloat, - jsonObject.get("brightness").asFloat, - )) - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/value/impl/ModeValue.kt b/src/main/kotlin/dev/blend/value/impl/ModeValue.kt deleted file mode 100644 index b39a965..0000000 --- a/src/main/kotlin/dev/blend/value/impl/ModeValue.kt +++ /dev/null @@ -1,70 +0,0 @@ -package dev.blend.value.impl - -import com.google.gson.JsonObject -import dev.blend.value.Value -import dev.blend.value.api.ValueHolder - -class ModeValue( - name: String, - parent: ValueHolder, - modes: Array, - visibility: () -> Boolean = { true }, -): Value( - name, parent, modes.first(), visibility -) { - - val modes = mutableListOf() - - init { - modes.forEach { - add(it) - } - } - - fun add(mode: String): ModeValue { - if (!modes.contains(mode)) { - modes.add(mode) - } - return this - } - - fun `is`(value: String): Boolean { - return this.value.equals(value, true) - } - fun isNot(value: String): Boolean { - return !`is`(value) - } - fun next() { - val index = modes.indexOf(value) - if (index < modes.size - 1) { - set(modes[index + 1]) - } else { - set(modes.first()) - } - } - fun previous() { - val index = modes.indexOf(value) - if (index > 0) { - set(modes[index - 1]) - } else { - set(modes.last()) - } - } - - override fun set(value: String) { - if (modes.contains(value)) { - super.set(value) - } - } - - override fun getJsonObject(): JsonObject { - val obj = JsonObject() - obj.addProperty("name", name) - obj.addProperty("value", value) - return obj - } - - override fun useJsonObject(jsonObject: JsonObject) { - set(jsonObject.get("value").asString) - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/blend/value/impl/NumberValue.kt b/src/main/kotlin/dev/blend/value/impl/NumberValue.kt deleted file mode 100644 index 0196894..0000000 --- a/src/main/kotlin/dev/blend/value/impl/NumberValue.kt +++ /dev/null @@ -1,43 +0,0 @@ -package dev.blend.value.impl - -import com.google.gson.JsonObject -import dev.blend.value.Value -import dev.blend.value.api.ValueHolder -import kotlin.math.* - -class NumberValue( - name: String, - parent: ValueHolder, - defaultValue: Number, - val min: Number, - val max: Number, - val increment: Number, - visibility: () -> Boolean = { true }, -): Value( - name, parent, defaultValue, visibility -) { - - override fun set(value: Number) { - val precision = 1 / increment.toDouble() - super.set(max(min.toDouble(), min(max.toDouble(), round(value.toDouble() * precision) / precision))) - } - - override fun toString(): String { - return if (increment.toDouble() % 1.0 == 0.0) { - value.toInt().toString() - } else { - value.toDouble().toString() - } - } - - override fun getJsonObject(): JsonObject { - val obj = JsonObject() - obj.addProperty("name", name) - obj.addProperty("value", value) - return obj - } - - override fun useJsonObject(jsonObject: JsonObject) { - set(jsonObject.get("value").asNumber) - } -} \ No newline at end of file diff --git a/src/main/resources/assets/blend/fonts/regular.ttf b/src/main/resources/assets/blend/fonts/regular.ttf deleted file mode 100644 index c0442ee..0000000 Binary files a/src/main/resources/assets/blend/fonts/regular.ttf and /dev/null differ diff --git a/src/main/resources/assets/blend/fonts/ubuntu.ttf b/src/main/resources/assets/blend/fonts/ubuntu.ttf deleted file mode 100644 index f98a2da..0000000 Binary files a/src/main/resources/assets/blend/fonts/ubuntu.ttf and /dev/null differ diff --git a/src/main/resources/blend.mixins.json b/src/main/resources/blend.mixins.json deleted file mode 100644 index 2d57ee3..0000000 --- a/src/main/resources/blend.mixins.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "dev.blend.mixin", - "compatibilityLevel": "JAVA_21", - "mixins": [ - ], - "client": [ - "client.KeyboardMixin", - "client.MinecraftClientMixin", - "client.gui.screen.ChatScreenMixin", - "client.network.ClientPlayerEntityMixin", - "client.option.KeybindingMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 index d16e242..0000000 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "schemaVersion": 1, - "id": "blend", - "version": "${version}", - "name": "Blend", - "description": "Minecraft mod which is very cool!", - "authors": [], - "contact": {}, - "license": "GPL-3.0", - "icon": "assets/blend/icon.png", - "environment": "client", - "entrypoints": { - "main": [ - "dev.blend.Initializer" - ] - }, - "mixins": [ - "blend.mixins.json" - ], - "depends": { - "fabricloader": ">=${loader_version}", - "fabric-language-kotlin": ">=${fabric_kotlin_version}", - "fabric": "*", - "minecraft": "${minecraft_version}" - } -}