Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SlotAssemblyTable extends Slot {
- private final InventoryCrafting craftMatrix;
- /** The player that is using the GUI where this slot resides. */
- private final EntityPlayer player;
- /** The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */
- private int amountCrafted;
- public SlotAssemblyTable(EntityPlayer par1EntityPlayer, InventoryCrafting par2IInventory, IInventory par3IInventory, int par4, int par5, int par6)
- {
- super(par3IInventory, par4, par5, par6);
- this.player = par1EntityPlayer;
- this.craftMatrix = par2IInventory;
- }
- @Override
- public boolean isItemValid(ItemStack par1ItemStack)
- {
- return false;
- }
- @Override
- public ItemStack decrStackSize(int par1)
- {
- if (this.getHasStack())
- {
- this.amountCrafted += Math.min(par1, this.getStack().getCount());
- }
- return super.decrStackSize(par1);
- }
- @Override
- protected void onCrafting(ItemStack par1ItemStack, int par2)
- {
- this.amountCrafted += par2;
- this.onCrafting(par1ItemStack);
- }
- @Override
- protected void onSwapCraft(int p_190900_1_)
- {
- this.amountCrafted += p_190900_1_;
- }
- /**
- * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
- */
- @Override
- protected void onCrafting(ItemStack stack)
- {
- if (this.amountCrafted > 0)
- {
- stack.onCrafting(this.player.world, this.player, this.amountCrafted);
- net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(this.player, stack, craftMatrix);
- }
- this.amountCrafted = 0;
- }
- @Override
- public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
- {
- this.onCrafting(stack);
- net.minecraftforge.common.ForgeHooks.setCraftingPlayer(thePlayer);
- NonNullList<ItemStack> nonnulllist = CraftingManager.getInstance().getRemainingItems(this.craftMatrix, thePlayer.world);
- net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
- for (int i = 0; i < nonnulllist.size(); ++i)
- {
- ItemStack itemstack = this.craftMatrix.getStackInSlot(i);
- ItemStack itemstack1 = (ItemStack)nonnulllist.get(i);
- if (!itemstack.isEmpty())
- {
- this.craftMatrix.decrStackSize(i, 1);
- itemstack = this.craftMatrix.getStackInSlot(i);
- }
- if (!itemstack1.isEmpty())
- {
- if (itemstack.isEmpty())
- {
- this.craftMatrix.setInventorySlotContents(i, itemstack1);
- }
- else if (ItemStack.areItemsEqual(itemstack, itemstack1) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1))
- {
- itemstack1.grow(itemstack.getCount());
- this.craftMatrix.setInventorySlotContents(i, itemstack1);
- }
- else if (!this.player.inventory.addItemStackToInventory(itemstack1))
- {
- this.player.dropItem(itemstack1, false);
- }
- }
- }
- return stack;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment