Skip to content

Commit

Permalink
Support edible foods for Talisman of Nourishment (gregtech foods and …
Browse files Browse the repository at this point in the history
…another) (#27)

* Support edible foods (gregtech food and another)

* spotlessApply

Co-authored-by: glowredman <[email protected]>
  • Loading branch information
Zereff06 and glowredman authored Dec 27, 2022
1 parent 2f12d0e commit 1e3e157
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import flaxbeard.thaumicexploration.interop.AppleCoreInterop;
import flaxbeard.thaumicexploration.misc.FakePlayerPotion;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
Expand All @@ -24,6 +21,12 @@

public class ItemFoodTalisman extends Item {

private static final String[] ALL_FOOD_BLACKLIST_NAMES = {
ConfigItems.itemManaBean.getUnlocalizedName(),
ConfigItems.itemZombieBrain.getUnlocalizedName(),
"item.foodstuff.0.name",
"ic2.itemterrawart",
};
public static List<String> foodBlacklist = new ArrayList<String>();
public static Map<String, Boolean> foodCache = new HashMap<String, Boolean>();
private final int MAX_HEAL_SIZE_TALISMAN = 1000;
Expand All @@ -33,9 +36,11 @@ public ItemFoodTalisman() {
super();
this.maxStackSize = 1;
this.setMaxDamage(MAX_HEAL_SIZE_TALISMAN);
foodBlacklist.add(ConfigItems.itemManaBean.getUnlocalizedName());
foodBlacklist.add(ConfigItems.itemZombieBrain.getUnlocalizedName());
foodBlacklist.add("item.foodstuff.0.name");
initFoodBlackList();
}

private void initFoodBlackList() {
Collections.addAll(foodBlacklist, ALL_FOOD_BLACKLIST_NAMES);
}

@Override
Expand Down Expand Up @@ -173,6 +178,19 @@ private boolean isEdible(ItemStack food, EntityPlayer player) {
return false;
}
}

if (Loader.isModLoaded("AppleCore")) {
try {
if (AppleCoreInterop.getHeal(food) > 0) {
foodCache.put(foodName.toLowerCase(), true);
return true;
}
} catch (Exception e) {
foodCache.put(foodName.toLowerCase(), false);
return false;
}
}

if (food.getItem() instanceof ItemFood) {
try {

Expand Down

0 comments on commit 1e3e157

Please sign in to comment.