-
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathSkyblockCraftingTableScreen.java
More file actions
139 lines (125 loc) · 6.38 KB
/
SkyblockCraftingTableScreen.java
File metadata and controls
139 lines (125 loc) · 6.38 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package de.hysky.skyblocker.skyblock.item;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.skyblock.itemlist.recipebook.SkyblockRecipeBookWidget;
import java.time.Duration;
import de.hysky.skyblocker.utils.render.texture.FallbackedTexture;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
public class SkyblockCraftingTableScreen extends AbstractContainerScreen<SkyblockCraftingTableScreenHandler> {
private static final FallbackedTexture<Identifier> TEXTURE = FallbackedTexture.ofTexture(
SkyblockerMod.id("textures/gui/container/skyblock_crafting_table.png"),
Identifier.withDefaultNamespace("textures/gui/container/crafting_table.png"));
private static final FallbackedTexture<Identifier> MIRRORVERSE_TEXTURE = FallbackedTexture.ofTexture(
SkyblockerMod.id("textures/gui/container/skyblock_crafting_table.png"),
Identifier.withDefaultNamespace("textures/gui/container/crafting_table.png"));
protected static final WidgetSprites MORE_CRAFTS_TEXTURES = new WidgetSprites(
SkyblockerMod.id("quick_craft/more_button"),
SkyblockerMod.id("quick_craft/more_button_disabled"),
SkyblockerMod.id("quick_craft/more_button_highlighted")
);
protected static final Identifier QUICK_CRAFT = SkyblockerMod.id("textures/gui/sprites/quick_craft/quick_craft_overlay.png");
private final SkyblockRecipeBookWidget recipeBook = new SkyblockRecipeBookWidget(menu);
private boolean narrow;
private ImageButton moreCraftsButton;
public SkyblockCraftingTableScreen(SkyblockCraftingTableScreenHandler handler, Inventory inventory, Component title) {
super(handler, inventory, title);
}
@Override
protected void init() {
super.init();
this.narrow = this.width < 379;
this.recipeBook.init(this.width, this.height, this.minecraft, this.narrow);
this.leftPos = this.recipeBook.updateScreenPosition(this.width, this.imageWidth);
this.addRenderableWidget(new ImageButton(this.leftPos + 5, this.height / 2 - 49, 20, 18, RecipeBookComponent.RECIPE_BUTTON_SPRITES, button -> {
this.recipeBook.toggleVisibility();
this.leftPos = this.recipeBook.updateScreenPosition(this.width, this.imageWidth);
button.setPosition(this.leftPos + 5, this.height / 2 - 49);
if (moreCraftsButton != null) moreCraftsButton.setPosition(this.leftPos + 152, this.topPos + 63);
}));
if (!menu.mirrorverse) {
moreCraftsButton = new ImageButton(this.leftPos + 152, topPos + 63, 16, 16, MORE_CRAFTS_TEXTURES,
button -> this.slotClicked(menu.slots.get(26), menu.slots.get(26).index, 0, ClickType.PICKUP));
moreCraftsButton.setTooltipDelay(Duration.ofMillis(250L));
moreCraftsButton.setTooltip(Tooltip.create(Component.literal("More Crafts")));
this.addRenderableWidget(moreCraftsButton);
}
assert (minecraft != null ? minecraft.player : null) != null;
this.addWidget(this.recipeBook);
this.setInitialFocus(this.recipeBook);
this.titleLabelX = 29;
}
@Override
public void containerTick() {
super.containerTick();
this.recipeBook.tick();
if (moreCraftsButton == null) return;
ItemStack stack = menu.slots.get(26).getItem();
moreCraftsButton.active = stack.isEmpty() || stack.is(Items.PLAYER_HEAD);
}
@Override
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
if (this.recipeBook.isVisible() && this.narrow) {
this.renderBackground(context, mouseX, mouseY, delta);
this.recipeBook.render(context, mouseX, mouseY, delta);
} else {
super.render(context, mouseX, mouseY, delta);
this.recipeBook.render(context, mouseX, mouseY, delta);
this.recipeBook.renderGhostRecipe(context, true);
}
this.renderTooltip(context, mouseX, mouseY);
this.recipeBook.renderTooltip(context, mouseX, mouseY, null);
}
@Override
protected void renderSlot(GuiGraphics context, Slot slot, int mouseX, int mouseY) {
ItemStack stack = slot.getItem();
if (slot.index == 23 && stack.is(Items.BARRIER)) return;
if (stack.is(Items.GRAY_STAINED_GLASS_PANE) && stack.getSkyblockId().isEmpty()) return;
super.renderSlot(context, slot, mouseX, mouseY);
}
@Override
protected void renderBg(GuiGraphics context, float delta, int mouseX, int mouseY) {
int i = this.leftPos;
int j = (this.height - this.imageHeight) / 2;
context.blit(RenderPipelines.GUI_TEXTURED, menu.mirrorverse ? MIRRORVERSE_TEXTURE.get() : TEXTURE.get(), i, j, 0, 0, this.imageWidth, this.imageHeight, 256, 256);
//4 px of margin to allow some space for custom resource packs that have size differences on the crafting table/inventory textures
if (TEXTURE.isUsingFallback() && !menu.mirrorverse) context.blit(RenderPipelines.GUI_TEXTURED, QUICK_CRAFT, i + 143, j - 3, 0, 0, 37, 90, 37, 90);
}
@Override
protected boolean isHovering(int x, int y, int width, int height, double pointX, double pointY) {
return (!this.narrow || !this.recipeBook.isVisible()) && super.isHovering(x, y, width, height, pointX, pointY);
}
@Override
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
if (this.recipeBook.mouseClicked(click, doubled)) {
this.setFocused(this.recipeBook);
return true;
}
if (this.narrow && this.recipeBook.isVisible()) {
return true;
}
return super.mouseClicked(click, doubled);
}
@Override
protected boolean hasClickedOutside(double mouseX, double mouseY, int left, int top) {
boolean bl = mouseX < (double) left || mouseY < (double) top || mouseX >= (double) (left + this.imageWidth) || mouseY >= (double) (top + this.imageHeight);
return this.recipeBook.hasClickedOutside(mouseX, mouseY, this.leftPos, this.topPos, this.imageWidth, this.imageHeight) && bl;
}
@Override
protected void slotClicked(Slot slot, int slotId, int button, ClickType actionType) {
super.slotClicked(slot, slotId, button, actionType);
this.recipeBook.slotClicked(slot);
}
}