Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Часть функционала InventoryAnimation - Fabric 1.21+

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
2 Янв 2022
Сообщения
89
Реакции
3
Выберите загрузчик игры
  1. Fabric
Пожалуйста, авторизуйтесь для просмотра ссылки.


HandledScreen:
Expand Collapse Copy
package thunder.hack.injection;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import thunder.hack.features.modules.render.InventoryAnimation;
import thunder.hack.utility.render.Render2DEngine;
import thunder.hack.utility.render.animation.AnimationUtility;

import java.awt.Color;

@Mixin(HandledScreen.class)
public abstract class MixinInventoryAnimationScreen<T extends ScreenHandler> extends Screen {

    @Unique private float progress = 0f;
    @Unique private boolean closing = false;
    @Unique private boolean bypassClose = false;
    @Unique private boolean scheduledClose = false;
    @Unique private boolean pushed = false;
    @Unique private boolean cursorHidden = false;

    protected MixinInventoryAnimationScreen(Text title) {
        super(title);
    }

    @Unique
    private boolean isActive() {
        if (InventoryAnimation.INSTANCE == null || !InventoryAnimation.INSTANCE.isEnabled()) return false;
        if (Boolean.TRUE.equals(InventoryAnimation.INSTANCE.inventoryOnly.getValue()))
            return (Object) this instanceof InventoryScreen;
        return true;
    }

    @Unique
    private float easeOutCubic(float t) {
        t = Math.min(1f, Math.max(0f, t));
        return 1f - (float) Math.pow(1f - t, 3);
    }

    @Unique
    private float easeOutBack(float t) {
        t = Math.min(1f, Math.max(0f, t));
        float c1 = 1.70158f;
        float c3 = c1 + 1f;
        return 1f + c3 * (float) Math.pow(t - 1f, 3) + c1 * (float) Math.pow(t - 1f, 2);
    }

    @Unique
    private float applyEasing(float raw) {
        if (closing) return easeOutCubic(raw);
        return switch (InventoryAnimation.INSTANCE.animationType.getValue()) {
            case Bounce -> Math.max(0.001f, easeOutBack(raw));
            default     -> easeOutCubic(raw);
        };
    }

    @Unique
    private void applyTransform(DrawContext ctx, float v) {
        float cx = this.width / 2f;
        float cy = this.height / 2f;

        switch (InventoryAnimation.INSTANCE.animationType.getValue()) {
            case Scale, Bounce -> {
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(Math.max(0.001f, v), Math.max(0.001f, v), 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
            case SlideUp    -> ctx.getMatrices().translate(0.0,  this.height * (1.0 - v), 0.0);
            case SlideDown  -> ctx.getMatrices().translate(0.0, -this.height * (1.0 - v), 0.0);
            case SlideLeft  -> ctx.getMatrices().translate( this.width * (1.0 - v), 0.0, 0.0);
            case SlideRight -> ctx.getMatrices().translate(-this.width * (1.0 - v), 0.0, 0.0);
            case Flip -> {
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(Math.max(0.001f, v), 1f, 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
            case Warp -> {
                float scale = closing ? v : (1.15f - 0.15f * v);
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(Math.max(0.001f, scale), Math.max(0.001f, scale), 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
            case Glitch -> {
                float shake = (1f - v) * 35f * (float) Math.sin(v * 28f);
                float scale = 0.88f + 0.12f * v;
                ctx.getMatrices().translate(shake, 0.0, 0.0);
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(scale, scale, 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
        }
    }

    @Inject(method = "render", at = @At("HEAD"), cancellable = true)
    private void onRenderPre(DrawContext ctx, int mx, int my, float delta, CallbackInfo ci) {
        pushed = false;

        if (scheduledClose) {
            ci.cancel();
            return;
        }

        if (!isActive()) return;

        float speed = InventoryAnimation.INSTANCE.speed.getValue();

        if (closing) {
            progress = AnimationUtility.fast(progress, 0f, speed * 3f);

            if (progress < 0.05f && !cursorHidden) {
                cursorHidden = true;
                GLFW.glfwSetInputMode(this.client.getWindow().getHandle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
            }

            if (progress < 0.005f) {
                scheduledClose = true;
                bypassClose = true;
                GLFW.glfwSetInputMode(this.client.getWindow().getHandle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
                cursorHidden = false;
                this.client.execute(((Screen) (Object) this)::close);
                ci.cancel();
                return;
            }
        } else {
            progress = Math.min(1f, AnimationUtility.fast(progress, 1f, speed));
            if (progress >= 0.999f) return;
        }


        ctx.getMatrices().push();
        pushed = true;
        applyTransform(ctx, applyEasing(progress));
    }

    @Inject(method = "render", at = @At("TAIL"))
    private void onRenderPost(DrawContext ctx, int mx, int my, float delta, CallbackInfo ci) {
        if (pushed) {
            ctx.getMatrices().pop();
            pushed = false;
        }

        if (!isActive() || scheduledClose) return;
        if (progress >= 0.999f && !closing) return;

        float alpha = 1f - applyEasing(progress);
        if (alpha > 0.005f) {
            RenderSystem.disableDepthTest();
            Render2DEngine.drawRectDumbWay(ctx.getMatrices(), 0, 0, this.width, this.height,
                    new Color(0, 0, 0, Math.min(255, (int) (alpha * 255))));
            RenderSystem.enableDepthTest();
        }
    }

    @Inject(method = "close", at = @At("HEAD"), cancellable = true)
    private void onClose(CallbackInfo ci) {
        if (bypassClose) return;
        if (!isActive()) return;
        if (closing || scheduledClose) {
            ci.cancel();
            return;
        }
        if (progress > 0.05f) {
            closing = true;
            ci.cancel();
        }
    }
}

Module:
Expand Collapse Copy
package thunder.hack.features.modules.render;

import thunder.hack.features.modules.Module;
import thunder.hack.setting.Setting;

public class InventoryAnimation extends Module {

    public static InventoryAnimation INSTANCE;

    public enum AnimationType {
        Scale, Bounce,
        SlideUp, SlideDown, SlideLeft, SlideRight,
        Flip, Warp, Glitch
    }

    public final Setting<AnimationType> animationType = new Setting<>("Type", AnimationType.Scale);
    public final Setting<Float> speed = new Setting<>("Speed", 10.0f, 1.0f, 30.0f);
    public final Setting<Boolean> inventoryOnly = new Setting<>("InventoryOnly", false);

    public InventoryAnimation() {
        super("InventoryAnimation", Category.RENDER);
        INSTANCE = this;
    }
}
 
Пожалуйста, авторизуйтесь для просмотра ссылки.


HandledScreen:
Expand Collapse Copy
package thunder.hack.injection;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import thunder.hack.features.modules.render.InventoryAnimation;
import thunder.hack.utility.render.Render2DEngine;
import thunder.hack.utility.render.animation.AnimationUtility;

import java.awt.Color;

@Mixin(HandledScreen.class)
public abstract class MixinInventoryAnimationScreen<T extends ScreenHandler> extends Screen {

    @Unique private float progress = 0f;
    @Unique private boolean closing = false;
    @Unique private boolean bypassClose = false;
    @Unique private boolean scheduledClose = false;
    @Unique private boolean pushed = false;
    @Unique private boolean cursorHidden = false;

    protected MixinInventoryAnimationScreen(Text title) {
        super(title);
    }

    @Unique
    private boolean isActive() {
        if (InventoryAnimation.INSTANCE == null || !InventoryAnimation.INSTANCE.isEnabled()) return false;
        if (Boolean.TRUE.equals(InventoryAnimation.INSTANCE.inventoryOnly.getValue()))
            return (Object) this instanceof InventoryScreen;
        return true;
    }

    @Unique
    private float easeOutCubic(float t) {
        t = Math.min(1f, Math.max(0f, t));
        return 1f - (float) Math.pow(1f - t, 3);
    }

    @Unique
    private float easeOutBack(float t) {
        t = Math.min(1f, Math.max(0f, t));
        float c1 = 1.70158f;
        float c3 = c1 + 1f;
        return 1f + c3 * (float) Math.pow(t - 1f, 3) + c1 * (float) Math.pow(t - 1f, 2);
    }

    @Unique
    private float applyEasing(float raw) {
        if (closing) return easeOutCubic(raw);
        return switch (InventoryAnimation.INSTANCE.animationType.getValue()) {
            case Bounce -> Math.max(0.001f, easeOutBack(raw));
            default     -> easeOutCubic(raw);
        };
    }

    @Unique
    private void applyTransform(DrawContext ctx, float v) {
        float cx = this.width / 2f;
        float cy = this.height / 2f;

        switch (InventoryAnimation.INSTANCE.animationType.getValue()) {
            case Scale, Bounce -> {
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(Math.max(0.001f, v), Math.max(0.001f, v), 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
            case SlideUp    -> ctx.getMatrices().translate(0.0,  this.height * (1.0 - v), 0.0);
            case SlideDown  -> ctx.getMatrices().translate(0.0, -this.height * (1.0 - v), 0.0);
            case SlideLeft  -> ctx.getMatrices().translate( this.width * (1.0 - v), 0.0, 0.0);
            case SlideRight -> ctx.getMatrices().translate(-this.width * (1.0 - v), 0.0, 0.0);
            case Flip -> {
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(Math.max(0.001f, v), 1f, 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
            case Warp -> {
                float scale = closing ? v : (1.15f - 0.15f * v);
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(Math.max(0.001f, scale), Math.max(0.001f, scale), 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
            case Glitch -> {
                float shake = (1f - v) * 35f * (float) Math.sin(v * 28f);
                float scale = 0.88f + 0.12f * v;
                ctx.getMatrices().translate(shake, 0.0, 0.0);
                ctx.getMatrices().translate(cx, cy, 0.0);
                ctx.getMatrices().scale(scale, scale, 1f);
                ctx.getMatrices().translate(-cx, -cy, 0.0);
            }
        }
    }

    @Inject(method = "render", at = @At("HEAD"), cancellable = true)
    private void onRenderPre(DrawContext ctx, int mx, int my, float delta, CallbackInfo ci) {
        pushed = false;

        if (scheduledClose) {
            ci.cancel();
            return;
        }

        if (!isActive()) return;

        float speed = InventoryAnimation.INSTANCE.speed.getValue();

        if (closing) {
            progress = AnimationUtility.fast(progress, 0f, speed * 3f);

            if (progress < 0.05f && !cursorHidden) {
                cursorHidden = true;
                GLFW.glfwSetInputMode(this.client.getWindow().getHandle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
            }

            if (progress < 0.005f) {
                scheduledClose = true;
                bypassClose = true;
                GLFW.glfwSetInputMode(this.client.getWindow().getHandle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
                cursorHidden = false;
                this.client.execute(((Screen) (Object) this)::close);
                ci.cancel();
                return;
            }
        } else {
            progress = Math.min(1f, AnimationUtility.fast(progress, 1f, speed));
            if (progress >= 0.999f) return;
        }


        ctx.getMatrices().push();
        pushed = true;
        applyTransform(ctx, applyEasing(progress));
    }

    @Inject(method = "render", at = @At("TAIL"))
    private void onRenderPost(DrawContext ctx, int mx, int my, float delta, CallbackInfo ci) {
        if (pushed) {
            ctx.getMatrices().pop();
            pushed = false;
        }

        if (!isActive() || scheduledClose) return;
        if (progress >= 0.999f && !closing) return;

        float alpha = 1f - applyEasing(progress);
        if (alpha > 0.005f) {
            RenderSystem.disableDepthTest();
            Render2DEngine.drawRectDumbWay(ctx.getMatrices(), 0, 0, this.width, this.height,
                    new Color(0, 0, 0, Math.min(255, (int) (alpha * 255))));
            RenderSystem.enableDepthTest();
        }
    }

    @Inject(method = "close", at = @At("HEAD"), cancellable = true)
    private void onClose(CallbackInfo ci) {
        if (bypassClose) return;
        if (!isActive()) return;
        if (closing || scheduledClose) {
            ci.cancel();
            return;
        }
        if (progress > 0.05f) {
            closing = true;
            ci.cancel();
        }
    }
}

Module:
Expand Collapse Copy
package thunder.hack.features.modules.render;

import thunder.hack.features.modules.Module;
import thunder.hack.setting.Setting;

public class InventoryAnimation extends Module {

    public static InventoryAnimation INSTANCE;

    public enum AnimationType {
        Scale, Bounce,
        SlideUp, SlideDown, SlideLeft, SlideRight,
        Flip, Warp, Glitch
    }

    public final Setting<AnimationType> animationType = new Setting<>("Type", AnimationType.Scale);
    public final Setting<Float> speed = new Setting<>("Speed", 10.0f, 1.0f, 30.0f);
    public final Setting<Boolean> inventoryOnly = new Setting<>("InventoryOnly", false);

    public InventoryAnimation() {
        super("InventoryAnimation", Category.RENDER);
        INSTANCE = this;
    }
}
ник спалил кст
 
Назад
Сверху Снизу