ContainerBrewingStand .java

net.minecraft.inventory.ContainerBrewingStand (class, 207 lines): members: Ingredient, Potion, tileBrewingStand, brewTime, theSlot, detectAndSendChanges.

net.minecraft.inventoryclass207 linescommonextends Container6.1 KB

API Surface (11)

void onCraftGuiOpened(ICrafting listener)
void detectAndSendChanges()
void updateProgressBar(int id, int data)
boolean canInteractWith(EntityPlayer playerIn)
ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
boolean isItemValid(ItemStack stack)
int getSlotStackLimit()
boolean isItemValid(ItemStack stack)
int getSlotStackLimit()
void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
boolean canHoldPotion(ItemStack stack)

Fields & Constants (3)

tileBrewingStand
theSlot
brewTime

Full Source

ContainerBrewingStand.java207 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.inventory;
2
3
import net.minecraft.entity.player.EntityPlayer;
4
import net.minecraft.entity.player.InventoryPlayer;
5
import net.minecraft.init.Items;
6
import net.minecraft.item.ItemStack;
7
import net.minecraft.stats.AchievementList;
8
9
public class ContainerBrewingStand extends Container
10
{
11
    private IInventory tileBrewingStand;
12
13
    /** Instance of Slot. */
14
    private final Slot theSlot;
15
    private int brewTime;
16
17
    public ContainerBrewingStand(InventoryPlayer playerInventory, IInventory tileBrewingStandIn)
18
    {
19
        this.tileBrewingStand = tileBrewingStandIn;
20
        this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory.player, tileBrewingStandIn, 0, 56, 46));
21
        this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory.player, tileBrewingStandIn, 1, 79, 53));
22
        this.addSlotToContainer(new ContainerBrewingStand.Potion(playerInventory.player, tileBrewingStandIn, 2, 102, 46));
23
        this.theSlot = this.addSlotToContainer(new ContainerBrewingStand.Ingredient(tileBrewingStandIn, 3, 79, 17));
24
25
        for (int i = 0; i < 3; ++i)
26
        {
27
            for (int j = 0; j < 9; ++j)
28
            {
29
                this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
30
            }
31
        }
32
33
        for (int k = 0; k < 9; ++k)
34
        {
35
            this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
36
        }
37
    }
38
39
    public void onCraftGuiOpened(ICrafting listener)
40
    {
41
        super.onCraftGuiOpened(listener);
42
        listener.sendAllWindowProperties(this, this.tileBrewingStand);
43
    }
44
45
    /**
46
     * Looks for changes made in the container, sends them to every listener.
47
     */
48
    public void detectAndSendChanges()
49
    {
50
        super.detectAndSendChanges();
51
52
        for (int i = 0; i < this.crafters.size(); ++i)
53
        {
54
            ICrafting icrafting = (ICrafting)this.crafters.get(i);
55
56
            if (this.brewTime != this.tileBrewingStand.getField(0))
57
            {
58
                icrafting.sendProgressBarUpdate(this, 0, this.tileBrewingStand.getField(0));
59
            }
60
        }
61
62
        this.brewTime = this.tileBrewingStand.getField(0);
63
    }
64
65
    public void updateProgressBar(int id, int data)
66
    {
67
        this.tileBrewingStand.setField(id, data);
68
    }
69
70
    public boolean canInteractWith(EntityPlayer playerIn)
71
    {
72
        return this.tileBrewingStand.isUseableByPlayer(playerIn);
73
    }
74
75
    /**
76
     * Take a stack from the specified inventory slot.
77
     */
78
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
79
    {
80
        ItemStack itemstack = null;
81
        Slot slot = (Slot)this.inventorySlots.get(index);
82
83
        if (slot != null && slot.getHasStack())
84
        {
85
            ItemStack itemstack1 = slot.getStack();
86
            itemstack = itemstack1.copy();
87
88
            if ((index < 0 || index > 2) && index != 3)
89
            {
90
                if (!this.theSlot.getHasStack() && this.theSlot.isItemValid(itemstack1))
91
                {
92
                    if (!this.mergeItemStack(itemstack1, 3, 4, false))
93
                    {
94
                        return null;
95
                    }
96
                }
97
                else if (ContainerBrewingStand.Potion.canHoldPotion(itemstack))
98
                {
99
                    if (!this.mergeItemStack(itemstack1, 0, 3, false))
100
                    {
101
                        return null;
102
                    }
103
                }
104
                else if (index >= 4 && index < 31)
105
                {
106
                    if (!this.mergeItemStack(itemstack1, 31, 40, false))
107
                    {
108
                        return null;
109
                    }
110
                }
111
                else if (index >= 31 && index < 40)
112
                {
113
                    if (!this.mergeItemStack(itemstack1, 4, 31, false))
114
                    {
115
                        return null;
116
                    }
117
                }
118
                else if (!this.mergeItemStack(itemstack1, 4, 40, false))
119
                {
120
                    return null;
121
                }
122
            }
123
            else
124
            {
125
                if (!this.mergeItemStack(itemstack1, 4, 40, true))
126
                {
127
                    return null;
128
                }
129
130
                slot.onSlotChange(itemstack1, itemstack);
131
            }
132
133
            if (itemstack1.stackSize == 0)
134
            {
135
                slot.putStack((ItemStack)null);
136
            }
137
            else
138
            {
139
                slot.onSlotChanged();
140
            }
141
142
            if (itemstack1.stackSize == itemstack.stackSize)
143
            {
144
                return null;
145
            }
146
147
            slot.onPickupFromSlot(playerIn, itemstack1);
148
        }
149
150
        return itemstack;
151
    }
152
153
    class Ingredient extends Slot
154
    {
155
        public Ingredient(IInventory inventoryIn, int index, int xPosition, int yPosition)
156
        {
157
            super(inventoryIn, index, xPosition, yPosition);
158
        }
159
160
        public boolean isItemValid(ItemStack stack)
161
        {
162
            return stack != null ? stack.getItem().isPotionIngredient(stack) : false;
163
        }
164
165
        public int getSlotStackLimit()
166
        {
167
            return 64;
168
        }
169
    }
170
171
    static class Potion extends Slot
172
    {
173
        private EntityPlayer player;
174
175
        public Potion(EntityPlayer playerIn, IInventory inventoryIn, int index, int xPosition, int yPosition)
176
        {
177
            super(inventoryIn, index, xPosition, yPosition);
178
            this.player = playerIn;
179
        }
180
181
        public boolean isItemValid(ItemStack stack)
182
        {
183
            return canHoldPotion(stack);
184
        }
185
186
        public int getSlotStackLimit()
187
        {
188
            return 1;
189
        }
190
191
        public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
192
        {
193
            if (stack.getItem() == Items.potionitem && stack.getMetadata() > 0)
194
            {
195
                this.player.triggerAchievement(AchievementList.potion);
196
            }
197
198
            super.onPickupFromSlot(playerIn, stack);
199
        }
200
201
        public static boolean canHoldPotion(ItemStack stack)
202
        {
203
            return stack != null && (stack.getItem() == Items.potionitem || stack.getItem() == Items.glass_bottle);
204
        }
205
    }
206
}
207

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