CreativeModeInventoryScreen .java

net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen (class): members: displayOperatorCreativeTab, UNSELECTED_BOTTOM_TABS, NUM_ROWS.

net.minecraft.client.gui.screens.inventoryclass1,060 linesclientextends AbstractContainerScreen<CreativeModeInventoryScreen.ItemPickerMenu>37.5 KB

Implements

API Surface (51)

void containerTick()
void slotClicked(final @Nullable Slot slot, final int slotId, final int buttonNum, ContainerInput containerInput)
void init()
void resize(final int width, final int height)
void removed()
boolean charTyped(final CharacterEvent event)
boolean preeditUpdated(final @Nullable PreeditEvent event)
boolean keyPressed(final KeyEvent event)
boolean keyReleased(final KeyEvent event)
boolean isInputCaptured()
void extractLabels(final GuiGraphicsExtractor graphics, final int xm, final int ym)
boolean mouseClicked(final MouseButtonEvent event, final boolean doubleClick)
boolean mouseReleased(final MouseButtonEvent event)
boolean mouseScrolled(final double x, final double y, final double scrollX, final double scrollY)
boolean hasClickedOutside(final double mx, final double my, final int xo, final int yo)
boolean insideScrollbar(final double xm, final double ym)
boolean mouseDragged(final MouseButtonEvent event, final double dx, final double dy)
void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a)
boolean showsActiveEffects()
List<Component> getTooltipFromContainerItem(final ItemStack itemStack)
void extractBackground(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a)
boolean checkTabClicked(final CreativeModeTab tab, final double xm, final double ym)
boolean checkTabHovering(final GuiGraphicsExtractor graphics, final CreativeModeTab tab, final int xm, final int ym)
void extractTabButton(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final CreativeModeTab tab)
boolean isInventoryOpen()
void handleHotbarLoadOrSave(final Minecraft minecraft, final int index, final boolean isLoadPressed, final boolean isSavePressed)
boolean mayPickup(final Player player)
boolean stillValid(final Player player)
int calculateRowCount()
int getRowIndexForScroll(final float scrollOffs)
float getScrollForRowIndex(final int rowIndex)
float subtractInputFromScroll(final float scrollOffs, final double input)
void scrollTo(final float scrollOffs)
boolean canScroll()
ItemStack quickMoveStack(final Player player, final int slotIndex)
boolean canTakeItemForPickAll(final ItemStack carried, final Slot target)
boolean canDragTo(final Slot slot)
ItemStack getCarried()
void setCarried(final ItemStack carried)
void onTake(final Player player, final ItemStack carried)
boolean mayPlace(final ItemStack itemStack)
ItemStack getItem()
boolean hasItem()
void setByPlayer(final ItemStack itemStack, final ItemStack previous)
void set(final ItemStack itemStack)
void setChanged()
int getMaxStackSize()
int getMaxStackSize(final ItemStack itemStack)
ItemStack remove(final int amount)
boolean isActive()
boolean mayPickup(final Player player)

Fields & Constants (27)

SCROLLER_SPRITE
SCROLLER_DISABLED_SPRITE
UNSELECTED_TOP_TABS
SELECTED_TOP_TABS
UNSELECTED_BOTTOM_TABS
SELECTED_BOTTOM_TABS
NUM_ROWS
NUM_COLS
TAB_WIDTH
TAB_HEIGHT
SCROLLER_WIDTH
SCROLLER_HEIGHT
CONTAINER
TRASH_SLOT_TOOLTIP
selectedTab
scrollOffs
scrolling
searchBox
originalSlots
destroyItemSlot
listener
ignoreTextInput
hasClickedOutside
visibleTags
displayOperatorCreativeTab
effects
hasPermissions

String literals (13)

"container/creative_inventory/scroller"
"container/creative_inventory/scroller_disabled"
"container/creative_inventory/tab_top_selected_1"
"container/creative_inventory/tab_top_selected_2"
"container/creative_inventory/tab_top_selected_3"
"container/creative_inventory/tab_top_selected_4"
"container/creative_inventory/tab_top_selected_5"
"container/creative_inventory/tab_top_selected_6"
"container/creative_inventory/tab_top_selected_7"
"inventory.binSlot"
"itemGroup.search"
"inventory.hotbarInfo"
"inventory.hotbarSaved"

Code Graph: Dependencies (49)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

CreativeModeInventoryScreen.java1060 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.inventory;
2
3
import com.google.common.collect.ImmutableList;
4
import com.google.common.collect.Lists;
5
import com.mojang.blaze3d.platform.InputConstants;
6
import com.mojang.blaze3d.platform.cursor.CursorTypes;
7
import java.util.Collection;
8
import java.util.HashSet;
9
import java.util.List;
10
import java.util.Locale;
11
import java.util.Objects;
12
import java.util.Set;
13
import java.util.function.Predicate;
14
import net.fabricmc.api.EnvType;
15
import net.fabricmc.api.Environment;
16
import net.fabricmc.fabric.api.client.creativetab.v1.FabricCreativeModeInventoryScreen;
17
import net.minecraft.ChatFormatting;
18
import net.minecraft.client.HotbarManager;
19
import net.minecraft.client.Minecraft;
20
import net.minecraft.client.gui.GuiGraphicsExtractor;
21
import net.minecraft.client.gui.components.EditBox;
22
import net.minecraft.client.input.CharacterEvent;
23
import net.minecraft.client.input.KeyEvent;
24
import net.minecraft.client.input.MouseButtonEvent;
25
import net.minecraft.client.input.PreeditEvent;
26
import net.minecraft.client.multiplayer.ClientPacketListener;
27
import net.minecraft.client.multiplayer.SessionSearchTrees;
28
import net.minecraft.client.player.LocalPlayer;
29
import net.minecraft.client.player.inventory.Hotbar;
30
import net.minecraft.client.renderer.RenderPipelines;
31
import net.minecraft.client.searchtree.SearchTree;
32
import net.minecraft.core.NonNullList;
33
import net.minecraft.core.RegistryAccess;
34
import net.minecraft.core.HolderLookup.Provider;
35
import net.minecraft.core.HolderSet.Named;
36
import net.minecraft.core.component.DataComponents;
37
import net.minecraft.core.registries.BuiltInRegistries;
38
import net.minecraft.network.chat.CommonComponents;
39
import net.minecraft.network.chat.Component;
40
import net.minecraft.resources.Identifier;
41
import net.minecraft.tags.TagKey;
42
import net.minecraft.util.Mth;
43
import net.minecraft.util.Prediction;
44
import net.minecraft.util.Unit;
45
import net.minecraft.world.Container;
46
import net.minecraft.world.SimpleContainer;
47
import net.minecraft.world.entity.player.Inventory;
48
import net.minecraft.world.entity.player.Player;
49
import net.minecraft.world.flag.FeatureFlagSet;
50
import net.minecraft.world.inventory.AbstractContainerMenu;
51
import net.minecraft.world.inventory.ContainerInput;
52
import net.minecraft.world.inventory.Slot;
53
import net.minecraft.world.item.CreativeModeTab;
54
import net.minecraft.world.item.CreativeModeTabs;
55
import net.minecraft.world.item.Item;
56
import net.minecraft.world.item.ItemStack;
57
import net.minecraft.world.item.Items;
58
import net.minecraft.world.item.TooltipFlag;
59
import net.minecraft.world.item.CreativeModeTab.Row;
60
import net.minecraft.world.item.CreativeModeTab.Type;
61
import net.minecraft.world.item.Item.TooltipContext;
62
import net.minecraft.world.item.TooltipFlag.Default;
63
import org.jspecify.annotations.Nullable;
64
65
@Environment(EnvType.CLIENT)
66
public class CreativeModeInventoryScreen
67
	extends AbstractContainerScreen<CreativeModeInventoryScreen.ItemPickerMenu>
68
	implements FabricCreativeModeInventoryScreen {
69
	private static final Identifier SCROLLER_SPRITE = Identifier.withDefaultNamespace("container/creative_inventory/scroller");
70
	private static final Identifier SCROLLER_DISABLED_SPRITE = Identifier.withDefaultNamespace("container/creative_inventory/scroller_disabled");
71
	private static final Identifier[] UNSELECTED_TOP_TABS = new Identifier[]{
72
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_unselected_1"),
73
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_unselected_2"),
74
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_unselected_3"),
75
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_unselected_4"),
76
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_unselected_5"),
77
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_unselected_6"),
78
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_unselected_7")
79
	};
80
	private static final Identifier[] SELECTED_TOP_TABS = new Identifier[]{
81
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_selected_1"),
82
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_selected_2"),
83
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_selected_3"),
84
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_selected_4"),
85
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_selected_5"),
86
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_selected_6"),
87
		Identifier.withDefaultNamespace("container/creative_inventory/tab_top_selected_7")
88
	};
89
	private static final Identifier[] UNSELECTED_BOTTOM_TABS = new Identifier[]{
90
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_unselected_1"),
91
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_unselected_2"),
92
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_unselected_3"),
93
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_unselected_4"),
94
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_unselected_5"),
95
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_unselected_6"),
96
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_unselected_7")
97
	};
98
	private static final Identifier[] SELECTED_BOTTOM_TABS = new Identifier[]{
99
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_selected_1"),
100
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_selected_2"),
101
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_selected_3"),
102
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_selected_4"),
103
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_selected_5"),
104
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_selected_6"),
105
		Identifier.withDefaultNamespace("container/creative_inventory/tab_bottom_selected_7")
106
	};
107
	private static final int NUM_ROWS = 5;
108
	private static final int NUM_COLS = 9;
109
	private static final int TAB_WIDTH = 26;
110
	private static final int TAB_HEIGHT = 32;
111
	private static final int SCROLLER_WIDTH = 12;
112
	private static final int SCROLLER_HEIGHT = 15;
113
	private static final SimpleContainer CONTAINER = new SimpleContainer(45);
114
	private static final Component TRASH_SLOT_TOOLTIP = Component.translatable("inventory.binSlot");
115
	private static CreativeModeTab selectedTab = CreativeModeTabs.getDefaultTab();
116
	private float scrollOffs;
117
	private boolean scrolling;
118
	private EditBox searchBox;
119
	private @Nullable List<Slot> originalSlots;
120
	private @Nullable Slot destroyItemSlot;
121
	private CreativeInventoryListener listener;
122
	private boolean ignoreTextInput;
123
	private boolean hasClickedOutside;
124
	private final Set<TagKey<Item>> visibleTags = new HashSet<>();
125
	private final boolean displayOperatorCreativeTab;
126
	private final EffectsInInventory effects;
127
128
	public CreativeModeInventoryScreen(final LocalPlayer player, final FeatureFlagSet enabledFeatures, final boolean displayOperatorCreativeTab) {
129
		super(new CreativeModeInventoryScreen.ItemPickerMenu(player), player.getInventory(), CommonComponents.EMPTY, 195, 136);
130
		player.containerMenu = this.menu;
131
		this.displayOperatorCreativeTab = displayOperatorCreativeTab;
132
		this.tryRebuildTabContents(player.connection.searchTrees(), enabledFeatures, this.hasPermissions(player), player.level().registryAccess());
133
		this.effects = new EffectsInInventory(this);
134
	}
135
136
	private boolean hasPermissions(final Player player) {
137
		return player.canUseGameMasterBlocks() && this.displayOperatorCreativeTab;
138
	}
139
140
	private void tryRefreshInvalidatedTabs(final FeatureFlagSet enabledFeatures, final boolean hasPermissions, final Provider holders) {
141
		ClientPacketListener connection = this.minecraft.getConnection();
142
		if (this.tryRebuildTabContents(connection != null ? connection.searchTrees() : null, enabledFeatures, hasPermissions, holders)) {
143
			for (CreativeModeTab tab : CreativeModeTabs.allTabs()) {
144
				Collection<ItemStack> displayList = tab.getDisplayItems();
145
				if (tab == selectedTab) {
146
					if (tab.getType() == Type.CATEGORY && displayList.isEmpty()) {
147
						this.selectTab(CreativeModeTabs.getDefaultTab());
148
					} else {
149
						this.refreshCurrentTabContents(displayList);
150
					}
151
				}
152
			}
153
		}
154
	}
155
156
	private boolean tryRebuildTabContents(
157
		final @Nullable SessionSearchTrees searchTrees, final FeatureFlagSet enabledFeatures, final boolean hasPermissions, final Provider holders
158
	) {
159
		if (!CreativeModeTabs.tryRebuildTabContents(enabledFeatures, hasPermissions, holders)) {
160
			return false;
161
		}
162
163
		if (searchTrees != null) {
164
			List<ItemStack> creativeSearchItems = List.copyOf(CreativeModeTabs.searchTab().getDisplayItems());
165
			searchTrees.updateCreativeTooltips(holders, creativeSearchItems);
166
			searchTrees.updateCreativeTags(creativeSearchItems);
167
		}
168
169
		return true;
170
	}
171
172
	private void refreshCurrentTabContents(final Collection<ItemStack> displayList) {
173
		int oldRowIndex = this.menu.getRowIndexForScroll(this.scrollOffs);
174
		this.menu.items.clear();
175
		if (selectedTab.getType() == Type.SEARCH) {
176
			this.refreshSearchResults();
177
		} else {
178
			this.menu.items.addAll(displayList);
179
		}
180
181
		this.scrollOffs = this.menu.getScrollForRowIndex(oldRowIndex);
182
		this.menu.scrollTo(this.scrollOffs);
183
	}
184
185
	@Override
186
	public void containerTick() {
187
		super.containerTick();
188
		LocalPlayer player = this.minecraft.player;
189
		if (player != null) {
190
			this.tryRefreshInvalidatedTabs(player.connection.enabledFeatures(), this.hasPermissions(player), player.level().registryAccess());
191
			if (!player.hasInfiniteMaterials()) {
192
				this.minecraft.gui.setScreen(new InventoryScreen(player));
193
			}
194
		}
195
	}
196
197
	@Override
198
	protected void slotClicked(final @Nullable Slot slot, final int slotId, final int buttonNum, ContainerInput containerInput) {
199
		if (this.isCreativeSlot(slot)) {
200
			this.searchBox.moveCursorToEnd(false);
201
			this.searchBox.setHighlightPos(0);
202
		}
203
204
		boolean quickKey = containerInput == ContainerInput.QUICK_MOVE;
205
		containerInput = slotId == -999 && containerInput == ContainerInput.PICKUP ? ContainerInput.THROW : containerInput;
206
		if (containerInput != ContainerInput.THROW || this.minecraft.player.canDropItems()) {
207
			this.onMouseClickAction(slot, containerInput);
208
			if (slot == null && selectedTab.getType() != Type.INVENTORY && containerInput != ContainerInput.QUICK_CRAFT) {
209
				if (!this.menu.getCarried().isEmpty() && this.hasClickedOutside) {
210
					if (!this.minecraft.player.canDropItems()) {
211
						return;
212
					}
213
214
					if (buttonNum == 0) {
215
						this.minecraft.player.drop(this.menu.getCarried(), true, Prediction.PREDICTED);
216
						this.minecraft.gameMode.handleCreativeModeItemDrop(this.menu.getCarried());
217
						this.menu.setCarried(ItemStack.EMPTY);
218
					}
219
220
					if (buttonNum == 1) {
221
						ItemStack removedItem = this.menu.getCarried().split(1);
222
						this.minecraft.player.drop(removedItem, true, Prediction.PREDICTED);
223
						this.minecraft.gameMode.handleCreativeModeItemDrop(removedItem);
224
					}
225
				}
226
			} else {
227
				if (slot != null && !slot.mayPickup(this.minecraft.player)) {
228
					return;
229
				}
230
231
				if (slot == this.destroyItemSlot && quickKey) {
232
					for (int i = 0; i < this.minecraft.player.inventoryMenu.getItems().size(); i++) {
233
						this.minecraft.player.inventoryMenu.getSlot(i).set(ItemStack.EMPTY);
234
						this.minecraft.gameMode.handleCreativeModeItemAdd(ItemStack.EMPTY, i);
235
					}
236
				} else if (selectedTab.getType() == Type.INVENTORY) {
237
					if (slot == this.destroyItemSlot) {
238
						this.menu.setCarried(ItemStack.EMPTY);
239
					} else if (containerInput == ContainerInput.THROW && slot != null && slot.hasItem()) {
240
						ItemStack toDrop = slot.remove(buttonNum == 0 ? 1 : slot.getItem().getMaxStackSize());
241
						ItemStack afterDrop = slot.getItem();
242
						this.minecraft.player.drop(toDrop, true, Prediction.PREDICTED);
243
						this.minecraft.gameMode.handleCreativeModeItemDrop(toDrop);
244
						this.minecraft.gameMode.handleCreativeModeItemAdd(afterDrop, ((CreativeModeInventoryScreen.SlotWrapper)slot).target.index);
245
					} else if (containerInput == ContainerInput.THROW && slotId == -999 && !this.menu.getCarried().isEmpty()) {
246
						this.minecraft.player.drop(this.menu.getCarried(), true, Prediction.PREDICTED);
247
						this.minecraft.gameMode.handleCreativeModeItemDrop(this.menu.getCarried());
248
						this.menu.setCarried(ItemStack.EMPTY);
249
					} else {
250
						this.minecraft
251
							.player
252
							.inventoryMenu
253
							.clicked(slot == null ? slotId : ((CreativeModeInventoryScreen.SlotWrapper)slot).target.index, buttonNum, containerInput, this.minecraft.player);
254
						this.minecraft.player.inventoryMenu.broadcastChanges();
255
					}
256
				} else if (containerInput != ContainerInput.QUICK_CRAFT && slot.container == CONTAINER) {
257
					ItemStack carried = this.menu.getCarried();
258
					ItemStack clicked = slot.getItem();
259
					if (containerInput == ContainerInput.SWAP) {
260
						if (!clicked.isEmpty()) {
261
							this.minecraft.player.getInventory().setItem(buttonNum, clicked.copyWithCount(clicked.getMaxStackSize()));
262
							this.minecraft.player.inventoryMenu.broadcastChanges();
263
						}
264
265
						return;
266
					}
267
268
					if (containerInput == ContainerInput.CLONE) {
269
						if (this.menu.getCarried().isEmpty() && slot.hasItem()) {
270
							ItemStack item = slot.getItem();
271
							this.menu.setCarried(item.copyWithCount(item.getMaxStackSize()));
272
						}
273
274
						return;
275
					}
276
277
					if (containerInput == ContainerInput.THROW) {
278
						if (!clicked.isEmpty()) {
279
							ItemStack toDrop = clicked.copyWithCount(buttonNum == 0 ? 1 : clicked.getMaxStackSize());
280
							this.minecraft.player.drop(toDrop, true, Prediction.PREDICTED);
281
							this.minecraft.gameMode.handleCreativeModeItemDrop(toDrop);
282
						}
283
284
						return;
285
					}
286
287
					if (!carried.isEmpty() && !clicked.isEmpty() && ItemStack.isSameItemSameComponents(carried, clicked)) {
288
						if (buttonNum == 0) {
289
							if (quickKey) {
290
								carried.setCount(carried.getMaxStackSize());
291
							} else if (carried.getCount() < carried.getMaxStackSize()) {
292
								carried.grow(1);
293
							}
294
						} else {
295
							carried.shrink(1);
296
						}
297
					} else if (!clicked.isEmpty() && carried.isEmpty()) {
298
						int count = quickKey ? clicked.getMaxStackSize() : clicked.getCount();
299
						this.menu.setCarried(clicked.copyWithCount(count));
300
					} else if (buttonNum == 0) {
301
						this.menu.setCarried(ItemStack.EMPTY);
302
					} else if (!this.menu.getCarried().isEmpty()) {
303
						this.menu.getCarried().shrink(1);
304
					}
305
				} else if (this.menu != null) {
306
					ItemStack oldItemStack = slot == null ? ItemStack.EMPTY : this.menu.getSlot(slot.index).getItem();
307
					this.menu.clicked(slot == null ? slotId : slot.index, buttonNum, containerInput, this.minecraft.player);
308
					if (AbstractContainerMenu.getQuickcraftHeader(buttonNum) == 2) {
309
						for (int i = 0; i < 9; i++) {
310
							this.minecraft.gameMode.handleCreativeModeItemAdd(this.menu.getSlot(45 + i).getItem(), 36 + i);
311
						}
312
					} else if (slot != null && Inventory.isHotbarSlot(slot.getContainerSlot()) && selectedTab.getType() != Type.INVENTORY) {
313
						if (containerInput == ContainerInput.THROW && !oldItemStack.isEmpty() && !this.menu.getCarried().isEmpty()) {
314
							int numToDrop = buttonNum == 0 ? 1 : oldItemStack.getCount();
315
							ItemStack toDrop = oldItemStack.copyWithCount(numToDrop);
316
							oldItemStack.shrink(numToDrop);
317
							this.minecraft.player.drop(toDrop, true, Prediction.PREDICTED);
318
							this.minecraft.gameMode.handleCreativeModeItemDrop(toDrop);
319
						}
320
321
						this.minecraft.player.inventoryMenu.broadcastChanges();
322
					}
323
				}
324
			}
325
		}
326
	}
327
328
	private boolean isCreativeSlot(final @Nullable Slot slot) {
329
		return slot != null && slot.container == CONTAINER;
330
	}
331
332
	@Override
333
	protected void init() {
334
		if (this.minecraft.player.hasInfiniteMaterials()) {
335
			super.init();
336
			this.searchBox = new EditBox(this.font, this.leftPos + 82, this.topPos + 6, 80, 9, Component.translatable("itemGroup.search"));
337
			this.searchBox.setMaxLength(50);
338
			this.searchBox.setBordered(false);
339
			this.searchBox.setVisible(false);
340
			this.searchBox.setTextColor(-1);
341
			this.searchBox.setInvertHighlightedTextColor(false);
342
			this.addWidget(this.searchBox);
343
			CreativeModeTab tab = selectedTab;
344
			selectedTab = CreativeModeTabs.getDefaultTab();
345
			this.selectTab(tab);
346
			this.minecraft.player.inventoryMenu.removeSlotListener(this.listener);
347
			this.listener = new CreativeInventoryListener(this.minecraft);
348
			this.minecraft.player.inventoryMenu.addSlotListener(this.listener);
349
			if (!selectedTab.shouldDisplay()) {
350
				this.selectTab(CreativeModeTabs.getDefaultTab());
351
			}
352
		} else {
353
			this.minecraft.gui.setScreen(new InventoryScreen(this.minecraft.player));
354
		}
355
	}
356
357
	@Override
358
	public void resize(final int width, final int height) {
359
		int oldRowIndex = this.menu.getRowIndexForScroll(this.scrollOffs);
360
		String oldEdit = this.searchBox.getValue();
361
		this.init(width, height);
362
		this.searchBox.setValue(oldEdit);
363
		if (!this.searchBox.getValue().isEmpty()) {
364
			this.refreshSearchResults();
365
		}
366
367
		this.scrollOffs = this.menu.getScrollForRowIndex(oldRowIndex);
368
		this.menu.scrollTo(this.scrollOffs);
369
	}
370
371
	@Override
372
	public void removed() {
373
		super.removed();
374
		if (this.minecraft.player != null && this.minecraft.player.getInventory() != null) {
375
			this.minecraft.player.inventoryMenu.removeSlotListener(this.listener);
376
		}
377
	}
378
379
	@Override
380
	public boolean charTyped(final CharacterEvent event) {
381
		if (this.ignoreTextInput) {
382
			return false;
383
		}
384
385
		if (selectedTab.getType() != Type.SEARCH) {
386
			return false;
387
		}
388
389
		String oldContents = this.searchBox.getValue();
390
		if (this.searchBox.charTyped(event)) {
391
			if (!Objects.equals(oldContents, this.searchBox.getValue())) {
392
				this.refreshSearchResults();
393
			}
394
395
			return true;
396
		} else {
397
			return false;
398
		}
399
	}
400
401
	@Override
402
	public boolean preeditUpdated(final @Nullable PreeditEvent event) {
403
		if (this.ignoreTextInput) {
404
			return false;
405
		} else {
406
			return selectedTab.getType() != Type.SEARCH ? false : this.searchBox.preeditUpdated(event);
407
		}
408
	}
409
410
	@Override
411
	public boolean keyPressed(final KeyEvent event) {
412
		this.ignoreTextInput = false;
413
		if (selectedTab.getType() != Type.SEARCH) {
414
			if (this.minecraft.options.keyChat.matches(event)) {
415
				this.ignoreTextInput = true;
416
				this.selectTab(CreativeModeTabs.searchTab());
417
				return true;
418
			} else {
419
				return super.keyPressed(event);
420
			}
421
		} else {
422
			boolean doQuickSwap = !this.isCreativeSlot(this.hoveredSlot) || this.hoveredSlot.hasItem();
423
			boolean pressingNumber = InputConstants.getKey(event).getNumericKeyValue().isPresent();
424
			if (doQuickSwap && pressingNumber && this.checkHotbarKeyPressed(event)) {
425
				this.ignoreTextInput = true;
426
				return true;
427
			}
428
429
			String oldContents = this.searchBox.getValue();
430
			if (this.searchBox.keyPressed(event)) {
431
				if (!Objects.equals(oldContents, this.searchBox.getValue())) {
432
					this.refreshSearchResults();
433
				}
434
435
				return true;
436
			} else {
437
				return this.searchBox.capturesInput() && !event.isEscape() ? true : super.keyPressed(event);
438
			}
439
		}
440
	}
441
442
	@Override
443
	public boolean keyReleased(final KeyEvent event) {
444
		this.ignoreTextInput = false;
445
		return super.keyReleased(event);
446
	}
447
448
	@Override
449
	public boolean isInputCaptured() {
450
		return super.isInputCaptured() || this.searchBox.capturesInput();
451
	}
452
453
	private void refreshSearchResults() {
454
		this.menu.items.clear();
455
		this.visibleTags.clear();
456
		String searchTerm = this.searchBox.getValue();
457
		if (searchTerm.isEmpty()) {
458
			this.menu.items.addAll(selectedTab.getDisplayItems());
459
		} else {
460
			ClientPacketListener connection = this.minecraft.getConnection();
461
			if (connection != null) {
462
				SessionSearchTrees searchTrees = connection.searchTrees();
463
				SearchTree<ItemStack> tree;
464
				if (searchTerm.startsWith("#")) {
465
					searchTerm = searchTerm.substring(1);
466
					tree = searchTrees.creativeTagSearch();
467
					this.updateVisibleTags(searchTerm);
468
				} else {
469
					tree = searchTrees.creativeNameSearch();
470
				}
471
472
				this.menu.items.addAll(tree.search(searchTerm.toLowerCase(Locale.ROOT)));
473
			}
474
		}
475
476
		this.scrollOffs = 0.0F;
477
		this.menu.scrollTo(0.0F);
478
	}
479
480
	private void updateVisibleTags(final String searchTerm) {
481
		int colonIndex = searchTerm.indexOf(58);
482
		Predicate<Identifier> matcher;
483
		if (colonIndex == -1) {
484
			matcher = id -> id.getPath().contains(searchTerm);
485
		} else {
486
			String nsMatcher = searchTerm.substring(0, colonIndex).trim();
487
			String pathMatcher = searchTerm.substring(colonIndex + 1).trim();
488
			matcher = id -> id.getNamespace().contains(nsMatcher) && id.getPath().contains(pathMatcher);
489
		}
490
491
		BuiltInRegistries.ITEM.getTags().map(Named::key).filter(tag -> matcher.test(tag.location())).forEach(this.visibleTags::add);
492
	}
493
494
	@Override
495
	protected void extractLabels(final GuiGraphicsExtractor graphics, final int xm, final int ym) {
496
		if (selectedTab.showTitle()) {
497
			graphics.text(this.font, selectedTab.getDisplayName(), 8, 6, -12566464, false);
498
		}
499
	}
500
501
	@Override
502
	public boolean mouseClicked(final MouseButtonEvent event, final boolean doubleClick) {
503
		if (event.button() == 1) {
504
			double xm = event.x() - this.leftPos;
505
			double ym = event.y() - this.topPos;
506
507
			for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
508
				if (this.checkTabClicked(tab, xm, ym)) {
509
					return true;
510
				}
511
			}
512
513
			if (selectedTab.getType() != Type.INVENTORY && this.insideScrollbar(event.x(), event.y())) {
514
				this.scrolling = this.canScroll();
515
				return true;
516
			}
517
		}
518
519
		return super.mouseClicked(event, doubleClick);
520
	}
