Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ContainerAssembly extends Container {
- public InventoryCrafting craftMatrix;
- public InventoryAssemblyResult craftResultA = new InventoryAssemblyResult();
- public InventoryCraftResult craftResult;
- public IRecipe lastRecipe;
- public final World world;
- final int x;
- final int y;
- final int z;
- final BlockPos pos;
- private final EntityPlayer player;
- // private SlotCraftingAssembly result;
- public ContainerAssembly(EntityPlayer player, World world, int x, int y, int z) {
- this(player, world, new BlockPos(x, y, z));
- }
- public ContainerAssembly(EntityPlayer player, World world, BlockPos pos) {
- this.player = player;
- this.inventorySlots.clear();
- this.inventoryItemStacks.clear();
- this.world = world;
- this.x = pos.getX();
- this.y = pos.getY();
- this.z = pos.getZ();
- this.pos = pos;
- this.craftMatrix = new InventoryCrafting(this, 5, 3);
- // this.result = new SlotCraftingAssembly(this, player, this.craftMatrix, this.craftResult, 0, 137, 35);
- this.addSlotToContainer(new SlotCraftingAssembly(this, player, this.craftMatrix, this.craftResult, 15, 137, 35));
- for(int i = 0; i < 3; ++i) {
- for(int j = 0; j < 5; ++j) {
- this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 5, 18 + j * 18, 17 + i * 18));
- // this.addSlotToContainer(new SlotCraftingAssembly(this, player, this.craftMatrix, this.craftResult,1 + j + i * 5, 18 + j * 18, 17 + i * 18));
- }
- }
- for (int k = 0; k < 3; ++k) {
- for (int i1 = 0; i1 < 9; ++i1) {
- this.addSlotToContainer(new Slot(player.inventory, 1 + i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
- }
- }
- for (int l = 0; l < 9; ++l) {
- this.addSlotToContainer(new Slot(player.inventory, l, 8 + l * 18, 142));
- }
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- if (this.world.getBlockState(this.pos).getBlock() != ExkvaBlocks.assembly) {
- return false;
- } else {
- return playerIn.getDistanceSq(x + 0.5D, y + 0.5D, z + 0.5D) <= 64.0D;
- }
- }
- @Override
- public void onContainerClosed(EntityPlayer player) {
- if (pos != BlockPos.ORIGIN) super.onContainerClosed(player);
- else {
- InventoryPlayer inv = player.inventory;
- if (!inv.getItemStack().isEmpty()) {
- player.dropItem(inv.getItemStack(), false);
- inv.setItemStack(ItemStack.EMPTY);
- }
- if (!this.world.isRemote) this.clearContainer(player, this.world, this.craftMatrix);
- }
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
- ItemStack stack_slot = ItemStack.EMPTY;
- Slot slot = inventorySlots.get(index);
- if(slot != null && slot.getHasStack()) {
- ItemStack stack = slot.getStack();
- stack_slot = stack.copy();
- slot.onSlotChanged();
- if(stack.getCount() == stack_slot.getCount()) {
- return ItemStack.EMPTY;
- }
- slot.onTake(playerIn, stack);
- }
- return stack_slot;
- }
- public void onCraftMatrixChanged(IInventory inventoryIn) {
- super.detectAndSendChanges();
- NonNullList<ItemStack> pattern = this.craftMatrix.stackList;
- for(RecipeExkvaAssembly recipe : Exkva.ASSEMBLY_RECIPES) {
- if(recipe.matches(pattern)) {
- this.inventorySlots.get(15).putStack(recipe.getOutput().copy());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement