TileEntityBrewingStand .java

net.minecraft.tileentity.TileEntityBrewingStand (class): members: brewingItemStacks, func_174902_m, ingredientID, filledSlots, outputSlots, inputSlots.

net.minecraft.tileentityclass449 linescommonextends TileEntityLockable13.0 KB

Implements

API Surface (26)

String getName()
boolean hasCustomName()
void setName(String name)
int getSizeInventory()
void update()
void readFromNBT(NBTTagCompound compound)
void writeToNBT(NBTTagCompound compound)
ItemStack getStackInSlot(int index)
ItemStack decrStackSize(int index, int count)
ItemStack removeStackFromSlot(int index)
void setInventorySlotContents(int index, ItemStack stack)
int getInventoryStackLimit()
boolean isUseableByPlayer(EntityPlayer player)
void openInventory(EntityPlayer player)
void closeInventory(EntityPlayer player)
boolean isItemValidForSlot(int index, ItemStack stack)
boolean[] func_174902_m()
int[] getSlotsForFace(EnumFacing side)
boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction)
boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
String getGuiID()
Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
int getField(int id)
void setField(int id, int value)
int getFieldCount()
void clear()

Fields & Constants (7)

inputSlots
outputSlots
brewingItemStacks
brewTime
filledSlots
ingredientID
customName

String literals (6)

"container.brewing"
"Items"
"Slot"
"BrewTime"
"CustomName"
"minecraft:brewing_stand"

Full Source

TileEntityBrewingStand.java449 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.tileentity;
2
3
import java.util.Arrays;
4
import java.util.List;
5
import net.minecraft.block.BlockBrewingStand;
6
import net.minecraft.block.state.IBlockState;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.entity.player.InventoryPlayer;
9
import net.minecraft.init.Items;
10
import net.minecraft.inventory.Container;
11
import net.minecraft.inventory.ContainerBrewingStand;
12
import net.minecraft.inventory.ISidedInventory;
13
import net.minecraft.item.Item;
14
import net.minecraft.item.ItemPotion;
15
import net.minecraft.item.ItemStack;
16
import net.minecraft.nbt.NBTTagCompound;
17
import net.minecraft.nbt.NBTTagList;
18
import net.minecraft.potion.PotionEffect;
19
import net.minecraft.potion.PotionHelper;
20
import net.minecraft.util.EnumFacing;
21
import net.minecraft.util.ITickable;
22
23
public class TileEntityBrewingStand extends TileEntityLockable implements ITickable, ISidedInventory
24
{
25
    /** an array of the input slot indices */
26
    private static final int[] inputSlots = new int[] {3};
27
28
    /** an array of the output slot indices */
29
    private static final int[] outputSlots = new int[] {0, 1, 2};
30
31
    /** The ItemStacks currently placed in the slots of the brewing stand */
32
    private ItemStack[] brewingItemStacks = new ItemStack[4];
33
    private int brewTime;
34
35
    /**
36
     * an integer with each bit specifying whether that slot of the stand contains a potion
37
     */
38
    private boolean[] filledSlots;
39
40
    /**
41
     * used to check if the current ingredient has been removed from the brewing stand during brewing
42
     */
43
    private Item ingredientID;
44
    private String customName;
45
46
    /**
47
     * Get the name of this object. For players this returns their username
48
     */
49
    public String getName()
50
    {
51
        return this.hasCustomName() ? this.customName : "container.brewing";
52
    }
53
54
    /**
55
     * Returns true if this thing is named
56
     */
57
    public boolean hasCustomName()
58
    {
59
        return this.customName != null && this.customName.length() > 0;
60
    }
61
62
    public void setName(String name)
63
    {
64
        this.customName = name;
65
    }
66
67
    /**
68
     * Returns the number of slots in the inventory.
69
     */
70
    public int getSizeInventory()
71
    {
72
        return this.brewingItemStacks.length;
73
    }
74
75
    /**
76
     * Like the old updateEntity(), except more generic.
77
     */
78
    public void update()
79
    {
80
        if (this.brewTime > 0)
81
        {
82
            --this.brewTime;
83
84
            if (this.brewTime == 0)
85
            {
86
                this.brewPotions();
87
                this.markDirty();
88
            }
89
            else if (!this.canBrew())
90
            {
91
                this.brewTime = 0;
92
                this.markDirty();
93
            }
94
            else if (this.ingredientID != this.brewingItemStacks[3].getItem())
95
            {
96
                this.brewTime = 0;
97
                this.markDirty();
98
            }
99
        }
100
        else if (this.canBrew())
101
        {
102
            this.brewTime = 400;
103
            this.ingredientID = this.brewingItemStacks[3].getItem();
104
        }
105
106
        if (!this.worldObj.isRemote)
107
        {
108
            boolean[] aboolean = this.func_174902_m();
109
110
            if (!Arrays.equals(aboolean, this.filledSlots))
111
            {
112
                this.filledSlots = aboolean;
113
                IBlockState iblockstate = this.worldObj.getBlockState(this.getPos());
114
115
                if (!(iblockstate.getBlock() instanceof BlockBrewingStand))
116
                {
117
                    return;
118
                }
119
120
                for (int i = 0; i < BlockBrewingStand.HAS_BOTTLE.length; ++i)
121
                {
122
                    iblockstate = iblockstate.withProperty(BlockBrewingStand.HAS_BOTTLE[i], Boolean.valueOf(aboolean[i]));
123
                }
124
125
                this.worldObj.setBlockState(this.pos, iblockstate, 2);
126
            }
127
        }
128
    }
129
130
    private boolean canBrew()
131
    {
132
        if (this.brewingItemStacks[3] != null && this.brewingItemStacks[3].stackSize > 0)
133
        {
134
            ItemStack itemstack = this.brewingItemStacks[3];
135
136
            if (!itemstack.getItem().isPotionIngredient(itemstack))
137
            {
138
                return false;
139
            }
140
            else
141
            {
142
                boolean flag = false;
143
144
                for (int i = 0; i < 3; ++i)
145
                {
146
                    if (this.brewingItemStacks[i] != null && this.brewingItemStacks[i].getItem() == Items.potionitem)
147
                    {
148
                        int j = this.brewingItemStacks[i].getMetadata();
149
                        int k = this.getPotionResult(j, itemstack);
150
151
                        if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
152
                        {
153
                            flag = true;
154
                            break;
155
                        }
156
157
                        List<PotionEffect> list = Items.potionitem.getEffects(j);
158
                        List<PotionEffect> list1 = Items.potionitem.getEffects(k);
159
160
                        if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null) && j != k)
161
                        {
162
                            flag = true;
163
                            break;
164
                        }
165
                    }
166
                }
167
168
                return flag;
169
            }
170
        }
171
        else
172
        {
173
            return false;
174
        }
175
    }
176
177
    private void brewPotions()
178
    {
179
        if (this.canBrew())
180
        {
181
            ItemStack itemstack = this.brewingItemStacks[3];
182
183
            for (int i = 0; i < 3; ++i)
184
            {
185
                if (this.brewingItemStacks[i] != null && this.brewingItemStacks[i].getItem() == Items.potionitem)
186
                {
187
                    int j = this.brewingItemStacks[i].getMetadata();
188
                    int k = this.getPotionResult(j, itemstack);
189
                    List<PotionEffect> list = Items.potionitem.getEffects(j);
190
                    List<PotionEffect> list1 = Items.potionitem.getEffects(k);
191
192
                    if (j > 0 && list == list1 || list != null && (list.equals(list1) || list1 == null))
193
                    {
194
                        if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
195
                        {
196
                            this.brewingItemStacks[i].setItemDamage(k);
197
                        }
198
                    }
199
                    else if (j != k)
200
                    {
201
                        this.brewingItemStacks[i].setItemDamage(k);
202
                    }
203
                }
204
            }
205
206
            if (itemstack.getItem().hasContainerItem())
207
            {
208
                this.brewingItemStacks[3] = new ItemStack(itemstack.getItem().getContainerItem());
209
            }
210
            else
211
            {
212
                --this.brewingItemStacks[3].stackSize;
213
214
                if (this.brewingItemStacks[3].stackSize <= 0)
215
                {
216
                    this.brewingItemStacks[3] = null;
217
                }
218
            }
219
        }
220
    }
221
222
    /**
223
     * The result of brewing a potion of the specified damage value with an ingredient itemstack.
224
     */
225
    private int getPotionResult(int meta, ItemStack stack)
226
    {
227
        return stack == null ? meta : (stack.getItem().isPotionIngredient(stack) ? PotionHelper.applyIngredient(meta, stack.getItem().getPotionEffect(stack)) : meta);
228
    }
229
230
    public void readFromNBT(NBTTagCompound compound)
231
    {
232
        super.readFromNBT(compound);
233
        NBTTagList nbttaglist = compound.getTagList("Items", 10);
234
        this.brewingItemStacks = new ItemStack[this.getSizeInventory()];
235
236
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
237
        {
238
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
239
            int j = nbttagcompound.getByte("Slot");
240
241
            if (j >= 0 && j < this.brewingItemStacks.length)
242
            {
243
                this.brewingItemStacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
244
            }
245
        }
246
247
        this.brewTime = compound.getShort("BrewTime");
248
249
        if (compound.hasKey("CustomName", 8))
250
        {
251
            this.customName = compound.getString("CustomName");
252
        }
253
    }
254
255
    public void writeToNBT(NBTTagCompound compound)
256
    {
257
        super.writeToNBT(compound);
258
        compound.setShort("BrewTime", (short)this.brewTime);
259
        NBTTagList nbttaglist = new NBTTagList();
260
261
        for (int i = 0; i < this.brewingItemStacks.length; ++i)
262
        {
263
            if (this.brewingItemStacks[i] != null)
264
            {
265
                NBTTagCompound nbttagcompound = new NBTTagCompound();
266
                nbttagcompound.setByte("Slot", (byte)i);
267
                this.brewingItemStacks[i].writeToNBT(nbttagcompound);
268
                nbttaglist.appendTag(nbttagcompound);
269
            }
270
        }
271
272
        compound.setTag("Items", nbttaglist);
273
274
        if (this.hasCustomName())
275
        {
276
            compound.setString("CustomName", this.customName);
277
        }
278
    }
279
280
    /**
281
     * Returns the stack in the given slot.
282
     */
283
    public ItemStack getStackInSlot(int index)
284
    {
285
        return index >= 0 && index < this.brewingItemStacks.length ? this.brewingItemStacks[index] : null;
286
    }
287
288
    /**
289
     * Removes up to a specified number of items from an inventory slot and returns them in a new stack.
290
     */
291
    public ItemStack decrStackSize(int index, int count)
292
    {
293
        if (index >= 0 && index < this.brewingItemStacks.length)
294
        {
295
            ItemStack itemstack = this.brewingItemStacks[index];
296
            this.brewingItemStacks[index] = null;
297
            return itemstack;
298
        }
299
        else
300
        {
301
            return null;
302
        }
303
    }
304
305
    /**
306
     * Removes a stack from the given slot and returns it.
307
     */
308
    public ItemStack removeStackFromSlot(int index)
309
    {
310
        if (index >= 0 && index < this.brewingItemStacks.length)
311
        {
312
            ItemStack itemstack = this.brewingItemStacks[index];
313
            this.brewingItemStacks[index] = null;
314
            return itemstack;
315
        }
316
        else
317
        {
318
            return null;
319
        }
320
    }
321
322
    /**
323
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
324
     */
325
    public void setInventorySlotContents(int index, ItemStack stack)
326
    {
327
        if (index >= 0 && index < this.brewingItemStacks.length)
328
        {
329
            this.brewingItemStacks[index] = stack;
330
        }
331
    }
332
333
    /**
334
     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
335
     */
336
    public int getInventoryStackLimit()
337
    {
338
        return 64;
339
    }
340
341
    /**
342
     * Do not make give this method the name canInteractWith because it clashes with Container
343
     */
344
    public boolean isUseableByPlayer(EntityPlayer player)
345
    {
346
        return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
347
    }
348
349
    public void openInventory(EntityPlayer player)
350
    {
351
    }
352
353
    public void closeInventory(EntityPlayer player)
354
    {
355
    }
356
357
    /**
358
     * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
359
     */
360
    public boolean isItemValidForSlot(int index, ItemStack stack)
361
    {
362
        return index == 3 ? stack.getItem().isPotionIngredient(stack) : stack.getItem() == Items.potionitem || stack.getItem() == Items.glass_bottle;
363
    }
364
365
    public boolean[] func_174902_m()
366
    {
367
        boolean[] aboolean = new boolean[3];
368
369
        for (int i = 0; i < 3; ++i)
370
        {
371
            if (this.brewingItemStacks[i] != null)
372
            {
373
                aboolean[i] = true;
374
            }
375
        }
376
377
        return aboolean;
378
    }
379
380
    public int[] getSlotsForFace(EnumFacing side)
381
    {
382
        return side == EnumFacing.UP ? inputSlots : outputSlots;
383
    }
384
385
    /**
386
     * Returns true if automation can insert the given item in the given slot from the given side. Args: slot, item,
387
     * side
388
     */
389
    public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction)
390
    {
391
        return this.isItemValidForSlot(index, itemStackIn);
392
    }
393
394
    /**
395
     * Returns true if automation can extract the given item in the given slot from the given side. Args: slot, item,
396
     * side
397
     */
398
    public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
399
    {
400
        return true;
401
    }
402
403
    public String getGuiID()
404
    {
405
        return "minecraft:brewing_stand";
406
    }
407
408
    public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
409
    {
410
        return new ContainerBrewingStand(playerInventory, this);
411
    }
412
413
    public int getField(int id)
414
    {
415
        switch (id)
416
        {
417
            case 0:
418
                return this.brewTime;
419
420
            default:
421
                return 0;
422
        }
423
    }
424
425
    public void setField(int id, int value)
426
    {
427
        switch (id)
428
        {
429
            case 0:
430
                this.brewTime = value;
431
432
            default:
433
        }
434
    }
435
436
    public int getFieldCount()
437
    {
438
        return 1;
439
    }
440
441
    public void clear()
442
    {
443
        for (int i = 0; i < this.brewingItemStacks.length; ++i)
444
        {
445
            this.brewingItemStacks[i] = null;
446
        }
447
    }
448
}
449

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