From abef647bebeaf5e5a893cd7b530f7c22c9c82391 Mon Sep 17 00:00:00 2001 From: 0x3C50 Date: Wed, 6 Apr 2022 00:11:00 +0200 Subject: [PATCH] i put the bezier --- .../client/feature/gui/screen/HomeScreen.java | 4 +- .../feature/gui/screen/StatsScreen.java | 86 +++++++++++++++++++ .../client/feature/gui/screen/TestScreen.java | 19 ++-- .../java/net/shadow/client/helper/Timer.java | 4 + .../shadow/client/helper/render/Renderer.java | 43 ++++++++++ .../shadow/client/mixin/GameMenuMixin.java | 4 +- 6 files changed, 149 insertions(+), 11 deletions(-) create mode 100644 src/main/java/net/shadow/client/feature/gui/screen/StatsScreen.java diff --git a/src/main/java/net/shadow/client/feature/gui/screen/HomeScreen.java b/src/main/java/net/shadow/client/feature/gui/screen/HomeScreen.java index 5fdacab..fa8ac3b 100644 --- a/src/main/java/net/shadow/client/feature/gui/screen/HomeScreen.java +++ b/src/main/java/net/shadow/client/feature/gui/screen/HomeScreen.java @@ -119,8 +119,8 @@ public class HomeScreen extends ClientScreen implements FastTickable { buttonsMap.add(new AbstractMap.SimpleEntry<>("Multiplayer", () -> ShadowMain.client.setScreen(new MultiplayerScreen(this)))); buttonsMap.add(new AbstractMap.SimpleEntry<>("Realms", () -> ShadowMain.client.setScreen(new RealmsMainScreen(this)))); buttonsMap.add(new AbstractMap.SimpleEntry<>("Alts", () -> ShadowMain.client.setScreen( - AltManagerScreen.instance() -// new AddonManagerScreen() +// AltManagerScreen.instance() + new TestScreen() ))); buttonsMap.add(new AbstractMap.SimpleEntry<>("Settings", () -> ShadowMain.client.setScreen(new OptionsScreen(this, ShadowMain.client.options)))); widgetsHeight = buttonsMap.size() * (widgetHeight + widPad) - widPad; diff --git a/src/main/java/net/shadow/client/feature/gui/screen/StatsScreen.java b/src/main/java/net/shadow/client/feature/gui/screen/StatsScreen.java new file mode 100644 index 0000000..eec0f0a --- /dev/null +++ b/src/main/java/net/shadow/client/feature/gui/screen/StatsScreen.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved. + */ + +package net.shadow.client.feature.gui.screen; + +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Util; +import net.minecraft.util.math.Vec2f; +import net.shadow.client.ShadowMain; +import net.shadow.client.feature.gui.FastTickable; +import net.shadow.client.helper.Timer; +import net.shadow.client.helper.render.Renderer; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; + +public class StatsScreen extends ClientScreen implements FastTickable { + static List packetIn = Util.make(() -> { + List f = new ArrayList<>(); + for(int i = 0;i<100;i++) f.add(0f); + return f; + }); + static List packetOut = Util.make(() -> { + List f = new ArrayList<>(); + for(int i = 0;i<100;i++) f.add(0f); + return f; + }); + Timer packetUpdater = new Timer(); + + @Override + public void onFastTick() { + if (packetUpdater.hasExpired(500)) { + packetUpdater.reset(); + float in = ShadowMain.client.getNetworkHandler().getConnection().getAveragePacketsReceived(); + packetIn.add(in); + float out = ShadowMain.client.getNetworkHandler().getConnection().getAveragePacketsSent(); + packetOut.add(out); + while(packetIn.size() > 100) { + packetIn.remove(0); + } + while(packetOut.size() > 100) packetOut.remove(0); + } + } + + @Override + public void renderInternal(MatrixStack stack, int mouseX, int mouseY, float delta) { + renderBackground(stack); + double contentWidth = width; + + List bezPositions = new ArrayList<>(); + List pIn = new ArrayList<>(StatsScreen.packetIn); + List pOut = new ArrayList<>(StatsScreen.packetOut); + pIn.removeIf(Objects::isNull); + float highest = Math.max(pIn.stream().max(Comparator.comparingDouble(value -> (double) value)).orElse(0f), + pOut.stream().max(Comparator.comparingDouble(value -> (double) value)).orElse(0f)); + double maxHeight = 300; + float scaleFactor = (float) Math.min(1,maxHeight/highest); + for (int i = 0; i < pIn.size(); i++) { + double prog = (i)/(double)(pIn.size()-3); + float x = (float) (prog*contentWidth-((System.currentTimeMillis()-packetUpdater.getLastReset())/500f*(1f/(pIn.size()-1)*contentWidth))); + float y = (float) height-pIn.get(i)*scaleFactor; + Vec2f a = new Vec2f(x,y); + bezPositions.add(a); + } + Renderer.R2D.renderBezierCurve(stack,bezPositions.toArray(new Vec2f[0]), 1f,1f,0f,1f,0.01f); + bezPositions.clear(); + for (int i = 0; i < pOut.size(); i++) { + double prog = (i)/(double)(pOut.size()-3); + float x = (float) (prog*contentWidth-((System.currentTimeMillis()-packetUpdater.getLastReset())/500f*(1f/(pOut.size()-1)*contentWidth))); + float y = (float) height-pOut.get(i)*scaleFactor; + Vec2f a = new Vec2f(x,y); + bezPositions.add(a); + } + Renderer.R2D.renderBezierCurve(stack,bezPositions.toArray(new Vec2f[0]), 0f,1f,1f,1f,0.01f); + + super.renderInternal(stack, mouseX, mouseY, delta); + } + + @Override + public boolean shouldPause() { + return false; + } +} diff --git a/src/main/java/net/shadow/client/feature/gui/screen/TestScreen.java b/src/main/java/net/shadow/client/feature/gui/screen/TestScreen.java index ea76e55..0f0c370 100644 --- a/src/main/java/net/shadow/client/feature/gui/screen/TestScreen.java +++ b/src/main/java/net/shadow/client/feature/gui/screen/TestScreen.java @@ -5,27 +5,30 @@ package net.shadow.client.feature.gui.screen; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.math.Vec2f; import net.shadow.client.helper.GifPlayer; +import net.shadow.client.helper.render.Renderer; import java.io.File; public class TestScreen extends ClientScreen { - private static final GifPlayer gp = GifPlayer.createFromFile(new File("/home/x150/Downloads/img.gif"), 30); - - public TestScreen() { - - } - @Override protected void init() { - gp.setGifFile(new File("/home/x150/Downloads/img.gif")); super.init(); } @Override public void renderInternal(MatrixStack stack, int mouseX, int mouseY, float delta) { renderBackground(stack); - gp.renderFrame(stack, 10, 10, 300, 300); + Vec2f[] points = new Vec2f[] { + new Vec2f(0,0), + new Vec2f(100,100), + new Vec2f(mouseX,mouseY), + new Vec2f(500,300), + new Vec2f(200,200), + new Vec2f(600,200) + }; + Renderer.R2D.renderBezierCurve(stack,points,1f,1f,1f,1f,0.01f); super.renderInternal(stack, mouseX, mouseY, delta); } diff --git a/src/main/java/net/shadow/client/helper/Timer.java b/src/main/java/net/shadow/client/helper/Timer.java index e3d6c75..4fd75ce 100644 --- a/src/main/java/net/shadow/client/helper/Timer.java +++ b/src/main/java/net/shadow/client/helper/Timer.java @@ -18,4 +18,8 @@ public class Timer { public boolean hasExpired(long timeout) { return System.currentTimeMillis() - lastReset > timeout; } + + public long getLastReset() { + return lastReset; + } } diff --git a/src/main/java/net/shadow/client/helper/render/Renderer.java b/src/main/java/net/shadow/client/helper/render/Renderer.java index 778f569..b462763 100644 --- a/src/main/java/net/shadow/client/helper/render/Renderer.java +++ b/src/main/java/net/shadow/client/helper/render/Renderer.java @@ -518,6 +518,49 @@ public class Renderer { renderTexturedQuad(matrices.peek() .getPositionMatrix(), x0, x1, y0, y1, z, (u + 0.0F) / (float) textureWidth, (u + (float) regionWidth) / (float) textureWidth, (v + 0.0F) / (float) textureHeight, (v + (float) regionHeight) / (float) textureHeight); } + static Vec2f lerp(Vec2f p1, Vec2f p2, float delta) { + float x = MathHelper.lerp(delta,p1.x,p2.x); + float y = MathHelper.lerp(delta,p1.y,p2.y); + return new Vec2f(x,y); + } + static Vec2f getMultiBezPoint(Vec2f[] vertecies, float delta) { + List verts = new ArrayList<>(List.of(vertecies)); + while(verts.size() > 1) { + for(int i = 0;i { assert client != null; - client.setScreen(new AddonManagerScreen()); +// client.setScreen(new AddonManagerScreen()); + client.setScreen(new StatsScreen()); })); } }