AbstractContainerScreen .java

net.minecraft.client.gui.screens.inventory.AbstractContainerScreen (class, 600 lines): members: addItemSlotMouseAction, quickCraftingRemainder, imageWidth.

net.minecraft.client.gui.screens.inventoryclass600 linesclientextends AbstractContainerMenu>20.4 KB

Implements

API Surface (28)

void init()
void addItemSlotMouseAction(final ItemSlotMouseAction itemSlotMouseAction)
void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a)
void extractContents(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a)
void extractCarriedItem(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY)
void extractSlots(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY)
boolean mouseScrolled(final double x, final double y, final double scrollX, final double scrollY)
void extractTooltip(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY)
List<Component> getTooltipFromContainerItem(final ItemStack itemStack)
void extractLabels(final GuiGraphicsExtractor graphics, final int xm, final int ym)
void extractSlot(final GuiGraphicsExtractor graphics, final Slot slot, final int mouseX, final int mouseY)
boolean mouseClicked(final MouseButtonEvent event, final boolean doubleClick)
boolean hasClickedOutside(final double mx, final double my, final int xo, final int yo)
boolean mouseDragged(final MouseButtonEvent event, final double dx, final double dy)
boolean mouseReleased(final MouseButtonEvent event)
boolean isHovering(final int left, final int top, final int w, final int h, double xm, double ym)
void slotClicked(final Slot slot, int slotId, final int buttonNum, final ContainerInput containerInput)
void onMouseClickAction(final @Nullable Slot slot, final ContainerInput containerInput)
void handleSlotStateChanged(final int slotId, final int containerId, final boolean newState)
boolean keyPressed(final KeyEvent event)
boolean checkHotbarKeyPressed(final KeyEvent event)
void removed()
boolean isPauseScreen()
boolean isInGameUi()
void tick()
void containerTick()
T getMenu()
void onClose()

Fields & Constants (28)

INVENTORY_LOCATION
SLOT_HIGHLIGHT_BACK_SPRITE
SLOT_HIGHLIGHT_FRONT_SPRITE
BACKGROUND_TEXTURE_WIDTH
BACKGROUND_TEXTURE_HEIGHT
DEFAULT_IMAGE_WIDTH
DEFAULT_IMAGE_HEIGHT
imageWidth
imageHeight
titleLabelX
titleLabelY
inventoryLabelX
inventoryLabelY
itemSlotMouseActions
menu
playerInventoryTitle
hoveredSlot
lastClickSlot
leftPos
topPos
quickCraftSlots
isQuickCrafting
quickCraftingType
quickCraftingButton
skipNextRelease
quickCraftingRemainder
doubleclick
lastQuickMoved

String literals (3)

"textures/gui/container/inventory.png"
"container/slot_highlight_back"
"container/slot_highlight_front"

Full Source

AbstractContainerScreen.java600 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.inventory;
2
3
import com.google.common.collect.Sets;
4
import java.util.ArrayList;
5
import java.util.List;
6
import java.util.Set;
7
import net.fabricmc.api.EnvType;
8
import net.fabricmc.api.Environment;
9
import net.minecraft.ChatFormatting;
10
import net.minecraft.client.gui.BundleMouseActions;
11
import net.minecraft.client.gui.GuiGraphicsExtractor;
12
import net.minecraft.client.gui.ItemSlotMouseAction;
13
import net.minecraft.client.gui.screens.Screen;
14
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
15
import net.minecraft.client.input.KeyEvent;
16
import net.minecraft.client.input.MouseButtonEvent;
17
import net.minecraft.client.input.MouseButtonInfo;
18
import net.minecraft.client.renderer.RenderPipelines;
19
import net.minecraft.core.component.DataComponents;
20
import net.minecraft.network.chat.Component;
21
import net.minecraft.resources.Identifier;
22
import net.minecraft.world.entity.player.Inventory;
23
import net.minecraft.world.inventory.AbstractContainerMenu;
24
import net.minecraft.world.inventory.ContainerInput;
25
import net.minecraft.world.inventory.Slot;
26
import net.minecraft.world.item.ItemStack;
27
import org.jspecify.annotations.Nullable;
28
29
@Environment(EnvType.CLIENT)
30
public abstract class AbstractContainerScreen<T extends AbstractContainerMenu> extends Screen implements MenuAccess<T> {
31
	public static final Identifier INVENTORY_LOCATION = Identifier.withDefaultNamespace("textures/gui/container/inventory.png");
32
	private static final Identifier SLOT_HIGHLIGHT_BACK_SPRITE = Identifier.withDefaultNamespace("container/slot_highlight_back");
33
	private static final Identifier SLOT_HIGHLIGHT_FRONT_SPRITE = Identifier.withDefaultNamespace("container/slot_highlight_front");
34
	protected static final int BACKGROUND_TEXTURE_WIDTH = 256;
35
	protected static final int BACKGROUND_TEXTURE_HEIGHT = 256;
36
	protected static final int DEFAULT_IMAGE_WIDTH = 176;
37
	protected static final int DEFAULT_IMAGE_HEIGHT = 166;
38
	protected final int imageWidth;
39
	protected final int imageHeight;
40
	protected int titleLabelX;
41
	protected int titleLabelY;
42
	protected int inventoryLabelX;
43
	protected int inventoryLabelY;
44
	private final List<ItemSlotMouseAction> itemSlotMouseActions;
45
	protected final T menu;
46
	protected final Component playerInventoryTitle;
47
	protected @Nullable Slot hoveredSlot;
48
	private @Nullable Slot lastClickSlot;
49
	protected int leftPos;
50
	protected int topPos;
51
	protected final Set<Slot> quickCraftSlots = Sets.newHashSet();
52
	protected boolean isQuickCrafting;
53
	private int quickCraftingType;
54
	private @MouseButtonInfo.MouseButton int quickCraftingButton;
55
	private boolean skipNextRelease;
56
	private int quickCraftingRemainder;
57
	private boolean doubleclick;
58
	private ItemStack lastQuickMoved = ItemStack.EMPTY;
59
60
	public AbstractContainerScreen(final T menu, final Inventory inventory, final Component title) {
61
		this(menu, inventory, title, 176, 166);
62
	}
63
64
	public AbstractContainerScreen(final T menu, final Inventory inventory, final Component title, final int imageWidth, final int imageHeight) {
65
		super(title);
66
		this.menu = menu;
67
		this.playerInventoryTitle = inventory.getDisplayName();
68
		this.imageWidth = imageWidth;
69
		this.imageHeight = imageHeight;
70
		this.skipNextRelease = true;
71
		this.titleLabelX = 8;
72
		this.titleLabelY = 6;
73
		this.inventoryLabelX = 8;
74
		this.inventoryLabelY = imageHeight - 94;
75
		this.itemSlotMouseActions = new ArrayList<>();
76
	}
77
78
	@Override
79
	protected void init() {
80
		this.leftPos = (this.width - this.imageWidth) / 2;
81
		this.topPos = (this.height - this.imageHeight) / 2;
82
		this.itemSlotMouseActions.clear();
83
		this.addItemSlotMouseAction(new BundleMouseActions(this.minecraft));
84
	}
85
86
	protected void addItemSlotMouseAction(final ItemSlotMouseAction itemSlotMouseAction) {
87
		this.itemSlotMouseActions.add(itemSlotMouseAction);
88
	}
89
90
	@Override
91
	public void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
92
		this.extractContents(graphics, mouseX, mouseY, a);
93
		this.extractCarriedItem(graphics, mouseX, mouseY);
94
		this.extractTooltip(graphics, mouseX, mouseY);
95
	}
96
97
	public void extractContents(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
98
		int xo = this.leftPos;
99
		int yo = this.topPos;
100
		super.extractRenderState(graphics, mouseX, mouseY, a);
101
		graphics.pose().pushMatrix();
102
		graphics.pose().translate(xo, yo);
103
		this.extractLabels(graphics, mouseX, mouseY);
104
		Slot previouslyHoveredSlot = this.hoveredSlot;
105
		this.hoveredSlot = this.getHoveredSlot(mouseX, mouseY);
106
		this.extractSlotHighlightBack(graphics);
107
		this.extractSlots(graphics, mouseX, mouseY);
108
		this.extractSlotHighlightFront(graphics);
109
		if (previouslyHoveredSlot != null && previouslyHoveredSlot != this.hoveredSlot) {
110
			this.onStopHovering(previouslyHoveredSlot);
111
		}
112
113
		graphics.pose().popMatrix();
114
	}
115
116
	public void extractCarriedItem(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY) {
117
		ItemStack carried = this.menu.getCarried();
118
		if (!carried.isEmpty()) {
119
			int xOffset = 8;
120
			int yOffset = 8;
121
			String itemCount = null;
122
			if (this.isQuickCrafting && this.quickCraftSlots.size() > 1) {
123
				carried = carried.copyWithCount(this.quickCraftingRemainder);
124
				if (carried.isEmpty()) {
125
					itemCount = ChatFormatting.YELLOW + "0";
126
				}
127
			}
128
129
			graphics.nextStratum();
130
			this.extractFloatingItem(graphics, carried, mouseX - 8, mouseY - 8, itemCount);
131
		}
132
	}
133
134
	protected void extractSlots(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY) {
135
		for (Slot slot : this.menu.slots) {
136
			if (slot.isActive()) {
137
				this.extractSlot(graphics, slot, mouseX, mouseY);
138
			}
139
		}
140
	}
141
142
	@Override
143
	public boolean mouseScrolled(final double x, final double y, final double scrollX, final double scrollY) {
144
		if (this.hoveredSlot != null && this.hoveredSlot.hasItem()) {
145
			for (ItemSlotMouseAction itemMouseAction : this.itemSlotMouseActions) {
146
				if (itemMouseAction.matches(this.hoveredSlot) && itemMouseAction.onMouseScrolled(scrollX, scrollY, this.hoveredSlot.index, this.hoveredSlot.getItem())) {
147
					return true;
148
				}
149
			}
150
		}
151
152
		return false;
153
	}
154
155
	private void extractSlotHighlightBack(final GuiGraphicsExtractor graphics) {
156
		if (this.hoveredSlot != null && this.hoveredSlot.isHighlightable()) {
157
			graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_HIGHLIGHT_BACK_SPRITE, this.hoveredSlot.x - 4, this.hoveredSlot.y - 4, 24, 24);
158
		}
159
	}
160
161
	private void extractSlotHighlightFront(final GuiGraphicsExtractor graphics) {
162
		if (this.hoveredSlot != null && this.hoveredSlot.isHighlightable()) {
163
			graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_HIGHLIGHT_FRONT_SPRITE, this.hoveredSlot.x - 4, this.hoveredSlot.y - 4, 24, 24);
164
		}
165
	}
166
167
	protected void extractTooltip(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY) {
168
		if (this.hoveredSlot != null && this.hoveredSlot.hasItem()) {
169
			ItemStack item = this.hoveredSlot.getItem();
170
			if (this.menu.getCarried().isEmpty() || this.showTooltipWithItemInHand(item)) {
171
				graphics.setTooltipForNextFrame(
172
					this.font, this.getTooltipFromContainerItem(item), item.getTooltipImage(), mouseX, mouseY, item.get(DataComponents.TOOLTIP_STYLE), true
173
				);
174
			}
175
		}
176
	}
177
178
	private boolean showTooltipWithItemInHand(final ItemStack item) {
179
		return item.getTooltipImage().map(ClientTooltipComponent::create).map(ClientTooltipComponent::showTooltipWithItemInHand).orElse(false);
180
	}
181
182
	protected List<Component> getTooltipFromContainerItem(final ItemStack itemStack) {
183
		return getTooltipFromItem(this.minecraft, itemStack);
184
	}
185
186
	private void extractFloatingItem(final GuiGraphicsExtractor graphics, final ItemStack carried, final int x, final int y, final @Nullable String itemCount) {
187
		graphics.item(carried, x, y);
188
		graphics.itemDecorations(this.font, carried, x, y, itemCount);
189
	}
190
191
	protected void extractLabels(final GuiGraphicsExtractor graphics, final int xm, final int ym) {
192
		graphics.text(this.font, this.title, this.titleLabelX, this.titleLabelY, -12566464, false);
193
		graphics.text(this.font, this.playerInventoryTitle, this.inventoryLabelX, this.inventoryLabelY, -12566464, false);
194
	}
195
196
	protected void extractSlot(final GuiGraphicsExtractor graphics, final Slot slot, final int mouseX, final int mouseY) {
197
		int x = slot.x;
198
		int y = slot.y;
199
		ItemStack itemStack = slot.getItem();
200
		boolean quickCraftStack = false;
201
		boolean done = false;
202
		ItemStack carried = this.menu.getCarried();
203
		String itemCount = null;
204
		if (this.isQuickCrafting && this.quickCraftSlots.contains(slot) && !carried.isEmpty()) {
205
			if (this.quickCraftSlots.size() == 1) {
206
				return;
207
			}
208
209
			if (AbstractContainerMenu.canItemQuickReplace(slot, carried, true) && this.menu.canDragTo(slot)) {
210
				quickCraftStack = true;
211
				int maxSize = Math.min(carried.getMaxStackSize(), slot.getMaxStackSize(carried));
212
				int carry = slot.getItem().isEmpty() ? 0 : slot.getItem().getCount();
213
				int newCount = AbstractContainerMenu.getQuickCraftPlaceCount(this.quickCraftSlots.size(), this.quickCraftingType, carried) + carry;
214
				if (newCount > maxSize) {
215
					newCount = maxSize;
216
					itemCount = ChatFormatting.YELLOW.toString() + maxSize;
217
				}
218
219
				itemStack = carried.copyWithCount(newCount);
220
			} else {
221
				this.quickCraftSlots.remove(slot);
222
				this.recalculateQuickCraftRemaining();
223
			}
224
		}
225
226
		if (itemStack.isEmpty() && slot.isActive()) {
227
			Identifier icon = slot.getNoItemIcon();
228
			if (icon != null) {
229
				graphics.blitSprite(RenderPipelines.GUI_TEXTURED, icon, x, y, 16, 16);
230
				done = true;
231
			}
232
		}
233
234
		if (!done) {
235
			if (quickCraftStack) {
236
				graphics.fill(x, y, x + 16, y + 16, -2130706433);
237
			}
238
239
			int seed = slot.x + slot.y * this.imageWidth;
240
			if (slot.isFake()) {
241
				graphics.fakeItem(itemStack, x, y, seed);
242
			} else {
243
				graphics.item(itemStack, x, y, seed);
244
			}
245
246
			graphics.itemDecorations(this.font, itemStack, x, y, itemCount);
247
		}
248
	}
249
250
	private void recalculateQuickCraftRemaining() {
251
		ItemStack carried = this.menu.getCarried();
252
		if (!carried.isEmpty() && this.isQuickCrafting) {
253
			if (this.quickCraftingType == 2) {
254
				this.quickCraftingRemainder = carried.getMaxStackSize();
255
			} else {
256
				this.quickCraftingRemainder = carried.getCount();
257
258
				for (Slot slot : this.quickCraftSlots) {
259
					ItemStack slotItemStack = slot.getItem();
260
					int carry = slotItemStack.isEmpty() ? 0 : slotItemStack.getCount();
261
					int maxSize = Math.min(carried.getMaxStackSize(), slot.getMaxStackSize(carried));
262
					int newCount = Math.min(AbstractContainerMenu.getQuickCraftPlaceCount(this.quickCraftSlots.size(), this.quickCraftingType, carried) + carry, maxSize);
263
					this.quickCraftingRemainder -= newCount - carry;
264
				}
265
			}
266
		}
267
	}
268
269
	private @Nullable Slot getHoveredSlot(final double x, final double y) {
270
		for (Slot slot : this.menu.slots) {
271
			if (slot.isActive() && this.isHovering(slot, x, y)) {
272
				return slot;
273
			}
274
		}
275
276
		return null;
277
	}
278
279
	private void slotClicked(final Slot slot, final int slotId, final MouseButtonEvent event, final ContainerInput containerInput) {
280
		this.slotClicked(slot, slotId, getContainerClickButton(event), containerInput);
281
	}
282
283
	private static int getContainerClickButton(final MouseButtonEvent event) {
284
		return switch (event.button()) {
285
			case 1 -> 0;
286
			case 3 -> 1;
287
			default -> event.button();
288
		};
289
	}
290
291
	@Override
