2019-02-17 22:51:05 +01:00
|
|
|
package de.ellpeck.naturesaura.gui;
|
|
|
|
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
|
|
import net.minecraft.world.inventory.MenuType;
|
|
|
|
import net.minecraft.world.inventory.Slot;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
2019-02-17 22:51:05 +01:00
|
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
import net.minecraftforge.items.SlotItemHandler;
|
|
|
|
|
2021-12-04 19:17:21 +01:00
|
|
|
public class ContainerEnderCrate extends AbstractContainerMenu {
|
2019-02-17 22:51:05 +01:00
|
|
|
|
2021-12-04 19:17:21 +01:00
|
|
|
public ContainerEnderCrate(MenuType<ContainerEnderCrate> type, int id, Player player, IItemHandler handler) {
|
2020-01-21 23:02:39 +01:00
|
|
|
super(type, id);
|
2021-12-15 16:30:22 +01:00
|
|
|
var i = (3 - 4) * 18;
|
|
|
|
for (var j = 0; j < 3; ++j)
|
|
|
|
for (var k = 0; k < 9; ++k)
|
2020-01-21 23:02:39 +01:00
|
|
|
this.addSlot(new SlotItemHandler(handler, k + j * 9, 8 + k * 18, 18 + j * 18));
|
2021-12-15 16:30:22 +01:00
|
|
|
for (var l = 0; l < 3; ++l)
|
|
|
|
for (var j1 = 0; j1 < 9; ++j1)
|
2021-12-04 19:17:21 +01:00
|
|
|
this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i));
|
2021-12-15 16:30:22 +01:00
|
|
|
for (var i1 = 0; i1 < 9; ++i1)
|
2021-12-04 19:17:21 +01:00
|
|
|
this.addSlot(new Slot(player.getInventory(), i1, 8 + i1 * 18, 161 + i));
|
2019-02-17 22:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 19:17:21 +01:00
|
|
|
public boolean stillValid(Player playerIn) {
|
2019-02-18 12:15:18 +01:00
|
|
|
return true;
|
2019-02-17 22:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 19:17:21 +01:00
|
|
|
public ItemStack quickMoveStack(Player player, int index) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var itemstack = ItemStack.EMPTY;
|
|
|
|
var slot = this.slots.get(index);
|
2019-02-17 22:51:05 +01:00
|
|
|
|
2021-12-04 19:17:21 +01:00
|
|
|
if (slot != null && slot.hasItem()) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var itemstack1 = slot.getItem();
|
2019-02-17 22:51:05 +01:00
|
|
|
itemstack = itemstack1.copy();
|
|
|
|
|
|
|
|
if (index < 3 * 9) {
|
2021-12-04 19:17:21 +01:00
|
|
|
if (!this.moveItemStackTo(itemstack1, 3 * 9, this.slots.size(), true))
|
2019-02-17 22:51:05 +01:00
|
|
|
return ItemStack.EMPTY;
|
2021-12-04 19:17:21 +01:00
|
|
|
} else if (!this.moveItemStackTo(itemstack1, 0, 3 * 9, false))
|
2019-02-17 22:51:05 +01:00
|
|
|
return ItemStack.EMPTY;
|
|
|
|
|
|
|
|
if (itemstack1.isEmpty())
|
2021-12-04 19:17:21 +01:00
|
|
|
slot.set(ItemStack.EMPTY);
|
2019-02-17 22:51:05 +01:00
|
|
|
else
|
2021-12-04 19:17:21 +01:00
|
|
|
slot.setChanged();
|
2019-02-17 22:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
2021-12-04 19:17:21 +01:00
|
|
|
|
2019-02-17 22:51:05 +01:00
|
|
|
}
|