2020-05-07 18:30:40 +02:00
|
|
|
package de.ellpeck.prettypipes.terminal.containers;
|
|
|
|
|
|
|
|
import de.ellpeck.prettypipes.Utility;
|
2021-12-02 14:44:26 +01:00
|
|
|
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
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;
|
2021-12-02 12:31:04 +01:00
|
|
|
import net.minecraft.world.item.ItemStack;
|
2020-05-07 18:30:40 +02:00
|
|
|
import net.minecraftforge.items.SlotItemHandler;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2021-12-02 14:44:26 +01:00
|
|
|
public class ItemTerminalContainer extends AbstractContainerMenu {
|
2020-05-07 18:30:40 +02:00
|
|
|
|
2021-12-02 14:44:26 +01:00
|
|
|
public final ItemTerminalBlockEntity tile;
|
2020-05-07 18:30:40 +02:00
|
|
|
|
2021-12-02 14:44:26 +01:00
|
|
|
public ItemTerminalContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos) {
|
2020-05-07 18:30:40 +02:00
|
|
|
super(type, id);
|
2023-07-07 19:54:52 +02:00
|
|
|
this.tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level(), pos);
|
2020-05-07 18:30:40 +02:00
|
|
|
|
2020-05-09 01:00:59 +02:00
|
|
|
this.addOwnSlots(player);
|
2020-05-07 18:30:40 +02:00
|
|
|
|
2021-12-02 17:46:56 +01:00
|
|
|
var off = this.getSlotXOffset();
|
|
|
|
for (var l = 0; l < 3; ++l)
|
|
|
|
for (var j1 = 0; j1 < 9; ++j1)
|
2021-12-02 14:44:26 +01:00
|
|
|
this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18));
|
2021-12-02 17:46:56 +01:00
|
|
|
for (var i1 = 0; i1 < 9; ++i1)
|
2021-12-02 14:44:26 +01:00
|
|
|
this.addSlot(new Slot(player.getInventory(), i1, 8 + off + i1 * 18, 212));
|
2020-05-08 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
2021-12-02 14:44:26 +01:00
|
|
|
protected void addOwnSlots(Player player) {
|
2021-12-02 17:46:56 +01:00
|
|
|
var off = this.getSlotXOffset();
|
|
|
|
for (var i = 0; i < 6; i++)
|
2020-05-09 01:00:59 +02:00
|
|
|
this.addSlot(new SlotItemHandler(this.tile.items, i, 8 + off + i % 3 * 18, 102 + i / 3 * 18));
|
2021-12-02 17:46:56 +01:00
|
|
|
for (var i = 0; i < 6; i++)
|
2020-05-09 01:00:59 +02:00
|
|
|
this.addSlot(new SlotItemHandler(this.tile.items, i + 6, 116 + off + i % 3 * 18, 102 + i / 3 * 18));
|
|
|
|
}
|
|
|
|
|
2020-05-08 22:58:16 +02:00
|
|
|
protected int getSlotXOffset() {
|
|
|
|
return 0;
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-02 14:44:26 +01:00
|
|
|
public ItemStack quickMoveStack(Player player, int slotIndex) {
|
|
|
|
return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> Pair.of(6, 12));
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-02 14:44:26 +01:00
|
|
|
public boolean stillValid(Player player) {
|
2020-05-07 18:30:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|