From d897138d906d93556efa796d1fbd527bf9a594f5 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Wed, 2 Aug 2017 00:01:44 -0500 Subject: [PATCH] Gourmaryllis now is healthy and likes balanced diets --- .../generating/SubTileGourmaryllis.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java index 2e8355e31..2594e0a8c 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java +++ b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileGourmaryllis.java @@ -20,6 +20,7 @@ import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.WorldServer; +import net.minecraftforge.items.ItemHandlerHelper; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.SubTileGenerating; @@ -30,10 +31,15 @@ import java.util.List; public class SubTileGourmaryllis extends SubTileGenerating { private static final String TAG_COOLDOWN = "cooldown"; + private static final String TAG_DIGESTING_MANA = "digestingMana"; + private static final String TAG_LAST_FOOD = "lastFood"; + private static final String TAG_LAST_FOOD_COUNT = "lastFoodCount"; private static final int RANGE = 1; - int cooldown = 0; - int storedMana = 0; + private int cooldown = 0; + private int digestingMana = 0; + private ItemStack lastFood = ItemStack.EMPTY; + private int lastFoodCount = 0; @Override public void onUpdate() { @@ -44,9 +50,9 @@ public class SubTileGourmaryllis extends SubTileGenerating { if(cooldown > -1) cooldown--; - if(cooldown == 0 && storedMana != 0) { - mana = Math.min(getMaxMana(), mana + storedMana); - storedMana = 0; + if(cooldown == 0 && digestingMana != 0) { + mana = Math.min(getMaxMana(), mana + digestingMana); + digestingMana = 0; getWorld().playSound(null, supertile.getPos(), SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.BLOCKS, 1, 1); sync(); } @@ -60,8 +66,17 @@ public class SubTileGourmaryllis extends SubTileGenerating { if(!stack.isEmpty() && stack.getItem() instanceof ItemFood && !item.isDead && item.age >= slowdown) { if(cooldown <= 0) { + if(ItemHandlerHelper.canItemStacksStack(lastFood, stack)) { + lastFoodCount++; + } else { + lastFood = stack.copy(); + lastFood.setCount(1); + lastFoodCount = 1; + } + int val = Math.min(12, ((ItemFood) stack.getItem()).getHealAmount(stack)); - storedMana = val * val * 64; + digestingMana = val * val * 64; + digestingMana *= 1F / lastFoodCount; cooldown = val * 10; item.playSound(SoundEvents.ENTITY_GENERIC_EAT, 0.2F, 0.5F + (float) Math.random() * 0.5F); sync(); @@ -77,13 +92,18 @@ public class SubTileGourmaryllis extends SubTileGenerating { public void writeToPacketNBT(NBTTagCompound cmp) { super.writeToPacketNBT(cmp); cmp.setInteger(TAG_COOLDOWN, cooldown); - cmp.setInteger(TAG_COOLDOWN, cooldown); + cmp.setInteger(TAG_DIGESTING_MANA, digestingMana); + cmp.setTag(TAG_LAST_FOOD, lastFood.writeToNBT(new NBTTagCompound())); + cmp.setInteger(TAG_LAST_FOOD_COUNT, lastFoodCount); } @Override public void readFromPacketNBT(NBTTagCompound cmp) { super.readFromPacketNBT(cmp); cooldown = cmp.getInteger(TAG_COOLDOWN); + digestingMana = cmp.getInteger(TAG_DIGESTING_MANA); + lastFood = new ItemStack(cmp.getCompoundTag(TAG_LAST_FOOD)); + lastFoodCount = cmp.getInteger(TAG_LAST_FOOD_COUNT); } @Override