521
522
	@Override
523
	public boolean mouseReleased(final MouseButtonEvent event) {
524
		if (event.button() == 1) {
525
			double xm = event.x() - this.leftPos;
526
			double ym = event.y() - this.topPos;
527
			this.scrolling = false;
528
529
			for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
530
				if (this.checkTabClicked(tab, xm, ym)) {
531
					this.selectTab(tab);
532
					return true;
533
				}
534
			}
535
		}
536
537
		return super.mouseReleased(event);
538
	}
539
540
	private boolean canScroll() {
541
		return selectedTab.canScroll() && this.menu.canScroll();
542
	}
543
544
	private void selectTab(final CreativeModeTab tab) {
545
		CreativeModeTab oldTab = selectedTab;
546
		selectedTab = tab;
547
		this.quickCraftSlots.clear();
548
		this.menu.items.clear();
549
		if (selectedTab.getType() == Type.HOTBAR) {
550
			HotbarManager manager = this.minecraft.getHotbarManager();
551
552
			for (int hotbarIndex = 0; hotbarIndex < 9; hotbarIndex++) {
553
				Hotbar hotbar = manager.get(hotbarIndex);
554
				if (hotbar.isEmpty()) {
555
					for (int i = 0; i < 9; i++) {
556
						if (i == hotbarIndex) {
557
							ItemStack placeholder = new ItemStack(Items.PAPER);
558
							placeholder.set(DataComponents.CREATIVE_SLOT_LOCK, Unit.INSTANCE);
559
							Component translatedKeyMessage = this.minecraft.options.keyHotbarSlots[hotbarIndex].getTranslatedKeyMessage();
560
							Component activatorKeyMessage = this.minecraft.options.keySaveHotbarActivator.getTranslatedKeyMessage();
561
							placeholder.set(DataComponents.ITEM_NAME, Component.translatable("inventory.hotbarInfo", activatorKeyMessage, translatedKeyMessage));
562
							this.menu.items.add(placeholder);
563
						} else {
564
							this.menu.items.add(ItemStack.EMPTY);
565
						}
566
					}
567
				} else {
568
					this.menu.items.addAll(hotbar.load(this.minecraft.level.registryAccess()));
569
				}
570
			}
571
		} else if (selectedTab.getType() == Type.CATEGORY) {
572
			this.menu.items.addAll(selectedTab.getDisplayItems());
573
		}
574
575
		if (selectedTab.getType() == Type.INVENTORY) {
576
			AbstractContainerMenu invMenu = this.minecraft.player.inventoryMenu;
577
			if (this.originalSlots == null) {
578
				this.originalSlots = ImmutableList.copyOf(this.menu.slots);
579
			}
580
581
			this.menu.slots.clear();
582
583
			for (int i = 0; i < invMenu.slots.size(); i++) {
584
				int x;
585
				int y;
586
				if (i >= 5 && i < 9) {
587
					int pos = i - 5;
588
					int col = pos / 2;
589
					int row = pos % 2;
590
					x = 54 + col * 54;
591
					y = 6 + row * 27;
592
				} else if (i >= 0 && i < 5) {
593
					x = -2000;
594
					y = -2000;
595
				} else if (i == 45) {
596
					x = 35;
597
					y = 20;
598
				} else {
599
					int pos = i - 9;
600
					int col = pos % 9;
601
					int row = pos / 9;
602
					x = 9 + col * 18;
603
					if (i >= 36) {
604
						y = 112;
605
					} else {
606
						y = 54 + row * 18;
607
					}
608
				}
609
610
				Slot slot = new CreativeModeInventoryScreen.SlotWrapper(invMenu.slots.get(i), i, x, y);
611
				this.menu.slots.add(slot);
612
			}
613
614
			this.destroyItemSlot = new Slot(CONTAINER, 0, 173, 112);
615
			this.menu.slots.add(this.destroyItemSlot);
616
		} else if (oldTab.getType() == Type.INVENTORY) {
617
			this.menu.slots.clear();
618
			this.menu.slots.addAll(this.originalSlots);
619
			this.originalSlots = null;
620
		}
621
622
		if (selectedTab.getType() == Type.SEARCH) {
623
			this.searchBox.setVisible(true);
624
			this.searchBox.setCanLoseFocus(false);
625
			this.searchBox.setFocused(true);
626
			if (oldTab != tab) {
627
				this.searchBox.setValue("");
628
			}
629
630
			this.refreshSearchResults();
631
		} else {
632
			this.searchBox.setVisible(false);
633
			this.searchBox.setCanLoseFocus(true);
634
			this.searchBox.setFocused(false);
635
			this.searchBox.setValue("");
636
		}
637
638
		this.scrollOffs = 0.0F;
639
		this.menu.scrollTo(0.0F);
640
	}
641
642
	@Override
643
	public boolean mouseScrolled(final double x, final double y, final double scrollX, final double scrollY) {
644
		if (super.mouseScrolled(x, y, scrollX, scrollY)) {
645
			return true;
646
		}
647
648
		if (!this.canScroll()) {
649
			return false;
650
		}
651
652
		this.scrollOffs = this.menu.subtractInputFromScroll(this.scrollOffs, scrollY);
653
		this.menu.scrollTo(this.scrollOffs);
654
		return true;
655
	}
656
657
	@Override
658
	protected boolean hasClickedOutside(final double mx, final double my, final int xo, final int yo) {
659
		boolean clickedOutside = mx < xo || my < yo || mx >= xo + this.imageWidth || my >= yo + this.imageHeight;
660
		this.hasClickedOutside = clickedOutside && !this.checkTabClicked(selectedTab, mx, my);
661
		return this.hasClickedOutside;
662
	}
663
664
	protected boolean insideScrollbar(final double xm, final double ym) {
665
		int xo = this.leftPos;
666
		int yo = this.topPos;
667
		int xscr = xo + 175;
668
		int yscr = yo + 18;
669
		int xscr2 = xscr + 14;
670
		int yscr2 = yscr + 112;
671
		return xm >= xscr && ym >= yscr && xm < xscr2 && ym < yscr2 && selectedTab.canScroll();
672
	}
