Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ModContainer extends Container {
- private IInventory lowerChestInventory;
- private int rows;
- private final ModTileEntity tileEntity;
- public ModTileEntity getTileEntity() { return this.tileEntity; }
- private BlockPos blockPos;
- public BlockPos getBlockPos() {
- return this.blockPos;
- }
- private int containerInd;
- public int getContainerInd() {
- return this.containerInd;
- }
- public void setBlockPos(ModTileEntity modTileEntity) {
- BlockPos blockPos1 = modTileEntity.getBlockPos();
- if (blockPos1 != null) {
- System.out.println("Working?");
- int containerInd1 = modTileEntity.getCapability(ModTeIDProvider.MOD_TE_ID).orElseThrow(
- () -> new IllegalArgumentException("LazyOptional cannot be empty!")).get()[3];
- modTileEntity.getCapability(ModTeIDProvider.MOD_TE_ID).ifPresent(iModTag -> iModTag.set(new int[]{blockPos1.getX(), blockPos1.getY(), blockPos1.getZ(), containerInd1}));
- }
- }
- public ModContainer(int id, PlayerInventory playerInventory) {
- this(ModContainerTypes2.MULTI_9X3, id, playerInventory, 3);
- }
- private ModContainer(ContainerType<?> type, int id, PlayerInventory playerInventory, int rows) {
- this(type, id, playerInventory, new Inventory(9 * rows), rows);
- }
- public ModContainer(ContainerType<?> type, int id, PlayerInventory playerInventory, IInventory iinventory, int rows) {
- super(type, id);
- this.tileEntity = new ModTileEntity();
- createInventory(playerInventory, iinventory, this.tileEntity, rows);
- }
- public ModContainer(int id, PlayerInventory playerInventory, ModTileEntity modTileEntity) {
- this(ModContainerTypes2.MULTI_9X3, id, playerInventory, modTileEntity, 3);
- }
- private ModContainer(ContainerType<?> type, int id, PlayerInventory playerInventory, ModTileEntity modTileEntity, int rows) {
- this(type, id, playerInventory, new Inventory(9 * rows), modTileEntity, rows);
- }
- public ModContainer(ContainerType<?> type, int id, PlayerInventory playerInventory, IInventory iinventory, ModTileEntity modTileEntity, int rows) {
- super(type, id);
- this.tileEntity = modTileEntity;
- System.out.println("TileEntity: " + modTileEntity);
- createInventory(playerInventory, iinventory, this.tileEntity, rows);
- }
- public void createInventory(PlayerInventory playerInventory, IInventory iinventory, ModTileEntity modTileEntity, int rows) {
- assertInventorySize(iinventory, rows * 9);
- this.lowerChestInventory = iinventory;
- iinventory.openInventory(playerInventory.player);
- this.containerInd = modTileEntity.getContainerInd();
- this.blockPos = modTileEntity.getBlockPos();
- System.out.println("BlockPos container: " + this.blockPos);
- setBlockPos(modTileEntity);
- this.rows = rows;
- int i = (this.rows - 4) * 18;
- for(int j = 0; j < this.rows; ++j) {
- for(int k = 0; k < 9; ++k) {
- this.addSlot(new Slot(iinventory, k + j * 9, 8 + k * 18, 19 + j * 18));
- }
- }
- for(int l = 0; l < 3; ++l) {
- for(int j1 = 0; j1 < 9; ++j1) {
- this.addSlot(new Slot(playerInventory, j1 + l * 9 + 9, 8 + j1 * 18, 122 + l * 18 + i));
- }
- }
- for(int i1 = 0; i1 < 9; ++i1) {
- this.addSlot(new Slot(playerInventory, i1, 8 + i1 * 18, 180 + i));
- }
- }
- public boolean canInteractWith(PlayerEntity playerIn) {
- return this.lowerChestInventory.isUsableByPlayer(playerIn);
- }
- public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
- ItemStack itemstack = ItemStack.EMPTY;
- Slot slot = this.inventorySlots.get(index);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- if (index < this.rows * 9) {
- if (!this.mergeItemStack(itemstack1, this.rows * 9, this.inventorySlots.size(), true)) {
- return ItemStack.EMPTY;
- }
- } else if (!this.mergeItemStack(itemstack1, 0, this.rows * 9, false)) {
- return ItemStack.EMPTY;
- }
- if (itemstack1.isEmpty()) {
- slot.putStack(ItemStack.EMPTY);
- } else {
- slot.onSlotChanged();
- }
- }
- return itemstack;
- }
- public void onContainerClosed(PlayerEntity playerIn) {
- super.onContainerClosed(playerIn);
- this.lowerChestInventory.closeInventory(playerIn);
- }
- public IInventory getLowerChestInventory() {
- return this.lowerChestInventory;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement