SlotCrafting .java

net.minecraft.inventory.SlotCrafting (class): members: amountCrafted, craftMatrix, onPickupFromSlot, isItemValid, onCrafting, thePlayer, decrStackSize.

net.minecraft.inventoryclass163 linescommonextends Slot5.1 KB

API Surface (5)

boolean isItemValid(ItemStack stack)
ItemStack decrStackSize(int amount)
void onCrafting(ItemStack stack, int amount)
void onCrafting(ItemStack stack)
void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)

Fields & Constants (3)

craftMatrix
thePlayer
amountCrafted

Full Source

SlotCrafting.java163 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.inventory;
2
3
import net.minecraft.entity.player.EntityPlayer;
4
import net.minecraft.init.Blocks;
5
import net.minecraft.init.Items;
6
import net.minecraft.item.Item;
7
import net.minecraft.item.ItemHoe;
8
import net.minecraft.item.ItemPickaxe;
9
import net.minecraft.item.ItemStack;
10
import net.minecraft.item.ItemSword;
11
import net.minecraft.item.crafting.CraftingManager;
12
import net.minecraft.stats.AchievementList;
13
14
public class SlotCrafting extends Slot
15
{
16
    /** The craft matrix inventory linked to this result slot. */
17
    private final InventoryCrafting craftMatrix;
18
19
    /** The player that is using the GUI where this slot resides. */
20
    private final EntityPlayer thePlayer;
21
22
    /**
23
     * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
24
     */
25
    private int amountCrafted;
26
27
    public SlotCrafting(EntityPlayer player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition)
28
    {
29
        super(p_i45790_3_, slotIndex, xPosition, yPosition);
30
        this.thePlayer = player;
31
        this.craftMatrix = craftingInventory;
32
    }
33
34
    /**
35
     * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
36
     */
37
    public boolean isItemValid(ItemStack stack)
38
    {
39
        return false;
40
    }
41
42
    /**
43
     * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
44
     * stack.
45
     */
46
    public ItemStack decrStackSize(int amount)
47
    {
48
        if (this.getHasStack())
49
        {
50
            this.amountCrafted += Math.min(amount, this.getStack().stackSize);
51
        }
52
53
        return super.decrStackSize(amount);
54
    }
55
56
    /**
57
     * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
58
     * internal count then calls onCrafting(item).
59
     */
60
    protected void onCrafting(ItemStack stack, int amount)
61
    {
62
        this.amountCrafted += amount;
63
        this.onCrafting(stack);
64
    }
65
66
    /**
67
     * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
68
     */
69
    protected void onCrafting(ItemStack stack)
70
    {
71
        if (this.amountCrafted > 0)
72
        {
73
            stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted);
74
        }
75
76
        this.amountCrafted = 0;
77
78
        if (stack.getItem() == Item.getItemFromBlock(Blocks.crafting_table))
79
        {
80
            this.thePlayer.triggerAchievement(AchievementList.buildWorkBench);
81
        }
82
83
        if (stack.getItem() instanceof ItemPickaxe)
84
        {
85
            this.thePlayer.triggerAchievement(AchievementList.buildPickaxe);
86
        }
87
88
        if (stack.getItem() == Item.getItemFromBlock(Blocks.furnace))
89
        {
90
            this.thePlayer.triggerAchievement(AchievementList.buildFurnace);
91
        }
92
93
        if (stack.getItem() instanceof ItemHoe)
94
        {
95
            this.thePlayer.triggerAchievement(AchievementList.buildHoe);
96
        }
97
98
        if (stack.getItem() == Items.bread)
99
        {
100
            this.thePlayer.triggerAchievement(AchievementList.makeBread);
101
        }
102
103
        if (stack.getItem() == Items.cake)
104
        {
105
            this.thePlayer.triggerAchievement(AchievementList.bakeCake);
106
        }
107
108
        if (stack.getItem() instanceof ItemPickaxe && ((ItemPickaxe)stack.getItem()).getToolMaterial() != Item.ToolMaterial.WOOD)
109
        {
110
            this.thePlayer.triggerAchievement(AchievementList.buildBetterPickaxe);
111
        }
112
113
        if (stack.getItem() instanceof ItemSword)
114
        {
115
            this.thePlayer.triggerAchievement(AchievementList.buildSword);
116
        }
117
118
        if (stack.getItem() == Item.getItemFromBlock(Blocks.enchanting_table))
119
        {
120
            this.thePlayer.triggerAchievement(AchievementList.enchantments);
121
        }
122
123
        if (stack.getItem() == Item.getItemFromBlock(Blocks.bookshelf))
124
        {
125
            this.thePlayer.triggerAchievement(AchievementList.bookcase);
126
        }
127
128
        if (stack.getItem() == Items.golden_apple && stack.getMetadata() == 1)
129
        {
130
            this.thePlayer.triggerAchievement(AchievementList.overpowered);
131
        }
132
    }
133
134
    public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
135
    {
136
        this.onCrafting(stack);
137
        ItemStack[] aitemstack = CraftingManager.getInstance().func_180303_b(this.craftMatrix, playerIn.worldObj);
138
139
        for (int i = 0; i < aitemstack.length; ++i)
140
        {
141
            ItemStack itemstack = this.craftMatrix.getStackInSlot(i);
142
            ItemStack itemstack1 = aitemstack[i];
143
144
            if (itemstack != null)
145
            {
146
                this.craftMatrix.decrStackSize(i, 1);
147
            }
148
149
            if (itemstack1 != null)
150
            {
151
                if (this.craftMatrix.getStackInSlot(i) == null)
152
                {
153
                    this.craftMatrix.setInventorySlotContents(i, itemstack1);
154
                }
155
                else if (!this.thePlayer.inventory.addItemStackToInventory(itemstack1))
156
                {
157
                    this.thePlayer.dropPlayerItemWithRandomChoice(itemstack1, false);
158
                }
159
            }
160
        }
161
    }
162
}
163

Deobfuscated MCP 1.8.9 source of SlotCrafting from Marcelektro/MavenMCP-1.8.9 (net/minecraft/inventory/SlotCrafting.java), stored verbatim.