From 50677411e91d2fc0bbe16f4fb1de64d22669156a Mon Sep 17 00:00:00 2001 From: Ari k <75741608+ArikSquad@users.noreply.github.com> Date: Thu, 1 Jun 2023 20:36:00 +0300 Subject: [PATCH 1/7] feature update --- .../client/mod/impl/VisibleSeasonsMod.java | 56 +++ .../client/ui/screen/mods/ModsScreen.java | 80 +++++ .../client/ui/screen/mods/SnakeScreen.java | 319 ++++++++++++++++++ .../assets/sol_client/lang/en_US.lang | 6 + .../assets/sol_client/lang/fi_FI.lang | 6 + .../sol_client/textures/gui/snowflake.png | Bin 0 -> 187 bytes src/main/resources/standard-mods.json | 6 + 7 files changed, 473 insertions(+) create mode 100644 src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java create mode 100644 src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java create mode 100644 src/main/resources/assets/sol_client/textures/gui/snowflake.png diff --git a/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java b/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java new file mode 100644 index 00000000..7921c0b2 --- /dev/null +++ b/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java @@ -0,0 +1,56 @@ +/* + * Sol Client - an open source Minecraft client + * Copyright (C) 2021-2023 TheKodeToad and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package io.github.solclient.client.mod.impl; + +import com.google.gson.annotations.Expose; +import io.github.solclient.client.mod.option.annotation.Option; +import io.github.solclient.client.mod.option.annotation.Slider; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.resource.language.I18n; + +public class VisibleSeasonsMod extends StandardMod { + public static VisibleSeasonsMod instance; + protected final MinecraftClient mc = MinecraftClient.getInstance(); + + @Expose + @Option + public boolean visibleSeasonsOverride; + + @Expose + @Option + @Slider(min = 10, max = 100, step = 5) + public float visibleSeasonsAmount = 50; + + @Expose + @Option + public boolean visibleSeasonsLowDetail; + + + @Override + public String getDetail() { + return I18n.translate("sol_client.mod.screen.by", "ArikSquad"); + } + + @Override + public void init() { + super.init(); + instance = this; + } + +} diff --git a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java index d6f498bd..3076de2f 100644 --- a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java +++ b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java @@ -18,6 +18,10 @@ package io.github.solclient.client.ui.screen.mods; +import io.github.solclient.client.mod.impl.VisibleSeasonsMod; +import net.minecraft.client.MinecraftClient; +import net.minecraft.util.Identifier; +import org.apache.logging.log4j.LogManager; import org.lwjgl.input.Keyboard; import io.github.solclient.client.SolClient; @@ -32,12 +36,24 @@ import io.github.solclient.client.util.data.*; import lombok.Getter; import net.minecraft.client.resource.language.I18n; +import org.lwjgl.nanovg.NVGPaint; +import org.lwjgl.nanovg.NanoVG; + +import java.time.LocalDate; +import java.time.Month; +import java.util.ArrayList; +import java.util.Random; + public class ModsScreen extends PanoramaBackgroundScreen { + protected MinecraftClient mc = MinecraftClient.getInstance(); private final ModsScreenComponent component; private final ScreenAnimation animation = new ScreenAnimation(); + public ArrayList snowflakes = new ArrayList<>(); + private final long nvg; + public ModsScreen() { this(null); } @@ -49,6 +65,7 @@ public ModsScreen(Mod mod) { } }); + nvg = NanoVGManager.getNvg(); component = (ModsScreenComponent) root.getSubComponents().get(0); background = false; } @@ -61,6 +78,49 @@ public void init() { @Override public void render(int mouseX, int mouseY, float tickDelta) { + if ((VisibleSeasonsMod.instance.visibleSeasonsOverride) || LocalDate.now().getMonth() == Month.DECEMBER) { + Random random = new Random(); + int snowflakeAmount = (int) VisibleSeasonsMod.instance.visibleSeasonsAmount; + for (int i = 0; i < snowflakeAmount; i++) { + if (snowflakes.size() < snowflakeAmount) { + int x = random.nextInt(client.width); + int y = random.nextInt(client.height); + int size = 5 + random.nextInt(6); + int speed = 1 + random.nextInt(3); + + snowflakes.add(new int[]{x, y, size, speed}); + } + + int x = snowflakes.get(i)[0]; + int y = snowflakes.get(i)[1]; + int size = snowflakes.get(i)[2]; + int speed = snowflakes.get(i)[3]; + + if (VisibleSeasonsMod.instance.visibleSeasonsLowDetail) { + NanoVG.nvgBeginPath(nvg); + NanoVG.nvgRect(nvg, x, y, size, size); + NanoVG.nvgFillColor(nvg, Colour.WHITE.nvg()); + NanoVG.nvgFill(nvg); + } else { + NanoVG.nvgBeginPath(nvg); + NVGPaint paint = MinecraftUtils.nvgMinecraftTexturePaint(nvg, new Identifier("sol_client", "textures/gui/snowflake.png"), x, y, size, size, 0); + NanoVG.nvgFillPaint(nvg, paint); + NanoVG.nvgRect(nvg, 0, 0, width, height); + NanoVG.nvgFill(nvg); + } + + // Reset the snowflake if it goes beyond the screen bounds + if (snowflakes.get(i)[1] > client.height) { + x = random.nextInt(client.width); + y = random.nextInt(client.height); + size = 5 + random.nextInt(6); + speed = 1 + random.nextInt(3); + } + + snowflakes.set(i, new int[]{x, y + speed, size, snowflakes.get(i)[3]}); + } + } + if (client.world == null) { if (CoreMod.instance.fancyMainMenu) { background = false; @@ -280,8 +340,28 @@ public boolean mouseClickedAnywhere(ComponentRenderInfo info, int button, boolea return super.mouseClickedAnywhere(info, button, inside, processed); } + public static final int[] keys = { + Keyboard.KEY_UP, Keyboard.KEY_UP, Keyboard.KEY_DOWN, Keyboard.KEY_DOWN, Keyboard.KEY_LEFT, Keyboard.KEY_RIGHT, + Keyboard.KEY_LEFT, Keyboard.KEY_RIGHT, Keyboard.KEY_B, Keyboard.KEY_A + }; + + private int keyIndex = 0; + @Override public boolean keyPressed(ComponentRenderInfo info, int keyCode, char character) { + if (keyCode == keys[keyIndex]) { + LogManager.getLogger().info("Konami code: " + keyIndex); + keyIndex++; + if (keyIndex == keys.length) { + // switchMod(VisibleSeasonsMod.instance); + mc.setScreen(new SnakeScreen()); + LogManager.getLogger().info("sucaiis"); + keyIndex = 0; + } + } else { + keyIndex = 0; + } + if ((screen.getRoot().getDialog() == null && (keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER))) { if (mod == null) { diff --git a/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java b/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java new file mode 100644 index 00000000..4c8e4ff5 --- /dev/null +++ b/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java @@ -0,0 +1,319 @@ +/* + * Sol Client - an open source Minecraft client + * Copyright (C) 2021-2023 TheKodeToad and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package io.github.solclient.client.ui.screen.mods; + +import io.github.solclient.client.SolClient; +import io.github.solclient.client.mod.impl.core.CoreMod; +import io.github.solclient.client.mod.impl.VisibleSeasonsMod; +import io.github.solclient.client.ui.ScreenAnimation; +import io.github.solclient.client.ui.Theme; +import io.github.solclient.client.ui.component.Component; +import io.github.solclient.client.ui.component.ComponentRenderInfo; +import io.github.solclient.client.ui.component.controller.AlignedBoundsController; +import io.github.solclient.client.ui.component.controller.Controller; +import io.github.solclient.client.ui.component.impl.BlockComponent; +import io.github.solclient.client.ui.component.impl.LabelComponent; +import io.github.solclient.client.ui.screen.PanoramaBackgroundScreen; +import io.github.solclient.client.util.ActiveMainMenu; +import io.github.solclient.client.util.MinecraftUtils; +import io.github.solclient.client.util.NanoVGManager; +import io.github.solclient.client.util.data.Alignment; +import io.github.solclient.client.util.data.Colour; +import io.github.solclient.client.util.data.Rectangle; +import net.minecraft.client.MinecraftClient; +import net.minecraft.util.Identifier; +import org.lwjgl.input.Keyboard; +import org.lwjgl.nanovg.NVGPaint; +import org.lwjgl.nanovg.NanoVG; + +import java.time.LocalDate; +import java.time.Month; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + + +public class SnakeScreen extends PanoramaBackgroundScreen { + + protected MinecraftClient mc = MinecraftClient.getInstance(); + private final ScreenAnimation animation = new ScreenAnimation(); + + public static ArrayList snowflakes = new ArrayList<>(); + private final long nvg; + + public SnakeScreen() { + super(new Component() { + { + add(new SnakeComponent(), new AlignedBoundsController(Alignment.CENTRE, Alignment.CENTRE)); + } + }); + + nvg = NanoVGManager.getNvg(); + background = false; + } + + @Override + public void init() { + super.init(); + Keyboard.enableRepeatEvents(true); + } + + @Override + public void render(int mouseX, int mouseY, float tickDelta) { + if ((VisibleSeasonsMod.instance.visibleSeasonsOverride) || LocalDate.now().getMonth() == Month.DECEMBER) { + Random random = new Random(); + int snowflakeAmount = (int) VisibleSeasonsMod.instance.visibleSeasonsAmount; + for (int i = 0; i < snowflakeAmount; i++) { + if (snowflakes.size() < snowflakeAmount) { + int x = random.nextInt(client.width); + int y = random.nextInt(client.height); + int size = 5 + random.nextInt(6); + int speed = 1 + random.nextInt(3); + + snowflakes.add(new int[]{x, y, size, speed}); + } + + int x = snowflakes.get(i)[0]; + int y = snowflakes.get(i)[1]; + int size = snowflakes.get(i)[2]; + int speed = snowflakes.get(i)[3]; + + if (VisibleSeasonsMod.instance.visibleSeasonsLowDetail) { + NanoVG.nvgBeginPath(nvg); + NanoVG.nvgRect(nvg, x, y, size, size); + NanoVG.nvgFillColor(nvg, Colour.WHITE.nvg()); + NanoVG.nvgFill(nvg); + } else { + NanoVG.nvgBeginPath(nvg); + NVGPaint paint = MinecraftUtils.nvgMinecraftTexturePaint(nvg, new Identifier("sol_client", "textures/gui/snowflake.png"), x, y, size, size, 0); + NanoVG.nvgFillPaint(nvg, paint); + NanoVG.nvgRect(nvg, 0, 0, width, height); + NanoVG.nvgFill(nvg); + } + + // Reset the snowflake if it goes beyond the screen bounds + if (snowflakes.get(i)[1] > client.height) { + x = random.nextInt(client.width); + y = random.nextInt(client.height); + size = 5 + random.nextInt(6); + speed = 1 + random.nextInt(3); + } + + snowflakes.set(i, new int[]{x, y + speed, size, snowflakes.get(i)[3]}); + } + } + + if (client.world == null) { + if (CoreMod.instance.fancyMainMenu) { + background = false; + drawPanorama(mouseX, mouseY, tickDelta); + } else + background = true; + } + + super.render(mouseX, mouseY, tickDelta); + } + + @Override + protected void wrap(Runnable task) { + animation.wrap(task); + } + + @Override + public void removed() { + super.removed(); + animation.close(); + SolClient.INSTANCE.saveAll(); + Keyboard.enableRepeatEvents(false); + } + + @Override + public void closeAll() { + if (client.world == null && CoreMod.instance.fancyMainMenu) { + client.setScreen(ActiveMainMenu.getInstance()); + return; + } + + super.closeAll(); + } + + public static class SnakeComponent extends BlockComponent { + + public static final int[] keys = {Keyboard.KEY_S, Keyboard.KEY_E, Keyboard.KEY_A, Keyboard.KEY_S, Keyboard.KEY_O, Keyboard.KEY_N, Keyboard.KEY_S}; + private int keyIndex = 0; + + private int foodX = 0; + private int foodY = 0; + + private int snakeLength = 1; + private final int snakeSize = 5; + private List snakeX = new ArrayList<>(); + private List snakeY = new ArrayList<>(); + private int snakeDirection = 3; // 0 = up, 1 = right, 2 = down, 3 = left + + private long lastFrameTime = 0; + + public SnakeComponent() { + super(Theme.bg(), Controller.of(12F), Controller.of(0F)); + add(new LabelComponent((component, defaultText) -> String.valueOf(snakeLength - 3)).scaled(1.45F), new AlignedBoundsController(Alignment.CENTRE, Alignment.START)); + + resetSnake(); + generateFood(); + } + + @Override + public void render(ComponentRenderInfo info) { + super.render(info); + + renderSnake(); + renderFood(); + + if (isCollidingFood()) { + generateFood(); + addFood(); + } + + long currentTime = System.currentTimeMillis(); + if (currentTime - lastFrameTime >= 50) { + moveSnake(); + lastFrameTime = currentTime; + } + } + + private void addFood() { + snakeLength++; + int lastIndex = snakeLength - 1; + snakeX.add(snakeX.get(lastIndex - 1)); + snakeY.add(snakeY.get(lastIndex - 1)); + } + + private boolean isCollidingFood() { + return snakeX.get(0) == foodX && snakeY.get(0) == foodY; + } + + private void generateFood() { + foodX = (int) (Math.random() * 300); + foodY = (int) (Math.random() * 300); + foodX = foodX - (foodX % snakeSize); + foodY = foodY - (foodY % snakeSize); + } + + private void moveSnake() { + for (int i = snakeLength - 1; i > 0; i--) { + snakeX.set(i, snakeX.get(i - 1)); + snakeY.set(i, snakeY.get(i - 1)); + } + + if (snakeDirection == 0) { + snakeY.set(0, snakeY.get(0) - snakeSize); + } else if (snakeDirection == 1) { + snakeX.set(0, snakeX.get(0) + snakeSize); + } else if (snakeDirection == 2) { + snakeY.set(0, snakeY.get(0) + snakeSize); + } else if (snakeDirection == 3) { + snakeX.set(0, snakeX.get(0) - snakeSize); + } + + // Check if the new head position is within bounds + if (snakeX.get(0) < 0 || snakeX.get(0) >= 300 || snakeY.get(0) < 0 || snakeY.get(0) >= 300) { + resetSnake(); + } + } + + + private void renderSnake() { + for (int i = 0; i < snakeLength; i++) { + if (i == 0) { + NanoVG.nvgBeginPath(nvg); + NanoVG.nvgRect(nvg, snakeX.get(i), snakeY.get(i), snakeSize, snakeSize); + NanoVG.nvgFillColor(nvg, Colour.PURE_RED.nvg()); + NanoVG.nvgFill(nvg); + } else { + NanoVG.nvgBeginPath(nvg); + NanoVG.nvgRect(nvg, snakeX.get(i), snakeY.get(i), snakeSize, snakeSize); + NanoVG.nvgFillColor(nvg, Colour.WHITE.nvg()); + NanoVG.nvgFill(nvg); + } + } + } + + private void renderFood() { + NanoVG.nvgBeginPath(nvg); + NanoVG.nvgRect(nvg, foodX, foodY, snakeSize, snakeSize); + NanoVG.nvgFillColor(nvg, Colour.PURE_GREEN.nvg()); + NanoVG.nvgFill(nvg); + } + + private void resetSnake() { + snakeLength = 3; + snakeDirection = 3; + snakeX.clear(); + snakeY.clear(); + + for (int i = 0; i < snakeLength; i++) { + snakeX.add(150 - (i * snakeSize)); + snakeY.add(150); + } + + moveSnake(); + } + + public void changeDirection(int newDirection) { + // Prevent the snake from immediately reversing its direction + if (Math.abs(snakeDirection - newDirection) != 2) { + snakeDirection = newDirection; + } + } + + @Override + public boolean keyPressed(ComponentRenderInfo info, int keyCode, char character) { + if (keyCode == keys[keyIndex]) { + keyIndex++; + if (keyIndex == keys.length) { + mc.setScreen(new ModsScreen(VisibleSeasonsMod.instance)); + keyIndex = 0; + } + } else { + keyIndex = 0; + } + + if (keyCode == Keyboard.KEY_UP) { + changeDirection(0); + } + if (keyCode == Keyboard.KEY_RIGHT) { + changeDirection(1); + } + if (keyCode == Keyboard.KEY_DOWN) { + changeDirection(2); + } + if (keyCode == Keyboard.KEY_LEFT) { + changeDirection(3); + } + + return super.keyPressed(info, keyCode, character); + } + + @Override + public Rectangle getDefaultBounds() { + return Rectangle.ofDimensions(300, 300); + } + + } + +} diff --git a/src/main/resources/assets/sol_client/lang/en_US.lang b/src/main/resources/assets/sol_client/lang/en_US.lang index dd990724..175419b4 100644 --- a/src/main/resources/assets/sol_client/lang/en_US.lang +++ b/src/main/resources/assets/sol_client/lang/en_US.lang @@ -427,6 +427,12 @@ sol_client.mod.screenshots.deleted=The screenshot was deleted sol_client.mod.chat_hotkeys.name=Chat Hotkeys sol_client.mod.chat_hotkeys.description=Bind commands and messages to keys. +sol_client.mod.visible_seasons.name=Visible Seasons +sol_client.mod.visible_seasons.description=Render season decorations in the module menu. +sol_client.mod.visible_seasons.option.visibleSeasonsOverride=Force season decorations +sol_client.mod.visible_seasons.option.visibleSeasonsAmount=Amount of decorations +sol_client.mod.visible_seasons.option.visibleSeasonsLowDetail=Low detail mode + sol_client.mod.chat_hotkeys.option.hotkeys=Hotkeys sol_client.mod.chat_hotkeys.option.cooldown=Rate limit diff --git a/src/main/resources/assets/sol_client/lang/fi_FI.lang b/src/main/resources/assets/sol_client/lang/fi_FI.lang index 3e162b5b..3a7908f9 100644 --- a/src/main/resources/assets/sol_client/lang/fi_FI.lang +++ b/src/main/resources/assets/sol_client/lang/fi_FI.lang @@ -494,3 +494,9 @@ sol_client.mod.toggle_sprint.sneak_toggled=Hiipiminen (kytketty) sol_client.mod.screenshots.delete=Poista sol_client.mod.screenshots.delete_error=Poiston aikana tapahtui virhe: %s. Sinä voit yrittää avata %s sen sijaan. sol_client.slider.pixels=%spx + +sol_client.mod.visible_seasons.name=Näkyvät vuodenajat +sol_client.mod.visible_seasons.description=Näytä vuodenaikaan liittyvät koristeet moduulivalikossa. +sol_client.mod.visible_seasons.option.visibleSeasonsOverride=Ohita vuodenaika koristeet +sol_client.mod.visible_seasons.option.visibleSeasonsAmount=Koristeiden määrä +sol_client.mod.visible_seasons.option.visibleSeasonsLowDetail=Alhainen yksityiskohtaisuus diff --git a/src/main/resources/assets/sol_client/textures/gui/snowflake.png b/src/main/resources/assets/sol_client/textures/gui/snowflake.png new file mode 100644 index 0000000000000000000000000000000000000000..64dfebe4374bd5dddb6fecb7e21b439aab602952 GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+iCQlc~5R21CCvW6Epuodo%<%i- z<_`Dfy&8J142df45}K#PMIIdP-?;v@I^&xbR<1&}4v{8al?6i94ojF`>bBc(IB<)f z_6g$1ojNgETG_wd>H40@rVB2ayKFgob&8u?WbX%2$yC$4`&TRzopr0D3P&lK=n! literal 0 HcmV?d00001 diff --git a/src/main/resources/standard-mods.json b/src/main/resources/standard-mods.json index e285cb70..cf221169 100644 --- a/src/main/resources/standard-mods.json +++ b/src/main/resources/standard-mods.json @@ -255,6 +255,12 @@ "main": "HitColourMod", "category": "visual" }, + { + "id": "visible_seasons", + "main": "VisibleSeasonsMod", + "category": "hidden", + "forcedOn": true + }, // integration { "id": "hypixel_util", From 5a1de24994aa8ec4227687f0727219d3f8a718f5 Mon Sep 17 00:00:00 2001 From: Ari k <75741608+ArikSquad@users.noreply.github.com> Date: Thu, 1 Jun 2023 20:52:48 +0300 Subject: [PATCH 2/7] remove the sneaky prints --- .../io/github/solclient/client/ui/screen/mods/ModsScreen.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java index 3076de2f..1fcd6759 100644 --- a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java +++ b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java @@ -350,12 +350,9 @@ public boolean mouseClickedAnywhere(ComponentRenderInfo info, int button, boolea @Override public boolean keyPressed(ComponentRenderInfo info, int keyCode, char character) { if (keyCode == keys[keyIndex]) { - LogManager.getLogger().info("Konami code: " + keyIndex); keyIndex++; if (keyIndex == keys.length) { - // switchMod(VisibleSeasonsMod.instance); mc.setScreen(new SnakeScreen()); - LogManager.getLogger().info("sucaiis"); keyIndex = 0; } } else { From e89d87220a3c6fd8497be6411f4c399781bcdeea Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 1 Jun 2023 18:55:32 +0100 Subject: [PATCH 3/7] Performance? --- .../io/github/solclient/client/ui/screen/mods/ModsScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java index 1fcd6759..c2c12287 100644 --- a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java +++ b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java @@ -105,7 +105,7 @@ public void render(int mouseX, int mouseY, float tickDelta) { NanoVG.nvgBeginPath(nvg); NVGPaint paint = MinecraftUtils.nvgMinecraftTexturePaint(nvg, new Identifier("sol_client", "textures/gui/snowflake.png"), x, y, size, size, 0); NanoVG.nvgFillPaint(nvg, paint); - NanoVG.nvgRect(nvg, 0, 0, width, height); + NanoVG.nvgRect(nvg, x, y, size, size); NanoVG.nvgFill(nvg); } From 0e624669db3ec5b3047c44e867fe9ce56c91ee42 Mon Sep 17 00:00:00 2001 From: Ari k <75741608+ArikSquad@users.noreply.github.com> Date: Thu, 1 Jun 2023 22:21:01 +0300 Subject: [PATCH 4/7] more feature --- .../client/ui/component/ComponentScreen.java | 72 +++++++++++-- .../client/ui/screen/mods/ModsScreen.java | 86 ++++----------- .../client/ui/screen/mods/SnakeScreen.java | 100 +++++------------- 3 files changed, 110 insertions(+), 148 deletions(-) diff --git a/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java b/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java index f6ee9a29..91cf14c3 100644 --- a/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java +++ b/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java @@ -18,18 +18,29 @@ package io.github.solclient.client.ui.component; -import org.apache.logging.log4j.*; -import org.lwjgl.LWJGLException; -import org.lwjgl.input.*; - +import io.github.solclient.client.mod.impl.VisibleSeasonsMod; import io.github.solclient.client.ui.component.controller.ParentBoundsController; -import io.github.solclient.client.util.*; -import io.github.solclient.client.util.cursors.SystemCursors; -import io.github.solclient.client.util.data.*; +import io.github.solclient.client.util.MinecraftUtils; +import io.github.solclient.client.util.NanoVGManager; +import io.github.solclient.client.util.data.Colour; +import io.github.solclient.client.util.data.Rectangle; import lombok.Getter; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.Window; +import net.minecraft.util.Identifier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.LWJGLException; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.nanovg.NVGPaint; +import org.lwjgl.nanovg.NanoVG; + +import java.time.LocalDate; +import java.time.Month; +import java.util.ArrayList; +import java.util.Random; public class ComponentScreen extends Screen { @@ -41,6 +52,9 @@ public class ComponentScreen extends Screen { protected boolean background = true; private float mouseX, mouseY; + public ArrayList snowflakes = new ArrayList<>(); + private final long nvg; + public ComponentScreen(Component root) { this.parentScreen = MinecraftClient.getInstance().currentScreen; rootWrapper = new Component() { @@ -53,6 +67,8 @@ public Rectangle getBounds() { }; rootWrapper.setScreen(this); + nvg = NanoVGManager.getNvg(); + rootWrapper.add(root, new ParentBoundsController()); this.root = root; } @@ -63,6 +79,48 @@ public Component getRoot() { @Override public void render(int mouseX, int mouseY, float tickDelta) { + if ((VisibleSeasonsMod.instance.visibleSeasonsOverride) || LocalDate.now().getMonth() == Month.DECEMBER) { + Random random = new Random(); + int snowflakeAmount = (int) VisibleSeasonsMod.instance.visibleSeasonsAmount; + for (int i = 0; i < snowflakeAmount; i++) { + if (snowflakes.size() < snowflakeAmount) { + int x = random.nextInt(client.width); + int y = random.nextInt(client.height); + int size = 5 + random.nextInt(6); + int speed = 1 + random.nextInt(3); + + snowflakes.add(new int[]{x, y, size, speed}); + } + + int x = snowflakes.get(i)[0]; + int y = snowflakes.get(i)[1]; + int size = snowflakes.get(i)[2]; + int speed = snowflakes.get(i)[3]; + + NanoVG.nvgBeginPath(nvg); + if (VisibleSeasonsMod.instance.visibleSeasonsLowDetail) { + NanoVG.nvgRect(nvg, x, y, size, size); + NanoVG.nvgFillColor(nvg, Colour.WHITE.nvg()); + NanoVG.nvgFill(nvg); + } else { + NVGPaint paint = MinecraftUtils.nvgMinecraftTexturePaint(nvg, new Identifier("sol_client", "textures/gui/snowflake.png"), x, y, size, size, 0); + NanoVG.nvgFillPaint(nvg, paint); + NanoVG.nvgFill(nvg); + } + + // Reset the snowflake if it goes beyond the screen bounds + if (snowflakes.get(i)[1] > client.height) { + x = random.nextInt(client.width); + y = random.nextInt(client.height); + size = 5 + random.nextInt(6); + speed = 1 + random.nextInt(3); + } + + + snowflakes.set(i, new int[]{x, y + speed, size, snowflakes.get(i)[3]}); + } + } + try { Window window = new Window(client); diff --git a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java index c2c12287..c712b446 100644 --- a/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java +++ b/src/main/java/io/github/solclient/client/ui/screen/mods/ModsScreen.java @@ -18,31 +18,30 @@ package io.github.solclient.client.ui.screen.mods; -import io.github.solclient.client.mod.impl.VisibleSeasonsMod; -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.Identifier; -import org.apache.logging.log4j.LogManager; -import org.lwjgl.input.Keyboard; - import io.github.solclient.client.SolClient; -import io.github.solclient.client.mod.*; +import io.github.solclient.client.mod.Mod; +import io.github.solclient.client.mod.ModUiStateManager; import io.github.solclient.client.mod.impl.core.CoreMod; -import io.github.solclient.client.ui.*; -import io.github.solclient.client.ui.component.*; -import io.github.solclient.client.ui.component.controller.*; -import io.github.solclient.client.ui.component.impl.*; +import io.github.solclient.client.ui.ScreenAnimation; +import io.github.solclient.client.ui.Theme; +import io.github.solclient.client.ui.component.Component; +import io.github.solclient.client.ui.component.ComponentRenderInfo; +import io.github.solclient.client.ui.component.controller.AlignedBoundsController; +import io.github.solclient.client.ui.component.controller.Controller; +import io.github.solclient.client.ui.component.impl.BlockComponent; +import io.github.solclient.client.ui.component.impl.ButtonComponent; +import io.github.solclient.client.ui.component.impl.LabelComponent; +import io.github.solclient.client.ui.component.impl.TextFieldComponent; import io.github.solclient.client.ui.screen.PanoramaBackgroundScreen; -import io.github.solclient.client.util.*; -import io.github.solclient.client.util.data.*; +import io.github.solclient.client.util.ActiveMainMenu; +import io.github.solclient.client.util.KeyBindingInterface; +import io.github.solclient.client.util.MinecraftUtils; +import io.github.solclient.client.util.data.Alignment; +import io.github.solclient.client.util.data.Rectangle; import lombok.Getter; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.resource.language.I18n; -import org.lwjgl.nanovg.NVGPaint; -import org.lwjgl.nanovg.NanoVG; - -import java.time.LocalDate; -import java.time.Month; -import java.util.ArrayList; -import java.util.Random; +import org.lwjgl.input.Keyboard; public class ModsScreen extends PanoramaBackgroundScreen { @@ -51,9 +50,6 @@ public class ModsScreen extends PanoramaBackgroundScreen { private final ModsScreenComponent component; private final ScreenAnimation animation = new ScreenAnimation(); - public ArrayList snowflakes = new ArrayList<>(); - private final long nvg; - public ModsScreen() { this(null); } @@ -65,7 +61,6 @@ public ModsScreen(Mod mod) { } }); - nvg = NanoVGManager.getNvg(); component = (ModsScreenComponent) root.getSubComponents().get(0); background = false; } @@ -78,49 +73,6 @@ public void init() { @Override public void render(int mouseX, int mouseY, float tickDelta) { - if ((VisibleSeasonsMod.instance.visibleSeasonsOverride) || LocalDate.now().getMonth() == Month.DECEMBER) { - Random random = new Random(); - int snowflakeAmount = (int) VisibleSeasonsMod.instance.visibleSeasonsAmount; - for (int i = 0; i < snowflakeAmount; i++) { - if (snowflakes.size() < snowflakeAmount) { - int x = random.nextInt(client.width); - int y = random.nextInt(client.height); - int size = 5 + random.nextInt(6); - int speed = 1 + random.nextInt(3); - - snowflakes.add(new int[]{x, y, size, speed}); - } - - int x = snowflakes.get(i)[0]; - int y = snowflakes.get(i)[1]; - int size = snowflakes.get(i)[2]; - int speed = snowflakes.get(i)[3]; - - if (VisibleSeasonsMod.instance.visibleSeasonsLowDetail) { - NanoVG.nvgBeginPath(nvg); - NanoVG.nvgRect(nvg, x, y, size, size); - NanoVG.nvgFillColor(nvg, Colour.WHITE.nvg()); - NanoVG.nvgFill(nvg); - } else { - NanoVG.nvgBeginPath(nvg); - NVGPaint paint = MinecraftUtils.nvgMinecraftTexturePaint(nvg, new Identifier("sol_client", "textures/gui/snowflake.png"), x, y, size, size, 0); - NanoVG.nvgFillPaint(nvg, paint); - NanoVG.nvgRect(nvg, x, y, size, size); - NanoVG.nvgFill(nvg); - } - - // Reset the snowflake if it goes beyond the screen bounds - if (snowflakes.get(i)[1] > client.height) { - x = random.nextInt(client.width); - y = random.nextInt(client.height); - size = 5 + random.nextInt(6); - speed = 1 + random.nextInt(3); - } - - snowflakes.set(i, new int[]{x, y + speed, size, snowflakes.get(i)[3]}); - } - } - if (client.world == null) { if (CoreMod.instance.fancyMainMenu) { background = false; diff --git a/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java b/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java index 4c8e4ff5..08665081 100644 --- a/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java +++ b/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java @@ -19,34 +19,25 @@ package io.github.solclient.client.ui.screen.mods; import io.github.solclient.client.SolClient; -import io.github.solclient.client.mod.impl.core.CoreMod; import io.github.solclient.client.mod.impl.VisibleSeasonsMod; +import io.github.solclient.client.mod.impl.core.CoreMod; import io.github.solclient.client.ui.ScreenAnimation; -import io.github.solclient.client.ui.Theme; import io.github.solclient.client.ui.component.Component; import io.github.solclient.client.ui.component.ComponentRenderInfo; import io.github.solclient.client.ui.component.controller.AlignedBoundsController; -import io.github.solclient.client.ui.component.controller.Controller; import io.github.solclient.client.ui.component.impl.BlockComponent; import io.github.solclient.client.ui.component.impl.LabelComponent; import io.github.solclient.client.ui.screen.PanoramaBackgroundScreen; import io.github.solclient.client.util.ActiveMainMenu; -import io.github.solclient.client.util.MinecraftUtils; -import io.github.solclient.client.util.NanoVGManager; import io.github.solclient.client.util.data.Alignment; import io.github.solclient.client.util.data.Colour; import io.github.solclient.client.util.data.Rectangle; import net.minecraft.client.MinecraftClient; -import net.minecraft.util.Identifier; import org.lwjgl.input.Keyboard; -import org.lwjgl.nanovg.NVGPaint; import org.lwjgl.nanovg.NanoVG; -import java.time.LocalDate; -import java.time.Month; import java.util.ArrayList; import java.util.List; -import java.util.Random; public class SnakeScreen extends PanoramaBackgroundScreen { @@ -54,9 +45,6 @@ public class SnakeScreen extends PanoramaBackgroundScreen { protected MinecraftClient mc = MinecraftClient.getInstance(); private final ScreenAnimation animation = new ScreenAnimation(); - public static ArrayList snowflakes = new ArrayList<>(); - private final long nvg; - public SnakeScreen() { super(new Component() { { @@ -64,7 +52,6 @@ public SnakeScreen() { } }); - nvg = NanoVGManager.getNvg(); background = false; } @@ -76,49 +63,6 @@ public void init() { @Override public void render(int mouseX, int mouseY, float tickDelta) { - if ((VisibleSeasonsMod.instance.visibleSeasonsOverride) || LocalDate.now().getMonth() == Month.DECEMBER) { - Random random = new Random(); - int snowflakeAmount = (int) VisibleSeasonsMod.instance.visibleSeasonsAmount; - for (int i = 0; i < snowflakeAmount; i++) { - if (snowflakes.size() < snowflakeAmount) { - int x = random.nextInt(client.width); - int y = random.nextInt(client.height); - int size = 5 + random.nextInt(6); - int speed = 1 + random.nextInt(3); - - snowflakes.add(new int[]{x, y, size, speed}); - } - - int x = snowflakes.get(i)[0]; - int y = snowflakes.get(i)[1]; - int size = snowflakes.get(i)[2]; - int speed = snowflakes.get(i)[3]; - - if (VisibleSeasonsMod.instance.visibleSeasonsLowDetail) { - NanoVG.nvgBeginPath(nvg); - NanoVG.nvgRect(nvg, x, y, size, size); - NanoVG.nvgFillColor(nvg, Colour.WHITE.nvg()); - NanoVG.nvgFill(nvg); - } else { - NanoVG.nvgBeginPath(nvg); - NVGPaint paint = MinecraftUtils.nvgMinecraftTexturePaint(nvg, new Identifier("sol_client", "textures/gui/snowflake.png"), x, y, size, size, 0); - NanoVG.nvgFillPaint(nvg, paint); - NanoVG.nvgRect(nvg, 0, 0, width, height); - NanoVG.nvgFill(nvg); - } - - // Reset the snowflake if it goes beyond the screen bounds - if (snowflakes.get(i)[1] > client.height) { - x = random.nextInt(client.width); - y = random.nextInt(client.height); - size = 5 + random.nextInt(6); - speed = 1 + random.nextInt(3); - } - - snowflakes.set(i, new int[]{x, y + speed, size, snowflakes.get(i)[3]}); - } - } - if (client.world == null) { if (CoreMod.instance.fancyMainMenu) { background = false; @@ -162,15 +106,18 @@ public static class SnakeComponent extends BlockComponent { private int foodY = 0; private int snakeLength = 1; - private final int snakeSize = 5; - private List snakeX = new ArrayList<>(); - private List snakeY = new ArrayList<>(); + private final int snakeSize = 10; + private final List snakeX = new ArrayList<>(); + private final List snakeY = new ArrayList<>(); private int snakeDirection = 3; // 0 = up, 1 = right, 2 = down, 3 = left private long lastFrameTime = 0; + private final List nextMoves = new ArrayList<>(); + + private final int screenSize = 500; public SnakeComponent() { - super(Theme.bg(), Controller.of(12F), Controller.of(0F)); + super(new Colour(0xFF202020)); add(new LabelComponent((component, defaultText) -> String.valueOf(snakeLength - 3)).scaled(1.45F), new AlignedBoundsController(Alignment.CENTRE, Alignment.START)); resetSnake(); @@ -208,13 +155,18 @@ private boolean isCollidingFood() { } private void generateFood() { - foodX = (int) (Math.random() * 300); - foodY = (int) (Math.random() * 300); + foodX = (int) (Math.random() * screenSize); + foodY = (int) (Math.random() * screenSize); foodX = foodX - (foodX % snakeSize); foodY = foodY - (foodY % snakeSize); } private void moveSnake() { + if (nextMoves.size() > 0) { + changeDirection(nextMoves.get(0)); + nextMoves.remove(0); + } + for (int i = snakeLength - 1; i > 0; i--) { snakeX.set(i, snakeX.get(i - 1)); snakeY.set(i, snakeY.get(i - 1)); @@ -231,7 +183,7 @@ private void moveSnake() { } // Check if the new head position is within bounds - if (snakeX.get(0) < 0 || snakeX.get(0) >= 300 || snakeY.get(0) < 0 || snakeY.get(0) >= 300) { + if (snakeX.get(0) < 0 || snakeX.get(0) >= screenSize || snakeY.get(0) < 0 || snakeY.get(0) >= screenSize) { resetSnake(); } } @@ -242,12 +194,12 @@ private void renderSnake() { if (i == 0) { NanoVG.nvgBeginPath(nvg); NanoVG.nvgRect(nvg, snakeX.get(i), snakeY.get(i), snakeSize, snakeSize); - NanoVG.nvgFillColor(nvg, Colour.PURE_RED.nvg()); + NanoVG.nvgFillColor(nvg, new Colour(0xFF5dd95b).nvg()); NanoVG.nvgFill(nvg); } else { NanoVG.nvgBeginPath(nvg); NanoVG.nvgRect(nvg, snakeX.get(i), snakeY.get(i), snakeSize, snakeSize); - NanoVG.nvgFillColor(nvg, Colour.WHITE.nvg()); + NanoVG.nvgFillColor(nvg, new Colour(0xFF69ff67).nvg()); NanoVG.nvgFill(nvg); } } @@ -256,7 +208,7 @@ private void renderSnake() { private void renderFood() { NanoVG.nvgBeginPath(nvg); NanoVG.nvgRect(nvg, foodX, foodY, snakeSize, snakeSize); - NanoVG.nvgFillColor(nvg, Colour.PURE_GREEN.nvg()); + NanoVG.nvgFillColor(nvg, new Colour(0xFFfe6666).nvg()); NanoVG.nvgFill(nvg); } @@ -267,8 +219,8 @@ private void resetSnake() { snakeY.clear(); for (int i = 0; i < snakeLength; i++) { - snakeX.add(150 - (i * snakeSize)); - snakeY.add(150); + snakeX.add((screenSize / 2) - (i * snakeSize)); + snakeY.add(screenSize / 2); } moveSnake(); @@ -294,16 +246,16 @@ public boolean keyPressed(ComponentRenderInfo info, int keyCode, char character) } if (keyCode == Keyboard.KEY_UP) { - changeDirection(0); + nextMoves.add(0); } if (keyCode == Keyboard.KEY_RIGHT) { - changeDirection(1); + nextMoves.add(1); } if (keyCode == Keyboard.KEY_DOWN) { - changeDirection(2); + nextMoves.add(2); } if (keyCode == Keyboard.KEY_LEFT) { - changeDirection(3); + nextMoves.add(3); } return super.keyPressed(info, keyCode, character); @@ -311,7 +263,7 @@ public boolean keyPressed(ComponentRenderInfo info, int keyCode, char character) @Override public Rectangle getDefaultBounds() { - return Rectangle.ofDimensions(300, 300); + return Rectangle.ofDimensions(screenSize, screenSize); } } From 79b92a4b600bdbadd81adc7ec8a55608779f620a Mon Sep 17 00:00:00 2001 From: Ari k <75741608+ArikSquad@users.noreply.github.com> Date: Sat, 3 Jun 2023 18:18:46 +0300 Subject: [PATCH 5/7] even more feature --- .../client/mod/impl/VisibleSeasonsMod.java | 7 ++- .../client/ui/component/ComponentScreen.java | 51 +++++++++---------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java b/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java index 7921c0b2..a467c001 100644 --- a/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java +++ b/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java @@ -24,9 +24,12 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.resource.language.I18n; +import java.util.ArrayList; + public class VisibleSeasonsMod extends StandardMod { public static VisibleSeasonsMod instance; protected final MinecraftClient mc = MinecraftClient.getInstance(); + public ArrayList snowflakes = new ArrayList<>(); @Expose @Option @@ -34,8 +37,8 @@ public class VisibleSeasonsMod extends StandardMod { @Expose @Option - @Slider(min = 10, max = 100, step = 5) - public float visibleSeasonsAmount = 50; + @Slider(min = 1, max = 50, step = 1) + public float visibleSeasonsAmount = 25; @Expose @Option diff --git a/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java b/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java index 91cf14c3..ce3ea709 100644 --- a/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java +++ b/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java @@ -39,8 +39,8 @@ import java.time.LocalDate; import java.time.Month; -import java.util.ArrayList; -import java.util.Random; +import java.util.Iterator; +import java.util.concurrent.ThreadLocalRandom; public class ComponentScreen extends Screen { @@ -52,7 +52,7 @@ public class ComponentScreen extends Screen { protected boolean background = true; private float mouseX, mouseY; - public ArrayList snowflakes = new ArrayList<>(); + private long lastFrameTime = 0; private final long nvg; public ComponentScreen(Component root) { @@ -79,23 +79,26 @@ public Component getRoot() { @Override public void render(int mouseX, int mouseY, float tickDelta) { - if ((VisibleSeasonsMod.instance.visibleSeasonsOverride) || LocalDate.now().getMonth() == Month.DECEMBER) { - Random random = new Random(); - int snowflakeAmount = (int) VisibleSeasonsMod.instance.visibleSeasonsAmount; - for (int i = 0; i < snowflakeAmount; i++) { - if (snowflakes.size() < snowflakeAmount) { - int x = random.nextInt(client.width); - int y = random.nextInt(client.height); - int size = 5 + random.nextInt(6); - int speed = 1 + random.nextInt(3); - - snowflakes.add(new int[]{x, y, size, speed}); + if (VisibleSeasonsMod.instance.visibleSeasonsOverride || LocalDate.now().getMonth() == Month.DECEMBER) { + long currentTime = System.currentTimeMillis(); + if (currentTime - lastFrameTime >= ThreadLocalRandom.current().nextInt(400)) { + if (VisibleSeasonsMod.instance.snowflakes.size() < (int) VisibleSeasonsMod.instance.visibleSeasonsAmount) { + int snowflakeX = ThreadLocalRandom.current().nextInt(client.width); + int snowflakeSize = 5 + ThreadLocalRandom.current().nextInt(6); + int snowflakeSpeed = 1 + ThreadLocalRandom.current().nextInt(3); + VisibleSeasonsMod.instance.snowflakes.add(new int[]{snowflakeX, 0, snowflakeSize, snowflakeSpeed}); + lastFrameTime = currentTime; } + } + - int x = snowflakes.get(i)[0]; - int y = snowflakes.get(i)[1]; - int size = snowflakes.get(i)[2]; - int speed = snowflakes.get(i)[3]; + Iterator iterator = VisibleSeasonsMod.instance.snowflakes.iterator(); + while (iterator.hasNext()) { + int[] snowflake = iterator.next(); + int x = snowflake[0]; + int y = snowflake[1]; + int size = snowflake[2]; + int speed = snowflake[3]; NanoVG.nvgBeginPath(nvg); if (VisibleSeasonsMod.instance.visibleSeasonsLowDetail) { @@ -109,15 +112,11 @@ public void render(int mouseX, int mouseY, float tickDelta) { } // Reset the snowflake if it goes beyond the screen bounds - if (snowflakes.get(i)[1] > client.height) { - x = random.nextInt(client.width); - y = random.nextInt(client.height); - size = 5 + random.nextInt(6); - speed = 1 + random.nextInt(3); + if (y > client.height) { + iterator.remove(); + } else { + snowflake[1] = y + speed; } - - - snowflakes.set(i, new int[]{x, y + speed, size, snowflakes.get(i)[3]}); } } From cc2e6f259491e9a740723bb22637aada0e25d115 Mon Sep 17 00:00:00 2001 From: Ari k <75741608+ArikSquad@users.noreply.github.com> Date: Sat, 3 Jun 2023 19:15:41 +0300 Subject: [PATCH 6/7] it's raining features --- .../mod/impl/visibleseasons/Snowflake.java | 36 +++++++++++++++++++ .../VisibleSeasonsMod.java | 8 +++-- .../client/ui/component/ComponentScreen.java | 20 +++++------ .../client/ui/screen/mods/SnakeScreen.java | 2 +- .../assets/sol_client/lang/en_US.lang | 2 +- .../assets/sol_client/lang/fi_FI.lang | 2 +- src/main/resources/standard-mods.json | 2 +- 7 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java rename src/main/java/io/github/solclient/client/mod/impl/{ => visibleseasons}/VisibleSeasonsMod.java (87%) diff --git a/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java b/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java new file mode 100644 index 00000000..eed5fe78 --- /dev/null +++ b/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java @@ -0,0 +1,36 @@ +/* + * Sol Client - an open source Minecraft client + * Copyright (C) 2021-2023 TheKodeToad and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package io.github.solclient.client.mod.impl.visibleseasons; + +import lombok.Data; + +@Data +public class Snowflake { + private int x; + private int y; + private int size; + private int speed; + + public Snowflake(int x, int y, int size, int speed) { + this.x = x; + this.y = y; + this.size = size; + this.speed = speed; + } +} diff --git a/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java b/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/VisibleSeasonsMod.java similarity index 87% rename from src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java rename to src/main/java/io/github/solclient/client/mod/impl/visibleseasons/VisibleSeasonsMod.java index a467c001..7eb8f48f 100644 --- a/src/main/java/io/github/solclient/client/mod/impl/VisibleSeasonsMod.java +++ b/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/VisibleSeasonsMod.java @@ -16,24 +16,26 @@ * along with this program. If not, see . */ -package io.github.solclient.client.mod.impl; +package io.github.solclient.client.mod.impl.visibleseasons; import com.google.gson.annotations.Expose; +import io.github.solclient.client.mod.impl.StandardMod; import io.github.solclient.client.mod.option.annotation.Option; import io.github.solclient.client.mod.option.annotation.Slider; import net.minecraft.client.MinecraftClient; import net.minecraft.client.resource.language.I18n; import java.util.ArrayList; +import java.util.List; public class VisibleSeasonsMod extends StandardMod { public static VisibleSeasonsMod instance; protected final MinecraftClient mc = MinecraftClient.getInstance(); - public ArrayList snowflakes = new ArrayList<>(); + public List snowflakes = new ArrayList<>(); @Expose @Option - public boolean visibleSeasonsOverride; + public boolean forceVisibleSeasons; @Expose @Option diff --git a/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java b/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java index ce3ea709..2d8ae765 100644 --- a/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java +++ b/src/main/java/io/github/solclient/client/ui/component/ComponentScreen.java @@ -18,7 +18,8 @@ package io.github.solclient.client.ui.component; -import io.github.solclient.client.mod.impl.VisibleSeasonsMod; +import io.github.solclient.client.mod.impl.visibleseasons.Snowflake; +import io.github.solclient.client.mod.impl.visibleseasons.VisibleSeasonsMod; import io.github.solclient.client.ui.component.controller.ParentBoundsController; import io.github.solclient.client.util.MinecraftUtils; import io.github.solclient.client.util.NanoVGManager; @@ -79,26 +80,25 @@ public Component getRoot() { @Override public void render(int mouseX, int mouseY, float tickDelta) { - if (VisibleSeasonsMod.instance.visibleSeasonsOverride || LocalDate.now().getMonth() == Month.DECEMBER) { + if (VisibleSeasonsMod.instance.forceVisibleSeasons || LocalDate.now().getMonth() == Month.DECEMBER) { long currentTime = System.currentTimeMillis(); if (currentTime - lastFrameTime >= ThreadLocalRandom.current().nextInt(400)) { if (VisibleSeasonsMod.instance.snowflakes.size() < (int) VisibleSeasonsMod.instance.visibleSeasonsAmount) { int snowflakeX = ThreadLocalRandom.current().nextInt(client.width); int snowflakeSize = 5 + ThreadLocalRandom.current().nextInt(6); int snowflakeSpeed = 1 + ThreadLocalRandom.current().nextInt(3); - VisibleSeasonsMod.instance.snowflakes.add(new int[]{snowflakeX, 0, snowflakeSize, snowflakeSpeed}); + VisibleSeasonsMod.instance.snowflakes.add(new Snowflake(snowflakeX, 0, snowflakeSize, snowflakeSpeed)); lastFrameTime = currentTime; } } - Iterator iterator = VisibleSeasonsMod.instance.snowflakes.iterator(); + Iterator iterator = VisibleSeasonsMod.instance.snowflakes.iterator(); while (iterator.hasNext()) { - int[] snowflake = iterator.next(); - int x = snowflake[0]; - int y = snowflake[1]; - int size = snowflake[2]; - int speed = snowflake[3]; + Snowflake snowflake = iterator.next(); + int x = snowflake.getX(); + int y = snowflake.getY(); + int size = snowflake.getSize(); NanoVG.nvgBeginPath(nvg); if (VisibleSeasonsMod.instance.visibleSeasonsLowDetail) { @@ -115,7 +115,7 @@ public void render(int mouseX, int mouseY, float tickDelta) { if (y > client.height) { iterator.remove(); } else { - snowflake[1] = y + speed; + snowflake.setY(y + snowflake.getSpeed()); } } } diff --git a/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java b/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java index 08665081..25fd0eb2 100644 --- a/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java +++ b/src/main/java/io/github/solclient/client/ui/screen/mods/SnakeScreen.java @@ -19,7 +19,7 @@ package io.github.solclient.client.ui.screen.mods; import io.github.solclient.client.SolClient; -import io.github.solclient.client.mod.impl.VisibleSeasonsMod; +import io.github.solclient.client.mod.impl.visibleseasons.VisibleSeasonsMod; import io.github.solclient.client.mod.impl.core.CoreMod; import io.github.solclient.client.ui.ScreenAnimation; import io.github.solclient.client.ui.component.Component; diff --git a/src/main/resources/assets/sol_client/lang/en_US.lang b/src/main/resources/assets/sol_client/lang/en_US.lang index 175419b4..a410612c 100644 --- a/src/main/resources/assets/sol_client/lang/en_US.lang +++ b/src/main/resources/assets/sol_client/lang/en_US.lang @@ -429,7 +429,7 @@ sol_client.mod.chat_hotkeys.description=Bind commands and messages to keys. sol_client.mod.visible_seasons.name=Visible Seasons sol_client.mod.visible_seasons.description=Render season decorations in the module menu. -sol_client.mod.visible_seasons.option.visibleSeasonsOverride=Force season decorations +sol_client.mod.visible_seasons.option.forceVisibleSeasons=Force season decorations sol_client.mod.visible_seasons.option.visibleSeasonsAmount=Amount of decorations sol_client.mod.visible_seasons.option.visibleSeasonsLowDetail=Low detail mode diff --git a/src/main/resources/assets/sol_client/lang/fi_FI.lang b/src/main/resources/assets/sol_client/lang/fi_FI.lang index 3a7908f9..7068fb04 100644 --- a/src/main/resources/assets/sol_client/lang/fi_FI.lang +++ b/src/main/resources/assets/sol_client/lang/fi_FI.lang @@ -497,6 +497,6 @@ sol_client.slider.pixels=%spx sol_client.mod.visible_seasons.name=Näkyvät vuodenajat sol_client.mod.visible_seasons.description=Näytä vuodenaikaan liittyvät koristeet moduulivalikossa. -sol_client.mod.visible_seasons.option.visibleSeasonsOverride=Ohita vuodenaika koristeet +sol_client.mod.visible_seasons.option.forceVisibleSeasons=Pakota vuodenaika koristeet sol_client.mod.visible_seasons.option.visibleSeasonsAmount=Koristeiden määrä sol_client.mod.visible_seasons.option.visibleSeasonsLowDetail=Alhainen yksityiskohtaisuus diff --git a/src/main/resources/standard-mods.json b/src/main/resources/standard-mods.json index cf221169..fff0029c 100644 --- a/src/main/resources/standard-mods.json +++ b/src/main/resources/standard-mods.json @@ -257,7 +257,7 @@ }, { "id": "visible_seasons", - "main": "VisibleSeasonsMod", + "main": "visibleseasons.VisibleSeasonsMod", "category": "hidden", "forcedOn": true }, From 230936b92cefafbb0829d507be7b4d09567f9c26 Mon Sep 17 00:00:00 2001 From: Ari k <75741608+ArikSquad@users.noreply.github.com> Date: Sat, 3 Jun 2023 19:19:24 +0300 Subject: [PATCH 7/7] cool AllArgsConstructor --- .../client/mod/impl/visibleseasons/Snowflake.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java b/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java index eed5fe78..7c486c92 100644 --- a/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java +++ b/src/main/java/io/github/solclient/client/mod/impl/visibleseasons/Snowflake.java @@ -18,19 +18,14 @@ package io.github.solclient.client.mod.impl.visibleseasons; +import lombok.AllArgsConstructor; import lombok.Data; @Data +@AllArgsConstructor public class Snowflake { private int x; private int y; private int size; private int speed; - - public Snowflake(int x, int y, int size, int speed) { - this.x = x; - this.y = y; - this.size = size; - this.speed = speed; - } }