673
674
	@Override
675
	public boolean mouseDragged(final MouseButtonEvent event, final double dx, final double dy) {
676
		if (this.scrolling) {
677
			int yscr = this.topPos + 18;
678
			int yscr2 = yscr + 112;
679
			this.scrollOffs = ((float)event.y() - yscr - 7.5F) / (yscr2 - yscr - 15.0F);
680
			this.scrollOffs = Mth.clamp(this.scrollOffs, 0.0F, 1.0F);
681
			this.menu.scrollTo(this.scrollOffs);
682
			return true;
683
		} else {
684
			return super.mouseDragged(event, dx, dy);
685
		}
686
	}
687
688
	@Override
689
	public void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
690
		this.effects.extractRenderState(graphics, mouseX, mouseY);
691
		super.extractRenderState(graphics, mouseX, mouseY, a);
692
693
		for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
694
			if (this.checkTabHovering(graphics, tab, mouseX, mouseY)) {
695
				break;
696
			}
697
		}
698
699
		if (this.destroyItemSlot != null
700
			&& selectedTab.getType() == Type.INVENTORY
701
			&& this.isHovering(this.destroyItemSlot.x, this.destroyItemSlot.y, 16, 16, mouseX, mouseY)) {
702
			graphics.setTooltipForNextFrame(this.font, TRASH_SLOT_TOOLTIP, mouseX, mouseY);
703
		}
704
	}
705
706
	@Override
707
	public boolean showsActiveEffects() {
708
		return this.effects.canSeeEffects();
709
	}
710
711
	@Override
712
	public List<Component> getTooltipFromContainerItem(final ItemStack itemStack) {
713
		boolean isCreativeSlot = this.hoveredSlot != null && this.hoveredSlot instanceof CreativeModeInventoryScreen.CustomCreativeSlot;
714
		boolean isSingleCategoryTab = selectedTab.getType() == Type.CATEGORY;
715
		boolean isSearchTab = selectedTab.getType() == Type.SEARCH;
716
		Default originalTooltipStyle = this.minecraft.options.advancedItemTooltips ? Default.ADVANCED : Default.NORMAL;
717
		TooltipFlag tooltipStyle = isCreativeSlot ? originalTooltipStyle.asCreative() : originalTooltipStyle;
718
		List<Component> originalLines = itemStack.getTooltipLines(TooltipContext.of(this.minecraft.level), this.minecraft.player, tooltipStyle);
719
		if (originalLines.isEmpty()) {
720
			return originalLines;
721
		}
722
723
		if (isSingleCategoryTab && isCreativeSlot) {
724
			return originalLines;
725
		}
726
727
		List<Component> linesToDisplay = Lists.newArrayList(originalLines);
728
		if (isSearchTab && isCreativeSlot) {
729
			this.visibleTags.forEach(tag -> {
730
				if (itemStack.is((TagKey<Item>)tag)) {
731
					linesToDisplay.add(1, Component.literal("#" + tag.location()).withStyle(ChatFormatting.DARK_PURPLE));
732
				}
733
			});
734
		}
735
736
		int i = 1;
737
738
		for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
739
			if (tab.getType() != Type.SEARCH && tab.contains(itemStack)) {
740
				linesToDisplay.add(i++, tab.getDisplayName().copy().withStyle(ChatFormatting.BLUE));
741
			}
742
		}
743
744
		return linesToDisplay;
745
	}
746
747
	@Override
748
	public void extractBackground(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
749
		super.extractBackground(graphics, mouseX, mouseY, a);
750
751
		for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
752
			if (tab != selectedTab) {
753
				this.extractTabButton(graphics, mouseX, mouseY, tab);
754
			}
755
		}
756
757
		graphics.blit(
758
			RenderPipelines.GUI_TEXTURED, selectedTab.getBackgroundTexture(), this.leftPos, this.topPos, 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 256
759
		);
760
		if (this.insideScrollbar(mouseX, mouseY)) {
761
			if (this.canScroll()) {
762
				graphics.requestCursor(this.scrolling ? CursorTypes.RESIZE_NS : CursorTypes.POINTING_HAND);
763
			} else {
764
				graphics.requestCursor(CursorTypes.NOT_ALLOWED);
765
			}
766
		}
767
768
		this.searchBox.extractRenderState(graphics, mouseX, mouseY, a);
769
		int xscr = this.leftPos + 175;
770
		int yscr = this.topPos + 18;
771
		int yscr2 = yscr + 112;
772
		if (selectedTab.canScroll()) {
773
			Identifier sprite = this.canScroll() ? SCROLLER_SPRITE : SCROLLER_DISABLED_SPRITE;
774
			graphics.blitSprite(RenderPipelines.GUI_TEXTURED, sprite, xscr, yscr + (int)((yscr2 - yscr - 17) * this.scrollOffs), 12, 15);
775
		}
776
777
		this.extractTabButton(graphics, mouseX, mouseY, selectedTab);
778
		if (selectedTab.getType() == Type.INVENTORY) {
779
			InventoryScreen.extractEntityInInventoryFollowsMouse(
780
				graphics, this.leftPos + 73, this.topPos + 6, this.leftPos + 105, this.topPos + 49, 20, 0.0625F, mouseX, mouseY, this.minecraft.player
781
			);
782
		}
783
	}
784
785
	private int getTabX(final CreativeModeTab tab) {
786
		int pos = tab.column();
787
		int spacing = 27;
788
		int x = 27 * pos;
789
		if (tab.isAlignedRight()) {
790
			x = this.imageWidth - 27 * (7 - pos) + 1;
791
		}
792
793
		return x;
794
	}
795
796
	private int getTabY(final CreativeModeTab tab) {
797
		int y = 0;
798
		if (tab.row() == Row.TOP) {
799
			y -= 32;
800
		} else {
801
			y += this.imageHeight;
802
		}
803
804
		return y;
805
	}
806
807
	protected boolean checkTabClicked(final CreativeModeTab tab, final double xm, final double ym) {
808
		int x = this.getTabX(tab);
809
		int y = this.getTabY(tab);
810
		return xm >= x && xm <= x + 26 && ym >= y && ym <= y + 32;
811
	}
812
813
	protected boolean checkTabHovering(final GuiGraphicsExtractor graphics, final CreativeModeTab tab, final int xm, final int ym) {
814
		int x = this.getTabX(tab);
815
		int y = this.getTabY(tab);
816
		if (this.isHovering(x + 3, y + 3, 21, 27, xm, ym)) {
817
			graphics.setTooltipForNextFrame(this.font, tab.getDisplayName(), xm, ym);
818
			return true;
819
		} else {
820
			return false;
821
		}
822
	}
823
824
	protected void extractTabButton(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final CreativeModeTab tab) {
825
		boolean selected = tab == selectedTab;
826
		boolean isTop = tab.row() == Row.TOP;
827
		int pos = tab.column();
828
		int x = this.leftPos + this.getTabX(tab);
829
		int y = this.topPos - (isTop ? 28 : -(this.imageHeight - 4));
830
		Identifier[] sprites;
831
		if (isTop) {
832
			sprites = selected ? SELECTED_TOP_TABS : UNSELECTED_TOP_TABS;
833
		} else {
834
			sprites = selected ? SELECTED_BOTTOM_TABS : UNSELECTED_BOTTOM_TABS;
835
		}
836
837
		if (!selected && mouseX > x && mouseY > y && mouseX < x + 26 && mouseY < y + 32) {
838
			graphics.requestCursor(CursorTypes.POINTING_HAND);
839
		}
840
841
		graphics.blitSprite(RenderPipelines.GUI_TEXTURED, sprites[Mth.clamp(pos, 0, sprites.length)], x, y, 26, 32);
842
		int iconX = x + 13 - 8;
843
		int iconY = y + 16 - 8 + (isTop ? 1 : -1);
844
		graphics.item(tab.getIconItem(), iconX, iconY);
845
	}
846
847
	public boolean isInventoryOpen() {
848
		return selectedTab.getType() == Type.INVENTORY;
849
	}
850
851
	public static void handleHotbarLoadOrSave(final Minecraft minecraft, final int index, final boolean isLoadPressed, final boolean isSavePressed) {
852
		LocalPlayer player = minecraft.player;
853
		RegistryAccess registries = player.level().registryAccess();
854
		HotbarManager manager = minecraft.getHotbarManager();
855
		Hotbar hotbar = manager.get(index);
856
		if (isLoadPressed) {
857
			List<ItemStack> originalItems = hotbar.load(registries);
858
859
			for (int i = 0; i < Inventory.getSelectionSize(); i++) {
860
				ItemStack itemStack = originalItems.get(i);
861
				player.getInventory().setItem(i, itemStack);
862
				minecraft.gameMode.handleCreativeModeItemAdd(itemStack, 36 + i);
863
			}
864
865
			player.inventoryMenu.broadcastChanges();
866
		} else if (isSavePressed) {
867
			hotbar.storeFrom(player.getInventory(), registries);
868
			Component translatedKeyMessage = minecraft.options.keyHotbarSlots[index].getTranslatedKeyMessage();
869
			Component activatorKeyMessage = minecraft.options.keyLoadHotbarActivator.getTranslatedKeyMessage();
870
			Component message = Component.translatable("inventory.hotbarSaved", activatorKeyMessage, translatedKeyMessage);
871
			minecraft.gui.hud.setOverlayMessage(message, false);
872
			minecraft.getNarrator().saySystemNow(message);
873
			manager.save();
874
		}
875
	}
