diff --git a/.gitignore b/.gitignore index ca7acaf..60fbfa6 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ bin run .skidfuscator +.idea diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 359bb53..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# 默认忽略的文件 -/shelf/ -/workspace.xml diff --git a/.idea/MarsCodeWorkspaceAppSettings.xml b/.idea/MarsCodeWorkspaceAppSettings.xml deleted file mode 100644 index d4a52f0..0000000 --- a/.idea/MarsCodeWorkspaceAppSettings.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index b86273d..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 8b8d44e..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 7d3b3e8..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index e754f00..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 4cc5492..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/migrateChatHistory.xml b/.idea/migrateChatHistory.xml deleted file mode 100644 index 94b2914..0000000 --- a/.idea/migrateChatHistory.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 61b50dc..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index a02bf5b..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/SoarClient-CN.iml b/.idea/modules/SoarClient-CN.iml deleted file mode 100644 index 2c92d42..0000000 --- a/.idea/modules/SoarClient-CN.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/SoarClient-CN.main.iml b/.idea/modules/SoarClient-CN.main.iml deleted file mode 100644 index 750b879..0000000 --- a/.idea/modules/SoarClient-CN.main.iml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - FABRIC - MIXIN - MCP - - 1 - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/SoarClient-CN.test.iml b/.idea/modules/SoarClient-CN.test.iml deleted file mode 100644 index 0fee84f..0000000 --- a/.idea/modules/SoarClient-CN.test.iml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - FABRIC - MIXIN - MCP - - 1 - - - - - - \ No newline at end of file diff --git a/.idea/modules/cn.pupperclient.SoarClient-CN.main.iml b/.idea/modules/cn.pupperclient.SoarClient-CN.main.iml deleted file mode 100644 index 0fee84f..0000000 --- a/.idea/modules/cn.pupperclient.SoarClient-CN.main.iml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - FABRIC - MIXIN - MCP - - 1 - - - - - - \ No newline at end of file diff --git a/.idea/modules/cn.pupperclient.SoarClient-CN.test.iml b/.idea/modules/cn.pupperclient.SoarClient-CN.test.iml deleted file mode 100644 index 0fee84f..0000000 --- a/.idea/modules/cn.pupperclient.SoarClient-CN.test.iml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - FABRIC - MIXIN - MCP - - 1 - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Minecraft_Client.xml b/.idea/runConfigurations/Minecraft_Client.xml deleted file mode 100644 index d5eb21a..0000000 --- a/.idea/runConfigurations/Minecraft_Client.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Minecraft_Server.xml b/.idea/runConfigurations/Minecraft_Server.xml deleted file mode 100644 index c3a8521..0000000 --- a/.idea/runConfigurations/Minecraft_Server.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index 355267f..3d6815b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.14-SNAPSHOT' + id 'fabric-loom' version "1.14-SNAPSHOT" } project.ext.lwjglVersion = "3.3.3" @@ -35,18 +35,18 @@ dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - modImplementation "com.viaversion:viafabricplus-api:4.0.2" - modRuntimeOnly "maven.modrinth:sodium:mc1.21.4-0.6.6-fabric" - modRuntimeOnly "maven.modrinth:iris:1.8.5+1.21.4-fabric" - modRuntimeOnly "maven.modrinth:sodium-extra:mc1.21.4-0.6.1+fabric" - modRuntimeOnly "maven.modrinth:lithium:mc1.21.4-0.14.7-fabric" - modImplementation "maven.modrinth:in-game-account-switcher:WBbjirJP" - modImplementation "com.viaversion:viafabricplus:4.0.2" - modRuntimeOnly "maven.modrinth:immediatelyfast:1.3.3+1.21.4-fabric" - modRuntimeOnly "maven.modrinth:entityculling:NkBXk0Ye" - modImplementation "maven.modrinth:modmenu:13.0.3" + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" + + modImplementation "com.viaversion:viafabricplus-api:4.1.5" + modRuntimeOnly "maven.modrinth:sodium:mc1.21.5-0.6.13-fabric" + modRuntimeOnly "maven.modrinth:iris:1.8.11+1.21.5-fabric" + modRuntimeOnly "maven.modrinth:sodium-extra:mc1.21.5-0.6.3+fabric" + modRuntimeOnly "maven.modrinth:lithium:mc1.21.5-0.16.3-fabric" + modImplementation "maven.modrinth:in-game-account-switcher:Rqmwlwr6" + modImplementation "com.viaversion:viafabricplus:4.1.5" + modRuntimeOnly "maven.modrinth:immediatelyfast:1.9.7+1.21.5-fabric" + // modRuntimeOnly "maven.modrinth:entityculling:ldvBBWG2" + modImplementation "maven.modrinth:modmenu:14.0.0" jij 'io.github.smartboot.socket:aio-core:1.7.1' jij 'com.github.ben-manes.caffeine:caffeine:3.1.8' @@ -64,10 +64,10 @@ dependencies { jij 'com.googlecode.soundlibs:jlayer:1.0.1.4' jij "net.lenni0451:MCPing:1.4.2" jij "net.lenni0451:Reflect:1.4.0" - modImplementation 'net.java.dev.jna:jna:5.12.1' - modImplementation 'net.java.dev.jna:jna-platform:5.12.1' + modImplementation 'net.java.dev.jna:jna:5.18.1' + modImplementation 'net.java.dev.jna:jna-platform:5.18.1' - modJij 'com.github.CCBlueX:mcef:3.0.0-1.21.4' + modJij 'com.github.CCBlueX:mcef:3.1.3-1.21.5' def lwjglNfdDeps = [ "org.lwjgl:lwjgl-nfd:$lwjglVersion", diff --git a/gradle.properties b/gradle.properties index a842401..28c9d88 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,15 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.4 -yarn_mappings=1.21.4+build.8 -loader_version=0.18.2 +minecraft_version=1.21.5 +yarn_mappings=1.21.5+build.1 +loader_version=0.18.4 + +# Fabric API +fabric_api_version=0.128.2+1.21.5 # Mod Properties -mod_version=25.12.3 +mod_version=26.1.1 maven_group=cn.pupperclient archives_base_name=pupper -# Dependencies -fabric_version=0.119.4+1.21.4 diff --git a/src/main/java/cn/pupperclient/PupperClient.java b/src/main/java/cn/pupperclient/PupperClient.java index 36f9ef7..7215137 100644 --- a/src/main/java/cn/pupperclient/PupperClient.java +++ b/src/main/java/cn/pupperclient/PupperClient.java @@ -26,6 +26,7 @@ import com.viaversion.viafabricplus.api.ViaFabricPlusBase; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.util.Identifier; import org.apache.logging.log4j.Logger; import java.io.IOException; @@ -37,7 +38,7 @@ public class PupperClient implements IMinecraft { private static final String CONFIG_FILE_NAME = "pupper.ok"; private static final String ICON_PATH = "assets/pupper/logo.png"; private static final String CLIENT_NAME = "Pupper Client"; - private static final String CLIENT_VERSION = "25.12.3"; + private static final String CLIENT_VERSION = "26.1.1"; private static final PupperClient INSTANCE = new PupperClient(); @@ -240,4 +241,8 @@ public enum MusicToolStatus { FAILED, DONE } + + public static Identifier identifier(String path) { + return Identifier.of("pupper", path); + } } diff --git a/src/main/java/cn/pupperclient/PupperLogger.java b/src/main/java/cn/pupperclient/PupperLogger.java index 05cd4e5..8d0479e 100644 --- a/src/main/java/cn/pupperclient/PupperLogger.java +++ b/src/main/java/cn/pupperclient/PupperLogger.java @@ -8,19 +8,19 @@ public class PupperLogger { private static final Logger logger = LogManager.getLogger("PupperClient Client"); public static void info(String prefix, String message) { - logger.info("[SC/INFO] [" + prefix + "] " + message); + logger.info("[PupperClient/INFO] [{}] {}", prefix, message); } public static void warn(String prefix, String message) { - logger.warn("[SC/WARN] [" + prefix + "] " + message); + logger.warn("[PupperClient/WARN] [{}] {}", prefix, message); } public static void error(String prefix, String message) { - logger.error("[SC/ERROR] [" + prefix + "] " + message); + logger.error("[PupperClient/ERROR] [{}] {}", prefix, message); } public static void error(String prefix, String message, Exception e) { - logger.error("[SC/ERROR] [" + prefix + "] " + message, e); + logger.error("[PupperClient/ERROR] [{}] {}", prefix, message, e); } public static Logger getLogger() { diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/SimpleSoarGui.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/SimpleSoarGui.java deleted file mode 100644 index 92ecb06..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/SimpleSoarGui.java +++ /dev/null @@ -1,113 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api; - -import cn.pupperclient.skia.Skia; -import cn.pupperclient.skia.context.SkiaContext; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; - -public class SimpleSoarGui { - public MinecraftClient client = MinecraftClient.getInstance(); - private final boolean mcScale; - - public SimpleSoarGui(boolean mcScale) { - this.mcScale = mcScale; - } - - public void init() { - } - - public void draw(double mouseX, double mouseY) { - } - - public void mousePressed(double mouseX, double mouseY, int button) { - } - - public void mouseReleased(double mouseX, double mouseY, int button) { - } - - public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - } - - public void charTyped(char chr, int modifiers) { - } - - public void keyPressed(int keyCode, int scanCode, int modifiers) { - } - - public Screen build() { - return new Screen(Text.empty()) { - - @Override - public void init() { - SimpleSoarGui.this.init(); - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - - SkiaContext.draw((skiaContext) -> { - - Skia.save(); - - if (mcScale) { - if (client != null) { - Skia.scale((float) client.getWindow().getScaleFactor()); - } - } - - if (client != null) { - SimpleSoarGui.this.draw(mcScale ? mouseX : client.mouse.getX(), - mcScale ? mouseY : client.mouse.getY()); - } - Skia.restore(); - }); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (client != null) { - SimpleSoarGui.this.mousePressed(mcScale ? mouseX : client.mouse.getX(), - mcScale ? mouseY : client.mouse.getY(), button); - } - return true; - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - if (client != null) { - SimpleSoarGui.this.mouseReleased(mcScale ? mouseX : client.mouse.getX(), - mcScale ? mouseY : (int) client.mouse.getY(), button); - } - return true; - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - if (client != null) { - SimpleSoarGui.this.mouseScrolled(mcScale ? mouseX : client.mouse.getX(), - mcScale ? mouseY : (int) client.mouse.getY(), horizontalAmount, verticalAmount); - } - return true; - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - SimpleSoarGui.this.keyPressed(keyCode, scanCode, modifiers); - return true; - } - - @Override - public boolean charTyped(char chr, int modifiers) { - SimpleSoarGui.this.charTyped(chr, modifiers); - return true; - } - - @Override - public boolean shouldPause() { - return false; - } - }; - } -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/SoarGui.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/SoarGui.java deleted file mode 100644 index 9781682..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/SoarGui.java +++ /dev/null @@ -1,264 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api; - -import cn.pupperclient.PupperClient; -import cn.pupperclient.animation.Animation; -import cn.pupperclient.animation.Duration; -import cn.pupperclient.animation.cubicbezier.impl.EaseEmphasizedDecelerate; -import cn.pupperclient.gui.api.page.impl.api.page.GuiTransition; -import cn.pupperclient.gui.api.page.impl.api.page.SimplePage; -import cn.pupperclient.management.color.api.ColorPalette; -import cn.pupperclient.management.config.ConfigType; -import cn.pupperclient.management.mod.impl.settings.ModMenuSettings; -import cn.pupperclient.shader.impl.Kawaseblur; -import cn.pupperclient.skia.Skia; -import cn.pupperclient.ui.component.Component; -import cn.pupperclient.utils.Multithreading; -import io.github.humbleui.skija.SurfaceOrigin; -import net.minecraft.client.gui.screen.Screen; -import org.lwjgl.glfw.GLFW; - -import java.util.ArrayList; -import java.util.List; - -public abstract class SoarGui extends SimpleSoarGui { - - protected List components = new ArrayList<>(); - protected List pages; - - protected SimplePage currentPage; - protected SimplePage lastPage; - - private Animation inOutAnimation; - private boolean closable; - private Screen nextScreen; - - public SoarGui(boolean mcScale) { - super(mcScale); - - this.pages = createPages(); - - if (!pages.isEmpty()) { - this.currentPage = pages.getFirst(); - } - } - - @Override - public void init() { - setPageSize(currentPage); - inOutAnimation = new EaseEmphasizedDecelerate(Duration.EXTRA_LONG_1, 0, 1); - closable = true; - currentPage.init(); - } - - public void setPageSize(SimplePage p) { - p.setX(getX()); - p.setY(getY()); - p.setWidth(getWidth()); - p.setHeight(getHeight()); - } - - @Override - public void draw(double mouseX, double mouseY) { - - ColorPalette palette = PupperClient.getInstance().getColorManager().getPalette(); - - if (ModMenuSettings.getInstance().getBlurSetting().isEnabled()) { - Skia.drawImage(Kawaseblur.GUI_BLUR.getTexture(), 0, 0, client.getWindow().getWidth(), - client.getWindow().getHeight(), inOutAnimation.getValue(), SurfaceOrigin.BOTTOM_LEFT); - } - - Skia.save(); - Skia.setAlpha((int) (inOutAnimation.getValue() * 255)); - Skia.scale(getX(), getY(), getWidth(), getHeight(), 2 - inOutAnimation.getValue()); - - Skia.clip(getX(), getY(), getWidth(), getHeight(), 35); - Skia.drawRoundedRect(getX(), getY(), getWidth(), getHeight(), 35, palette.getSurfaceContainer()); - - if (currentPage != null && lastPage == null) { - currentPage.draw(mouseX, mouseY); - } - - if (lastPage != null) { - - GuiTransition transition = lastPage.getTransition(); - - if (currentPage.getTransition().isConsecutive()) { - - Skia.save(); - - if (transition != null) { - float[] result = transition.onTransition(lastPage.getAnimation()); - Skia.translate(result[0] * getWidth(), result[1] * getHeight()); - } - - lastPage.draw(mouseX, mouseY); - Skia.restore(); - } - - Skia.save(); - transition = currentPage.getTransition(); - - if (transition != null) { - float[] result = transition.onTransition(currentPage.getAnimation()); - Skia.translate(result[0] * getWidth(), result[1] * getHeight()); - } - - currentPage.draw(mouseX, mouseY); - Skia.restore(); - - if (lastPage.getAnimation().isFinished()) { - lastPage = null; - } - } - - for (Component c : components) { - c.draw(mouseX, mouseY); - } - - Skia.restore(); - - if (inOutAnimation.getEnd() == 0 && inOutAnimation.isFinished()) { - client.setScreen(nextScreen); - nextScreen = null; - } - } - - @Override - public void mousePressed(double mouseX, double mouseY, int button) { - - if (currentPage != null) { - currentPage.mousePressed(mouseX, mouseY, button); - } - - for (Component c : components) { - c.mousePressed(mouseX, mouseY, button); - } - } - - @Override - public void mouseReleased(double mouseX, double mouseY, int button) { - - if (currentPage != null) { - currentPage.mouseReleased(mouseX, mouseY, button); - } - - for (Component c : components) { - c.mouseReleased(mouseX, mouseY, button); - } - } - - @Override - public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - if (currentPage != null) { - currentPage.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); - } - } - - @Override - public void charTyped(char chr, int modifiers) { - - if (currentPage != null) { - currentPage.charTyped(chr, modifiers); - } - - for (Component c : components) { - c.charTyped(chr, modifiers); - } - } - - @Override - public void keyPressed(int keyCode, int scanCode, int modifiers) { - - if (keyCode == GLFW.GLFW_KEY_ESCAPE && inOutAnimation.getEnd() == 1 && closable) { - close(); - } - - if (currentPage != null) { - currentPage.keyPressed(keyCode, scanCode, modifiers); - } - - for (Component c : components) { - c.keyPressed(keyCode, scanCode, modifiers); - } - } - - public void close(Screen nextScreen) { - if (inOutAnimation.getEnd() == 1) { - this.nextScreen = nextScreen; - inOutAnimation = new EaseEmphasizedDecelerate(Duration.EXTRA_LONG_1, 1, 0); - Multithreading.runAsync(() -> { - PupperClient.getInstance().getConfigManager().save(ConfigType.MOD); - }); - } - } - - public void close() { - close(null); - } - - public SimplePage getCurrentPage() { - return currentPage; - } - - public void setCurrentPage(SimplePage page) { - - if (currentPage != null) { - lastPage = currentPage; - currentPage.onClosed(); - } - - this.currentPage = page; - currentPage.setAnimation(new EaseEmphasizedDecelerate(Duration.MEDIUM_1, 0, 1)); - lastPage.setAnimation(new EaseEmphasizedDecelerate(Duration.MEDIUM_1, 1, 0)); - - if (currentPage != null) { - setPageSize(currentPage); - currentPage.init(); - } - } - - public void setCurrentPage(Class clazz) { - - SimplePage page = getPage(clazz); - - if (page != null) { - setCurrentPage(page); - } - } - - public SimplePage getPage(Class clazz) { - - SimplePage page = null; - - for (SimplePage p : pages) { - if (p.getClass().equals(clazz)) { - page = p; - break; - } - } - - return page; - } - - public List getPages() { - return pages; - } - - public boolean isClosable() { - return closable; - } - - public void setClosable(boolean closable) { - this.closable = closable; - } - - public abstract List createPages(); - - public abstract float getX(); - - public abstract float getY(); - - public abstract float getWidth(); - - public abstract float getHeight(); -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/GuiTransition.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/GuiTransition.java deleted file mode 100644 index f56b2e9..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/GuiTransition.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api.page; - -import cn.pupperclient.animation.Animation; - -public abstract class GuiTransition { - - private final boolean consecutive; - - public GuiTransition(boolean consecutive) { - this.consecutive = consecutive; - } - - public abstract float[] onTransition(Animation animation); - - public boolean isConsecutive() { - return consecutive; - } -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/Page.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/Page.java deleted file mode 100644 index 31fffc0..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/Page.java +++ /dev/null @@ -1,71 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api.page; - -import cn.pupperclient.gui.api.page.impl.api.SoarGui; -import cn.pupperclient.skia.Skia; -import cn.pupperclient.ui.component.impl.text.SearchBar; -import cn.pupperclient.utils.mouse.ScrollHelper; - -public class Page extends SimplePage { - - protected ScrollHelper scrollHelper = new ScrollHelper(); - protected SearchBar searchBar; - - public Page(SoarGui parent, String title, String icon, GuiTransition transition) { - super(parent, title, icon, transition); - } - - @Override - public void init() { - - String text = ""; - - if (searchBar != null) { - text = searchBar.getText(); - } - - searchBar = new SearchBar(x + width - 260 - 32, y + 32, 260, text, () -> { - scrollHelper.reset(); - }); - } - - @Override - public void draw(double mouseX, double mouseY) { - - scrollHelper.onUpdate(); - - Skia.save(); - Skia.translate(0, scrollHelper.getValue()); - - mouseY = (int) (mouseY - scrollHelper.getValue()); - searchBar.draw(mouseX, mouseY); - - Skia.restore(); - } - - @Override - public void mousePressed(double mouseX, double mouseY, int button) { - mouseY = mouseY - scrollHelper.getValue(); - searchBar.mousePressed(mouseX, mouseY, button); - } - - @Override - public void mouseReleased(double mouseX, double mouseY, int button) { - mouseY = mouseY - scrollHelper.getValue(); - searchBar.mouseReleased(mouseX, mouseY, button); - } - - @Override - public void charTyped(char chr, int modifiers) { - searchBar.charTyped(chr, modifiers); - } - - @Override - public void keyPressed(int keyCode, int scanCode, int modifiers) { - searchBar.keyPressed(keyCode, scanCode, modifiers); - } - - @Override - public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - scrollHelper.onScroll(verticalAmount); - } -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/SimplePage.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/SimplePage.java deleted file mode 100644 index b0ce1d6..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/SimplePage.java +++ /dev/null @@ -1,110 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api.page; - -import cn.pupperclient.animation.Animation; -import cn.pupperclient.animation.other.DummyAnimation; -import cn.pupperclient.gui.api.page.impl.api.SoarGui; - -public class SimplePage { - - protected float x, y, width, height; - private String title, icon; - protected SoarGui parent; - private Animation animation; - private GuiTransition transition; - - public SimplePage(SoarGui parent, String title, String icon, GuiTransition transition) { - this.parent = parent; - this.title = title; - this.icon = icon; - this.x = 0; - this.y = 0; - this.width = 0; - this.height = 0; - this.transition = transition; - this.animation = new DummyAnimation(1); - } - - public void init() { - } - - public void draw(double mouseX, double mouseY) { - } - - public void mousePressed(double mouseX, double mouseY, int button) { - } - - public void mouseReleased(double mouseX, double mouseY, int button) { - } - - public void mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - } - - public void charTyped(char chr, int modifiers) { - } - - public void keyPressed(int keyCode, int scanCode, int modifiers) { - } - - public void onClosed() { - } - - 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; - } - - public float getWidth() { - return width; - } - - public void setWidth(float width) { - this.width = width; - } - - public float getHeight() { - return height; - } - - public void setHeight(float height) { - this.height = height; - } - - public String getTitle() { - return title; - } - - public String getIcon() { - return icon; - } - - public GuiTransition getTransition() { - return transition; - } - - public void setTransition(GuiTransition transition) { - this.transition = transition; - } - - public Animation getAnimation() { - return animation; - } - - public void setAnimation(Animation animation) { - this.animation = animation; - } - - public SoarGui getParent() { - return parent; - } -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/LeftRightTransition.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/LeftRightTransition.java deleted file mode 100644 index b082c09..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/LeftRightTransition.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api.page.impl; - -import cn.pupperclient.animation.Animation; -import cn.pupperclient.gui.api.page.impl.api.page.GuiTransition; - -public class LeftRightTransition extends GuiTransition { - - public LeftRightTransition(boolean consecutive) { - super(consecutive); - } - - @Override - public float[] onTransition(Animation animation) { - - float progress = animation.getValue(); - float x = 0; - - if (animation.getEnd() == 1) { - x = -1 + progress; - } else { - x = -1 + progress; - } - - return new float[] { x, 0 }; - } -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/LeftTransition.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/LeftTransition.java deleted file mode 100644 index 8042623..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/LeftTransition.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api.page.impl; - -import cn.pupperclient.animation.Animation; -import cn.pupperclient.gui.api.page.impl.api.page.GuiTransition; - -public class LeftTransition extends GuiTransition { - - public LeftTransition(boolean consecutive) { - super(consecutive); - } - - @Override - public float[] onTransition(Animation animation) { - - float progress = animation.getValue(); - float x = 0; - - if (animation.getEnd() == 1) { - x = -1 + progress; - } else { - x = -1 + progress; - } - - return new float[] { x, 0 }; - } -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/RightLeftTransition.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/RightLeftTransition.java deleted file mode 100644 index 9c3efc7..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/RightLeftTransition.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api.page.impl; - -import cn.pupperclient.animation.Animation; -import cn.pupperclient.gui.api.page.impl.api.page.GuiTransition; - -public class RightLeftTransition extends GuiTransition { - - public RightLeftTransition(boolean consecutive) { - super(consecutive); - } - - @Override - public float[] onTransition(Animation animation) { - - float progress = animation.getValue(); - float x = 0; - - if (animation.getEnd() == 1) { - x = 1 - progress; - } else { - x = -1 + progress; - } - - return new float[] { x, 0 }; - } -} diff --git a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/RightTransition.java b/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/RightTransition.java deleted file mode 100644 index 38d9164..0000000 --- a/src/main/java/cn/pupperclient/gui/api/page/impl/api/page/impl/RightTransition.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.pupperclient.gui.api.page.impl.api.page.impl; - -import cn.pupperclient.animation.Animation; -import cn.pupperclient.gui.api.page.impl.api.page.GuiTransition; - -public class RightTransition extends GuiTransition { - - public RightTransition(boolean consecutive) { - super(consecutive); - } - - @Override - public float[] onTransition(Animation animation) { - - float progress = animation.getValue(); - float x = 0; - - if (animation.getEnd() == 1) { - x = 1 - progress; - } else { - x = 1 + -progress; - } - - return new float[] { x, 0 }; - } -} diff --git a/src/main/java/cn/pupperclient/gui/modmenu/pages/MusicPage.java b/src/main/java/cn/pupperclient/gui/modmenu/pages/MusicPage.java index 91445bd..bd55c4b 100644 --- a/src/main/java/cn/pupperclient/gui/modmenu/pages/MusicPage.java +++ b/src/main/java/cn/pupperclient/gui/modmenu/pages/MusicPage.java @@ -264,12 +264,10 @@ private void refreshMusicList() { isRefreshing = true; - // 在后台线程中刷新音乐列表 new Thread(() -> { try { PupperClient.getInstance().getMusicManager().load(); - // 在主线程中更新UI cn.pupperclient.utils.Multithreading.runMainThread(() -> { this.init(); isRefreshing = false; @@ -324,12 +322,12 @@ private void drawRoundedImage(File file, float x, float y, float width, float he Skia.restore(); } - private class Item { + private static class Item { - private Music music; - private SimpleAnimation xAnimation = new SimpleAnimation(); - private SimpleAnimation yAnimation = new SimpleAnimation(); - private SimpleAnimation focusAnimation = new SimpleAnimation(); + private final Music music; + private final SimpleAnimation xAnimation = new SimpleAnimation(); + private final SimpleAnimation yAnimation = new SimpleAnimation(); + private final SimpleAnimation focusAnimation = new SimpleAnimation(); private Item(Music music) { this.music = music; diff --git a/src/main/java/cn/pupperclient/libraries/browser/JCefBrowser.java b/src/main/java/cn/pupperclient/libraries/browser/JCefBrowser.java index 4756451..7cfe24d 100644 --- a/src/main/java/cn/pupperclient/libraries/browser/JCefBrowser.java +++ b/src/main/java/cn/pupperclient/libraries/browser/JCefBrowser.java @@ -11,6 +11,7 @@ import net.ccbluex.liquidbounce.mcef.MCEFDownloadManager; import net.ccbluex.liquidbounce.mcef.MCEFPlatform; import net.ccbluex.liquidbounce.mcef.cef.MCEFBrowser; +import net.ccbluex.liquidbounce.mcef.cef.MCEFBrowserSettings; public class JCefBrowser { @@ -24,7 +25,7 @@ public static void init() { if(browser == null) { String url = "https://cn.bing.com"; boolean transparent = true; - browser = MCEF.INSTANCE.createBrowser(url, transparent, 60); + browser = MCEF.INSTANCE.createBrowser(url, transparent, null); browser.resize(1280, 720); } } diff --git a/src/main/java/cn/pupperclient/management/auth/AuthManager.java b/src/main/java/cn/pupperclient/management/auth/AuthManager.java deleted file mode 100644 index 2fa18f5..0000000 --- a/src/main/java/cn/pupperclient/management/auth/AuthManager.java +++ /dev/null @@ -1,266 +0,0 @@ -package cn.pupperclient.management.auth; - -import cn.pupperclient.PupperClient; -import cn.pupperclient.utils.file.FileLocation; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardOpenOption; -import java.security.MessageDigest; -import java.util.HashMap; -import java.util.Map; - -public class AuthManager { - private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - private static final String SECRET_KEY = "pupper"; - private static AuthManager instance; - - private Map users = new HashMap<>(); - private UserData currentUser; - - public static AuthManager getInstance() { - if (instance == null) { - instance = new AuthManager(); - } - return instance; - } - - private AuthManager() { - loadUserData(); - } - - public static class UserData { - private String username; - private String passwordHash; - private long createdAt; - private long lastLogin; - - public UserData() {} - - public UserData(String username, String password) { - this.username = username; - this.passwordHash = hashPassword(password); - this.createdAt = System.currentTimeMillis(); - this.lastLogin = System.currentTimeMillis(); - } - - // Getters and Setters - public String getUsername() { return username; } - public void setUsername(String username) { this.username = username; } - public String getPasswordHash() { return passwordHash; } - public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; } - public long getCreatedAt() { return createdAt; } - public void setCreatedAt(long createdAt) { this.createdAt = createdAt; } - public long getLastLogin() { return lastLogin; } - public void setLastLogin(long lastLogin) { this.lastLogin = lastLogin; } - } - - private static String hashPassword(String password) { - try { - String data = password + SECRET_KEY; - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(data.getBytes(StandardCharsets.UTF_8)); - - // 转换为十六进制字符串 - StringBuilder hexString = new StringBuilder(); - for (byte b : hash) { - String hex = Integer.toHexString(0xff & b); - if (hex.length() == 1) hexString.append('0'); - hexString.append(hex); - } - return hexString.toString(); - } catch (Exception e) { - PupperClient.LOGGER.error("Failed to hash password", e); - throw new RuntimeException("Password hashing failed", e); - } - } - - /** - * 加载用户数据 - */ - private void loadUserData() { - try { - File userDataFile = FileLocation.USER_DATA_DIR; - Path userDataPath = userDataFile.toPath(); - - PupperClient.LOGGER.info("Attempting to load user data from: {}", userDataPath); - - // 如果文件不存在,创建空的数据文件 - if (!userDataFile.exists()) { - PupperClient.LOGGER.info("No existing user data found, creating new file"); - users = new HashMap<>(); - - // 确保目录存在 - File parentDir = userDataFile.getParentFile(); - if (parentDir != null && !parentDir.exists()) { - boolean dirsCreated = parentDir.mkdirs(); - if (!dirsCreated) { - PupperClient.LOGGER.warn("Failed to create parent directories: {}", parentDir.getAbsolutePath()); - } - } - - // 创建空文件 - boolean fileCreated = userDataFile.createNewFile(); - if (!fileCreated) { - PupperClient.LOGGER.warn("Failed to create user data file: {}", userDataPath); - } - - saveUserData(); // 保存空的用户数据 - return; - } - - // 检查是否是文件而不是目录 - if (userDataFile.isDirectory()) { - PupperClient.LOGGER.error("User data path is a directory, not a file: {}", userDataPath); - users = new HashMap<>(); - return; - } - - // 读取并解析用户数据 - String json = new String(Files.readAllBytes(userDataPath)); - if (json.trim().isEmpty()) { - users = new HashMap<>(); - PupperClient.LOGGER.info("User data file is empty, starting fresh"); - } else { - java.lang.reflect.Type type = new TypeToken>(){}.getType(); - users = GSON.fromJson(json, type); - - if (users == null) { - users = new HashMap<>(); - } - - PupperClient.LOGGER.info("Loaded {} users from disk", users.size()); - } - } catch (Exception e) { - PupperClient.LOGGER.error("Failed to load user data from: {}", FileLocation.USER_DATA_DIR.getAbsolutePath(), e); - users = new HashMap<>(); - } - } - - private void saveUserData() { - try { - File userDataFile = FileLocation.USER_DATA_DIR; - Path userDataPath = userDataFile.toPath(); - - PupperClient.LOGGER.info("Attempting to save user data to: {}", userDataPath); - - File parentDir = userDataFile.getParentFile(); - if (parentDir != null && !parentDir.exists()) { - boolean dirsCreated = parentDir.mkdirs(); - if (!dirsCreated) { - PupperClient.LOGGER.error("Failed to create parent directories: {}", parentDir.getAbsolutePath()); - return; - } - } - - if (userDataFile.isDirectory()) { - PupperClient.LOGGER.error("Cannot save user data: path is a directory: {}", userDataPath); - return; - } - - String json = GSON.toJson(users); - Files.write(userDataPath, json.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); - - PupperClient.LOGGER.info("Successfully saved {} users to disk", users.size()); - } catch (Exception e) { - PupperClient.LOGGER.error("Failed to save user data to: {}", FileLocation.USER_DATA_DIR.getAbsolutePath(), e); - } - } - - public boolean register(String username, String password) { - if (username == null || username.trim().isEmpty() || password == null || password.isEmpty()) { - PupperClient.LOGGER.warn("Registration failed: invalid username or password"); - return false; - } - - username = username.trim(); - - if (users.containsKey(username)) { - PupperClient.LOGGER.warn("Registration failed: user already exists: {}", username); - return false; - } - - UserData userData = new UserData(username, password); - users.put(username, userData); - saveUserData(); - - PupperClient.LOGGER.info("Registered new user: {}", username); - return true; - } - - public boolean login(String username, String password) { - if (username == null || password == null) { - return false; - } - - username = username.trim(); - UserData userData = users.get(username); - - if (userData == null) { - PupperClient.LOGGER.warn("Login failed: user not found: {}", username); - return false; - } - - String inputHash = hashPassword(password); - if (userData.getPasswordHash().equals(inputHash)) { - userData.setLastLogin(System.currentTimeMillis()); - currentUser = userData; - saveUserData(); - - PupperClient.LOGGER.info("User logged in: {}", username); - return true; - } - - PupperClient.LOGGER.warn("Login failed: incorrect password for user: {}", username); - return false; // 密码错误 - } - - public void logout() { - if (currentUser != null) { - PupperClient.LOGGER.info("User logged out: {}", currentUser.getUsername()); - } - currentUser = null; - } - - public boolean isLoggedIn() { - return currentUser != null; - } - - public UserData getCurrentUser() { - return currentUser; - } - - public boolean userExists(String username) { - return users.containsKey(username.trim()); - } - - public boolean deleteUser(String username) { - if (username == null) { - return false; - } - - username = username.trim(); - if (users.remove(username) != null) { - if (currentUser != null && currentUser.getUsername().equals(username)) { - logout(); - } - saveUserData(); - PupperClient.LOGGER.info("Deleted user: {}", username); - return true; - } - return false; - } - - public int getUserCount() { - return users.size(); - } - - public String getUserDataPath() { - return FileLocation.USER_DATA_DIR.getAbsolutePath(); - } -} diff --git a/src/main/java/cn/pupperclient/management/cape/CapeManager.java b/src/main/java/cn/pupperclient/management/cape/CapeManager.java index 17b6c9b..8895f1b 100644 --- a/src/main/java/cn/pupperclient/management/cape/CapeManager.java +++ b/src/main/java/cn/pupperclient/management/cape/CapeManager.java @@ -1,5 +1,6 @@ package cn.pupperclient.management.cape; +import cn.pupperclient.utils.Multithreading; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.texture.NativeImage; @@ -52,15 +53,17 @@ public void loadCape(String id, byte[] textureData) { if (id == null || textureData == null) return; executorService.submit(() -> { - RenderSystem.recordRenderCall(() -> { - NativeImageBackedTexture nativeImage = createNativeTexture(textureData); - if (nativeImage != null) { - Identifier identifier = Identifier.of("pupper", namespace + "/" + id); - MinecraftClient.getInstance().getTextureManager().registerTexture(identifier, nativeImage); - loadedCapes.put(id, identifier); - loadedCapeTextures.put(identifier, nativeImage); - } - }); + NativeImageBackedTexture nativeImage = createNativeTexture(textureData); + if (nativeImage != null) { + Multithreading.runMainThread( + () -> { + Identifier identifier = Identifier.of("pupper", namespace + "/" + id); + MinecraftClient.getInstance().getTextureManager().registerTexture(identifier, nativeImage); + loadedCapes.put(id, identifier); + loadedCapeTextures.put(identifier, nativeImage); + } + ); + } }); } @@ -92,7 +95,7 @@ public Set getLoadedCapeIds() { private static NativeImageBackedTexture createNativeTexture(byte[] bytes) { if (bytes == null) return null; try { - return new NativeImageBackedTexture(NativeImage.read(bytes)); + return new NativeImageBackedTexture(() -> "Native_Texture",NativeImage.read(bytes)); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/cn/pupperclient/management/cape/CapeRenderer.java b/src/main/java/cn/pupperclient/management/cape/CapeRenderer.java index 1fc227d..6454108 100644 --- a/src/main/java/cn/pupperclient/management/cape/CapeRenderer.java +++ b/src/main/java/cn/pupperclient/management/cape/CapeRenderer.java @@ -9,17 +9,19 @@ import io.github.humbleui.types.RRect; import io.github.humbleui.types.Rect; +import java.util.Objects; + public class CapeRenderer { public static void renderCapePreview(Identifier capeTexture, float x, float y, float width, float height) { if (capeTexture == null) return; try { - int textureId = MinecraftClient.getInstance().getTextureManager().getTexture(capeTexture).getGlId(); + var textureId = MinecraftClient.getInstance().getTextureManager().getTexture(capeTexture).getGlTexture(); // 尝试不同的纹理尺寸 - boolean loaded = Skia.getImageHelper().load(textureId, 64, 32, SurfaceOrigin.TOP_LEFT) || - Skia.getImageHelper().load(textureId, 128, 64, SurfaceOrigin.TOP_LEFT); + boolean loaded = Skia.getImageHelper().load(textureId, 64, 32) != null || + Skia.getImageHelper().load(textureId, 128, 64) != null; if (loaded) { Skia.save(); @@ -28,7 +30,7 @@ public static void renderCapePreview(Identifier capeTexture, float x, float y, f Rect srcRect = Rect.makeXYWH(1, 1, 10, 16); Rect dstRect = Rect.makeXYWH(0, 0, 10, 16); - Skia.getCanvas().drawImageRect(Skia.getImageHelper().get(textureId), srcRect, dstRect, null, false); + Skia.getCanvas().drawImageRect(Objects.requireNonNull(Skia.getImageHelper().get(textureId)), srcRect, dstRect, null, false); Skia.restore(); @@ -38,7 +40,7 @@ public static void renderCapePreview(Identifier capeTexture, float x, float y, f Rect srcRect2 = Rect.makeXYWH(12, 1, 10, 16); Rect dstRect2 = Rect.makeXYWH(0, 0, 10, 16); - Skia.getCanvas().drawImageRect(Skia.getImageHelper().get(textureId), srcRect2, dstRect2, null, false); + Skia.getCanvas().drawImageRect(Objects.requireNonNull(Skia.getImageHelper().get(textureId)), srcRect2, dstRect2, null, false); Skia.restore(); } @@ -52,11 +54,11 @@ public static void renderRoundedCapePreview(Identifier capeTexture, float x, flo if (capeTexture == null) return; try { - int textureId = MinecraftClient.getInstance().getTextureManager().getTexture(capeTexture).getGlId(); + var textureId = MinecraftClient.getInstance().getTextureManager().getTexture(capeTexture).getGlTexture(); // 尝试不同的纹理尺寸 - boolean loaded = Skia.getImageHelper().load(textureId, 64, 32, SurfaceOrigin.TOP_LEFT) || - Skia.getImageHelper().load(textureId, 128, 64, SurfaceOrigin.TOP_LEFT); + boolean loaded = Skia.getImageHelper().load(textureId, 64, 32) != null || + Skia.getImageHelper().load(textureId, 128, 64) != null; if (loaded) { Path path = Path.makeRRect(RRect.makeXYWH(x, y, width, height, radius)); @@ -67,7 +69,7 @@ public static void renderRoundedCapePreview(Identifier capeTexture, float x, flo Skia.save(); Skia.getCanvas().clipPath(path, ClipMode.INTERSECT, true); - Skia.getCanvas().drawImageRect(Skia.getImageHelper().get(textureId), srcRect, dstRect, null, false); + Skia.getCanvas().drawImageRect(Objects.requireNonNull(Skia.getImageHelper().get(textureId)), srcRect, dstRect, null, false); Skia.restore(); } } catch (Exception e) { diff --git a/src/main/java/cn/pupperclient/management/command/SoarCommand.java b/src/main/java/cn/pupperclient/management/command/SoarCommand.java index 9b8d221..f5329e5 100644 --- a/src/main/java/cn/pupperclient/management/command/SoarCommand.java +++ b/src/main/java/cn/pupperclient/management/command/SoarCommand.java @@ -185,9 +185,10 @@ private static MutableText createClickableText(String displayText, String comman return Text.literal(displayText) .formatted(color) .styled(style -> style - .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - Text.literal(hoverText).formatted(Formatting.GRAY)))); + .withClickEvent(new ClickEvent.SuggestCommand(command)) + .withHoverEvent(new HoverEvent.ShowText( + Text.literal(hoverText).formatted(Formatting.GRAY) + ))); } private static String getShortModName(String fullName) { diff --git a/src/main/java/cn/pupperclient/management/command/impl/BindCommand.java b/src/main/java/cn/pupperclient/management/command/impl/BindCommand.java index 9345a74..70dec2c 100644 --- a/src/main/java/cn/pupperclient/management/command/impl/BindCommand.java +++ b/src/main/java/cn/pupperclient/management/command/impl/BindCommand.java @@ -140,8 +140,8 @@ private static void listKeybinds() { for (Mod mod : mods) { MutableText message = Text.literal("§b• " + mod.getName() + " §7→ §a" + keyName + " §7(keycode: " + keyCode + ")") .styled(style -> style - .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, ".bind " + mod.getName() + " none")) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + .withClickEvent(new ClickEvent.SuggestCommand( ".bind " + mod.getName() + " none")) + .withHoverEvent(new HoverEvent.ShowText( Text.literal("Click to clear this keybind").formatted(Formatting.GRAY)))); ChatUtils.addChatMessage(message); diff --git a/src/main/java/cn/pupperclient/management/command/impl/LoginCommand.java b/src/main/java/cn/pupperclient/management/command/impl/LoginCommand.java index 79cf759..df86e28 100644 --- a/src/main/java/cn/pupperclient/management/command/impl/LoginCommand.java +++ b/src/main/java/cn/pupperclient/management/command/impl/LoginCommand.java @@ -141,8 +141,8 @@ private static void phoneLoginWithCaptcha(String phone, String captcha) { // 提供重新发送验证码的快捷方式 MutableText retryText = Text.literal("§7[重新发送验证码]") .styled(style -> style - .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, ".login send " + phone)) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + .withClickEvent(new ClickEvent.SuggestCommand( ".login send " + phone)) + .withHoverEvent(new HoverEvent.ShowText( Text.literal("点击重新发送验证码")))); ChatUtils.addChatMessage(retryText); }); diff --git a/src/main/java/cn/pupperclient/management/command/impl/MusicCommand.java b/src/main/java/cn/pupperclient/management/command/impl/MusicCommand.java index 38301c8..b053a8c 100644 --- a/src/main/java/cn/pupperclient/management/command/impl/MusicCommand.java +++ b/src/main/java/cn/pupperclient/management/command/impl/MusicCommand.java @@ -159,8 +159,8 @@ private static void searchMusic(String keyword, int limit) { // 格式化显示 MutableText songText = Text.literal("§b" + (i + 1) + ". §f" + songName) .styled(style -> style - .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, ".music download " + songId)) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + .withClickEvent(new ClickEvent.SuggestCommand( ".music download " + songId)) + .withHoverEvent(new HoverEvent.ShowText( Text.literal("§6点击快速下载\n§7歌手: " + artistsStr + "\n§7专辑: " + albumName)))); MutableText artistText = Text.literal(" §7- " + artistsStr); @@ -350,8 +350,7 @@ private static void listDownloadedMusic() { MutableText fileText = Text.literal("§b" + (i + 1) + ". §f" + displayName) .styled(style -> style - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - Text.literal("§6文件: " + fileName + "\n§7大小: " + formatFileSize(musicFile.length()))))); + .withHoverEvent(new HoverEvent.ShowText(Text.literal("§6文件: " + fileName + "\n§7大小: " + formatFileSize(musicFile.length()))))); ChatUtils.addChatMessage(fileText); } @@ -485,8 +484,9 @@ private static MutableText createClickableText(String command, String hoverText) return Text.literal(" [下载]") .formatted(Formatting.GREEN) .styled(style -> style - .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - Text.literal(hoverText).formatted(Formatting.GRAY)))); + .withClickEvent(new ClickEvent.SuggestCommand(command)) + .withHoverEvent(new HoverEvent.ShowText( + Text.literal(hoverText).formatted(Formatting.GRAY) + ))); } } diff --git a/src/main/java/cn/pupperclient/management/mod/impl/hud/MusicInfoMod.java b/src/main/java/cn/pupperclient/management/mod/impl/hud/MusicInfoMod.java index f47556f..4a848ce 100644 --- a/src/main/java/cn/pupperclient/management/mod/impl/hud/MusicInfoMod.java +++ b/src/main/java/cn/pupperclient/management/mod/impl/hud/MusicInfoMod.java @@ -318,7 +318,7 @@ private void drawInfo(float width, float height) { String albumPath = m.getAlbum().getAbsolutePath(); if (!albumPath.equals(currentAlbumPath)) { currentAlbumPath = albumPath; - if (Skia.getImageHelper().load(m.getAlbum())) { + if (Skia.getImageHelper().load(m.getAlbum()) != null) { Image image = Skia.getImageHelper().get(m.getAlbum().getName()); if (image != null) { albumBitmap = new Bitmap(); @@ -464,7 +464,7 @@ private static float getDynamicPulseMagnitude(float[] spectrum) { private void drawBlurredImage(File file, float x, float y, float width, float height) { Paint blurPaint = new Paint(); blurPaint.setImageFilter(ImageFilter.makeBlur(DEFAULT_BLUR_RADIUS, DEFAULT_BLUR_RADIUS, FilterTileMode.REPEAT)); - if (Skia.getImageHelper().load(file)) { + if (Skia.getImageHelper().load(file) != null) { Image image = Skia.getImageHelper().get(file.getName()); if (image != null) { Skia.getCanvas().drawImageRect(image, Rect.makeWH(image.getWidth(), image.getHeight()), diff --git a/src/main/java/cn/pupperclient/management/mod/impl/hud/WebBrowserMod.java b/src/main/java/cn/pupperclient/management/mod/impl/hud/WebBrowserMod.java index c30cf3e..e13097d 100644 --- a/src/main/java/cn/pupperclient/management/mod/impl/hud/WebBrowserMod.java +++ b/src/main/java/cn/pupperclient/management/mod/impl/hud/WebBrowserMod.java @@ -34,7 +34,7 @@ public WebBrowserMod() { if (MCEF.INSTANCE.isInitialized() && JCefBrowser.getBrowser() != null) { MCEF.INSTANCE.getApp().getHandle().N_DoMessageLoopWork(); this.drawBlurBackground(getX(), getY(), currentWidth, currentHeight); - Skia.drawRoundedImage(JCefBrowser.getBrowser().getRenderer().getTextureID(), getX(), getY(), currentWidth, currentHeight, + Skia.drawRoundedImage(JCefBrowser.getBrowser().getRenderer().getTexture(), getX(), getY(), currentWidth, currentHeight, getRadius(), opacitySetting.getValue()); } diff --git a/src/main/java/cn/pupperclient/management/mod/impl/render/ProjectileTrailMod.java b/src/main/java/cn/pupperclient/management/mod/impl/render/ProjectileTrailMod.java index 670bd13..3b1cdf6 100644 --- a/src/main/java/cn/pupperclient/management/mod/impl/render/ProjectileTrailMod.java +++ b/src/main/java/cn/pupperclient/management/mod/impl/render/ProjectileTrailMod.java @@ -47,7 +47,7 @@ public ProjectileTrailMod() { ParticleType type = getCurrentType(); if (type != null && type instanceof ParticleEffect) { - mc.world.addParticle((ParticleEffect) type, projectile.getX(), projectile.getY(), + mc.world.addParticleClient((ParticleEffect) type, projectile.getX(), projectile.getY(), projectile.getZ(), 0.0, 0.0, 0.0); } } diff --git a/src/main/java/cn/pupperclient/mixin/interfaces/IMixinCameraEntity.java b/src/main/java/cn/pupperclient/mixin/interfaces/IMixinCameraEntity.java index 9ab481f..1a89268 100644 --- a/src/main/java/cn/pupperclient/mixin/interfaces/IMixinCameraEntity.java +++ b/src/main/java/cn/pupperclient/mixin/interfaces/IMixinCameraEntity.java @@ -1,9 +1,9 @@ package cn.pupperclient.mixin.interfaces; public interface IMixinCameraEntity { - float soarClient_CN$getCameraPitch(); - float soarClient_CN$getCameraYaw(); + float pupper$getCameraPitch(); + float pupper$getCameraYaw(); - void soarClient_CN$setCameraPitch(float pitch); - void soarClient_CN$setCameraYaw(float yaw); + void pupper$setCameraPitch(float pitch); + void pupper$setCameraYaw(float yaw); } diff --git a/src/main/java/cn/pupperclient/mixin/interfaces/IMixinLivingEntity.java b/src/main/java/cn/pupperclient/mixin/interfaces/IMixinLivingEntity.java index 5b12dcd..bf91a58 100644 --- a/src/main/java/cn/pupperclient/mixin/interfaces/IMixinLivingEntity.java +++ b/src/main/java/cn/pupperclient/mixin/interfaces/IMixinLivingEntity.java @@ -3,5 +3,5 @@ import net.minecraft.util.Hand; public interface IMixinLivingEntity { - void soarClient_CN$fakeSwingHand(Hand hand); + void pupper$fakeSwingHand(Hand hand); } diff --git a/src/main/java/cn/pupperclient/mixin/interfaces/IRenderPipeline.java b/src/main/java/cn/pupperclient/mixin/interfaces/IRenderPipeline.java new file mode 100644 index 0000000..75839f8 --- /dev/null +++ b/src/main/java/cn/pupperclient/mixin/interfaces/IRenderPipeline.java @@ -0,0 +1,7 @@ +package cn.pupperclient.mixin.interfaces; + +public interface IRenderPipeline { + void pupper$setLineSmooth(boolean lineSmooth); + + boolean pupper$getLineSmooth(); +} diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/MixinMinecraftClient.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/MixinMinecraftClient.java index b16df75..4c8d3fc 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/MixinMinecraftClient.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/MixinMinecraftClient.java @@ -5,6 +5,7 @@ import cn.pupperclient.event.client.WorldChangeEvent; import cn.pupperclient.shader.impl.Kawaseblur; +import cn.pupperclient.skia.Skia; import net.minecraft.client.gui.screen.Screen; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; @@ -107,7 +108,7 @@ private void handleBlockBreaking(boolean breaking, CallbackInfo ci) { if (!this.world.getBlockState(blockPos).isAir()) { Direction direction = blockHitResult.getSide(); this.particleManager.addBlockBreakingParticles(blockPos, direction); - ((IMixinLivingEntity) player).soarClient_CN$fakeSwingHand(Hand.MAIN_HAND); + ((IMixinLivingEntity) player).pupper$fakeSwingHand(Hand.MAIN_HAND); } } } @@ -133,8 +134,14 @@ public void updateWindowTitle() { @Inject(method = "", at = @At("TAIL")) public void init(CallbackInfo ci) throws IOException { - SkiaContext.createSurface(window.getWidth(), window.getHeight()); - PupperClient.getInstance().start(); + int width = window.getWidth(); + int height = window.getHeight(); + if (width > 0 && height > 0) { + SkiaContext.createSurface(width, height); + } else { + PupperClient.LOGGER.warn("Window size during init is invalid: {}x{}", width, height); + } + PupperClient.getInstance().start(); } @Inject(method = "stop", at = @At("HEAD")) diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/gui/MixinSplashScreen.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/gui/MixinSplashScreen.java index 534c732..7e40d86 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/gui/MixinSplashScreen.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/gui/MixinSplashScreen.java @@ -3,6 +3,7 @@ import cn.pupperclient.skia.Skia; import cn.pupperclient.skia.context.SkiaContext; import cn.pupperclient.skia.font.Fonts; +import com.mojang.blaze3d.textures.GpuTexture; import io.github.humbleui.skija.Canvas; import io.github.humbleui.skija.Font; import io.github.humbleui.types.Rect; @@ -73,7 +74,7 @@ private void pupper_takeOverAndRender(DrawContext context, int mouseX, int mouse // Recreate surface if window size changed if (lastWindowWidth != width || lastWindowHeight != height) { - SkiaContext.createSurface(width, height); + SkiaContext.createSimpleSurface(width, height); lastWindowWidth = width; lastWindowHeight = height; } @@ -248,7 +249,7 @@ private void renderLoadingScreen(int width, int height, long timePassed, float a @Unique private void drawLogo(int x, int y, int size, float alpha) { // Draw logo using Skia - int textureId = MinecraftClient.getInstance().getTextureManager().getTexture(CUSTOM_LOGO).getGlId(); + GpuTexture textureId = MinecraftClient.getInstance().getTextureManager().getTexture(CUSTOM_LOGO).getGlTexture(); Skia.drawImage(textureId, x, y, size, size, alpha); } diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/BufferRendererAccessor.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/BufferRendererAccessor.java deleted file mode 100644 index 1b90209..0000000 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/BufferRendererAccessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.pupperclient.mixin.mixins.minecraft.client.render; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import net.minecraft.client.gl.VertexBuffer; -import net.minecraft.client.render.BufferRenderer; - -@Mixin(BufferRenderer.class) -public interface BufferRendererAccessor { - @Accessor("currentVertexBuffer") - static void setCurrentVertexBuffer(VertexBuffer vertexBuffer) { - } -} diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinCamera.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinCamera.java index 29aef97..4aa215c 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinCamera.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinCamera.java @@ -34,11 +34,11 @@ public void lockRotation(BlockView focusedBlock, Entity cameraEntity, boolean is IMixinCameraEntity cameraOverriddenEntity = (IMixinCameraEntity) cameraEntity; if (firstTime && MinecraftClient.getInstance().player != null) { - cameraOverriddenEntity.soarClient_CN$setCameraPitch(client.player.getPitch()); - cameraOverriddenEntity.soarClient_CN$setCameraYaw(client.player.getYaw()); + cameraOverriddenEntity.pupper$setCameraPitch(client.player.getPitch()); + cameraOverriddenEntity.pupper$setCameraYaw(client.player.getYaw()); firstTime = false; } - this.setRotation(cameraOverriddenEntity.soarClient_CN$getCameraYaw(), cameraOverriddenEntity.soarClient_CN$getCameraPitch()); + this.setRotation(cameraOverriddenEntity.pupper$getCameraYaw(), cameraOverriddenEntity.pupper$getCameraPitch()); } if (FreelookMod.getInstance().isEnabled() && !FreelookMod.getInstance().isActive() && cameraEntity instanceof ClientPlayerEntity) { diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinHeldItemRenderer.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinHeldItemRenderer.java index d7ebc44..2352f65 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinHeldItemRenderer.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/MixinHeldItemRenderer.java @@ -26,22 +26,30 @@ public abstract class MixinHeldItemRenderer { @Shadow protected abstract void applySwingOffset(MatrixStack matrices, Arm arm, float swingProgress); - @Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = ("Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"), ordinal = 1)) - private void renderFirstPersonItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, - float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, - VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { + @Inject(method = "renderFirstPersonItem", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/render/item/HeldItemRenderer;" + + "renderItem(Lnet/minecraft/entity/LivingEntity;" + + "Lnet/minecraft/item/ItemStack;" + + "Lnet/minecraft/item/ItemDisplayContext;" + + "Lnet/minecraft/client/util/math/MatrixStack;" + + "Lnet/minecraft/client/render/VertexConsumerProvider;I)V", + ordinal = 1)) + private void onRenderFirstPersonItem(AbstractClientPlayerEntity player, float tickProgress, float pitch, + Hand hand, float swingProgress, ItemStack item, float equipProgress, + MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, + CallbackInfo ci) { + OldAnimationsMod mod = OldAnimationsMod.getInstance(); - OldAnimationsMod mod = OldAnimationsMod.getInstance(); + if (item.getItem() instanceof BowItem && mod.isEnabled() && mod.isOldBow()) { + matrices.translate(0f, 0.05f, 0.04f); + matrices.scale(0.93f, 1f, 1f); + } else if (item.getItem() instanceof FishingRodItem && mod.isEnabled() && mod.isOldRod()) { + matrices.translate(0.08f, -0.027f, -0.33f); + matrices.scale(0.93f, 1f, 1f); + } + } - if (item.getItem() instanceof BowItem && mod.isEnabled() && mod.isOldBow()) { - matrices.translate(0f, 0.05f, 0.04f); - matrices.scale(0.93f, 1f, 1f); - } else if (item.getItem() instanceof FishingRodItem && mod.isEnabled() && mod.isOldRod()) { - matrices.translate(0.08f, -0.027f, -0.33f); - matrices.scale(0.93f, 1f, 1f); - } - } - @Inject(method = "renderFirstPersonItem", at = @At("HEAD")) private void applyCustomHand(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/PupperInGameHud.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/PupperInGameHud.java index 2613860..57463d7 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/PupperInGameHud.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/render/PupperInGameHud.java @@ -55,7 +55,7 @@ private void drawCustomHotbar(DrawContext context, RenderTickCounter tickCounter int centerX = context.getScaledWindowWidth() / 2; int hotbarY = context.getScaledWindowHeight() - 22; - int selectedSlot = playerEntity.getInventory().selectedSlot; + int selectedSlot = playerEntity.getInventory().getSelectedSlot(); updateSlotAnimation(selectedSlot); updateOffhandAlpha(playerEntity); @@ -90,7 +90,7 @@ private void drawCustomHotbar(DrawContext context, RenderTickCounter tickCounter } this.renderHotbarItem(context, slotX, (int)(slotY + slotOffset), tickCounter, playerEntity, - playerEntity.getInventory().main.get(i), i + 1); + playerEntity.getInventory().getMainStacks().get(i), i + 1); } // 绘制副手物品(带透明度) diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/util/MixinWindow.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/util/MixinWindow.java index c5637d3..4dc2c7b 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/util/MixinWindow.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/client/util/MixinWindow.java @@ -24,7 +24,11 @@ public class MixinWindow { @Inject(method = "onFramebufferSizeChanged", at = @At("RETURN")) private void onFramebufferSizeChanged(long window, int width, int height, CallbackInfo ci) { - SkiaContext.createSurface(width, height); + if (width > 0 && height > 0) { + SkiaContext.createSurface(width, height); + } else { + PupperClient.LOGGER.warn("Window size is invalid: {}x{}, skipping surface creation", width, height); + } } @Inject(method = "", at = @At("RETURN")) diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinEntity.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinEntity.java index 5d9d5c7..fb0ed5b 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinEntity.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinEntity.java @@ -84,25 +84,25 @@ public void changeCameraLookDirection(double xDelta, double yDelta, CallbackInfo @Override @Unique - public float soarClient_CN$getCameraPitch() { + public float pupper$getCameraPitch() { return this.cameraPitch; } @Override @Unique - public float soarClient_CN$getCameraYaw() { + public float pupper$getCameraYaw() { return this.cameraYaw; } @Override @Unique - public void soarClient_CN$setCameraPitch(float pitch) { + public void pupper$setCameraPitch(float pitch) { this.cameraPitch = pitch; } @Override @Unique - public void soarClient_CN$setCameraYaw(float yaw) { + public void pupper$setCameraYaw(float yaw) { this.cameraYaw = yaw; } diff --git a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinLivingEntity.java b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinLivingEntity.java index c41445b..46fd8b4 100644 --- a/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinLivingEntity.java +++ b/src/main/java/cn/pupperclient/mixin/mixins/minecraft/entity/MixinLivingEntity.java @@ -80,7 +80,7 @@ private void onDamage(CallbackInfo info) { } @Override - public void soarClient_CN$fakeSwingHand(Hand hand) { + public void pupper$fakeSwingHand(Hand hand) { if (!this.handSwinging || this.handSwingTicks >= this.getHandSwingDuration() / 2 || this.handSwingTicks < 0) { this.handSwingTicks = -1; this.handSwinging = true; diff --git a/src/main/java/cn/pupperclient/shader/Framebuffer.java b/src/main/java/cn/pupperclient/shader/Framebuffer.java index c8d51f4..fa82d0a 100644 --- a/src/main/java/cn/pupperclient/shader/Framebuffer.java +++ b/src/main/java/cn/pupperclient/shader/Framebuffer.java @@ -1,24 +1,17 @@ package cn.pupperclient.shader; -import static org.lwjgl.opengl.GL11C.*; -import static org.lwjgl.opengl.GL12C.GL_CLAMP_TO_EDGE; -import static org.lwjgl.opengl.GL30C.GL_COLOR_ATTACHMENT0; -import static org.lwjgl.opengl.GL30C.GL_FRAMEBUFFER; -import static org.lwjgl.opengl.GL30C.glGenerateMipmap; - -import org.lwjgl.opengl.GL30C; - -import com.mojang.blaze3d.platform.GlStateManager; - +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.textures.AddressMode; +import com.mojang.blaze3d.textures.FilterMode; +import com.mojang.blaze3d.textures.GpuTexture; +import com.mojang.blaze3d.textures.TextureFormat; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.Window; public class Framebuffer { - - private int id; - public int texture; + private GpuTexture texture; public double sizeMulti = 1; - public int width, height; + private FilterMode filterMode = FilterMode.LINEAR; private boolean mipmapEnabled = false; public Framebuffer(double sizeMulti) { @@ -33,72 +26,46 @@ public Framebuffer() { private void init() { Window window = MinecraftClient.getInstance().getWindow(); - id = GlStateManager.glGenFramebuffers(); - bind(); - - texture = GlStateManager._genTexture(); - ShaderHelper.bindTexture(texture); - ShaderHelper.defaultPixelStore(); - - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + int width = Math.max(1, (int) (window.getFramebufferWidth() * sizeMulti)); + int height = Math.max(1, (int) (window.getFramebufferHeight() * sizeMulti)); - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + texture = RenderSystem.getDevice().createTexture( + () -> "PupperFramebuffer", + TextureFormat.RGBA8, + width, + height, + 1 + ); - width = Math.max(1, (int) (window.getFramebufferWidth() * sizeMulti)); - height = Math.max(1, (int) (window.getFramebufferHeight() * sizeMulti)); - - ShaderHelper.textureImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null); - ShaderHelper.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); - - unbind(); + texture.setTextureFilter(filterMode, false); + texture.setAddressMode(AddressMode.CLAMP_TO_EDGE); } public void enableMipmap() { if (sizeMulti < 1.0) { mipmapEnabled = true; - bind(); - ShaderHelper.bindTexture(texture); - - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - ShaderHelper.textureParam(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - unbind(); + texture.setTextureFilter(FilterMode.LINEAR, true); + texture.setAddressMode(AddressMode.CLAMP_TO_EDGE); } } - public void generateMipmap() { - if (mipmapEnabled && sizeMulti < 1.0) { - bind(); - ShaderHelper.bindTexture(texture); - // 直接使用原生的OpenGL调用生成Mipmap - glGenerateMipmap(GL_TEXTURE_2D); - unbind(); - } - } - - public void bind() { - GlStateManager._glBindFramebuffer(GL30C.GL_FRAMEBUFFER, id); - } - - public void setViewport() { - ShaderHelper.viewport(0, 0, width, height); - } - - public void unbind() { - MinecraftClient.getInstance().getFramebuffer().beginWrite(false); + public GpuTexture getTexture() { + return texture; } public void resize() { - GlStateManager._glDeleteFramebuffers(id); - GlStateManager._deleteTexture(texture); + if (texture != null) { + texture.close(); + } init(); if (mipmapEnabled) { enableMipmap(); } } + + public void close() { + if (texture != null) { + texture.close(); + } + } } diff --git a/src/main/java/cn/pupperclient/shader/MeshBuilder.java b/src/main/java/cn/pupperclient/shader/MeshBuilder.java new file mode 100644 index 0000000..572aa31 --- /dev/null +++ b/src/main/java/cn/pupperclient/shader/MeshBuilder.java @@ -0,0 +1,112 @@ +package cn.pupperclient.shader; + +import com.mojang.blaze3d.buffers.BufferType; +import com.mojang.blaze3d.buffers.BufferUsage; +import com.mojang.blaze3d.buffers.GpuBuffer; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.VertexFormat; +import org.lwjgl.BufferUtils; + +import java.nio.ByteBuffer; +import static org.lwjgl.system.MemoryUtil.*; + +public class MeshBuilder { + private final VertexFormat format; + private final VertexFormat.DrawMode drawMode; + + private final ByteBuffer vertices; + private final long verticesPointerStart; + private long verticesPointer; + + private final ByteBuffer indices; + private final long indicesPointer; + + private int vertexI, indicesCount; + private boolean building; + + public MeshBuilder(VertexFormat format, VertexFormat.DrawMode drawMode) { + this.format = format; + this.drawMode = drawMode; + + int vertexSize = format.getVertexSize(); + vertices = BufferUtils.createByteBuffer(vertexSize * 256 * 4); + verticesPointerStart = memAddress0(vertices); + + indices = BufferUtils.createByteBuffer(6 * 512 * 4); + indicesPointer = memAddress0(indices); + } + + public void begin() { + if (building) return; + + verticesPointer = verticesPointerStart; + vertexI = 0; + indicesCount = 0; + building = true; + } + + // 添加位置 (x, y, z) + public MeshBuilder vec3(float x, float y, float z) { + long p = verticesPointer; + memPutFloat(p, x); + memPutFloat(p + 4, y); + memPutFloat(p + 8, z); + verticesPointer += 12; + return this; + } + + // 添加纹理坐标 (u, v) + public MeshBuilder vec2(float u, float v) { + long p = verticesPointer; + memPutFloat(p, u); + memPutFloat(p + 4, v); + verticesPointer += 8; + return this; + } + + public int next() { + return vertexI++; + } + + public void quad(int i1, int i2, int i3, int i4) { + long p = indicesPointer + indicesCount * 4L; + memPutInt(p, i1); + memPutInt(p + 4, i2); + memPutInt(p + 8, i3); + memPutInt(p + 12, i3); + memPutInt(p + 16, i4); + memPutInt(p + 20, i1); + indicesCount += 6; + } + + public void end() { + if (!building) return; + building = false; + } + + public GpuBuffer createVertexBuffer() { + int size = (int) (verticesPointer - verticesPointerStart); + vertices.limit(size); + + return RenderSystem.getDevice().createBuffer( + () -> "MeshVertexBuffer", + BufferType.VERTICES, + BufferUsage.DYNAMIC_WRITE, + vertices + ); + } + + public GpuBuffer createIndexBuffer() { + indices.limit(indicesCount * 4); + return RenderSystem.getDevice().createBuffer( + () -> "MeshIndexBuffer", + BufferType.INDICES, + BufferUsage.DYNAMIC_WRITE, + indices + ); + } + + public int getIndicesCount() { + return indicesCount; + } +} diff --git a/src/main/java/cn/pupperclient/shader/PostProcessRenderer.java b/src/main/java/cn/pupperclient/shader/PostProcessRenderer.java deleted file mode 100644 index a2a413b..0000000 --- a/src/main/java/cn/pupperclient/shader/PostProcessRenderer.java +++ /dev/null @@ -1,184 +0,0 @@ -package cn.pupperclient.shader; - -import static org.lwjgl.opengl.GL11C.GL_FLOAT; -import static org.lwjgl.opengl.GL11C.GL_UNSIGNED_INT; -import static org.lwjgl.opengl.GL15C.GL_ARRAY_BUFFER; -import static org.lwjgl.opengl.GL15C.GL_DYNAMIC_DRAW; -import static org.lwjgl.opengl.GL15C.GL_ELEMENT_ARRAY_BUFFER; -import static org.lwjgl.system.MemoryUtil.memAddress0; -import static org.lwjgl.system.MemoryUtil.memPutFloat; -import static org.lwjgl.system.MemoryUtil.memPutInt; - -import java.nio.ByteBuffer; - -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL15C; -import org.lwjgl.opengl.GL32C; - -import com.mojang.blaze3d.platform.GlStateManager; - -import net.minecraft.client.util.math.MatrixStack; - -public class PostProcessRenderer { - - private static final Mesh mesh = new Mesh(); - private static final MatrixStack matrices = new MatrixStack(); - - static { - mesh.begin(); - mesh.quad(mesh.vec2(-1, -1).next(), mesh.vec2(-1, 1).next(), mesh.vec2(1, 1).next(), mesh.vec2(1, -1).next()); - mesh.end(); - } - - public static void beginRender() { - mesh.beginRender(matrices); - } - - public static void render() { - mesh.render(matrices); - } - - public static void endRender() { - mesh.endRender(); - } - - private static class Mesh { - - private final int vao, vbo, ibo; - - private final ByteBuffer vertices; - private final long verticesPointerStart; - private long verticesPointer; - - private final ByteBuffer indices; - private final long indicesPointer; - - private int vertexI, indicesCount; - - private boolean building; - private boolean beganRendering; - - public Mesh() { - int drawMode = 3; - int stride = 8; - - int primitiveVerticesSize = stride * drawMode; - - vertices = BufferUtils.createByteBuffer(primitiveVerticesSize * 256 * 4); - verticesPointerStart = memAddress0(vertices); - - indices = BufferUtils.createByteBuffer(drawMode * 512 * 4); - indicesPointer = memAddress0(indices); - - vao = GlStateManager._glGenVertexArrays(); - ShaderHelper.bindVertexArray(vao); - - vbo = GlStateManager._glGenBuffers(); - GlStateManager._glBindBuffer(GL15C.GL_ARRAY_BUFFER, vbo); - - ibo = GlStateManager._glGenBuffers(); - ShaderHelper.bindIndexBuffer(ibo); - GlStateManager._enableVertexAttribArray(0); - GlStateManager._vertexAttribPointer(0, 2, GL_FLOAT, false, stride, 0); - - ShaderHelper.bindVertexArray(0); - GlStateManager._glBindBuffer(GL15C.GL_ARRAY_BUFFER, 0); - ShaderHelper.bindIndexBuffer(0); - } - - public void begin() { - - if (building) { - return; - } - - verticesPointer = verticesPointerStart; - vertexI = 0; - indicesCount = 0; - - building = true; - } - - public Mesh vec2(double x, double y) { - long p = verticesPointer; - - memPutFloat(p, (float) x); - memPutFloat(p + 4, (float) y); - - verticesPointer += 8; - return this; - } - - public int next() { - return vertexI++; - } - - public void quad(int i1, int i2, int i3, int i4) { - long p = indicesPointer + indicesCount * 4L; - - memPutInt(p, i1); - memPutInt(p + 4, i2); - memPutInt(p + 8, i3); - - memPutInt(p + 12, i3); - memPutInt(p + 16, i4); - memPutInt(p + 20, i1); - - indicesCount += 6; - } - - public void end() { - - if (!building) { - return; - } - - if (indicesCount > 0) { - GlStateManager._glBindBuffer(GL15C.GL_ARRAY_BUFFER, vbo); - GlStateManager._glBufferData(GL_ARRAY_BUFFER, vertices.limit(getVerticesOffset()), GL_DYNAMIC_DRAW); - GlStateManager._glBindBuffer(GL15C.GL_ARRAY_BUFFER, 0); - - ShaderHelper.bindIndexBuffer(ibo); - GlStateManager._glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.limit(indicesCount * 4), GL_DYNAMIC_DRAW); - ShaderHelper.bindIndexBuffer(0); - } - - building = false; - } - - public void beginRender(MatrixStack matrices) { - ShaderHelper.disableCull(); - - beganRendering = true; - } - - public void render(MatrixStack matrices) { - if (building) - end(); - - if (indicesCount > 0) { - boolean wasBeganRendering = beganRendering; - if (!wasBeganRendering) - beginRender(matrices); - - Shader.BOUND.setDefaults(); - - ShaderHelper.bindVertexArray(vao); - GlStateManager._drawElements(GL32C.GL_TRIANGLES, indicesCount, GL_UNSIGNED_INT, 0); - - ShaderHelper.bindVertexArray(0); - - if (!wasBeganRendering) - endRender(); - } - } - - public void endRender() { - beganRendering = false; - } - - private int getVerticesOffset() { - return (int) (verticesPointer - verticesPointerStart); - } - } -} diff --git a/src/main/java/cn/pupperclient/shader/PupperRenderPipelines.java b/src/main/java/cn/pupperclient/shader/PupperRenderPipelines.java new file mode 100644 index 0000000..8f3ecbb --- /dev/null +++ b/src/main/java/cn/pupperclient/shader/PupperRenderPipelines.java @@ -0,0 +1,88 @@ +package cn.pupperclient.shader; + +import cn.pupperclient.PupperClient; +import com.mojang.blaze3d.pipeline.RenderPipeline; +import com.mojang.blaze3d.pipeline.BlendFunction; +import com.mojang.blaze3d.platform.DepthTestFunction; +import com.mojang.blaze3d.systems.GpuDevice; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.VertexFormat; +import net.minecraft.client.gl.UniformType; +import net.minecraft.client.render.VertexFormats; +import net.minecraft.resource.ResourceManager; +import net.minecraft.resource.SynchronousResourceReloader; +import net.minecraft.util.Identifier; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +public class PupperRenderPipelines { + private static final List PIPELINES = new ArrayList<>(); + + public static final RenderPipeline BLUR_DOWN = register(new RenderPipeline.Builder() + .withLocation(PupperClient.identifier("pipeline/blur/up")) + .withVertexFormat(PupperVertexFormats.POS2, VertexFormat.DrawMode.TRIANGLES) + .withVertexShader(PupperClient.identifier("shaders/passthrough.vert")) + .withFragmentShader(PupperClient.identifier("shaders/passthrough.frag")) + .withSampler("uTexture") + .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) + .withDepthWrite(false) + .withBlend(BlendFunction.TRANSLUCENT) + .withCull(false) + .build()); + + public static final RenderPipeline BLUR_UP = register(new RenderPipeline.Builder() + .withLocation(PupperClient.identifier("pipeline/blur/up")) + .withVertexFormat(PupperVertexFormats.POS2, VertexFormat.DrawMode.TRIANGLES) + .withVertexShader(PupperClient.identifier("shaders/blur.vert")) + .withFragmentShader(PupperClient.identifier("shaders/blur_up.frag")) + .withSampler("uTexture") + .withUniform("uHalfTexelSize", UniformType.VEC2) + .withUniform("uOffset", UniformType.FLOAT) + .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) + .withDepthWrite(false) + .withBlend(BlendFunction.TRANSLUCENT) + .withCull(false) + .build() + ); + + public static final RenderPipeline PASSTHROUGH = register(new RenderPipeline.Builder() + .withLocation(PupperClient.identifier("pipeline/blur/up")) + .withVertexFormat(PupperVertexFormats.POS2, VertexFormat.DrawMode.TRIANGLES) + .withVertexShader(PupperClient.identifier("shaders/passthrough.vert")) + .withFragmentShader(PupperClient.identifier("shaders/passthrough.frag")) + .withSampler("uTexture") + .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) + .withDepthWrite(false) + .withBlend(BlendFunction.TRANSLUCENT) + .withCull(false) + .build() + ); + + private static RenderPipeline register(RenderPipeline pipeline) { + PIPELINES.add(pipeline); + return pipeline; + } + + public static class Reloader implements SynchronousResourceReloader { + @Override + public void reload(ResourceManager manager) { + GpuDevice device = RenderSystem.getDevice(); + + for (RenderPipeline pipeline : PIPELINES) { + device.precompilePipeline(pipeline, (identifier, shaderType) -> { + var resource = manager.getResource(identifier).get(); + + try (var in = resource.getInputStream()) { + return IOUtils.toString(in, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + } + } +} diff --git a/src/main/java/cn/pupperclient/shader/PupperVertexFormats.java b/src/main/java/cn/pupperclient/shader/PupperVertexFormats.java new file mode 100644 index 0000000..fffac80 --- /dev/null +++ b/src/main/java/cn/pupperclient/shader/PupperVertexFormats.java @@ -0,0 +1,28 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package cn.pupperclient.shader; + +import com.mojang.blaze3d.vertex.VertexFormat; +import com.mojang.blaze3d.vertex.VertexFormatElement; + +public abstract class PupperVertexFormats { + public static final VertexFormat POS2 = VertexFormat.builder() + .add("Position", VertexFormatElements.POS2) + .build(); + + public static final VertexFormat POS2_COLOR = VertexFormat.builder() + .add("Position", VertexFormatElements.POS2) + .add("Color", VertexFormatElement.COLOR) + .build(); + + public static final VertexFormat POS2_TEXTURE_COLOR = VertexFormat.builder() + .add("Position", VertexFormatElements.POS2) + .add("Texture", VertexFormatElement.UV) + .add("Color", VertexFormatElement.COLOR) + .build(); + + private PupperVertexFormats() {} +} diff --git a/src/main/java/cn/pupperclient/shader/Shader.java b/src/main/java/cn/pupperclient/shader/Shader.java deleted file mode 100644 index ba9e22c..0000000 --- a/src/main/java/cn/pupperclient/shader/Shader.java +++ /dev/null @@ -1,111 +0,0 @@ -package cn.pupperclient.shader; - -import static org.lwjgl.opengl.GL11C.GL_FALSE; -import static org.lwjgl.opengl.GL11C.GL_TRUE; -import static org.lwjgl.opengl.GL20C.GL_FRAGMENT_SHADER; -import static org.lwjgl.opengl.GL20C.GL_VERTEX_SHADER; - -import java.io.IOException; -import java.nio.FloatBuffer; -import java.nio.charset.StandardCharsets; - -import org.apache.commons.io.IOUtils; -import org.joml.Matrix4f; -import org.lwjgl.BufferUtils; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; - -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.Identifier; - -public class Shader { - - private static final FloatBuffer MAT = BufferUtils.createFloatBuffer(4 * 4); - - public static Shader BOUND; - - private final int id; - private final Object2IntMap uniformLocations = new Object2IntOpenHashMap<>(); - - public Shader(String vertPath, String fragPath) { - int vert = GlStateManager.glCreateShader(GL_VERTEX_SHADER); - GlStateManager.glShaderSource(vert, read(vertPath)); - - String vertError = ShaderHelper.compileShader(vert); - if (vertError != null) { - throw new RuntimeException("Failed to compile vertex shader: " + vertError); - } - - int frag = GlStateManager.glCreateShader(GL_FRAGMENT_SHADER); - GlStateManager.glShaderSource(frag, read(fragPath)); - - String fragError = ShaderHelper.compileShader(frag); - if (fragError != null) { - throw new RuntimeException("Failed to compile fragment shader: " + fragError); - } - - id = GlStateManager.glCreateProgram(); - - String programError = ShaderHelper.linkProgram(id, vert, frag); - if (programError != null) { - throw new RuntimeException("Failed to link program: " + programError); - } - - GlStateManager.glDeleteShader(vert); - GlStateManager.glDeleteShader(frag); - } - - private String read(String path) { - try { - return IOUtils.toString( - MinecraftClient.getInstance().getResourceManager() - .getResource(Identifier.of("pupper", "shaders/" + path)).get().getInputStream(), - StandardCharsets.UTF_8); - } catch (IOException e) { - throw new IllegalStateException("Could not read shader '" + path + "'", e); - } - } - - public void bind() { - ShaderHelper.useProgram(id); - BOUND = this; - } - - private int getLocation(String name) { - if (uniformLocations.containsKey(name)) - return uniformLocations.getInt(name); - - int location = ShaderHelper.getUniformLocation(id, name); - uniformLocations.put(name, location); - return location; - } - - public void set(String name, boolean v) { - ShaderHelper.uniformInt(getLocation(name), v ? GL_TRUE : GL_FALSE); - } - - public void set(String name, int v) { - ShaderHelper.uniformInt(getLocation(name), v); - } - - public void set(String name, double v) { - ShaderHelper.uniformFloat(getLocation(name), (float) v); - } - - public void set(String name, double v1, double v2) { - ShaderHelper.uniformFloat2(getLocation(name), (float) v1, (float) v2); - } - - public void set(String name, Matrix4f mat) { - mat.get(MAT); - GlStateManager._glUniformMatrix4(getLocation(name), false, MAT); - } - - public void setDefaults() { - set("u_Proj", RenderSystem.getProjectionMatrix()); - set("u_ModelView", RenderSystem.getModelViewStack()); - } -} diff --git a/src/main/java/cn/pupperclient/shader/ShaderHelper.java b/src/main/java/cn/pupperclient/shader/ShaderHelper.java deleted file mode 100644 index 6868632..0000000 --- a/src/main/java/cn/pupperclient/shader/ShaderHelper.java +++ /dev/null @@ -1,203 +0,0 @@ -package cn.pupperclient.shader; - -import static org.lwjgl.opengl.GL11C.GL_FALSE; -import static org.lwjgl.opengl.GL11C.GL_LINE_SMOOTH; -import static org.lwjgl.opengl.GL11C.GL_ONE_MINUS_SRC_ALPHA; -import static org.lwjgl.opengl.GL11C.GL_SRC_ALPHA; -import static org.lwjgl.opengl.GL11C.GL_UNPACK_ALIGNMENT; -import static org.lwjgl.opengl.GL11C.GL_UNPACK_LSB_FIRST; -import static org.lwjgl.opengl.GL11C.GL_UNPACK_ROW_LENGTH; -import static org.lwjgl.opengl.GL11C.GL_UNPACK_SKIP_PIXELS; -import static org.lwjgl.opengl.GL11C.GL_UNPACK_SKIP_ROWS; -import static org.lwjgl.opengl.GL11C.GL_UNPACK_SWAP_BYTES; -import static org.lwjgl.opengl.GL11C.glDisable; -import static org.lwjgl.opengl.GL11C.glEnable; -import static org.lwjgl.opengl.GL11C.glLineWidth; -import static org.lwjgl.opengl.GL11C.glTexImage2D; -import static org.lwjgl.opengl.GL12C.GL_UNPACK_IMAGE_HEIGHT; -import static org.lwjgl.opengl.GL12C.GL_UNPACK_SKIP_IMAGES; -import static org.lwjgl.opengl.GL13C.GL_TEXTURE0; -import static org.lwjgl.opengl.GL15C.GL_ELEMENT_ARRAY_BUFFER; -import static org.lwjgl.opengl.GL20C.GL_COMPILE_STATUS; -import static org.lwjgl.opengl.GL20C.GL_LINK_STATUS; -import static org.lwjgl.opengl.GL20C.glUniform1f; -import static org.lwjgl.opengl.GL20C.glUniform2f; -import static org.lwjgl.opengl.GL20C.glUniform3f; -import static org.lwjgl.opengl.GL20C.glUniform3fv; -import static org.lwjgl.opengl.GL20C.glUniform4f; -import static org.lwjgl.opengl.GL30C.glGenerateMipmap; - -import java.nio.ByteBuffer; - -import com.mojang.blaze3d.platform.GlStateManager; -import cn.pupperclient.mixin.mixins.minecraft.client.render.BufferRendererAccessor; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.texture.AbstractTexture; -import net.minecraft.util.Identifier; - -public class ShaderHelper { - - public static int CURRENT_IBO; - private static int prevIbo; - - private ShaderHelper() { - } - - public static void bindVertexArray(int vao) { - GlStateManager._glBindVertexArray(vao); - BufferRendererAccessor.setCurrentVertexBuffer(null); - } - - public static void bindIndexBuffer(int ibo) { - if (ibo != 0) - prevIbo = CURRENT_IBO; - GlStateManager._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo != 0 ? ibo : prevIbo); - } - - public static String compileShader(int shader) { - GlStateManager.glCompileShader(shader); - - if (GlStateManager.glGetShaderi(shader, GL_COMPILE_STATUS) == GL_FALSE) { - return GlStateManager.glGetShaderInfoLog(shader, 512); - } - - return null; - } - - public static String linkProgram(int program, int vertShader, int fragShader) { - GlStateManager.glAttachShader(program, vertShader); - GlStateManager.glAttachShader(program, fragShader); - GlStateManager.glLinkProgram(program); - - if (GlStateManager.glGetProgrami(program, GL_LINK_STATUS) == GL_FALSE) { - return GlStateManager.glGetProgramInfoLog(program, 512); - } - - return null; - } - - public static void useProgram(int program) { - GlStateManager._glUseProgram(program); - } - - public static void viewport(int x, int y, int width, int height) { - GlStateManager._viewport(x, y, width, height); - } - - public static int getUniformLocation(int program, String name) { - return GlStateManager._glGetUniformLocation(program, name); - } - - public static void uniformInt(int location, int v) { - GlStateManager._glUniform1i(location, v); - } - - public static void uniformFloat(int location, float v) { - glUniform1f(location, v); - } - - public static void uniformFloat2(int location, float v1, float v2) { - glUniform2f(location, v1, v2); - } - - public static void uniformFloat3(int location, float v1, float v2, float v3) { - glUniform3f(location, v1, v2, v3); - } - - public static void uniformFloat4(int location, float v1, float v2, float v3, float v4) { - glUniform4f(location, v1, v2, v3, v4); - } - - public static void uniformFloat3Array(int location, float[] v) { - glUniform3fv(location, v); - } - - public static void pixelStore(int name, int param) { - GlStateManager._pixelStore(name, param); - } - - public static void textureParam(int target, int name, int param) { - GlStateManager._texParameter(target, name, param); - } - - public static void textureImage2D(int target, int level, int internalFormat, int width, int height, int border, - int format, int type, ByteBuffer pixels) { - glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels); - } - - public static void defaultPixelStore() { - pixelStore(GL_UNPACK_SWAP_BYTES, GL_FALSE); - pixelStore(GL_UNPACK_LSB_FIRST, GL_FALSE); - pixelStore(GL_UNPACK_ROW_LENGTH, 0); - pixelStore(GL_UNPACK_IMAGE_HEIGHT, 0); - pixelStore(GL_UNPACK_SKIP_ROWS, 0); - pixelStore(GL_UNPACK_SKIP_PIXELS, 0); - pixelStore(GL_UNPACK_SKIP_IMAGES, 0); - pixelStore(GL_UNPACK_ALIGNMENT, 4); - } - - public static void framebufferTexture2D(int target, int attachment, int textureTarget, int texture, int level) { - GlStateManager._glFramebufferTexture2D(target, attachment, textureTarget, texture, level); - } - - public static void enableDepth() { - GlStateManager._enableDepthTest(); - } - - public static void disableDepth() { - GlStateManager._disableDepthTest(); - } - - public static void enableBlend() { - GlStateManager._enableBlend(); - GlStateManager._blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - public static void disableBlend() { - GlStateManager._disableBlend(); - } - - public static void enableCull() { - GlStateManager._enableCull(); - } - - public static void disableCull() { - GlStateManager._disableCull(); - } - - public static void enableLineSmooth() { - glEnable(GL_LINE_SMOOTH); - glLineWidth(1); - } - - public static void disableLineSmooth() { - glDisable(GL_LINE_SMOOTH); - } - - public static void bindTexture(Identifier id) { - AbstractTexture texture = MinecraftClient.getInstance().getTextureManager().getTexture(id); - bindTexture(texture.getGlId(), 0); - } - - public static void bindTexture(int i, int slot) { - GlStateManager._activeTexture(GL_TEXTURE0 + slot); - GlStateManager._bindTexture(i); - } - - public static void bindTexture(int i) { - bindTexture(i, 0); - } - - public static void resetTextureSlot() { - GlStateManager._activeTexture(GL_TEXTURE0); - } - - public static void generateMipmap(int target) { - glGenerateMipmap(target); - } - - public static void textureParam(int target, int pname, float param) { - GlStateManager._texParameter(target, pname, param); - } -} diff --git a/src/main/java/cn/pupperclient/shader/VertexFormatElements.java b/src/main/java/cn/pupperclient/shader/VertexFormatElements.java new file mode 100644 index 0000000..d2690d7 --- /dev/null +++ b/src/main/java/cn/pupperclient/shader/VertexFormatElements.java @@ -0,0 +1,28 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package cn.pupperclient.shader; + +import com.mojang.blaze3d.vertex.VertexFormatElement; + +public abstract class VertexFormatElements { + public static final VertexFormatElement POS2 = VertexFormatElement.register(getNextVertexFormatElementId(), 0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.POSITION, 2); + + private VertexFormatElements() {} + + private static int getNextVertexFormatElementId() { + int id = 0; + + while (VertexFormatElement.byId(id) != null) { + id++; + + if (id >= 32) { + throw new RuntimeException("Too many mods registering VertexFormatElements"); + } + } + + return id; + } +} diff --git a/src/main/java/cn/pupperclient/shader/impl/Kawaseblur.java b/src/main/java/cn/pupperclient/shader/impl/Kawaseblur.java index dffeb86..dd4a676 100644 --- a/src/main/java/cn/pupperclient/shader/impl/Kawaseblur.java +++ b/src/main/java/cn/pupperclient/shader/impl/Kawaseblur.java @@ -1,14 +1,21 @@ package cn.pupperclient.shader.impl; -import cn.pupperclient.management.mod.impl.settings.SystemSettings; -import cn.pupperclient.shader.*; - -import cn.pupperclient.utils.TimerUtils; +import cn.pupperclient.shader.Framebuffer; +import cn.pupperclient.shader.MeshBuilder; +import cn.pupperclient.shader.PupperRenderPipelines; +import com.mojang.blaze3d.buffers.GpuBuffer; +import com.mojang.blaze3d.pipeline.RenderPipeline; +import com.mojang.blaze3d.systems.RenderPass; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.textures.GpuTexture; +import com.mojang.blaze3d.vertex.VertexFormat; import it.unimi.dsi.fastutil.ints.IntDoubleImmutablePair; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.VertexFormats; -public class Kawaseblur { +import java.util.OptionalInt; +public class Kawaseblur { public static final Kawaseblur GUI_BLUR = new Kawaseblur(); public static final Kawaseblur INGAME_BLUR = new Kawaseblur(); @@ -21,10 +28,9 @@ public class Kawaseblur { IntDoubleImmutablePair.of(5, 4.5), IntDoubleImmutablePair.of(5, 5.25), IntDoubleImmutablePair.of(5, 6.25), IntDoubleImmutablePair.of(5, 7.25), IntDoubleImmutablePair.of(5, 8.5) }; - private static Shader shaderDown, shaderUp, shaderPassthrough; private final Framebuffer[] fbos = new Framebuffer[6]; - private final TimerUtils timer = new TimerUtils(); private boolean firstTick = true; + private MeshBuilder mesh; public void resize() { for (int i = 0; i < fbos.length; i++) { @@ -37,68 +43,94 @@ public void resize() { } public void draw(int radius) { - - if (shaderDown == null) { - shaderDown = new Shader("blur.vert", "blur_down.frag"); - shaderUp = new Shader("blur.vert", "blur_up.frag"); - shaderPassthrough = new Shader("passthrough.vert", "passthrough.frag"); - } - if (firstTick) { for (int i = 0; i < fbos.length; i++) { if (fbos[i] == null) { fbos[i] = new Framebuffer(1 / Math.pow(2, i)); } } - firstTick = false; - } - SystemSettings setting = SystemSettings.getInstance(); + // 创建全屏四边形网格,使用正确的顶点数据 + mesh = new MeshBuilder(VertexFormats.POSITION_TEXTURE, VertexFormat.DrawMode.TRIANGLES); + mesh.begin(); - if(setting.isFastBlur()) { - if (timer.delay(16)) { - timer.reset(); - } else { - return; - } + // 顶点1: (-1, -1, 0) 纹理坐标: (0, 0) + mesh.vec3(-1, -1, 0).vec2(0, 0).next(); + + // 顶点2: (-1, 1, 0) 纹理坐标: (0, 1) + mesh.vec3(-1, 1, 0).vec2(0, 1).next(); + + // 顶点3: (1, 1, 0) 纹理坐标: (1, 1) + mesh.vec3(1, 1, 0).vec2(1, 1).next(); + + // 顶点4: (1, -1, 0) 纹理坐标: (1, 0) + mesh.vec3(1, -1, 0).vec2(1, 0).next(); + + mesh.quad(0, 1, 2, 3); + mesh.end(); + + firstTick = false; } - IntDoubleImmutablePair strength = STRENGTHS[(int) ((radius - 1))]; + IntDoubleImmutablePair strength = STRENGTHS[Math.min(radius - 1, STRENGTHS.length - 1)]; int iterations = strength.leftInt(); double offset = strength.rightDouble(); - PostProcessRenderer.beginRender(); + try (GpuBuffer vertexBuffer = mesh.createVertexBuffer(); GpuBuffer indexBuffer = mesh.createIndexBuffer()) { + // 第一遍:降采样 + renderToFbo(fbos[0], + MinecraftClient.getInstance().getFramebuffer().getColorAttachment(), + PupperRenderPipelines.BLUR_DOWN, + vertexBuffer, indexBuffer, offset); + + // 多次降采样 + for (int i = 0; i < iterations; i++) { + renderToFbo(fbos[i + 1], + fbos[i].getTexture(), + PupperRenderPipelines.BLUR_DOWN, + vertexBuffer, indexBuffer, offset); + } - renderToFbo(fbos[0], MinecraftClient.getInstance().getFramebuffer().getColorAttachment(), shaderDown, - offset); + // 多次上采样 + for (int i = iterations; i >= 1; i--) { + renderToFbo(fbos[i - 1], + fbos[i].getTexture(), + PupperRenderPipelines.BLUR_UP, + vertexBuffer, indexBuffer, offset); + } - for (int i = 0; i < iterations; i++) { - renderToFbo(fbos[i + 1], fbos[i].texture, shaderDown, offset); - } + // 最终绘制到屏幕 + RenderPass pass = RenderSystem.getDevice().createCommandEncoder() + .createRenderPass(MinecraftClient.getInstance().getFramebuffer().getColorAttachment(), OptionalInt.empty()); - for (int i = iterations; i >= 1; i--) { - renderToFbo(fbos[i - 1], fbos[i].texture, shaderUp, offset); - } + pass.setPipeline(PupperRenderPipelines.PASSTHROUGH); + pass.bindSampler("uTexture", fbos[0].getTexture()); + pass.setVertexBuffer(0, vertexBuffer); + pass.setIndexBuffer(indexBuffer, VertexFormat.IndexType.INT); + pass.drawIndexed(0, mesh.getIndicesCount()); + pass.close(); - MinecraftClient.getInstance().getFramebuffer().beginWrite(true); - shaderPassthrough.bind(); - ShaderHelper.bindTexture(fbos[0].texture); - shaderPassthrough.set("uTexture", 0); - PostProcessRenderer.endRender(); + } } - public int getTexture() { - return fbos[0].texture; + private void renderToFbo(Framebuffer target, GpuTexture source, + RenderPipeline pipeline, + GpuBuffer vertexBuffer, GpuBuffer indexBuffer, + double offset) { + RenderPass pass = RenderSystem.getDevice().createCommandEncoder() + .createRenderPass(target.getTexture(), OptionalInt.empty()); + + pass.setPipeline(pipeline); + pass.bindSampler("uTexture", source); + pass.setUniform("uHalfTexelSize", 0.5f / target.getTexture().getWidth(0), 0.5f / target.getTexture().getHeight(0)); + pass.setUniform("uOffset", (float) offset); + pass.setVertexBuffer(0, vertexBuffer); + pass.setIndexBuffer(indexBuffer, VertexFormat.IndexType.INT); + pass.drawIndexed(0, mesh.getIndicesCount()); + pass.close(); } - private void renderToFbo(Framebuffer targetFbo, int sourceText, Shader shader, double offset) { - targetFbo.bind(); - targetFbo.setViewport(); - shader.bind(); - ShaderHelper.bindTexture(sourceText); - shader.set("uTexture", 0); - shader.set("uHalfTexelSize", .5 / targetFbo.width, .5 / targetFbo.height); - shader.set("uOffset", offset); - PostProcessRenderer.render(); + public GpuTexture getTexture() { + return fbos[0].getTexture(); } } diff --git a/src/main/java/cn/pupperclient/skia/context/SkiaContext.java b/src/main/java/cn/pupperclient/skia/context/SkiaContext.java index 3167791..52f19d8 100644 --- a/src/main/java/cn/pupperclient/skia/context/SkiaContext.java +++ b/src/main/java/cn/pupperclient/skia/context/SkiaContext.java @@ -2,92 +2,84 @@ import java.util.function.Consumer; +import com.mojang.blaze3d.opengl.GlConst; +import com.mojang.blaze3d.opengl.GlStateManager; +import io.github.humbleui.skija.*; +import net.minecraft.client.gl.Framebuffer; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL33; -import com.mojang.blaze3d.platform.GlConst; import com.mojang.blaze3d.systems.RenderSystem; -import io.github.humbleui.skija.BackendRenderTarget; -import io.github.humbleui.skija.Canvas; -import io.github.humbleui.skija.ColorSpace; -import io.github.humbleui.skija.DirectContext; -import io.github.humbleui.skija.Surface; -import io.github.humbleui.skija.SurfaceColorFormat; -import io.github.humbleui.skija.SurfaceOrigin; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.BufferRenderer; - public class SkiaContext { - private static DirectContext context = null; - private static Surface surface; - private static BackendRenderTarget renderTarget; - - public static Canvas getCanvas() { - return surface.getCanvas(); - } - - public static void createSurface(int width, int height) { - - if (context == null) { - context = DirectContext.makeGL(); - } - - if (surface != null) { - surface.close(); - surface = null; - } - - if (renderTarget != null) { - renderTarget.close(); - renderTarget = null; - } - - renderTarget = BackendRenderTarget.makeGL(width, height, 0, 8, - MinecraftClient.getInstance().getFramebuffer().fbo, GL11.GL_RGBA8); - surface = Surface.wrapBackendRenderTarget(context, renderTarget, SurfaceOrigin.BOTTOM_LEFT, - SurfaceColorFormat.RGBA_8888, ColorSpace.getSRGB()); - } - - public static void draw(Consumer drawingLogic) { - - RenderSystem.pixelStore(GlConst.GL_UNPACK_ROW_LENGTH, 0); - RenderSystem.pixelStore(GlConst.GL_UNPACK_SKIP_PIXELS, 0); - RenderSystem.pixelStore(GlConst.GL_UNPACK_SKIP_ROWS, 0); - RenderSystem.pixelStore(GlConst.GL_UNPACK_ALIGNMENT, 4); - RenderSystem.clearColor(0f, 0f, 0f, 0f); - context.resetGLAll(); - - Canvas canvas = getCanvas(); - drawingLogic.accept(canvas); - - context.flush(); - - BufferRenderer.reset(); - GL33.glBindSampler(0, 0); - RenderSystem.disableBlend(); - GL11.glDisable(GL11.GL_BLEND); - RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); - RenderSystem.blendEquation(GL33.GL_FUNC_ADD); - GL33.glBlendEquation(GL33.GL_FUNC_ADD); - RenderSystem.colorMask(true, true, true, true); - GL11.glColorMask(true, true, true, true); - RenderSystem.depthMask(true); - GL11.glDepthMask(true); - RenderSystem.disableScissor(); - GL11.glDisable(GL11.GL_SCISSOR_TEST); - GL11.glDisable(GL11.GL_STENCIL_TEST); - RenderSystem.disableDepthTest(); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL13.glActiveTexture(GL13.GL_TEXTURE0); - RenderSystem.activeTexture(GL13.GL_TEXTURE0); - RenderSystem.disableCull(); - } - - public static DirectContext getContext() { - return context; - } + private static DirectContext context = null; + private static Surface surface; + private static BackendRenderTarget renderTarget; + + public static Canvas getCanvas() { + return surface.getCanvas(); + } + + public static void createSurface(int width, int height) { + + if (context == null) { + context = DirectContext.makeGL(); + } + + if (surface != null) { + surface.close(); + surface = null; + } + + if (renderTarget != null) { + renderTarget.close(); + renderTarget = null; + } + + renderTarget = BackendRenderTarget.makeGL(width, height, 0, 8, + Framebuffer.index, GL11.GL_RGBA8); + surface = Surface.wrapBackendRenderTarget(context, renderTarget, SurfaceOrigin.BOTTOM_LEFT, + SurfaceColorFormat.BGRA_8888, ColorSpace.getSRGB()); + } + + public static void draw(Consumer drawingLogic) { + + GlStateManager._pixelStore(GlConst.GL_UNPACK_ROW_LENGTH, 0); + GlStateManager._pixelStore(GlConst.GL_UNPACK_SKIP_PIXELS, 0); + GlStateManager._pixelStore(GlConst.GL_UNPACK_SKIP_ROWS, 0); + GlStateManager._pixelStore(GlConst.GL_UNPACK_ALIGNMENT, 4); + GL11.glClearColor(0f, 0f, 0f, 0f); + context.resetGLAll(); + + Canvas canvas = getCanvas(); + drawingLogic.accept(canvas); + + context.flush(); + + GlStateManager._glBindVertexArray(0); + + GL33.glBindSampler(0, 0); + GlStateManager._disableBlend(); + GL11.glDisable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + GL33.glBlendEquation(GL33.GL_FUNC_ADD); + GlStateManager._colorMask(true, true, true, true); + GL11.glColorMask(true, true, true, true); + GlStateManager._depthMask(true); + GL11.glDepthMask(true); + RenderSystem.disableScissor(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + GL11.glDisable(GL11.GL_STENCIL_TEST); + GlStateManager._disableDepthTest(); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + GlStateManager._activeTexture(GL13.GL_TEXTURE0); + GlStateManager._disableCull(); + } + + public static DirectContext getContext() { + return context; + } } diff --git a/src/main/java/cn/pupperclient/skia/image/ImageHelper.java b/src/main/java/cn/pupperclient/skia/image/ImageHelper.java index 3ea6054..a403ae4 100644 --- a/src/main/java/cn/pupperclient/skia/image/ImageHelper.java +++ b/src/main/java/cn/pupperclient/skia/image/ImageHelper.java @@ -1,19 +1,8 @@ package cn.pupperclient.skia.image; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.lwjgl.opengl.GL11; - import cn.pupperclient.skia.context.SkiaContext; import cn.pupperclient.skia.utils.SkiaUtils; - +import cn.pupperclient.utils.ImageUtils; import io.github.humbleui.skija.ColorType; import io.github.humbleui.skija.Image; import io.github.humbleui.skija.SurfaceOrigin; @@ -21,96 +10,111 @@ import net.minecraft.resource.Resource; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; +import org.lwjgl.opengl.GL11; + +import java.io.*; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; public class ImageHelper { - private Map images = new HashMap<>(); - private Map textures = new HashMap<>(); - - public boolean load(int texture, float width, float height, SurfaceOrigin origin) { - - if (!textures.containsKey(texture)) { - Image image = Image.adoptGLTextureFrom(SkiaContext.getContext(), texture, GL11.GL_TEXTURE_2D, (int) width, - (int) height, GL11.GL_RGBA8, origin, ColorType.RGBA_8888); - textures.put(texture, image); - } - - return true; - } - - public boolean load(Identifier identifier) { - - if (!images.containsKey(identifier.getPath())) { - ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager(); - Resource resource; - try { - resource = resourceManager.getResourceOrThrow(identifier); - try (InputStream inputStream = resource.getInputStream()) { - - byte[] imageData = inputStream.readAllBytes(); - Image image = Image.makeDeferredFromEncodedBytes(imageData); - if (image == null) { - return false; - } - images.put(identifier.getPath(), image); - return true; - } catch (IOException e) { - e.printStackTrace(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - - } - return true; - } - - public boolean load(String filePath) { - if (!images.containsKey(filePath)) { - Optional encodedBytes = SkiaUtils.convertToBytes(filePath); - if (encodedBytes.isPresent()) { - images.put(filePath, Image.makeDeferredFromEncodedBytes(encodedBytes.get())); - return true; - } else { - return false; - } - } - return true; - } - - public boolean load(File file) { - - if (!images.containsKey(file.getName())) { - - try { - byte[] encoded = org.apache.commons.io.IOUtils.toByteArray(new FileInputStream(file)); - images.put(file.getName(), Image.makeDeferredFromEncodedBytes(encoded)); - return true; - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } - - return true; - } - - public Image get(String path) { - - if (images.containsKey(path)) { - return images.get(path); - } - - return null; - } - - public Image get(int texture) { - - if (textures.containsKey(texture)) { - return textures.get(texture); - } - - return null; - } + private final Map images = new HashMap<>(); + private final Map textures = new HashMap<>(); + + public boolean load(int texture, float width, float height, SurfaceOrigin origin) { + + if (!textures.containsKey(texture)) { + Image image = Image.adoptGLTextureFrom(SkiaContext.getContext(), texture, GL11.GL_TEXTURE_2D, (int) width, + (int) height, GL11.GL_RGBA8, origin, ColorType.RGBA_8888); + textures.put(texture, image); + } + + return true; + } + + public boolean load(Identifier identifier) { + + if (!images.containsKey(identifier.getPath())) { + ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager(); + Resource resource; + try { + resource = resourceManager.getResourceOrThrow(identifier); + try (InputStream inputStream = resource.getInputStream()) { + + byte[] imageData = inputStream.readAllBytes(); + Image image = Image.makeDeferredFromEncodedBytes(imageData); + images.put(identifier.getPath(), image); + return true; + } catch (IOException e) { + e.printStackTrace(); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + + } + return true; + } + + public boolean load(String filePath) { + if (!images.containsKey(filePath)) { + Optional encodedBytes = SkiaUtils.convertToBytes(filePath); + if (encodedBytes.isPresent()) { + Image image; + try { + image = Image.makeDeferredFromEncodedBytes(ImageUtils.convertToPng(encodedBytes.get())); + } catch (IOException e) { + return false; + } + images.put(filePath, image); + return true; + } else { + return false; + } + } + return true; + } + + public boolean load(File file) { + + if (!images.containsKey(file.getName())) { + + try { + byte[] encoded = org.apache.commons.io.IOUtils.toByteArray(new FileInputStream(file)); + Image image; + try { + image = Image.makeDeferredFromEncodedBytes(ImageUtils.convertToPng(encoded)); + } catch (IOException e) { + return false; + } + images.put(file.getName(), image); + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + + return true; + } + + public Image get(String path) { + + if (images.containsKey(path)) { + return images.get(path); + } + + return null; + } + + public Image get(int texture) { + + if (textures.containsKey(texture)) { + return textures.get(texture); + } + + return null; + } } diff --git a/src/main/java/cn/pupperclient/utils/ImageUtils.java b/src/main/java/cn/pupperclient/utils/ImageUtils.java index cda9733..b5245d4 100644 --- a/src/main/java/cn/pupperclient/utils/ImageUtils.java +++ b/src/main/java/cn/pupperclient/utils/ImageUtils.java @@ -1,39 +1,65 @@ package cn.pupperclient.utils; -import java.awt.Color; +import javax.imageio.ImageIO; +import java.awt.*; import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; public class ImageUtils { - public static Color calculateAverageColor(BufferedImage image) { - long totalRed = 0; - long totalGreen = 0; - long totalBlue = 0; - int width = image.getWidth(); - int height = image.getHeight(); - int totalPixels = width * height; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Color pixelColor = new Color(image.getRGB(x, y)); - totalRed += pixelColor.getRed(); - totalGreen += pixelColor.getGreen(); - totalBlue += pixelColor.getBlue(); - } - } - - int averageRed = (int) (totalRed / totalPixels); - int averageGreen = (int) (totalGreen / totalPixels); - int averageBlue = (int) (totalBlue / totalPixels); - - return new Color(averageRed, averageGreen, averageBlue); - } - - public static int[] imageToPixels(BufferedImage image) { - - int width = image.getWidth(); - int height = image.getHeight(); - - return image.getRGB(0, 0, width, height, null, 0, width); - } + public static Color calculateAverageColor(BufferedImage image) { + long totalRed = 0; + long totalGreen = 0; + long totalBlue = 0; + int width = image.getWidth(); + int height = image.getHeight(); + int totalPixels = width * height; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + Color pixelColor = new Color(image.getRGB(x, y)); + totalRed += pixelColor.getRed(); + totalGreen += pixelColor.getGreen(); + totalBlue += pixelColor.getBlue(); + } + } + + int averageRed = (int) (totalRed / totalPixels); + int averageGreen = (int) (totalGreen / totalPixels); + int averageBlue = (int) (totalBlue / totalPixels); + + return new Color(averageRed, averageGreen, averageBlue); + } + + public static int[] imageToPixels(BufferedImage image) { + + int width = image.getWidth(); + int height = image.getHeight(); + + return image.getRGB(0, 0, width, height, null, 0, width); + } + + + public static byte[] convertToPng(byte[] bytes) throws IOException { + BufferedImage image = createImageFromBytes(bytes); + if (image == null) { + return bytes; + } + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageIO.write(image, "png", outputStream); + return outputStream.toByteArray(); + } + + public static BufferedImage createImageFromBytes(byte[] imageData) { + ByteArrayInputStream bais = new ByteArrayInputStream(imageData); + try { + return ImageIO.read(bais); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/main/java/cn/pupperclient/utils/Unstable.java b/src/main/java/cn/pupperclient/utils/Unstable.java new file mode 100644 index 0000000..ec1e67f --- /dev/null +++ b/src/main/java/cn/pupperclient/utils/Unstable.java @@ -0,0 +1,12 @@ +package cn.pupperclient.utils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Unstable { + String reason() default ""; +} diff --git a/src/main/java/cn/pupperclient/utils/mouse/ScrollHelper.java b/src/main/java/cn/pupperclient/utils/mouse/ScrollHelper.java index 52d9adf..3edb892 100644 --- a/src/main/java/cn/pupperclient/utils/mouse/ScrollHelper.java +++ b/src/main/java/cn/pupperclient/utils/mouse/ScrollHelper.java @@ -13,7 +13,7 @@ public ScrollHelper() { } public void onScroll(double amount) { - scroll += amount * 60; + scroll += (float) (amount * 60); } public void onUpdate() { diff --git a/src/main/java/cn/pupperclient/utils/server/ServerUtils.java b/src/main/java/cn/pupperclient/utils/server/ServerUtils.java index 2bb082e..0c2c8fe 100644 --- a/src/main/java/cn/pupperclient/utils/server/ServerUtils.java +++ b/src/main/java/cn/pupperclient/utils/server/ServerUtils.java @@ -2,9 +2,11 @@ import net.minecraft.client.MinecraftClient; +import java.util.Objects; + public class ServerUtils { - private static MinecraftClient client = MinecraftClient.getInstance(); + private static final MinecraftClient client = MinecraftClient.getInstance(); public static boolean isJoin(Server server) { return isMultiplayer() && getAddress().contains(server.getAddress()); @@ -19,6 +21,6 @@ public static boolean isMultiplayer() { } public static String getAddress() { - return isMultiplayer() ? client.getCurrentServerEntry().address : "null"; + return isMultiplayer() ? Objects.requireNonNull(client.getCurrentServerEntry()).address : "null"; } } diff --git a/src/main/resources/assets/pupper/shaders/blur_down.frag b/src/main/resources/assets/pupper/shaders/blur_down.frag index 7f49298..acb880c 100644 --- a/src/main/resources/assets/pupper/shaders/blur_down.frag +++ b/src/main/resources/assets/pupper/shaders/blur_down.frag @@ -9,11 +9,6 @@ uniform sampler2D uTexture; uniform vec2 uHalfTexelSize; uniform float uOffset; -vec4 safeTexture2D(sampler2D tex, vec2 uv) { - uv = clamp(uv, 0.001, 0.999); // 防止在边缘采样 - return texture(tex, uv); -} - void main() { color = ( texture(uTexture, uv) * 4 + @@ -24,4 +19,3 @@ void main() { ) / 8; color.a = 1; } - diff --git a/src/main/resources/assets/pupper/shaders/blur_up.frag b/src/main/resources/assets/pupper/shaders/blur_up.frag index dfd8931..28a006d 100644 --- a/src/main/resources/assets/pupper/shaders/blur_up.frag +++ b/src/main/resources/assets/pupper/shaders/blur_up.frag @@ -9,11 +9,6 @@ uniform sampler2D uTexture; uniform vec2 uHalfTexelSize; uniform float uOffset; -vec4 safeTexture2D(sampler2D tex, vec2 uv) { - uv = clamp(uv, 0.001, 0.999); // 防止在边缘采样 - return texture(tex, uv); -} - void main() { color = ( texture(uTexture, uv + vec2(- uHalfTexelSize.x * 2, 0) * uOffset) + @@ -27,4 +22,3 @@ void main() { ) / 12; color.a = 1; } - diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index fce97ca..24e992c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,7 +21,7 @@ "depends": { "fabricloader": ">=0.16.10", "fabric": "*", - "minecraft": "1.21.4", + "minecraft": "1.21.5", "viafabricplus": "*", "ias": "*" }, diff --git a/src/main/resources/pupper.accesswidener b/src/main/resources/pupper.accesswidener index 8d73f3a..4ea2f24 100644 --- a/src/main/resources/pupper.accesswidener +++ b/src/main/resources/pupper.accesswidener @@ -36,3 +36,8 @@ accessible method net/minecraft/client/render/entity/LivingEntityRenderer addFea accessible field net/minecraft/client/render/entity/EntityRenderDispatcher renderers Ljava/util/Map; accessible field net/minecraft/client/render/entity/LivingEntityRenderer features Ljava/util/List; accessible field net/minecraft/client/render/entity/EntityRenderDispatcher modelRenderers Ljava/util/Map; + +accessible method com/mojang/blaze3d/pipeline/RenderPipeline$Builder ()V +accessible method com/mojang/blaze3d/pipeline/RenderPipeline$Builder withSnippet (Lcom/mojang/blaze3d/pipeline/RenderPipeline$Snippet;)V + +accessible field net/minecraft/client/gl/Framebuffer index I diff --git a/src/main/resources/pupper.mixins.json b/src/main/resources/pupper.mixins.json index 0b4d894..17dfd8a 100644 --- a/src/main/resources/pupper.mixins.json +++ b/src/main/resources/pupper.mixins.json @@ -15,7 +15,6 @@ "minecraft.client.gui.MixinSplashScreen", "minecraft.client.gui.MixinTitleScreen", "minecraft.client.option.MixinKeyBinding", - "minecraft.client.render.BufferRendererAccessor", "minecraft.client.render.MixinCamera", "minecraft.client.render.MixinEntityRenderer", "minecraft.client.render.MixinGameRenderer",