292
	public boolean mouseClicked(final MouseButtonEvent event, final boolean doubleClick) {
293
		if (super.mouseClicked(event, doubleClick)) {
294
			return true;
295
		}
296
297
		boolean cloning = this.minecraft.options.keyPickItem.matchesMouse(event) && this.minecraft.player.hasInfiniteMaterials();
298
		Slot slot = this.getHoveredSlot(event.x(), event.y());
299
		this.doubleclick = this.lastClickSlot == slot && doubleClick;
300
		this.skipNextRelease = false;
301
		if (event.button() != 1 && event.button() != 3 && !cloning) {
302
			this.checkHotbarMouseClicked(event);
303
		} else {
304
			int xo = this.leftPos;
305
			int yo = this.topPos;
306
			boolean clickedOutside = this.hasClickedOutside(event.x(), event.y(), xo, yo);
307
			int slotId = -1;
308
			if (slot != null) {
309
				slotId = slot.index;
310
			}
311
312
			if (clickedOutside) {
313
				slotId = -999;
314
			}
315
316
			if (slotId != -1 && !this.isQuickCrafting) {
317
				if (this.menu.getCarried().isEmpty()) {
318
					if (cloning) {
319
						this.slotClicked(slot, slotId, event, ContainerInput.CLONE);
320
					} else {
321
						boolean quickKey = slotId != -999 && event.hasShiftDown();
322
						ContainerInput containerInput = ContainerInput.PICKUP;
323
						if (quickKey) {
324
							this.lastQuickMoved = slot != null && slot.hasItem() ? slot.getItem().copy() : ItemStack.EMPTY;
325
							containerInput = ContainerInput.QUICK_MOVE;
326
						} else if (slotId == -999) {
327
							containerInput = ContainerInput.THROW;
328
						}
329
330
						this.slotClicked(slot, slotId, event, containerInput);
331
					}
332
333
					this.skipNextRelease = true;
334
				} else {
335
					this.isQuickCrafting = true;
336
					this.quickCraftingButton = event.button();
337
					this.quickCraftSlots.clear();
338
					if (event.button() == 1) {
339
						this.quickCraftingType = 0;
340
					} else if (event.button() == 3) {
341
						this.quickCraftingType = 1;
342
					} else if (cloning) {
343
						this.quickCraftingType = 2;
344
					}
345
				}
346
			}
347
		}
348
349
		this.lastClickSlot = slot;
350
		return true;
351
	}
352
353
	private void checkHotbarMouseClicked(final MouseButtonEvent event) {
354
		if (this.hoveredSlot != null && this.menu.getCarried().isEmpty()) {
355
			if (this.minecraft.options.keySwapOffhand.matchesMouse(event)) {
356
				this.slotClicked(this.hoveredSlot, this.hoveredSlot.index, 40, ContainerInput.SWAP);
357
				return;
358
			}
359
360
			for (int i = 0; i < 9; i++) {
361
				if (this.minecraft.options.keyHotbarSlots[i].matchesMouse(event)) {
362
					this.slotClicked(this.hoveredSlot, this.hoveredSlot.index, i, ContainerInput.SWAP);
363
				}
364
			}
365
		}
366
	}
367
368
	protected boolean hasClickedOutside(final double mx, final double my, final int xo, final int yo) {
369
		return mx < xo || my < yo || mx >= xo + this.imageWidth || my >= yo + this.imageHeight;
370
	}
371
372
	@Override
373
	public boolean mouseDragged(final MouseButtonEvent event, final double dx, final double dy) {
374
		Slot slot = this.getHoveredSlot(event.x(), event.y());
375
		ItemStack carried = this.menu.getCarried();
376
		if (slot != null && this.shouldAddSlotToQuickCraft(slot, carried) && this.quickCraftSlots.add(slot)) {
377
			this.recalculateQuickCraftRemaining();
378
			return true;
379
		} else {
380
			return slot == null && this.menu.getCarried().isEmpty() ? super.mouseDragged(event, dx, dy) : true;
381
		}
382
	}
383
384
	@Override
385
	public boolean mouseReleased(final MouseButtonEvent event) {
386
		Slot slot = this.getHoveredSlot(event.x(), event.y());
387
		int xo = this.leftPos;
388
		int yo = this.topPos;
389
		boolean clickedOutside = this.hasClickedOutside(event.x(), event.y(), xo, yo);
390
		int slotId = -1;
391
		if (slot != null) {
392
			slotId = slot.index;
393
		}
394
395
		if (clickedOutside) {
396
			slotId = -999;
397
		}
398
399
		if (this.doubleclick && slot != null && event.button() == 1 && this.menu.canTakeItemForPickAll(ItemStack.EMPTY, slot)) {
400
			if (event.hasShiftDown()) {
401
				if (!this.lastQuickMoved.isEmpty()) {
402
					for (Slot target : this.menu.slots) {
403
						if (target != null
404
							&& target.mayPickup(this.minecraft.player)
405
							&& target.hasItem()
406
							&& target.container == slot.container
407
							&& AbstractContainerMenu.canItemQuickReplace(target, this.lastQuickMoved, true)) {
408
							this.slotClicked(target, target.index, event, ContainerInput.QUICK_MOVE);
409
						}
410
					}
411
				}
412
			} else {
413
				this.slotClicked(slot, slotId, event, ContainerInput.PICKUP_ALL);
414
			}
415
416
			this.doubleclick = false;
417
		} else {
418
			if (this.isQuickCrafting && this.quickCraftingButton != event.button()) {
419
				this.isQuickCrafting = false;
420
				this.quickCraftSlots.clear();
421
				this.skipNextRelease = true;
422
				return true;
423
			}
424
425
			if (this.skipNextRelease) {
426
				this.skipNextRelease = false;
427
				return true;
428
			}
429
430
			if (this.isQuickCrafting && !this.quickCraftSlots.isEmpty()) {
431
				this.quickCraftToSlots();
432
			} else if (!this.menu.getCarried().isEmpty()) {
433
				if (this.minecraft.options.keyPickItem.matchesMouse(event)) {
434
					this.slotClicked(slot, slotId, event, ContainerInput.CLONE);
435
				} else {
436
					boolean quickKey = slotId != -999 && event.hasShiftDown();
437
					if (quickKey) {
438
						this.lastQuickMoved = slot != null && slot.hasItem() ? slot.getItem().copy() : ItemStack.EMPTY;
439
					}
440
441
					this.slotClicked(slot, slotId, event, quickKey ? ContainerInput.QUICK_MOVE : ContainerInput.PICKUP);
442
				}
443
			}
444
		}
445
446
		this.isQuickCrafting = false;
447
		return super.mouseReleased(event);
448
	}
449
450
	private boolean isHovering(final Slot slot, final double xm, final double ym) {
451
		return this.isHovering(slot.x, slot.y, 16, 16, xm, ym);
452
	}
453
454
	protected boolean isHovering(final int left, final int top, final int w, final int h, double xm, double ym) {
455
		int xo = this.leftPos;
456
		int yo = this.topPos;
457
		xm -= xo;
458
		ym -= yo;
459
		return xm >= left - 1 && xm < left + w + 1 && ym >= top - 1 && ym < top + h + 1;
460
	}
461
462
	private void onStopHovering(final Slot slot) {
463
		if (slot.hasItem()) {
464
			for (ItemSlotMouseAction itemMouseAction : this.itemSlotMouseActions) {
465
				if (itemMouseAction.matches(slot)) {
466
					itemMouseAction.onStopHovering(slot);
467
				}
468
			}
469
		}
470
	}
471
472
	protected void slotClicked(final Slot slot, int slotId, final int buttonNum, final ContainerInput containerInput) {
473
		if (slot != null) {
474
			slotId = slot.index;
475
		}
476
477
		this.onMouseClickAction(slot, containerInput);
478
		this.minecraft.gameMode.handleContainerInput(this.menu.containerId, slotId, buttonNum, containerInput, this.minecraft.player);
479
	}
480
481
	protected void onMouseClickAction(final @Nullable Slot slot, final ContainerInput containerInput) {
482
		if (slot != null && slot.hasItem()) {
483
			for (ItemSlotMouseAction itemMouseAction : this.itemSlotMouseActions) {
484
				if (itemMouseAction.matches(slot)) {
485
					itemMouseAction.onSlotClicked(slot, containerInput);
486
				}
487
			}
488
		}
489
	}
490
491
	protected void handleSlotStateChanged(final int slotId, final int containerId, final boolean newState) {
492
		this.minecraft.gameMode.handleSlotStateChanged(slotId, containerId, newState);
493
	}
494
495
	@Override
496
	public boolean keyPressed(final KeyEvent event) {
497
		if (super.keyPressed(event)) {
498
			return true;
499
		}
500
501
		if (this.minecraft.options.keyInventory.matches(event)) {
502
			this.onClose();
503
			return true;
504
		}
505
506
		this.checkHotbarKeyPressed(event);
507
		if (this.hoveredSlot != null && this.hoveredSlot.hasItem()) {
508
			if (this.minecraft.options.keyPickItem.matches(event)) {
509
				this.slotClicked(this.hoveredSlot, this.hoveredSlot.index, 0, ContainerInput.CLONE);
510
			} else if (this.minecraft.options.keyDrop.matches(event)) {
511
				this.slotClicked(this.hoveredSlot, this.hoveredSlot.index, event.hasControlDown() ? 1 : 0, ContainerInput.THROW);
512
			}
513
		}
514
515
		return false;
516
	}
517
518
	protected boolean checkHotbarKeyPressed(final KeyEvent event) {
519
		if (this.menu.getCarried().isEmpty() && this.hoveredSlot != null) {
520
			if (this.minecraft.options.keySwapOffhand.matches(event)) {
521
				this.slotClicked(this.hoveredSlot, this.hoveredSlot.index, 40, ContainerInput.SWAP);
522
				return true;
523
			}
524
525
			for (int i = 0; i < 9; i++) {
526
				if (this.minecraft.options.keyHotbarSlots[i].matches(event)) {
527
					this.slotClicked(this.hoveredSlot, this.hoveredSlot.index, i, ContainerInput.SWAP);
528
					return true;
529
				}
530
			}
531
		}
532
533
		return false;
534
	}
535
536
	@Override
537
	public void removed() {
538
		if (this.minecraft.player != null) {
539
			this.menu.removed(this.minecraft.player);
540
		}
541
	}
542
543
	@Override
544
	public boolean isPauseScreen() {
545
		return false;
546
	}
547
548
	@Override
549
	public boolean isInGameUi() {
550
		return true;
551
	}
552
553
	@Override
554
	public final void tick() {
555
		super.tick();
556
		if (this.minecraft.player.isAlive() && !this.minecraft.player.isRemoved()) {
557
			this.containerTick();
558
		} else {
559
			this.minecraft.player.closeContainer();
560
		}
561
	}
562
563
	protected void containerTick() {
564
	}
565
566
	private boolean shouldAddSlotToQuickCraft(final Slot slot, final ItemStack carried) {
567
		return this.isQuickCrafting
568
			&& !carried.isEmpty()
569
			&& (carried.getCount() > this.quickCraftSlots.size() || this.quickCraftingType == 2)
570
			&& AbstractContainerMenu.canItemQuickReplace(slot, carried, true)
571
			&& slot.mayPlace(carried)
572
			&& this.menu.canDragTo(slot);
573
	}
574
575
	private void quickCraftToSlots() {
576
		this.slotClicked(null, -999, AbstractContainerMenu.getQuickcraftMask(0, this.quickCraftingType), ContainerInput.QUICK_CRAFT);
577
578
		for (Slot quickSlot : this.quickCraftSlots) {
579
			this.slotClicked(quickSlot, quickSlot.index, AbstractContainerMenu.getQuickcraftMask(1, this.quickCraftingType), ContainerInput.QUICK_CRAFT);
580
		}
581
582
		this.slotClicked(null, -999, AbstractContainerMenu.getQuickcraftMask(2, this.quickCraftingType), ContainerInput.QUICK_CRAFT);
583
	}
584
585
	@Override
586
	public T getMenu() {
587
		return this.menu;
588
	}
589
590
	@Override
591
	public void onClose() {
592
		this.minecraft.player.closeContainer();
593
		if (this.hoveredSlot != null) {
594
			this.onStopHovering(this.hoveredSlot);
595
		}
596
597
		super.onClose();
598
	}
599
}
600

Decompiled Minecraft 26.3 source of AbstractContainerScreen (net/minecraft/client/gui/screens/inventory/AbstractContainerScreen.java) with Mojang official mappings, stored verbatim on the site.