diff --git a/README.md b/README.md index a8321b5..4385914 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ Kosher client base ported to Minecraft 1.21.5 by [@cattyngmd](https://github.com # What Add stuff to it like you would add stuff to your 1.12.2 OyVey paste - + \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/OyVey.java b/src/main/java/me/alpha432/oyvey/OyVey.java index 5cafbb2..3e5ab17 100644 --- a/src/main/java/me/alpha432/oyvey/OyVey.java +++ b/src/main/java/me/alpha432/oyvey/OyVey.java @@ -1,5 +1,6 @@ package me.alpha432.oyvey; +import me.alpha432.oyvey.features.gui.HudEditorScreen; import me.alpha432.oyvey.manager.*; import me.alpha432.oyvey.util.TextUtil; import net.fabricmc.api.ClientModInitializer; @@ -26,6 +27,7 @@ public class OyVey implements ModInitializer, ClientModInitializer { public static FriendManager friendManager; public static ModuleManager moduleManager; public static ConfigManager configManager; + public static HudEditorScreen hudEditorScreen; @Override public void onInitialize() { @@ -47,6 +49,7 @@ public class OyVey implements ModInitializer, ClientModInitializer { public void onInitializeClient() { eventManager.init(); moduleManager.init(); + hudEditorScreen = new HudEditorScreen(); configManager = new ConfigManager(); configManager.load(); diff --git a/src/main/java/me/alpha432/oyvey/event/impl/MouseEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/MouseEvent.java new file mode 100644 index 0000000..cd403b1 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/MouseEvent.java @@ -0,0 +1,22 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; + +public class MouseEvent extends Event { + private final int button; + private final int action; + + public MouseEvent(int button, int action) { + this.button = button; + this.action = action; + } + + public int getButton() { + return button; + } + + public int getAction() { + return action; + } +} + diff --git a/src/main/java/me/alpha432/oyvey/features/gui/Component.java b/src/main/java/me/alpha432/oyvey/features/gui/Component.java index 68e097d..53f4af1 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/Component.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/Component.java @@ -57,7 +57,7 @@ public class Component this.drag(mouseX, mouseY); counter1 = new int[]{1}; float totalItemHeight = this.open ? this.getTotalItemHeight() - 2.0f : 0.0f; - int color = ColorUtil.toARGB(ClickGui.getInstance().topRed.getValue(), ClickGui.getInstance().topGreen.getValue(), ClickGui.getInstance().topBlue.getValue(), 255); + int color = ClickGui.getInstance().topColor.getValue().getRGB(); context.fill(this.x, this.y - 1, this.x + this.width, this.y + this.height - 6, ClickGui.getInstance().rainbow.getValue() ? ColorUtil.rainbow(ClickGui.getInstance().rainbowHue.getValue()).getRGB() : color); if (this.open) { RenderUtil.rect(context.getMatrices(), this.x, (float) this.y + 12.5f, this.x + this.width, (float) (this.y + this.height) + totalItemHeight, 0x77000000); diff --git a/src/main/java/me/alpha432/oyvey/features/gui/HudEditorScreen.java b/src/main/java/me/alpha432/oyvey/features/gui/HudEditorScreen.java new file mode 100644 index 0000000..8cbf99c --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/HudEditorScreen.java @@ -0,0 +1,89 @@ +package me.alpha432.oyvey.features.gui; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.gui.items.buttons.ModuleButton; +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.modules.client.HudModule; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +import java.util.ArrayList; +import java.util.Comparator; + +public class HudEditorScreen extends Screen { + private final ArrayList components = new ArrayList<>(); + public HudModule currentDragging; + public boolean anyHover; + + public HudEditorScreen() { + super(Text.literal("oyvey-hudeditor")); + load(); + } + + private void load() { + this.components.add(new Component("Hud", 50, 50, true) { + @Override + public void setupItems() { + Component.counter1 = new int[]{1}; + OyVey.moduleManager.getModulesByCategory(Module.Category.HUD).forEach(module -> { + if (!module.hidden) { + this.addButton(new ModuleButton(module)); + } + }); + } + }); + this.components.forEach(component -> component.getItems().sort(Comparator.comparing(Feature::getName))); + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + anyHover = false; + this.components.forEach(component -> component.drawScreen(context, mouseX, mouseY, delta)); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int clickedButton) { + this.components.forEach(component -> component.mouseClicked((int) mouseX, (int) mouseY, clickedButton)); + return super.mouseClicked(mouseX, mouseY, clickedButton); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int releaseButton) { + this.components.forEach(component -> component.mouseReleased((int) mouseX, (int) mouseY, releaseButton)); + return super.mouseReleased(mouseX, mouseY, releaseButton); + } + + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + if (verticalAmount < 0) { + this.components.forEach(component -> component.setY(component.getY() - 10)); + } else if (verticalAmount > 0) { + this.components.forEach(component -> component.setY(component.getY() + 10)); + } + return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + this.components.forEach(component -> component.onKeyPressed(keyCode)); + return super.keyPressed(keyCode, scanCode, modifiers); + } + + @Override + public boolean charTyped(char chr, int modifiers) { + this.components.forEach(component -> component.onKeyTyped(chr, modifiers)); + return super.charTyped(chr, modifiers); + } + + @Override + public boolean shouldPause() { + return false; + } + + public ArrayList getComponents() { + return components; + } +} + diff --git a/src/main/java/me/alpha432/oyvey/features/gui/OyVeyGui.java b/src/main/java/me/alpha432/oyvey/features/gui/OyVeyGui.java index 9caba9e..8aeca6e 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/OyVeyGui.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/OyVeyGui.java @@ -14,8 +14,8 @@ import java.util.ArrayList; import java.util.Comparator; public class OyVeyGui extends Screen { - private static OyVeyGui oyveyGui; private static OyVeyGui INSTANCE; + private static Color colorClipboard = null; static { INSTANCE = new OyVeyGui(); @@ -47,6 +47,7 @@ public class OyVeyGui extends Screen { private void load() { int x = -84; for (final Module.Category category : OyVey.moduleManager.getCategories()) { + if (category == Module.Category.HUD) continue; // Skip HUD category in ClickGui this.components.add(new Component(category.getName(), x += 90, 4, true) { @Override @@ -136,4 +137,12 @@ public class OyVeyGui extends Screen { } return null; } + + public static Color getColorClipboard() { + return colorClipboard; + } + + public static void setColorClipboard(Color color) { + colorClipboard = color; + } } diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java index 2f6ffdf..511ecfc 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java @@ -26,8 +26,8 @@ public class BindButton @Override public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { - int color = ColorUtil.toARGB(ClickGui.getInstance().red.getValue(), ClickGui.getInstance().green.getValue(), ClickGui.getInstance().blue.getValue(), 255); - RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515) : (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue()))); + int color = ClickGui.getInstance().color.getValue().getRGB(); + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515) : (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().color.getValue().getAlpha()) : OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha()))); if (this.isListening) { drawString("Press a Key...", this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), -1); } else { diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BooleanButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BooleanButton.java index 2a1165c..ac415a3 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BooleanButton.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BooleanButton.java @@ -22,7 +22,7 @@ public class BooleanButton @Override public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { - RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().color.getValue().getAlpha()) : OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); drawString(this.getName(), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); } diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Button.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Button.java index 5590e45..a6e54fd 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Button.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Button.java @@ -21,7 +21,7 @@ public class Button @Override public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { - RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().color.getValue().getAlpha()) : OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); drawString(this.getName(), this.x + 2.3f, this.y - 2.0f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); } diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ColorButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ColorButton.java new file mode 100644 index 0000000..51ef0eb --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ColorButton.java @@ -0,0 +1,200 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.gui.Component; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.render.RenderUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.math.MathHelper; + +import java.awt.Color; + +public class ColorButton extends Button { + private final Setting setting; + private boolean open = false; + private boolean hoveringHue = false, hoveringColor = false, hoveringAlpha = false, hoveringCopy = false, hoveringPaste = false; + private boolean draggingHue = false, draggingColor = false, draggingAlpha = false; + private int pickerSize = 84; + private float[] hsb; + + public ColorButton(Setting setting) { + super(setting.getName()); + this.setting = setting; + this.width = 15; + hsb = Color.RGBtoHSB(setting.getValue().getRed(), setting.getValue().getGreen(), setting.getValue().getBlue(), null); + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + Color currentColor = setting.getValue(); + Color outlineColor = Color.BLACK; + Color realColor = Color.getHSBColor(hsb[0], 1, 1); + + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, + !this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515); + + RenderUtil.rect(context.getMatrices(), this.x + (float) this.width - 3.0f, this.y + 2.0f, + this.x + (float) this.width + 5.0f, this.y + (float) this.height - 2.5f, + new Color(currentColor.getRed(), currentColor.getGreen(), currentColor.getBlue(), 255).getRGB()); + + drawString(this.getName(), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), -1); + + if (open) { + float yOffset = this.height; + int availableWidth = this.width + 3; + int pickerWidth = Math.min(pickerSize, availableWidth); + float pickerX = this.x + 2.0f; + + int dragX = MathHelper.clamp(mouseX - (int)pickerX, 0, pickerWidth); + int dragY = MathHelper.clamp(mouseY - (int)(getY() + yOffset), 0, pickerWidth); + float dragHue = pickerWidth * hsb[0]; + float dragSaturation = pickerWidth * hsb[1]; + float dragBrightness = pickerWidth * (1.0f - hsb[2]); + float dragAlpha = pickerWidth * (currentColor.getAlpha() / 255.0f); + + RenderUtil.horizontalGradient(context.getMatrices(), pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + pickerWidth, Color.WHITE, realColor); + RenderUtil.verticalGradient(context.getMatrices(), pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + pickerWidth, new Color(0, 0, 0, 0), Color.BLACK); + RenderUtil.rect(context.getMatrices(), pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + pickerWidth, outlineColor.getRGB(), 1.0f); + + hoveringColor = isHoveringArea(mouseX, mouseY, pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + pickerWidth); + + if (dragSaturation < pickerWidth && dragBrightness < pickerWidth) { + RenderUtil.rect(context.getMatrices(), pickerX + dragSaturation - 1.5f, this.y + yOffset + dragBrightness - 1.5f, + pickerX + dragSaturation + 1.5f, this.y + yOffset + dragBrightness + 1.5f, outlineColor.getRGB()); + RenderUtil.rect(context.getMatrices(), pickerX + dragSaturation - 0.5f, this.y + yOffset + dragBrightness - 0.5f, + pickerX + dragSaturation + 0.5f, this.y + yOffset + dragBrightness + 0.5f, Color.WHITE.getRGB()); + } + + if (draggingColor) { + hsb[1] = (float) dragX / pickerWidth; + hsb[2] = 1.0f - (float) dragY / pickerWidth; + setColor(hsb); + } + + yOffset += pickerWidth + 2; + + RenderUtil.horizontalGradient(context.getMatrices(), pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + 8, + new Color(currentColor.getRed(), currentColor.getGreen(), currentColor.getBlue(), 0), + new Color(currentColor.getRed(), currentColor.getGreen(), currentColor.getBlue(), 255)); + RenderUtil.rect(context.getMatrices(), pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + 8, outlineColor.getRGB(), 1.0f); + hoveringAlpha = isHoveringArea(mouseX, mouseY, pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + 8); + + RenderUtil.rect(context.getMatrices(), pickerX + dragAlpha - 1.5f, this.y + yOffset - 1, + pickerX + dragAlpha + 1.5f, this.y + yOffset + 9, outlineColor.getRGB()); + RenderUtil.rect(context.getMatrices(), pickerX + dragAlpha - 0.5f, this.y + yOffset, + pickerX + dragAlpha + 0.5f, this.y + yOffset + 8, Color.WHITE.getRGB()); + + if (draggingAlpha) { + setColor(hsb, (int) (255 * (float) dragX / pickerWidth)); + } + + yOffset += 10; + + for (float i = 0; i < pickerWidth; i += 0.5f) { + RenderUtil.rect(context.getMatrices(), pickerX + i, this.y + yOffset, pickerX + i + 0.5f, this.y + yOffset + 8, + Color.getHSBColor(i / pickerWidth, 1.0f, 1.0f).getRGB()); + } + RenderUtil.rect(context.getMatrices(), pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + 8, outlineColor.getRGB(), 1.0f); + hoveringHue = isHoveringArea(mouseX, mouseY, pickerX, this.y + yOffset, pickerX + pickerWidth, this.y + yOffset + 8); + + if (dragHue < pickerWidth) { + RenderUtil.rect(context.getMatrices(), pickerX + dragHue - 1.5f, this.y + yOffset - 1, + pickerX + dragHue + 1.5f, this.y + yOffset + 9, outlineColor.getRGB()); + RenderUtil.rect(context.getMatrices(), pickerX + dragHue - 0.5f, this.y + yOffset, + pickerX + dragHue + 0.5f, this.y + yOffset + 8, Color.WHITE.getRGB()); + } + + if (draggingHue) { + hsb[0] = (float) dragX / pickerWidth; + setColor(hsb); + } + + yOffset += 10; + + int buttonWidth = availableWidth / 2; + RenderUtil.rect(context.getMatrices(), pickerX, this.y + yOffset, pickerX + buttonWidth, this.y + yOffset + 14, + hoveringCopy ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha()) : 0x11555555); + drawString("Copy", pickerX + buttonWidth / 2 - mc.textRenderer.getWidth("Copy") / 2, this.y + yOffset + 2, -1); + hoveringCopy = isHoveringArea(mouseX, mouseY, pickerX, this.y + yOffset, pickerX + buttonWidth, this.y + yOffset + 14); + + RenderUtil.rect(context.getMatrices(), pickerX + buttonWidth + 1, this.y + yOffset, pickerX + buttonWidth * 2 + 1, this.y + yOffset + 14, + hoveringPaste ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha()) : 0x11555555); + drawString("Paste", pickerX + buttonWidth + buttonWidth / 2 - mc.textRenderer.getWidth("Paste") / 2 + 1, this.y + yOffset + 2, -1); + hoveringPaste = isHoveringArea(mouseX, mouseY, pickerX + buttonWidth + 1, this.y + yOffset, pickerX + buttonWidth * 2 + 1, this.y + yOffset + 14); + } + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (this.isHovering(mouseX, mouseY) && mouseButton == 1) { + open = !open; + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + + if (mouseButton == 0) { + if (hoveringHue) draggingHue = true; + if (hoveringColor) draggingColor = true; + if (hoveringAlpha) draggingAlpha = true; + + if (hoveringCopy) { + OyVeyGui.setColorClipboard(setting.getValue()); + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + if (hoveringPaste && OyVeyGui.getColorClipboard() != null) { + setting.setValue(OyVeyGui.getColorClipboard()); + hsb = Color.RGBtoHSB(setting.getValue().getRed(), setting.getValue().getGreen(), setting.getValue().getBlue(), null); + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + } + } + + @Override + public void mouseReleased(int mouseX, int mouseY, int releaseButton) { + if (releaseButton == 0) { + draggingHue = false; + draggingColor = false; + draggingAlpha = false; + } + } + + @Override + public void update() { + this.setHidden(!this.setting.isVisible()); + } + + @Override + public int getHeight() { + if (!open) return 14; + int pickerWidth = Math.min(pickerSize, this.width + 3); + return 14 + pickerWidth + 8 + 8 + 14 + 10; + } + + @Override + public boolean isHovering(int mouseX, int mouseY) { + for (Component component : OyVeyGui.getClickGui().getComponents()) { + if (component.drag) return false; + } + return (float) mouseX >= this.getX() && (float) mouseX <= this.getX() + (float) this.getWidth() + 8.0f + && (float) mouseY >= this.getY() && (float) mouseY <= this.getY() + (float) this.height; + } + + private boolean isHoveringArea(int mouseX, int mouseY, float left, float top, float right, float bottom) { + for (Component component : OyVeyGui.getClickGui().getComponents()) { + if (component.drag) return false; + } + return left <= mouseX && top <= mouseY && right > mouseX && bottom > mouseY; + } + + private void setColor(float[] hsb) { + setColor(hsb, setting.getValue().getAlpha()); + } + + private void setColor(float[] hsb, int alpha) { + Color color = new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2])); + setting.setValue(new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha)); + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/EnumButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/EnumButton.java index ed29548..9cca3c1 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/EnumButton.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/EnumButton.java @@ -23,7 +23,7 @@ public class EnumButton @Override public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { - RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().color.getValue().getAlpha()) : OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); drawString(this.setting.getName() + " " + Formatting.GRAY + (this.setting.currentEnumName().equalsIgnoreCase("ABC") ? "ABC" : this.setting.currentEnumName()), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); } diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ModuleButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ModuleButton.java index a037602..14f0df8 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ModuleButton.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ModuleButton.java @@ -37,6 +37,10 @@ public class ModuleButton if ((setting.getValue() instanceof String || setting.getValue() instanceof Character) && !setting.getName().equalsIgnoreCase("displayName")) { newItems.add(new StringButton((Setting) setting)); } + if (setting.isColorSetting()) { + newItems.add(new ColorButton((Setting) setting)); + continue; + } if (setting.isNumberSetting() && setting.hasRestriction()) { newItems.add(new Slider((Setting) setting)); continue; @@ -54,14 +58,14 @@ public class ModuleButton super.drawScreen(context, mouseX, mouseY, partialTicks); if (!this.items.isEmpty()) { if (this.subOpen) { - float height = 1.0f; + float height = 14.0f; for (Item item : this.items) { Component.counter1[0] = Component.counter1[0] + 1; if (!item.isHidden()) { - item.setLocation(this.x + 1.0f, this.y + (height += 15.0f)); - item.setHeight(15); + item.setLocation(this.x + 1.0f, this.y + height); item.setWidth(this.width - 9); item.drawScreen(context, mouseX, mouseY, partialTicks); + height += item.getHeight() + 1; } item.update(); } @@ -86,6 +90,17 @@ public class ModuleButton } } + @Override + public void mouseReleased(int mouseX, int mouseY, int releaseButton) { + super.mouseReleased(mouseX, mouseY, releaseButton); + if (!this.items.isEmpty() && this.subOpen) { + for (Item item : this.items) { + if (item.isHidden()) continue; + item.mouseReleased(mouseX, mouseY, releaseButton); + } + } + } + @Override public void onKeyTyped(char typedChar, int keyCode) { super.onKeyTyped(typedChar, keyCode); diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Slider.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Slider.java index 7c36eda..c7eb27b 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Slider.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Slider.java @@ -30,7 +30,7 @@ public class Slider public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { this.dragSetting(mouseX, mouseY); RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, !this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515); - RenderUtil.rect(context.getMatrices(), this.x, this.y, (this.setting.getValue()).floatValue() <= this.min.floatValue() ? this.x : this.x + ((float) this.width + 7.4f) * this.partialMultiplier(), this.y + (float) this.height - 0.5f, !this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())); + RenderUtil.rect(context.getMatrices(), this.x, this.y, (this.setting.getValue()).floatValue() <= this.min.floatValue() ? this.x : this.x + ((float) this.width + 7.4f) * this.partialMultiplier(), this.y + (float) this.height - 0.5f, !this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().color.getValue().getAlpha()) : OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha())); drawString(this.getName() + " " + Formatting.GRAY + (this.setting.getValue() instanceof Float ? this.setting.getValue() : Double.valueOf((this.setting.getValue()).doubleValue())), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), -1); } diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/StringButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/StringButton.java index 35988d4..93180dd 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/StringButton.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/StringButton.java @@ -36,7 +36,7 @@ public class StringButton @Override public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { - RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().color.getValue().getAlpha()) : OyVey.colorManager.getColorWithAlpha(ClickGui.getInstance().topColor.getValue().getAlpha())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); if (this.isListening) { drawString(this.currentString.string() + "_", this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); } else { diff --git a/src/main/java/me/alpha432/oyvey/features/modules/Module.java b/src/main/java/me/alpha432/oyvey/features/modules/Module.java index 160714c..c7fc513 100644 --- a/src/main/java/me/alpha432/oyvey/features/modules/Module.java +++ b/src/main/java/me/alpha432/oyvey/features/modules/Module.java @@ -171,6 +171,10 @@ public class Module extends Feature implements Jsonable { try { if (setting.getValue() instanceof Bind bind) { object.addProperty(setting.getName(), bind.getKey()); + } else if (setting.getValue() instanceof java.awt.Color color) { + object.addProperty(setting.getName(), color.getRed() + "," + color.getGreen() + "," + color.getBlue() + "," + color.getAlpha()); + } else if (setting.getValue() instanceof me.alpha432.oyvey.features.settings.Pos pos) { + object.addProperty(setting.getName(), pos.getX() + "," + pos.getY()); } else { object.addProperty(setting.getName(), setting.getValueAsString()); } @@ -182,13 +186,20 @@ public class Module extends Feature implements Jsonable { @Override public void fromJson(JsonElement element) { + if (element == null || element.isJsonNull()) return; JsonObject object = element.getAsJsonObject(); - String enabled = object.get("Enabled").getAsString(); - if (Boolean.parseBoolean(enabled)) toggle(); + if (object.has("Enabled")) { + String enabled = object.get("Enabled").getAsString(); + if (Boolean.parseBoolean(enabled)) toggle(); + } for (Setting setting : getSettings()) { try { - ConfigManager.setValueFromJson(this, setting, object.get(setting.getName())); + JsonElement settingElement = object.get(setting.getName()); + if (settingElement != null && !settingElement.isJsonNull()) { + ConfigManager.setValueFromJson(this, setting, settingElement); + } } catch (Throwable throwable) { + throwable.printStackTrace(); } } } @@ -199,7 +210,8 @@ public class Module extends Feature implements Jsonable { RENDER("Render"), MOVEMENT("Movement"), PLAYER("Player"), - CLIENT("Client"); + CLIENT("Client"), + HUD("Hud"); private final String name; diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/ClickGui.java b/src/main/java/me/alpha432/oyvey/features/modules/client/ClickGui.java index 5348a95..9597dcb 100644 --- a/src/main/java/me/alpha432/oyvey/features/modules/client/ClickGui.java +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/ClickGui.java @@ -9,21 +9,17 @@ import me.alpha432.oyvey.features.modules.Module; import me.alpha432.oyvey.features.settings.Setting; import org.lwjgl.glfw.GLFW; +import java.awt.Color; + public class ClickGui extends Module { private static ClickGui INSTANCE = new ClickGui(); public Setting prefix = str("Prefix", "."); - public Setting red = num("Red", 0, 0, 255); - public Setting green = num("Green", 0, 0, 255); - public Setting blue = num("Blue", 255, 0, 255); - public Setting hoverAlpha = num("Alpha", 180, 0, 255); - public Setting topRed = num("SecondRed", 0, 0, 255); - public Setting topGreen = num("SecondGreen", 0, 0, 255); - public Setting topBlue = num("SecondBlue", 150, 0, 255); - public Setting alpha = num("HoverAlpha", 240, 0, 255); + public Setting color = color("Color", 0, 0, 255, 180); + public Setting topColor = color("TopColor", 0, 0, 150, 240); public Setting rainbow = bool("Rainbow", false); public Setting rainbowHue = num("Delay", 240, 0, 600); - public Setting rainbowBrightness = num("Brightness ", 150.0f, 1.0f, 255.0f); + public Setting rainbowBrightness = num("Brightness", 150.0f, 1.0f, 255.0f); public Setting rainbowSaturation = num("Saturation", 150.0f, 1.0f, 255.0f); public ClickGui() { @@ -53,7 +49,9 @@ public class ClickGui OyVey.commandManager.setPrefix(this.prefix.getPlannedValue()); Command.sendMessage("Prefix set to {global} %s", OyVey.commandManager.getPrefix()); } - OyVey.colorManager.setColor(this.red.getPlannedValue(), this.green.getPlannedValue(), this.blue.getPlannedValue(), this.hoverAlpha.getPlannedValue()); + if (event.getSetting().equals(this.color)) { + OyVey.colorManager.setColor(this.color.getPlannedValue()); + } } } @@ -67,7 +65,7 @@ public class ClickGui @Override public void onLoad() { - OyVey.colorManager.setColor(this.red.getValue(), this.green.getValue(), this.blue.getValue(), this.hoverAlpha.getValue()); + OyVey.colorManager.setColor(this.color.getValue()); OyVey.commandManager.setPrefix(this.prefix.getValue()); } diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/Coordinates.java b/src/main/java/me/alpha432/oyvey/features/modules/client/Coordinates.java new file mode 100644 index 0000000..126b0e8 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/Coordinates.java @@ -0,0 +1,43 @@ +package me.alpha432.oyvey.features.modules.client; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.event.impl.Render2DEvent; +import me.alpha432.oyvey.features.settings.Setting; + +public class Coordinates extends HudModule { + public Setting nether = bool("Nether", false); + + public Coordinates() { + super("Coordinates", "Display coordinates", 150, 20); + } + + @Override + @Subscribe + public void onRender2D(Render2DEvent e) { + super.onRender2DHud(e); + + if (fullNullCheck()) return; + + String coordsStr = String.format("X: %d Y: %d Z: %d", + mc.player.getBlockX(), + mc.player.getBlockY(), + mc.player.getBlockZ()); + + if (nether.getValue()) { + int netherX = mc.player.getWorld().getRegistryKey().getValue().getPath().equals("the_nether") + ? mc.player.getBlockX() * 8 + : mc.player.getBlockX() / 8; + int netherZ = mc.player.getWorld().getRegistryKey().getValue().getPath().equals("the_nether") + ? mc.player.getBlockZ() * 8 + : mc.player.getBlockZ() / 8; + coordsStr += String.format(" [%d, %d]", netherX, netherZ); + } + + e.getContext().drawTextWithShadow(mc.textRenderer, coordsStr, + (int) getX(), (int) getY(), -1); + + setWidth(mc.textRenderer.getWidth(coordsStr)); + setHeight(mc.textRenderer.fontHeight); + } +} + diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/HudEditor.java b/src/main/java/me/alpha432/oyvey/features/modules/client/HudEditor.java new file mode 100644 index 0000000..0580962 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/HudEditor.java @@ -0,0 +1,37 @@ +package me.alpha432.oyvey.features.modules.client; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.impl.UpdateEvent; +import me.alpha432.oyvey.features.gui.HudEditorScreen; +import me.alpha432.oyvey.features.modules.Module; + +public class HudEditor extends Module { + public HudEditor() { + super("HudEditor", "Edit HUD element positions", Category.CLIENT, true, false, false); + } + + @Override + public void onEnable() { + if (fullNullCheck()) { + disable(); + return; + } + mc.setScreen(OyVey.hudEditorScreen); + } + + @Override + public void onDisable() { + if (fullNullCheck()) return; + mc.setScreen(null); + } + + @Subscribe + public void onUpdate(UpdateEvent event) { + if (fullNullCheck()) return; + if (!(mc.currentScreen instanceof HudEditorScreen)) { + disable(); + } + } +} + diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java b/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java index dff692f..cb42a53 100644 --- a/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java @@ -1,22 +1,143 @@ package me.alpha432.oyvey.features.modules.client; +import com.google.common.eventbus.Subscribe; import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.impl.MouseEvent; import me.alpha432.oyvey.event.impl.Render2DEvent; +import me.alpha432.oyvey.features.gui.HudEditorScreen; import me.alpha432.oyvey.features.modules.Module; -import me.alpha432.oyvey.util.TextUtil; +import me.alpha432.oyvey.features.settings.Pos; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.render.RenderUtil; +import net.minecraft.client.gui.screen.ChatScreen; -public class HudModule extends Module { - public HudModule() { - super("Hud", "hud", Category.CLIENT, true, false, false); +public abstract class HudModule extends Module { + public final Setting pos = pos("Position", 0.5f, 0.5f); + public final Setting chatOffset = bool("ChatOffset", true); + private float dragX, dragY, width, height; + private boolean dragging, button; + + public HudModule(String name, String description, float width, float height) { + super(name, description, Category.HUD, true, false, false); + this.width = width; + this.height = height; } - @Override - public void onRender2D(Render2DEvent event) { - event.getContext().drawTextWithShadow( - mc.textRenderer, - TextUtil.text("{global} %s {} %s", OyVey.NAME, OyVey.VERSION), - 2, 2, - -1 - ); + public float getX() { + return mc.getWindow().getScaledWidth() * pos.getValue().getX(); + } + + public float getY() { + float baseY = mc.getWindow().getScaledHeight() * pos.getValue().getY(); + if (chatOffset.getValue() && mc.currentScreen instanceof ChatScreen && !(mc.currentScreen instanceof HudEditorScreen)) { + float chatHeight = 14f; + if (baseY > mc.getWindow().getScaledHeight() / 2f) { + baseY -= chatHeight; + } + } + return baseY; + } + + @Subscribe + public void onRender2DHud(Render2DEvent e) { + if (!(mc.currentScreen instanceof HudEditorScreen) || fullNullCheck()) return; + + float x = getX(); + float y = getY(); + + if (button) { + if (!dragging && isHovering() && (OyVey.hudEditorScreen == null || !OyVey.hudEditorScreen.anyHover)) { + dragX = getMouseX() - x; + dragY = getMouseY() - y; + dragging = true; + if (OyVey.hudEditorScreen != null) { + OyVey.hudEditorScreen.currentDragging = this; + } + } + + if (dragging) { + float finalX = Math.min(Math.max(getMouseX() - dragX, 0), + mc.getWindow().getScaledWidth() - width); + float finalY = Math.min(Math.max(getMouseY() - dragY, 0), + mc.getWindow().getScaledHeight() - height); + + pos.getValue().setX(finalX / mc.getWindow().getScaledWidth()); + pos.getValue().setY(finalY / mc.getWindow().getScaledHeight()); + } + } else { + dragging = false; + } + + if (isHovering()) { + int textWidth = mc.textRenderer.getWidth(getName()); + int textHeight = mc.textRenderer.fontHeight; + float textX = x + width + 5; + if (textX + textWidth > mc.getWindow().getScaledWidth()) { + textX = x - 5 - textWidth; + } + e.getContext().drawTextWithShadow(mc.textRenderer, getName(), + (int) textX, (int) (y + height / 2f - textHeight / 2f), -1); + } + + RenderUtil.rect(e.getContext().getMatrices(), + x - 1, y - 1, x + width + 1, y + height + 1, + OyVey.colorManager.getColor().getRGB(), 1.0f); + } + + @Subscribe + public void onMouse(MouseEvent e) { + if (!(mc.currentScreen instanceof HudEditorScreen) || fullNullCheck()) return; + + if (e.getAction() == 0) { + button = false; + dragging = false; + if (OyVey.hudEditorScreen != null) { + OyVey.hudEditorScreen.currentDragging = null; + } + } else if (e.getAction() == 1 && isHovering() && + (OyVey.hudEditorScreen == null || OyVey.hudEditorScreen.currentDragging == null)) { + button = true; + } + } + + public int getMouseX() { + return (int) (mc.mouse.getX() / mc.getWindow().getScaleFactor()); + } + + public int getMouseY() { + return (int) (mc.mouse.getY() / mc.getWindow().getScaleFactor()); + } + + public void setBounds(float x, float y, float width, float height) { + this.width = width; + this.height = height; + pos.getValue().setX(x / mc.getWindow().getScaledWidth()); + pos.getValue().setY(y / mc.getWindow().getScaledHeight()); + } + + public boolean isHovering() { + float x = getX(); + float y = getY(); + int mouseX = getMouseX(); + int mouseY = getMouseY(); + + return mouseX >= x - 1 && mouseX <= x + width + 1 && + mouseY >= y - 1 && mouseY <= y + height + 1; + } + + public float getWidth() { + return width; + } + + public float getHeight() { + return height; + } + + public void setWidth(float width) { + this.width = width; + } + + public void setHeight(float height) { + this.height = height; } } diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/Watermark.java b/src/main/java/me/alpha432/oyvey/features/modules/client/Watermark.java new file mode 100644 index 0000000..2c0c327 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/Watermark.java @@ -0,0 +1,30 @@ +package me.alpha432.oyvey.features.modules.client; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.impl.Render2DEvent; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.TextUtil; + +public class Watermark extends HudModule { + public Setting text = str("Text", "OyVey"); + + public Watermark() { + super("Watermark", "Display watermark", 100, 10); + } + + @Override + @Subscribe + public void onRender2D(Render2DEvent e) { + super.onRender2DHud(e); + + e.getContext().drawTextWithShadow(mc.textRenderer, + TextUtil.text("{global} %s {} %s", text.getValue(), OyVey.VERSION), + (int) getX(), (int) getY(), -1); + + String watermarkString = text.getValue() + " " + OyVey.VERSION; + setWidth(mc.textRenderer.getWidth(watermarkString)); + setHeight(mc.textRenderer.fontHeight); + } +} + diff --git a/src/main/java/me/alpha432/oyvey/features/modules/render/BlockHighlight.java b/src/main/java/me/alpha432/oyvey/features/modules/render/BlockHighlight.java index 9e39b14..46e8906 100644 --- a/src/main/java/me/alpha432/oyvey/features/modules/render/BlockHighlight.java +++ b/src/main/java/me/alpha432/oyvey/features/modules/render/BlockHighlight.java @@ -3,6 +3,7 @@ package me.alpha432.oyvey.features.modules.render; import com.google.common.eventbus.Subscribe; import me.alpha432.oyvey.event.impl.Render3DEvent; import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.settings.Setting; import me.alpha432.oyvey.util.render.RenderUtil; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.Box; @@ -11,6 +12,9 @@ import net.minecraft.util.shape.VoxelShape; import java.awt.*; public class BlockHighlight extends Module { + public Setting color = color("Color", 255, 0, 0, 255); + public Setting lineWidth = num("LineWidth", 1.0f, 0.1f, 5.0f); + public BlockHighlight() { super("BlockHighlight", "Draws box at the block that you are looking at", Category.RENDER, true, false, false); } @@ -22,7 +26,7 @@ public class BlockHighlight extends Module { if (shape.isEmpty()) return; Box box = shape.getBoundingBox(); box = box.offset(result.getBlockPos()); - RenderUtil.drawBox(event.getMatrix(), box, Color.red, 1f); + RenderUtil.drawBox(event.getMatrix(), box, color.getValue(), lineWidth.getValue()); } } } diff --git a/src/main/java/me/alpha432/oyvey/features/settings/Pos.java b/src/main/java/me/alpha432/oyvey/features/settings/Pos.java new file mode 100644 index 0000000..ed7cb20 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/settings/Pos.java @@ -0,0 +1,32 @@ +package me.alpha432.oyvey.features.settings; + +public class Pos { + private float x, y; + + public Pos(float x, float y) { + this.x = x; + this.y = y; + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } + + @Override + public String toString() { + return x + "," + y; + } +} + diff --git a/src/main/java/me/alpha432/oyvey/features/settings/Setting.java b/src/main/java/me/alpha432/oyvey/features/settings/Setting.java index ce60cf9..cf4e15a 100644 --- a/src/main/java/me/alpha432/oyvey/features/settings/Setting.java +++ b/src/main/java/me/alpha432/oyvey/features/settings/Setting.java @@ -208,6 +208,12 @@ public class Setting { if (this.isEnumSetting()) { return "Enum"; } + if (this.isColorSetting()) { + return "Color"; + } + if (this.isPoseSetting()) { + return "Pos"; + } return this.getClassName(this.defaultValue); } @@ -227,13 +233,21 @@ public class Setting { } public boolean isEnumSetting() { - return !this.isNumberSetting() && !(this.value instanceof String) && !(this.value instanceof Bind) && !(this.value instanceof Character) && !(this.value instanceof Boolean); + return !this.isNumberSetting() && !(this.value instanceof String) && !(this.value instanceof Bind) && !(this.value instanceof Character) && !(this.value instanceof Boolean) && !this.isColorSetting() && !this.isPoseSetting(); } public boolean isStringSetting() { return this.value instanceof String; } + public boolean isColorSetting() { + return this.value instanceof java.awt.Color; + } + + public boolean isPoseSetting() { + return this.value instanceof Pos; + } + public T getDefaultValue() { return this.defaultValue; } diff --git a/src/main/java/me/alpha432/oyvey/features/settings/SettingFactory.java b/src/main/java/me/alpha432/oyvey/features/settings/SettingFactory.java index 3f3da5e..d0729fa 100644 --- a/src/main/java/me/alpha432/oyvey/features/settings/SettingFactory.java +++ b/src/main/java/me/alpha432/oyvey/features/settings/SettingFactory.java @@ -1,5 +1,7 @@ package me.alpha432.oyvey.features.settings; +import java.awt.Color; + public interface SettingFactory { > T register(T setting); @@ -23,4 +25,20 @@ public interface SettingFactory { return register(new Setting<>(name, bind)); } + default Setting color(String name, Color value) { + return register(new Setting<>(name, value)); + } + + default Setting color(String name, int r, int g, int b, int a) { + return register(new Setting<>(name, new Color(r, g, b, a))); + } + + default Setting pos(String name, Pos value) { + return register(new Setting<>(name, value)); + } + + default Setting pos(String name, float x, float y) { + return register(new Setting<>(name, new Pos(x, y))); + } + } diff --git a/src/main/java/me/alpha432/oyvey/manager/ColorManager.java b/src/main/java/me/alpha432/oyvey/manager/ColorManager.java index 0f4ba1e..3c51aec 100644 --- a/src/main/java/me/alpha432/oyvey/manager/ColorManager.java +++ b/src/main/java/me/alpha432/oyvey/manager/ColorManager.java @@ -7,15 +7,11 @@ import me.alpha432.oyvey.util.ColorUtil; import java.awt.*; public class ColorManager { - private float red = 1.0f; - private float green = 1.0f; - private float blue = 1.0f; - private float alpha = 1.0f; - private Color color = new Color(this.red, this.green, this.blue, this.alpha); + private Color color = new Color(0, 0, 255, 180); public void init() { ClickGui ui = ClickGui.getInstance(); - setColor(ui.red.getValue(), ui.green.getValue(), ui.blue.getValue(), ui.hoverAlpha.getValue()); + setColor(ui.color.getValue()); } public Color getColor() { @@ -38,46 +34,6 @@ public class ColorManager { if (ClickGui.getInstance().rainbow.getValue()) { return ColorUtil.rainbow(Component.counter1[0] * ClickGui.getInstance().rainbowHue.getValue()).getRGB(); } - return ColorUtil.toRGBA(new Color(this.red, this.green, this.blue, (float) alpha / 255.0f)); - } - - public void setColor(float red, float green, float blue, float alpha) { - this.red = red; - this.green = green; - this.blue = blue; - this.alpha = alpha; - this.updateColor(); - } - - public void updateColor() { - this.setColor(new Color(this.red, this.green, this.blue, this.alpha)); - } - - public void setColor(int red, int green, int blue, int alpha) { - this.red = (float) red / 255.0f; - this.green = (float) green / 255.0f; - this.blue = (float) blue / 255.0f; - this.alpha = (float) alpha / 255.0f; - this.updateColor(); - } - - public void setRed(float red) { - this.red = red; - this.updateColor(); - } - - public void setGreen(float green) { - this.green = green; - this.updateColor(); - } - - public void setBlue(float blue) { - this.blue = blue; - this.updateColor(); - } - - public void setAlpha(float alpha) { - this.alpha = alpha; - this.updateColor(); + return new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), alpha).getRGB(); } } diff --git a/src/main/java/me/alpha432/oyvey/manager/ConfigManager.java b/src/main/java/me/alpha432/oyvey/manager/ConfigManager.java index b5092fb..7321eec 100644 --- a/src/main/java/me/alpha432/oyvey/manager/ConfigManager.java +++ b/src/main/java/me/alpha432/oyvey/manager/ConfigManager.java @@ -12,6 +12,7 @@ import me.alpha432.oyvey.features.settings.Setting; import me.alpha432.oyvey.util.traits.Jsonable; import net.fabricmc.loader.api.FabricLoader; +import java.awt.Color; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -25,6 +26,7 @@ public class ConfigManager { @SuppressWarnings({"rawtypes", "unchecked"}) public static void setValueFromJson(Feature feature, Setting setting, JsonElement element) { + if (element == null || element.isJsonNull()) return; String str; switch (setting.getType()) { case "Boolean" -> { @@ -46,6 +48,34 @@ public class ConfigManager { case "Bind" -> { setting.setValue(new Bind(element.getAsInt())); } + case "Color" -> { + try { + String colorStr = element.getAsString(); + String[] parts = colorStr.split(","); + if (parts.length == 4) { + int r = Integer.parseInt(parts[0]); + int g = Integer.parseInt(parts[1]); + int b = Integer.parseInt(parts[2]); + int a = Integer.parseInt(parts[3]); + setting.setValue(new Color(r, g, b, a)); + } + } catch (Exception exception) { + OyVey.LOGGER.error("Error parsing color for: " + feature.getName() + " : " + setting.getName()); + } + } + case "Pos" -> { + try { + String posStr = element.getAsString(); + String[] parts = posStr.split(","); + if (parts.length == 2) { + float x = Float.parseFloat(parts[0]); + float y = Float.parseFloat(parts[1]); + setting.setValue(new me.alpha432.oyvey.features.settings.Pos(x, y)); + } + } catch (Exception exception) { + OyVey.LOGGER.error("Error parsing position for: " + feature.getName() + " : " + setting.getName()); + } + } case "Enum" -> { try { EnumConverter converter = new EnumConverter(((Enum) setting.getValue()).getClass()); diff --git a/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java b/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java index b496d61..45e40f2 100644 --- a/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java +++ b/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java @@ -7,6 +7,7 @@ import me.alpha432.oyvey.event.impl.Render3DEvent; import me.alpha432.oyvey.features.Feature; import me.alpha432.oyvey.features.modules.Module; import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.modules.client.*; import me.alpha432.oyvey.features.modules.client.HudModule; import me.alpha432.oyvey.features.modules.combat.Criticals; import me.alpha432.oyvey.features.modules.misc.MCF; @@ -31,7 +32,9 @@ public class ModuleManager implements Jsonable, Util { public List sortedModulesABC = new ArrayList<>(); public void init() { - modules.add(new HudModule()); + modules.add(new Watermark()); + modules.add(new Coordinates()); + modules.add(new HudEditor()); modules.add(new ClickGui()); modules.add(new Criticals()); modules.add(new MCF()); diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinMouse.java b/src/main/java/me/alpha432/oyvey/mixin/MixinMouse.java new file mode 100644 index 0000000..809b994 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinMouse.java @@ -0,0 +1,23 @@ +package me.alpha432.oyvey.mixin; + +import me.alpha432.oyvey.event.impl.MouseEvent; +import net.minecraft.client.Mouse; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +@Mixin(Mouse.class) +public class MixinMouse { + @Inject(method = "onMouseButton", at = @At("HEAD"), cancellable = true) + private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) { + MouseEvent event = new MouseEvent(button, action); + EVENT_BUS.post(event); + if (event.isCancelled()) { + ci.cancel(); + } + } +} + diff --git a/src/main/java/me/alpha432/oyvey/util/render/RenderUtil.java b/src/main/java/me/alpha432/oyvey/util/render/RenderUtil.java index 978aaea..ae02ee3 100644 --- a/src/main/java/me/alpha432/oyvey/util/render/RenderUtil.java +++ b/src/main/java/me/alpha432/oyvey/util/render/RenderUtil.java @@ -93,6 +93,28 @@ public class RenderUtil implements Util { Layers.getGlobalQuads().draw(bufferBuilder.end()); } + public static void horizontalGradient(MatrixStack matrix, float x1, float y1, float x2, float y2, Color left, Color right) { + BufferBuilder bufferBuilder = Tessellator.getInstance() + .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x1, y1, 0.0F).color(left.getRed() / 255.0F, left.getGreen() / 255.0F, left.getBlue() / 255.0F, left.getAlpha() / 255.0F); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x1, y2, 0.0F).color(left.getRed() / 255.0F, left.getGreen() / 255.0F, left.getBlue() / 255.0F, left.getAlpha() / 255.0F); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x2, y2, 0.0F).color(right.getRed() / 255.0F, right.getGreen() / 255.0F, right.getBlue() / 255.0F, right.getAlpha() / 255.0F); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x2, y1, 0.0F).color(right.getRed() / 255.0F, right.getGreen() / 255.0F, right.getBlue() / 255.0F, right.getAlpha() / 255.0F); + + Layers.getGlobalQuads().draw(bufferBuilder.end()); + } + + public static void verticalGradient(MatrixStack matrix, float x1, float y1, float x2, float y2, Color top, Color bottom) { + BufferBuilder bufferBuilder = Tessellator.getInstance() + .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x1, y1, 0.0F).color(top.getRed() / 255.0F, top.getGreen() / 255.0F, top.getBlue() / 255.0F, top.getAlpha() / 255.0F); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x1, y2, 0.0F).color(bottom.getRed() / 255.0F, bottom.getGreen() / 255.0F, bottom.getBlue() / 255.0F, bottom.getAlpha() / 255.0F); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x2, y2, 0.0F).color(bottom.getRed() / 255.0F, bottom.getGreen() / 255.0F, bottom.getBlue() / 255.0F, bottom.getAlpha() / 255.0F); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x2, y1, 0.0F).color(top.getRed() / 255.0F, top.getGreen() / 255.0F, top.getBlue() / 255.0F, top.getAlpha() / 255.0F); + + Layers.getGlobalQuads().draw(bufferBuilder.end()); + } + // 3d public static void drawBoxFilled(MatrixStack stack, Box box, Color c) { float minX = (float) (box.minX - mc.getEntityRenderDispatcher().camera.getPos().getX()); diff --git a/src/main/resources/oyvey.mixins.json b/src/main/resources/oyvey.mixins.json index 9bb9584..e76e443 100644 --- a/src/main/resources/oyvey.mixins.json +++ b/src/main/resources/oyvey.mixins.json @@ -11,6 +11,7 @@ "MixinClientPlayNetworkHandler", "MixinInGameHud", "MixinKeyboard", + "MixinMouse", "MixinRenderTickCounter", "MixinWorldRenderer" ],