diff options
Diffstat (limited to 'src/main/java')
4 files changed, 68 insertions, 2 deletions
diff --git a/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java index 8a1af570..0c779ebe 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.mixin; import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.systems.RenderSystem; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.experiment.ChronomatronSolver; @@ -29,6 +30,7 @@ import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; @@ -52,6 +54,9 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen @Unique private static final int OUT_OF_BOUNDS_SLOT = -999; + @Unique + private static final Identifier ITEM_PROTECTION = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/item_protection.png"); + @Shadow @Nullable protected Slot focusedSlot; @@ -66,8 +71,15 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen @Inject(at = @At("HEAD"), method = "keyPressed") public void skyblocker$keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) { - if (this.client != null && this.focusedSlot != null && keyCode != 256 && !this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && WikiLookup.wikiLookup.matchesKey(keyCode, scanCode)) { - WikiLookup.openWiki(this.focusedSlot, client.player); + if (this.client != null && this.focusedSlot != null && keyCode != 256) { + //wiki lookup + if (!this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && WikiLookup.wikiLookup.matchesKey(keyCode, scanCode)) { + WikiLookup.openWiki(this.focusedSlot, client.player); + } + //item protection + if (!this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && ItemProtection.itemProtection.matchesKey(keyCode, scanCode)) { + ItemProtection.handleKeyPressed(this.focusedSlot.getStack()); + } } } @@ -207,5 +219,11 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen private void skyblocker$drawItemRarityBackground(DrawContext context, Slot slot, CallbackInfo ci) { if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().general.itemInfoDisplay.itemRarityBackgrounds) ItemRarityBackgrounds.tryDraw(slot.getStack(), context, slot.x, slot.y); + // Item protection + if (ItemProtection.isItemProtected(slot.getStack())){ + RenderSystem.enableBlend(); + context.drawTexture(ITEM_PROTECTION, slot.x, slot.y, 0, 0, 16, 16, 16, 16); + RenderSystem.disableBlend(); + } } } diff --git a/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java b/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java index 88be60cd..5e3daf3c 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java @@ -3,6 +3,7 @@ package de.hysky.skyblocker.mixin; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; import com.mojang.blaze3d.systems.RenderSystem; +import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.FancyStatusBars; import de.hysky.skyblocker.skyblock.dungeon.DungeonMap; @@ -10,6 +11,7 @@ import de.hysky.skyblocker.skyblock.dungeon.DungeonScore; import de.hysky.skyblocker.skyblock.dungeon.DungeonScoreHUD; import de.hysky.skyblocker.skyblock.item.HotbarSlotLock; import de.hysky.skyblocker.skyblock.item.ItemCooldowns; +import de.hysky.skyblocker.skyblock.item.ItemProtection; import de.hysky.skyblocker.skyblock.item.ItemRarityBackgrounds; import de.hysky.skyblocker.utils.Utils; import net.fabricmc.api.EnvType; @@ -38,6 +40,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public abstract class InGameHudMixin { @Unique private static final Supplier<Identifier> SLOT_LOCK_ICON = () -> SkyblockerConfigManager.get().general.itemProtection.slotLockStyle.tex; + + @Unique + private static final Identifier ITEM_PROTECTION = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/item_protection.png"); @Unique private static final Pattern DICER_TITLE_BLACKLIST = Pattern.compile(".+? DROP!"); @@ -56,12 +61,19 @@ public abstract class InGameHudMixin { @Inject(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;renderHotbarItem(Lnet/minecraft/client/gui/DrawContext;IIFLnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;I)V", ordinal = 0)) public void skyblocker$renderHotbarItemLockOrRarityBg(float tickDelta, DrawContext context, CallbackInfo ci, @Local(ordinal = 4, name = "m") int index, @Local(ordinal = 5, name = "n") int x, @Local(ordinal = 6, name = "o") int y, @Local PlayerEntity player) { if (Utils.isOnSkyblock()) { + // slot lock if (SkyblockerConfigManager.get().general.itemInfoDisplay.itemRarityBackgrounds) ItemRarityBackgrounds.tryDraw(player.getInventory().main.get(index), context, x, y); if (HotbarSlotLock.isLocked(index)) { RenderSystem.enableBlend(); context.drawTexture(SLOT_LOCK_ICON.get(), x, y, 0, 0, 16, 16, 16, 16); RenderSystem.disableBlend(); } + //item protection + if (ItemProtection.isItemProtected(player.getInventory().main.get(index))){ + RenderSystem.enableBlend(); + context.drawTexture(ITEM_PROTECTION, x, y, 0, 0, 16, 16, 16, 16); + RenderSystem.disableBlend(); + } } } diff --git a/src/main/java/de/hysky/skyblocker/mixin/MinecraftClientMixin.java b/src/main/java/de/hysky/skyblocker/mixin/MinecraftClientMixin.java index cf8aab78..dd671b2e 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/MinecraftClientMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixin/MinecraftClientMixin.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.mixin; import de.hysky.skyblocker.skyblock.item.HotbarSlotLock; +import de.hysky.skyblocker.skyblock.item.ItemProtection; import de.hysky.skyblocker.utils.JoinWorldPlaceholderScreen; import de.hysky.skyblocker.utils.ReconfiguringPlaceholderScreen; import de.hysky.skyblocker.utils.Utils; @@ -34,6 +35,7 @@ public abstract class MinecraftClientMixin { public void skyblocker$handleInputEvents(CallbackInfo ci) { if (Utils.isOnSkyblock()) { HotbarSlotLock.handleInputEvents(player); + ItemProtection.handleHotbarKeyPressed(player); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java index 2d929c28..5fc0fed5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java @@ -10,13 +10,23 @@ import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.option.KeyBinding; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; +import org.lwjgl.glfw.GLFW; public class ItemProtection { + public static KeyBinding itemProtection; public static void init() { + itemProtection = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.itemProtection", + GLFW.GLFW_KEY_V, + "key.categories.skyblocker" + )); ClientCommandRegistrationCallback.EVENT.register(ItemProtection::registerCommand); } @@ -61,4 +71,28 @@ public class ItemProtection { return Command.SINGLE_SUCCESS; } + + public static void handleKeyPressed(ItemStack heldItem) { + if (!Utils.isOnSkyblock() || heldItem.isEmpty()) return; + + String itemUuid = ItemUtils.getItemUuid(heldItem); + if (!itemUuid.isEmpty()) { + ObjectOpenHashSet<String> protectedItems = SkyblockerConfigManager.get().general.protectedItems; + + if (!protectedItems.contains(itemUuid)) { + protectedItems.add(itemUuid); + SkyblockerConfigManager.save(); + } else { + protectedItems.remove(itemUuid); + SkyblockerConfigManager.save(); + } + } + } + + public static void handleHotbarKeyPressed(ClientPlayerEntity player) { + while (itemProtection.wasPressed()) { + ItemStack heldItem = player.getMainHandStack(); + handleKeyPressed(heldItem); + } + } } |