Skip to content

Commit 3c411f1

Browse files
committed
cellar: Bugfix for Yeast Jar
* Fixed possible item dup and lost of fluid * Prevent jar from updating time with invalid items in slot
1 parent 0289379 commit 3c411f1

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

src/java/growthcraft/cellar/common/tileentity/device/YeastGenerator.java

+44-4
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,56 @@ public YeastGenerator(TileEntityCellarDevice te, int fs, int is)
3636
setTimeMax(1200);
3737
}
3838

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)
4045
{
41-
this.consumption = t;
46+
this.consumption = c;
4247
return this;
4348
}
4449

50+
/**
51+
* Returns the current biome of the Yeast Generator's parent TileEntity.
52+
*
53+
* @return biome
54+
*/
4555
public BiomeGenBase getCurrentBiome()
4656
{
4757
return getWorld().getBiomeGenForCoords(parent.xCoord, parent.zCoord);
4858
}
4959

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+
*/
5080
public boolean canProduceYeast()
5181
{
5282
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+
}
5489
return CellarRegistry.instance().booze().hasTags(parent.getFluid(fluidSlot), BoozeTag.YOUNG);
5590
}
5691

@@ -96,7 +131,12 @@ public void produceYeast()
96131
else
97132
{
98133
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))
100140
{
101141
getInventory().setInventorySlotContents(invSlot, ItemUtils.increaseStack(contents));
102142
consumeFluid();

0 commit comments

Comments
 (0)