aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionHouseScreenHandler.java
blob: 7df3cef5f2fa00ade5e2e22ff607181839df56e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package de.hysky.skyblocker.skyblock.auction;

import de.hysky.skyblocker.mixin.accessor.SlotAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;

public class AuctionHouseScreenHandler extends GenericContainerScreenHandler {
    public AuctionHouseScreenHandler(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, Inventory inventory, int rows, boolean isView) {
        super(type, syncId, playerInventory, inventory, rows);

        int yOffset = (rows - 4) * 18;
        // Shift player inventory by 2 pixels and also remove the yOffset
        for (int i = rows*9; i < slots.size(); i++) {
            Slot slot = slots.get(i);
            SlotAccessor slotAccessor = (SlotAccessor) slot;
            slotAccessor.setY(slot.y+2-yOffset);
        }

        if (isView) return;
        // disable ALL THE OTHER SLOTS MWAHAHAHA and also move the good ones around and stuff
        for (int i = 0; i < rows*9; i++) {
            int lineI = i % 9;
            Slot slot = slots.get(i);
            if (i>9 && i<(rows-1)*9 && lineI > 1 && lineI < 8) {
                int miniInventorySlot = lineI - 2 + (i/9 - 1)*6;
                SlotAccessor slotAccessor = (SlotAccessor) slot;
                slotAccessor.setX(8 + miniInventorySlot%8 * 18);
                slotAccessor.setY(18 + miniInventorySlot/8 * 18);
            } else {
                slots.set(i, new Slot(slot.inventory, slot.getIndex(), slot.x, slot.y){
                    @Override
                    public boolean isEnabled() {
                        return false;
                    }
                });
            }
        }
    }
    
    public static AuctionHouseScreenHandler of(GenericContainerScreenHandler original, boolean isView) {
        return new AuctionHouseScreenHandler(original.getType(),
                original.syncId,
                MinecraftClient.getInstance().player.getInventory(),
                original.getInventory(),
                original.getRows(),
                isView);
    }

    @Override
    public void setStackInSlot(int slot, int revision, ItemStack stack) {
        super.setStackInSlot(slot, revision, stack);
        onContentChanged(slots.get(slot).inventory);
    }
}