876
877
	@Environment(EnvType.CLIENT)
878
	private static class CustomCreativeSlot extends Slot {
879
		public CustomCreativeSlot(final Container container, final int slot, final int x, final int y) {
880
			super(container, slot, x, y);
881
		}
882
883
		@Override
884
		public boolean mayPickup(final Player player) {
885
			ItemStack item = this.getItem();
886
			return super.mayPickup(player) && !item.isEmpty()
887
				? item.isItemEnabled(player.level().enabledFeatures()) && !item.has(DataComponents.CREATIVE_SLOT_LOCK)
888
				: item.isEmpty();
889
		}
890
	}
891
892
	@Environment(EnvType.CLIENT)
893
	public static class ItemPickerMenu extends AbstractContainerMenu {
894
		public final NonNullList<ItemStack> items = NonNullList.create();
895
		private final AbstractContainerMenu inventoryMenu;
896
897
		public ItemPickerMenu(final Player player) {
898
			super(null, 0);
899
			this.inventoryMenu = player.inventoryMenu;
900
			Inventory inventory = player.getInventory();
901
902
			for (int y = 0; y < 5; y++) {
903
				for (int x = 0; x < 9; x++) {
904
					this.addSlot(new CreativeModeInventoryScreen.CustomCreativeSlot(CreativeModeInventoryScreen.CONTAINER, y * 9 + x, 9 + x * 18, 18 + y * 18));
905
				}
906
			}
907
908
			this.addInventoryHotbarSlots(inventory, 9, 112);
909
			this.scrollTo(0.0F);
910
		}
911
912
		@Override
913
		public boolean stillValid(final Player player) {
914
			return true;
915
		}
916
917
		protected int calculateRowCount() {
918
			return Mth.positiveCeilDiv(this.items.size(), 9) - 5;
919
		}
920
921
		protected int getRowIndexForScroll(final float scrollOffs) {
922
			return Math.max((int)(scrollOffs * this.calculateRowCount() + 0.5), 0);
923
		}
924
925
		protected float getScrollForRowIndex(final int rowIndex) {
926
			return Mth.clamp((float)rowIndex / this.calculateRowCount(), 0.0F, 1.0F);
927
		}
928
929
		protected float subtractInputFromScroll(final float scrollOffs, final double input) {
930
			return Mth.clamp(scrollOffs - (float)(input / this.calculateRowCount()), 0.0F, 1.0F);
931
		}
932
933
		public void scrollTo(final float scrollOffs) {
934
			int rowToScrollTo = this.getRowIndexForScroll(scrollOffs);
935
936
			for (int y = 0; y < 5; y++) {
937
				for (int x = 0; x < 9; x++) {
938
					int slot = x + (y + rowToScrollTo) * 9;
939
					if (slot >= 0 && slot < this.items.size()) {
940
						CreativeModeInventoryScreen.CONTAINER.setItem(x + y * 9, this.items.get(slot));
941
					} else {
942
						CreativeModeInventoryScreen.CONTAINER.setItem(x + y * 9, ItemStack.EMPTY);
943
					}
944
				}
945
			}
946
		}
947
948
		public boolean canScroll() {
949
			return this.items.size() > 45;
950
		}
951
952
		@Override
953
		public ItemStack quickMoveStack(final Player player, final int slotIndex) {
954
			if (slotIndex >= this.slots.size() - 9 && slotIndex < this.slots.size()) {
955
				Slot slot = this.slots.get(slotIndex);
956
				if (slot != null && slot.hasItem()) {
957
					slot.setByPlayer(ItemStack.EMPTY);
958
				}
959
			}
960
961
			return ItemStack.EMPTY;
962
		}
963
964
		@Override
965
		public boolean canTakeItemForPickAll(final ItemStack carried, final Slot target) {
966
			return target.container != CreativeModeInventoryScreen.CONTAINER;
967
		}
968
969
		@Override
970
		public boolean canDragTo(final Slot slot) {
971
			return slot.container != CreativeModeInventoryScreen.CONTAINER;
972
		}
973
974
		@Override
975
		public ItemStack getCarried() {
976
			return this.inventoryMenu.getCarried();
977
		}
978
979
		@Override
980
		public void setCarried(final ItemStack carried) {
981
			this.inventoryMenu.setCarried(carried);
982
		}
983
	}
984
985
	@Environment(EnvType.CLIENT)
986
	private static class SlotWrapper extends Slot {
987
		private final Slot target;
988
989
		public SlotWrapper(final Slot target, final int index, final int x, final int y) {
990
			super(target.container, index, x, y);
991
			this.target = target;
992
		}
993
994
		@Override
995
		public void onTake(final Player player, final ItemStack carried) {
996
			this.target.onTake(player, carried);
997
		}
998
999
		@Override
1000
		public boolean mayPlace(final ItemStack itemStack) {
1001
			return this.target.mayPlace(itemStack);
1002
		}
1003
1004
		@Override
1005
		public ItemStack getItem() {
1006
			return this.target.getItem();
1007
		}
1008
1009
		@Override
1010
		public boolean hasItem() {
1011
			return this.target.hasItem();
1012
		}
1013
1014
		@Override
1015
		public void setByPlayer(final ItemStack itemStack, final ItemStack previous) {
1016
			this.target.setByPlayer(itemStack, previous);
1017
		}
1018
1019
		@Override
1020
		public void set(final ItemStack itemStack) {
1021
			this.target.set(itemStack);
1022
		}
1023
1024
		@Override
1025
		public void setChanged() {
1026
			this.target.setChanged();
1027
		}
1028
1029
		@Override
1030
		public int getMaxStackSize() {
1031
			return this.target.getMaxStackSize();
1032
		}
1033
1034
		@Override
1035
		public int getMaxStackSize(final ItemStack itemStack) {
1036
			return this.target.getMaxStackSize(itemStack);
1037
		}
1038
1039
		@Override
1040
		public @Nullable Identifier getNoItemIcon() {
1041
			return this.target.getNoItemIcon();
1042
		}
1043
1044
		@Override
1045
		public ItemStack remove(final int amount) {
1046
			return this.target.remove(amount);
1047
		}
1048
1049
		@Override
1050
		public boolean isActive() {
1051
			return this.target.isActive();
1052
		}
1053
1054
		@Override
1055
		public boolean mayPickup(final Player player) {
1056
			return this.target.mayPickup(player);
1057
		}
1058
	}
1059
}
1060

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