Allow the Gourmaryllis to reward longer "streaks" of foods (#3335)

* Allow the Gourmaryllis to reward longer "streaks" of foods

* Document streaks in lexica entry

* Fix bug where the first dupe food sneaks by free

* Move some logic to where it actually belongs
This commit is contained in:
Al Winfy authored and GitHub committed 2020-06-24 16:38:48 -05:00
1 parent 94841df9aa
commit c8d6bcd70e
3 files changed
+65 -16

No files matched your search

@@ -11,6 +11,7 @@ package vazkii.botania.common.block.subtile.generating;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.tileentity.TileEntityType;
@@ -19,6 +20,7 @@ import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.registries.ObjectHolder;
@@ -28,24 +30,67 @@ import vazkii.botania.common.block.ModSubtiles;
import vazkii.botania.common.block.tile.ModTiles;
import vazkii.botania.common.lib.LibMisc;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
public class SubTileGourmaryllis extends TileEntityGeneratingFlower {
private static final String TAG_COOLDOWN = "cooldown";
private static final String TAG_DIGESTING_MANA = "digestingMana";
public static final String TAG_LAST_FOOD = "lastFood";
public static final String TAG_LAST_FOODS = "lastFoods";
public static final String TAG_LAST_FOOD_COUNT = "lastFoodCount";
public static final String TAG_STREAK_LENGTH = "streakLength";
private static final int RANGE = 1;
private static final double[] STREAK_MULTIPLIERS = { 0, 1, 1.3, 1.5, 1.6, 1.7, 1.75, 1.8 };
private int cooldown = 0;
private int digestingMana = 0;
private ItemStack lastFood = ItemStack.EMPTY;
private List<ItemStack> lastFoods = new LinkedList<>();
private int streakLength = 0;
private int lastFoodCount = 0;
public SubTileGourmaryllis() {
super(ModSubtiles.GOURMARYLLIS);
}
private int getMaxStreak() {
return STREAK_MULTIPLIERS.length - 1;
}
private double getMultiplierForStreak(int index) {
// special-case repeated first foods
if (index == 0) {
return 1.0 / ++lastFoodCount;
} else {
lastFoodCount = 1;
return STREAK_MULTIPLIERS[index];
}
}
/**
* Processes a food, placing it in the appropriate place in the history.
*
* @return the last time the food showed up in history.
*/
private int processFood(ItemStack food) {
for (ListIterator<ItemStack> it = lastFoods.listIterator(); it.hasNext();) {
int index = it.nextIndex();
ItemStack streakFood = it.next();
if (ItemHandlerHelper.canItemStacksStack(streakFood, food)) {
it.remove();
lastFoods.add(0, streakFood);
return index;
}
}
ItemStack newestFood = food.copy();
newestFood.setCount(1);
lastFoods.add(0, newestFood);
if (lastFoods.size() >= getMaxStreak()) {
lastFoods.remove(lastFoods.size() - 1);
}
return getMaxStreak();
}
@Override
public void tickFlower() {
super.tickFlower();
@@ -72,7 +117,7 @@ public class SubTileGourmaryllis extends TileEntityGeneratingFlower {
Vec3d offset = getWorld().getBlockState(getEffectivePos()).getOffset(getWorld(), getEffectivePos()).add(0.4, 0.6, 0.4);
((ServerWorld) getWorld()).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, lastFood), getEffectivePos().getX() + offset.x, getEffectivePos().getY() + offset.y, getEffectivePos().getZ() + offset.z, 10, 0.1D, 0.1D, 0.1D, 0.03D);
((ServerWorld) getWorld()).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, lastFoods.get(0)), getEffectivePos().getX() + offset.x, getEffectivePos().getY() + offset.y, getEffectivePos().getZ() + offset.z, 10, 0.1D, 0.1D, 0.1D, 0.03D);
}
}
@@ -85,17 +130,11 @@ public class SubTileGourmaryllis extends TileEntityGeneratingFlower {
if (!stack.isEmpty() && stack.getItem().isFood() && !item.removed && item.age >= slowdown) {
if (cooldown <= 0) {
if (ItemHandlerHelper.canItemStacksStack(lastFood, stack)) {
lastFoodCount++;
} else {
lastFood = stack.copy();
lastFood.setCount(1);
lastFoodCount = 1;
}
streakLength = Math.min(streakLength + 1, processFood(stack));
int val = Math.min(12, stack.getItem().getFood().getHealing());
digestingMana = val * val * 70;
digestingMana *= 1F / lastFoodCount;
digestingMana *= getMultiplierForStreak(streakLength);
cooldown = val * 10;
item.playSound(SoundEvents.ENTITY_GENERIC_EAT, 0.2F, 0.6F);
sync();
@@ -112,8 +151,13 @@ public class SubTileGourmaryllis extends TileEntityGeneratingFlower {
super.writeToPacketNBT(cmp);
cmp.putInt(TAG_COOLDOWN, cooldown);
cmp.putInt(TAG_DIGESTING_MANA, digestingMana);
cmp.put(TAG_LAST_FOOD, lastFood.write(new CompoundNBT()));
ListNBT foodList = new ListNBT();
for (ItemStack food : lastFoods) {
foodList.add(food.write(new CompoundNBT()));
}
cmp.put(TAG_LAST_FOODS, foodList);
cmp.putInt(TAG_LAST_FOOD_COUNT, lastFoodCount);
cmp.putInt(TAG_STREAK_LENGTH, streakLength);
}
@Override
@@ -121,8 +165,13 @@ public class SubTileGourmaryllis extends TileEntityGeneratingFlower {
super.readFromPacketNBT(cmp);
cooldown = cmp.getInt(TAG_COOLDOWN);
digestingMana = cmp.getInt(TAG_DIGESTING_MANA);
lastFood = ItemStack.read(cmp.getCompound(TAG_LAST_FOOD));
lastFoods.clear();
ListNBT foodList = cmp.getList(TAG_LAST_FOODS, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < foodList.size(); i++) {
lastFoods.add(ItemStack.read(foodList.getCompound(i)));
}
lastFoodCount = cmp.getInt(TAG_LAST_FOOD_COUNT);
streakLength = cmp.getInt(TAG_STREAK_LENGTH);
}
@Override
@@ -99,8 +99,8 @@ public class BlockLootProvider implements IDataProvider {
functionTable.put(ModBlocks.tinyPotato, BlockLootProvider::genTinyPotato);
// Flower NBT saving
functionTable.put(ModSubtiles.gourmaryllis, b -> genCopyNbt(b, SubTileGourmaryllis.TAG_LAST_FOOD, SubTileGourmaryllis.TAG_LAST_FOOD_COUNT));
functionTable.put(ModSubtiles.gourmaryllisFloating, b -> genCopyNbt(b, SubTileGourmaryllis.TAG_LAST_FOOD, SubTileGourmaryllis.TAG_LAST_FOOD_COUNT));
functionTable.put(ModSubtiles.gourmaryllis, b -> genCopyNbt(b, SubTileGourmaryllis.TAG_LAST_FOODS, SubTileGourmaryllis.TAG_LAST_FOOD_COUNT, SubTileGourmaryllis.TAG_STREAK_LENGTH));
functionTable.put(ModSubtiles.gourmaryllisFloating, b -> genCopyNbt(b, SubTileGourmaryllis.TAG_LAST_FOODS, SubTileGourmaryllis.TAG_LAST_FOOD_COUNT, SubTileGourmaryllis.TAG_STREAK_LENGTH));
functionTable.put(ModSubtiles.hydroangeas, b -> genCopyNbt(b, SubTileHydroangeas.TAG_COOLDOWN, TileEntityGeneratingFlower.TAG_PASSIVE_DECAY_TICKS));
functionTable.put(ModSubtiles.hydroangeasFloating, b -> genCopyNbt(b, SubTileHydroangeas.TAG_COOLDOWN, TileEntityGeneratingFlower.TAG_PASSIVE_DECAY_TICKS));
functionTable.put(ModSubtiles.munchdew, b -> genCopyNbt(b, SubTileMunchdew.TAG_COOLDOWN));
@@ -2189,7 +2189,7 @@
"botania.tagline.gourmaryllis": "Mana from food",
"botania.page.gourmaryllis0": "The $(item)Gourmaryllis$(0) is one hungry flower. It'll eat any food items it finds in a small area and turn them into $(thing)Mana$(0).$(p)There's a catch, though: it can only digest a single food item at any given time, outputting $(thing)Mana$(0) once it's done. It will devour any other foods while digesting, but yield no returns for those.",
"botania.page.gourmaryllis1": "The amount of time it takes to digest a delicacy depends on the food's nutritional value-- in layman's terms: the number of food points it restores.$(p)Thus, a $(item)Steak$(0) will take four seconds to digest, an $(item)Apple$(0) will take two, a loaf of $(item)Bread$(0) will take two and a half, and so on.",
"botania.page.gourmaryllis2": "The rate of $(thing)Mana$(0) production will also vary with nutrition: the $(item)Gourmaryllis$(0) prefers bigger foods. For example, a single $(item)Steak$(0) will produce more $(item)Mana$(0) than two $(item)Apples$(0), both in total and per-second.$(p)Note that feeding the $(item)Gourmaryllis$(0) the same type of food multiple times in a row will result in each subsequent food producing less $(thing)Mana$(0).",
"botania.page.gourmaryllis2": "The rate of $(thing)Mana$(0) production will also vary with nutrition: the $(item)Gourmaryllis$(0) prefers bigger foods. For example, a single $(item)Steak$(0) will produce more $(item)Mana$(0) than two $(item)Apples$(0), both in total and per-second.$(p)Of course, like any proper gourmand, the $(item)Gourmaryllis$(0) loves variety in its diet; feeding it many different foods can be very rewarding.$(p)Giving it the same food repeatedly might not go over so well, though.",
"botania.page.gourmaryllis3": "$(o)A hot pot for our new residents$().",
"botania.entry.narslimmus": "Narslimmus",