@@ -36,21 +36,56 @@ public YeastGenerator(TileEntityCellarDevice te, int fs, int is)
36
36
setTimeMax (1200 );
37
37
}
38
38
39
- public YeastGenerator setConsumption (int t )
39
+ /**
40
+ * How many fluid units are consumed per yeast gen?
41
+ *
42
+ * @param c - fluid consumption in milli-buckets
43
+ */
44
+ public YeastGenerator setConsumption (int c )
40
45
{
41
- this .consumption = t ;
46
+ this .consumption = c ;
42
47
return this ;
43
48
}
44
49
50
+ /**
51
+ * Returns the current biome of the Yeast Generator's parent TileEntity.
52
+ *
53
+ * @return biome
54
+ */
45
55
public BiomeGenBase getCurrentBiome ()
46
56
{
47
57
return getWorld ().getBiomeGenForCoords (parent .xCoord , parent .zCoord );
48
58
}
49
59
60
+ /**
61
+ * Determines if the given item stack can be replicated as a yeast item
62
+ *
63
+ * @param stack - item stack to test
64
+ * @return true, it can be replicated, false otherwise
65
+ */
66
+ public boolean canReplicateYeast (ItemStack stack )
67
+ {
68
+ // prevent production if the stack size is currently maxed
69
+ if (stack .stackSize >= stack .getMaxStackSize ()) return false ;
70
+ // prevent item pointless ticking with invalid items
71
+ if (!CellarRegistry .instance ().yeast ().isYeast (stack )) return false ;
72
+ return true ;
73
+ }
74
+
75
+ /**
76
+ * Determines if the jar can produce any yeast
77
+ *
78
+ * @return true, the generator can produce yeast, false otherwise
79
+ */
50
80
public boolean canProduceYeast ()
51
81
{
52
82
if (parent .getFluidAmount (0 ) < consumption ) return false ;
53
-
83
+ final ItemStack yeastItem = getInventory ().getStackInSlot (invSlot );
84
+ // we can ignore null items, this will fallback to the initProduceYeast
85
+ if (yeastItem != null )
86
+ {
87
+ if (!canReplicateYeast (yeastItem )) return false ;
88
+ }
54
89
return CellarRegistry .instance ().booze ().hasTags (parent .getFluid (fluidSlot ), BoozeTag .YOUNG );
55
90
}
56
91
@@ -96,7 +131,12 @@ public void produceYeast()
96
131
else
97
132
{
98
133
final ItemStack contents = getInventory ().getStackInSlot (invSlot );
99
- if (CellarRegistry .instance ().yeast ().isYeast (contents ))
134
+ // ensure that the item is indeed some form of yeast, prevents item duplication
135
+ // while canProduceYeast will prevent invalid items from popping up
136
+ // produceYeast is public, and can be called outside the update
137
+ // logic to force yeast generation, as such, this must ensure
138
+ // item correctness
139
+ if (canReplicateYeast (contents ))
100
140
{
101
141
getInventory ().setInventorySlotContents (invSlot , ItemUtils .increaseStack (contents ));
102
142
consumeFluid ();
0 commit comments