aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-25 20:28:34 -0400
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-25 20:28:34 -0400
commit6c8b6dfa0186c0a50f28562c718a237336b8dfb4 (patch)
tree8bed7c410cfb9f0d6db57d720f54f6f485c7a67d /src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java
parent44a35dee12a033cfbaf14801d412a3359a065628 (diff)
downloadSkyblocker-6c8b6dfa0186c0a50f28562c718a237336b8dfb4.tar.gz
Skyblocker-6c8b6dfa0186c0a50f28562c718a237336b8dfb4.tar.bz2
Skyblocker-6c8b6dfa0186c0a50f28562c718a237336b8dfb4.zip
Refactor Backpack Preview
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java')
-rw-r--r--src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java
index e65bc576..597faa3d 100644
--- a/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java
+++ b/src/main/java/de/hysky/skyblocker/mixin/HandledScreenMixin.java
@@ -41,15 +41,15 @@ import java.util.regex.Matcher;
@Mixin(HandledScreen.class)
public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen {
/**
- * This is the slot id returned for when a click is outside of the screen's bounds
+ * This is the slot id returned for when a click is outside the screen's bounds
*/
@Unique
private static final int OUT_OF_BOUNDS_SLOT = -999;
-
+
@Shadow
@Nullable
protected Slot focusedSlot;
-
+
@Shadow
@Final
protected T handler;
@@ -78,7 +78,7 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
// Backpack Preview
boolean shiftDown = SkyblockerConfigManager.get().general.backpackPreviewWithoutShift ^ Screen.hasShiftDown();
- if (shiftDown && getTitle().getString().equals("Storage") && focusedSlot.inventory != client.player.getInventory() && BackpackPreview.renderPreview(context, focusedSlot.getIndex(), x, y)) {
+ if (shiftDown && getTitle().getString().equals("Storage") && focusedSlot.inventory != client.player.getInventory() && BackpackPreview.renderPreview(context, this, focusedSlot.getIndex(), x, y)) {
ci.cancel();
}
@@ -133,21 +133,21 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
}
}
}
-
+
/**
* The naming of this method in yarn is half true, its mostly to handle slot/item interactions (which are mouse or keyboard clicks)
* For example, using the drop key bind while hovering over an item will invoke this method to drop the players item
*/
@Inject(method = "onMouseClick(Lnet/minecraft/screen/slot/Slot;IILnet/minecraft/screen/slot/SlotActionType;)V", at = @At("HEAD"), cancellable = true)
private void skyblocker$onSlotInteract(Slot slot, int slotId, int button, SlotActionType actionType, CallbackInfo ci) {
- if (Utils.isOnSkyblock()) {
+ if (Utils.isOnSkyblock()) {
// When you try and drop the item by picking it up then clicking outside of the screen
if (slotId == OUT_OF_BOUNDS_SLOT) {
ItemStack cursorStack = this.handler.getCursorStack();
if (ItemProtection.isItemProtected(cursorStack)) ci.cancel();
}
-
+
if (slot != null) {
// When you click your drop key while hovering over an item
if (actionType == SlotActionType.THROW) {
@@ -155,35 +155,36 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
if (ItemProtection.isItemProtected(stack)) ci.cancel();
}
-
+
//Prevent salvaging
if (this.getTitle().getString().equals("Salvage Items")) {
ItemStack stack = slot.getStack();
if (ItemProtection.isItemProtected(stack)) ci.cancel();
}
-
+
//Prevent selling to NPC shops
if (this.client != null && this.handler instanceof GenericContainerScreenHandler genericContainerScreenHandler && genericContainerScreenHandler.getRows() == 6) {
ItemStack sellItem = this.handler.slots.get(49).getStack();
-
+
if (sellItem.getName().getString().equals("Sell Item") || skyblocker$doesLoreContain(sellItem, this.client, "buyback")) {
ItemStack stack = slot.getStack();
-
+
if (ItemProtection.isItemProtected(stack)) ci.cancel();
}
}
}
- }
+ }
}
-
+
//TODO make this a util method somewhere else, eventually
private static boolean skyblocker$doesLoreContain(ItemStack stack, MinecraftClient client, String searchString) {
return stack.getTooltip(client.player, TooltipContext.BASIC).stream().map(Text::getString).anyMatch(line -> line.contains(searchString));
}
-
+
@Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawItem(Lnet/minecraft/item/ItemStack;III)V"))
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);
+ if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().general.itemInfoDisplay.itemRarityBackgrounds)
+ ItemRarityBackgrounds.tryDraw(slot.getStack(), context, slot.x, slot.y);
}
}