Advertisement
Exokem

Untitled

Mar 25th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.69 KB | None | 0 0
  1. public class ContainerAssembly extends Container {
  2.  
  3.     public InventoryCrafting craftMatrix;
  4.     public InventoryAssemblyResult craftResultA = new InventoryAssemblyResult();
  5.     public InventoryCraftResult craftResult;
  6.     public IRecipe lastRecipe;
  7.     public final World world;
  8.     final int x;
  9.     final int y;
  10.     final int z;
  11.     final BlockPos pos;
  12.     private final EntityPlayer player;
  13. //    private SlotCraftingAssembly result;
  14.  
  15.     public ContainerAssembly(EntityPlayer player, World world, int x, int y, int z) {
  16.         this(player, world, new BlockPos(x, y, z));
  17.     }
  18.     public ContainerAssembly(EntityPlayer player, World world, BlockPos pos) {
  19.         this.player = player;
  20.         this.inventorySlots.clear();
  21.         this.inventoryItemStacks.clear();
  22.         this.world = world;
  23.         this.x = pos.getX();
  24.         this.y = pos.getY();
  25.         this.z = pos.getZ();
  26.         this.pos = pos;
  27.         this.craftMatrix = new InventoryCrafting(this, 5, 3);
  28. //        this.result = new SlotCraftingAssembly(this, player, this.craftMatrix, this.craftResult, 0, 137, 35);
  29.  
  30.         this.addSlotToContainer(new SlotCraftingAssembly(this, player, this.craftMatrix, this.craftResult, 15, 137, 35));
  31.  
  32.         for(int i = 0; i < 3; ++i) {
  33.             for(int j = 0; j < 5; ++j) {
  34.                 this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 5, 18 + j * 18, 17 + i * 18));
  35. //                this.addSlotToContainer(new SlotCraftingAssembly(this, player, this.craftMatrix, this.craftResult,1 + j + i * 5, 18 + j * 18, 17 + i * 18));
  36.             }
  37.         }
  38.         for (int k = 0; k < 3; ++k) {
  39.             for (int i1 = 0; i1 < 9; ++i1) {
  40.                 this.addSlotToContainer(new Slot(player.inventory, 1 + i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
  41.             }
  42.         }
  43.         for (int l = 0; l < 9; ++l) {
  44.             this.addSlotToContainer(new Slot(player.inventory, l, 8 + l * 18, 142));
  45.         }
  46.     }
  47.  
  48.     @Override
  49.     public boolean canInteractWith(EntityPlayer playerIn) {
  50.         if (this.world.getBlockState(this.pos).getBlock() != ExkvaBlocks.assembly) {
  51.             return false;
  52.         } else {
  53.             return playerIn.getDistanceSq(x + 0.5D, y + 0.5D, z + 0.5D) <= 64.0D;
  54.         }
  55.     }
  56.  
  57.     @Override
  58.     public void onContainerClosed(EntityPlayer player) {
  59.         if (pos != BlockPos.ORIGIN) super.onContainerClosed(player);
  60.         else {
  61.             InventoryPlayer inv = player.inventory;
  62.             if (!inv.getItemStack().isEmpty()) {
  63.                 player.dropItem(inv.getItemStack(), false);
  64.                 inv.setItemStack(ItemStack.EMPTY);
  65.             }
  66.             if (!this.world.isRemote) this.clearContainer(player, this.world, this.craftMatrix);
  67.         }
  68.     }
  69.  
  70.     @Override
  71.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
  72.  
  73.         ItemStack stack_slot = ItemStack.EMPTY;
  74.         Slot slot = inventorySlots.get(index);
  75.         if(slot != null && slot.getHasStack()) {
  76.             ItemStack stack = slot.getStack();
  77.             stack_slot = stack.copy();
  78.  
  79.             slot.onSlotChanged();
  80.             if(stack.getCount() == stack_slot.getCount()) {
  81.                 return ItemStack.EMPTY;
  82.             }
  83.             slot.onTake(playerIn, stack);
  84.         }
  85.         return stack_slot;
  86.     }
  87.  
  88.     public void onCraftMatrixChanged(IInventory inventoryIn) {
  89.  
  90.         super.detectAndSendChanges();
  91.         NonNullList<ItemStack> pattern = this.craftMatrix.stackList;
  92.  
  93.         for(RecipeExkvaAssembly recipe : Exkva.ASSEMBLY_RECIPES) {
  94.             if(recipe.matches(pattern)) {
  95.                 this.inventorySlots.get(15).putStack(recipe.getOutput().copy());
  96.             }
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement