|
| 1 | +// skidded by ___hj from skid hack |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +package com.nerds.addon.mixin; |
| 6 | + |
| 7 | +import net.minecraft.text.Text; |
| 8 | +import org.jetbrains.annotations.Nullable; |
| 9 | +import com.nerds.addon.modules.Loadouts; |
| 10 | +import org.spongepowered.asm.mixin.Mixin; |
| 11 | +import org.spongepowered.asm.mixin.Unique; |
| 12 | +import net.minecraft.client.gui.tooltip.Tooltip; |
| 13 | +import org.spongepowered.asm.mixin.injection.At; |
| 14 | +import net.minecraft.screen.PlayerScreenHandler; |
| 15 | +import net.minecraft.entity.player.PlayerInventory; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import net.minecraft.client.gui.widget.ButtonWidget; |
| 18 | +import net.minecraft.client.gui.screen.ingame.InventoryScreen; |
| 19 | +import meteordevelopment.meteorclient.systems.modules.Modules; |
| 20 | +import net.minecraft.client.gui.screen.ingame.RecipeBookScreen; |
| 21 | +import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; |
| 22 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 23 | +import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; |
| 24 | + |
| 25 | + |
| 26 | +@Mixin(InventoryScreen.class) |
| 27 | +public abstract class InventoryScreenMixin extends RecipeBookScreen<PlayerScreenHandler> |
| 28 | + implements RecipeBookProvider { |
| 29 | + |
| 30 | + public InventoryScreenMixin(PlayerScreenHandler handler, RecipeBookWidget<?> recipeBook, PlayerInventory inventory, Text title) { |
| 31 | + super(handler, recipeBook, inventory, title); |
| 32 | + } |
| 33 | + |
| 34 | + @Unique @Nullable |
| 35 | + private Loadouts loadouts = null; |
| 36 | + |
| 37 | + @Unique @Nullable |
| 38 | + private ButtonWidget saveLoadoutButton = null; |
| 39 | + |
| 40 | + @Unique @Nullable |
| 41 | + private ButtonWidget loadLoadoutButton = null; |
| 42 | + |
| 43 | + @Unique |
| 44 | + private void onSaveLoadoutButtonPress(ButtonWidget btn) { |
| 45 | + if (loadouts == null) { |
| 46 | + Modules modules = Modules.get(); |
| 47 | + if (modules == null) return; |
| 48 | + loadouts = modules.get(Loadouts.class); |
| 49 | + if (loadouts == null) return; |
| 50 | + } |
| 51 | + loadouts.saveLoadout("quicksave"); |
| 52 | + btn.setMessage(Text.literal("§6§o✨§fSave")); |
| 53 | + } |
| 54 | + |
| 55 | + @Unique |
| 56 | + private void onLoadLoadoutButtonPress(ButtonWidget btn) { |
| 57 | + if (loadouts == null) { |
| 58 | + Modules modules = Modules.get(); |
| 59 | + if (modules == null) return; |
| 60 | + loadouts = modules.get(Loadouts.class); |
| 61 | + if (loadouts == null) return; |
| 62 | + } |
| 63 | + loadouts.loadLoadout("quicksave"); |
| 64 | + btn.setMessage(Text.literal("Load§6§o✨")); |
| 65 | + } |
| 66 | + |
| 67 | + @Inject(method = "init", at = @At("TAIL")) |
| 68 | + private void mixinInit(CallbackInfo ci) { |
| 69 | + if (loadouts == null) { |
| 70 | + Modules modules = Modules.get(); |
| 71 | + if (modules == null) return; |
| 72 | + loadouts = modules.get(Loadouts.class); |
| 73 | + if (loadouts == null) return; |
| 74 | + } |
| 75 | + |
| 76 | + if (!loadouts.quickLoadout.get()) return; |
| 77 | + saveLoadoutButton = this.addDrawableChild( |
| 78 | + ButtonWidget.builder( |
| 79 | + Text.literal("§6§o✨§fSave"), |
| 80 | + btn -> onSaveLoadoutButtonPress(btn) |
| 81 | + ) |
| 82 | + .dimensions(this.width / 2 - 42, this.height / 2 + 83, 42, 16) |
| 83 | + .tooltip(Tooltip.of(Text.literal("§7§oSave your current inventory to Loadouts."))) |
| 84 | + .build() |
| 85 | + ); |
| 86 | + |
| 87 | + loadLoadoutButton = this.addDrawableChild( |
| 88 | + ButtonWidget.builder( |
| 89 | + Text.literal("Load§6§o✨"), |
| 90 | + btn -> onLoadLoadoutButtonPress(btn) |
| 91 | + ) |
| 92 | + .dimensions(this.width / 2, this.height / 2 + 83, 42, 16) |
| 93 | + .tooltip(Tooltip.of(Text.literal("§7§oLoad your quicksave loadout."))) |
| 94 | + .build() |
| 95 | + ); |
| 96 | + |
| 97 | + if (saveLoadoutButton != null) saveLoadoutButton.visible = loadouts.isActive(); |
| 98 | + if (loadLoadoutButton != null) loadLoadoutButton.visible = loadouts.isActive(); |
| 99 | + } |
| 100 | + |
| 101 | + @Inject(method = "render", at = @At("TAIL")) |
| 102 | + private void mixinRender(CallbackInfo ci) { |
| 103 | + if (loadouts == null) { |
| 104 | + Modules modules = Modules.get(); |
| 105 | + if (modules == null) return; |
| 106 | + loadouts = modules.get(Loadouts.class); |
| 107 | + if (loadouts == null) return; |
| 108 | + } |
| 109 | + |
| 110 | + if (!loadouts.quickLoadout.get()) return; |
| 111 | + if (saveLoadoutButton != null) saveLoadoutButton.visible = loadouts.isActive(); |
| 112 | + if (loadLoadoutButton != null) loadLoadoutButton.visible = loadouts.isActive(); |
| 113 | + } |
| 114 | + |
| 115 | + @Inject(method = "handledScreenTick", at = @At("HEAD")) |
| 116 | + private void animateButtons(CallbackInfo ci) { |
| 117 | + if (loadouts == null) { |
| 118 | + Modules modules = Modules.get(); |
| 119 | + if (modules == null) return; |
| 120 | + loadouts = modules.get(Loadouts.class); |
| 121 | + if (loadouts == null) return; |
| 122 | + } |
| 123 | + |
| 124 | + if (!loadouts.quickLoadout.get()) return; |
| 125 | + if (loadouts.isActive() && !loadouts.isSorted) { |
| 126 | + if (saveLoadoutButton != null) saveLoadoutButton.setMessage(Text.literal("§6§o✨§fSave")); |
| 127 | + if (loadLoadoutButton != null) loadLoadoutButton.setMessage(Text.literal("Load§6§o✨")); |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments