123 lines
3.8 KiB
Java
123 lines
3.8 KiB
Java
package net.minecraft.world.inventory;
|
|
|
|
import net.minecraft.world.Container;
|
|
import net.minecraft.world.SimpleContainer;
|
|
import net.minecraft.world.entity.player.Inventory;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
public class ChestMenu extends AbstractContainerMenu {
|
|
private static final int SLOTS_PER_ROW = 9;
|
|
private final Container container;
|
|
private final int containerRows;
|
|
|
|
private ChestMenu(MenuType<?> type, int containerId, Inventory playerInventory, int rows) {
|
|
this(type, containerId, playerInventory, new SimpleContainer(9 * rows), rows);
|
|
}
|
|
|
|
public static ChestMenu oneRow(int containerId, Inventory playerInventory) {
|
|
return new ChestMenu(MenuType.GENERIC_9x1, containerId, playerInventory, 1);
|
|
}
|
|
|
|
public static ChestMenu twoRows(int containerId, Inventory playerInventory) {
|
|
return new ChestMenu(MenuType.GENERIC_9x2, containerId, playerInventory, 2);
|
|
}
|
|
|
|
public static ChestMenu threeRows(int containerId, Inventory playerInventory) {
|
|
return new ChestMenu(MenuType.GENERIC_9x3, containerId, playerInventory, 3);
|
|
}
|
|
|
|
public static ChestMenu fourRows(int containerId, Inventory playerInventory) {
|
|
return new ChestMenu(MenuType.GENERIC_9x4, containerId, playerInventory, 4);
|
|
}
|
|
|
|
public static ChestMenu fiveRows(int containerId, Inventory playerInventory) {
|
|
return new ChestMenu(MenuType.GENERIC_9x5, containerId, playerInventory, 5);
|
|
}
|
|
|
|
public static ChestMenu sixRows(int containerId, Inventory playerInventory) {
|
|
return new ChestMenu(MenuType.GENERIC_9x6, containerId, playerInventory, 6);
|
|
}
|
|
|
|
public static ChestMenu threeRows(int containerId, Inventory playerInventory, Container container) {
|
|
return new ChestMenu(MenuType.GENERIC_9x3, containerId, playerInventory, container, 3);
|
|
}
|
|
|
|
public static ChestMenu sixRows(int containerId, Inventory playerInventory, Container container) {
|
|
return new ChestMenu(MenuType.GENERIC_9x6, containerId, playerInventory, container, 6);
|
|
}
|
|
|
|
public ChestMenu(MenuType<?> type, int containerId, Inventory playerInventory, Container container, int rows) {
|
|
super(type, containerId);
|
|
checkContainerSize(container, rows * 9);
|
|
this.container = container;
|
|
this.containerRows = rows;
|
|
container.startOpen(playerInventory.player);
|
|
int i = (this.containerRows - 4) * 18;
|
|
|
|
for (int j = 0; j < this.containerRows; j++) {
|
|
for (int k = 0; k < 9; k++) {
|
|
this.addSlot(new Slot(container, k + j * 9, 8 + k * 18, 18 + j * 18));
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
for (int k = 0; k < 9; k++) {
|
|
this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < 9; j++) {
|
|
this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 161 + i));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean stillValid(Player player) {
|
|
return this.container.stillValid(player);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack quickMoveStack(Player player, int index) {
|
|
ItemStack itemStack = ItemStack.EMPTY;
|
|
Slot slot = this.slots.get(index);
|
|
if (slot != null && slot.hasItem()) {
|
|
ItemStack itemStack2 = slot.getItem();
|
|
itemStack = itemStack2.copy();
|
|
if (index < this.containerRows * 9) {
|
|
if (!this.moveItemStackTo(itemStack2, this.containerRows * 9, this.slots.size(), true)) {
|
|
return ItemStack.EMPTY;
|
|
}
|
|
} else if (!this.moveItemStackTo(itemStack2, 0, this.containerRows * 9, false)) {
|
|
return ItemStack.EMPTY;
|
|
}
|
|
|
|
if (itemStack2.isEmpty()) {
|
|
slot.setByPlayer(ItemStack.EMPTY);
|
|
} else {
|
|
slot.setChanged();
|
|
}
|
|
}
|
|
|
|
return itemStack;
|
|
}
|
|
|
|
@Override
|
|
public void removed(Player player) {
|
|
super.removed(player);
|
|
this.container.stopOpen(player);
|
|
}
|
|
|
|
/**
|
|
* Gets the inventory associated with this chest container.
|
|
*
|
|
* @see #field_75155_e
|
|
*/
|
|
public Container getContainer() {
|
|
return this.container;
|
|
}
|
|
|
|
public int getRowCount() {
|
|
return this.containerRows;
|
|
}
|
|
}
|