Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TeleporterMenu extends AbstractContainerMenu {
- public final WarpPipeBlockEntity blockEntity;
- private final Level level;
- // Client constructor
- public TeleporterMenu(int pContainerId, Inventory inv, FriendlyByteBuf extraData) {
- this(pContainerId, inv, inv.player.level.getBlockEntity(extraData.readBlockPos()));
- }
- // Server constructor
- public TeleporterMenu(int pContainerId, Inventory inv, BlockEntity entity) {
- super(ModMenuTypes.TELEPORTER_MENU.get(), pContainerId);
- checkContainerSize(inv, Constants.TELEPORTER_TOTALSLOTS);
- blockEntity = ((WarpPipeBlockEntity) entity);
- this.level = inv.player.level;
- addPlayerInventory(inv);
- addPlayerHotbar(inv);
- this.blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(handler -> {
- //The third and fourth numbers are the position of the slots
- // (this.addSlot(new SlotItemHandler(handler, 0, THIRD, FOURTH));)
- //in an editing program, put your mouse above one of the slots at the top left part
- //(the mouse goes starting from the lightest grey pixel)
- this.addSlot(new TeleporterSlot(handler, 0, 152, 8));
- });
- }
- private static final int HOTBAR_SLOT_COUNT = 9;
- private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
- private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
- private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
- private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
- private static final int VANILLA_FIRST_SLOT_INDEX = 0;
- private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
- // THIS YOU HAVE TO DEFINE!
- private static final int TE_INVENTORY_SLOT_COUNT = Constants.TELEPORTER_TOTALSLOTS; // must be the number of slots you have!
- @Override
- public ItemStack quickMoveStack(Player playerIn, int index) {
- Slot sourceSlot = slots.get(index);
- if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM
- ItemStack sourceStack = sourceSlot.getItem();
- ItemStack copyOfSourceStack = sourceStack.copy();
- // Check if the slot clicked is one of the vanilla container slots
- if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
- // This is a vanilla container slot so merge the stack into the tile inventory
- if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX
- + TE_INVENTORY_SLOT_COUNT, false)) {
- return ItemStack.EMPTY; // EMPTY_ITEM
- }
- } else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
- // This is a TE slot so merge the stack into the players inventory
- if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
- return ItemStack.EMPTY;
- }
- } else {
- System.out.println("Invalid slotIndex:" + index);
- return ItemStack.EMPTY;
- }
- // If stack size == 0 (the entire stack was moved) set slot contents to null
- if (sourceStack.getCount() == 0) {
- sourceSlot.set(ItemStack.EMPTY);
- } else {
- sourceSlot.setChanged();
- }
- sourceSlot.onTake(playerIn, sourceStack);
- return copyOfSourceStack;
- }
- @Override
- public boolean stillValid(Player pPlayer) {
- /*return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()),
- pPlayer, ModBlocks.TELEPORTER_WHITE.get()) ||
- stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()),
- pPlayer, ModBlocks.TELEPORTER_RED.get());*/
- return true;
- }
- private final void addPlayerInventory(Inventory playerInventory) {
- for (int i = 0; i < 3; ++i) {
- for (int l = 0; l < 9; ++l) {
- this.addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, 86 + i * 18)); //default: 122
- }
- }
- }
- private final void addPlayerHotbar(Inventory playerInventory) {
- for (int i = 0; i < 9; ++i) {
- this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 144)); //default: 180
- }
- }
- public WarpPipeBlockEntity getBlockEntity() {
- return this.blockEntity;
- }
- }
Add Comment
Please, Sign In to add comment