Skip to content

Commit

Permalink
AppleCore Support
Browse files Browse the repository at this point in the history
GT4 food is now recognized by AppleCore, providing them with Nutritional Bonuses, Diminishing Returns, Food Groups and visible food values.

*Credit to GT5U for showing the way.*
  • Loading branch information
DrParadox7 committed Nov 9, 2023
1 parent d44a1e1 commit 7e8c62d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies {
compile files("libs/ThermalFoundation-[1.7.10]1.2.6-118-dev.jar")
compile files("libs/Railcraft_1.7.10-9.12.2.1-dev.jar")
compile files("libs/MineFactoryReloaded-[1.7.10]2.8.1-174-dev.jar")
compile files("libs/AppleCore-3.2.11-dev.jar")
}

processResources {
Expand Down
50 changes: 37 additions & 13 deletions src/main/java/gregtechmod/api/items/GT_MetaGenerated_Item.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gregtechmod.api.items;

import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;
import gregtechmod.api.GregTech_API;
import gregtechmod.api.enums.Materials;
import gregtechmod.api.enums.OrePrefixes;
Expand All @@ -23,13 +25,17 @@
import net.minecraft.inventory.Container;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import squeek.applecore.api.food.FoodValues;
import squeek.applecore.api.food.IEdible;
import squeek.applecore.api.food.ItemFoodProxy;

/**
* @author Gregorius Techneticies
Expand All @@ -43,7 +49,8 @@
*
* These Items can also have special RightClick abilities, electric Charge or even be set to become a Food alike Item.
*/
public abstract class GT_MetaGenerated_Item extends GT_Generic_Item implements ISpecialElectricItem, IElectricItemManager {
@Optional.Interface(iface = "squeek.applecore.api.food.IEdible", modid = "AppleCore")
public abstract class GT_MetaGenerated_Item extends GT_Generic_Item implements ISpecialElectricItem, IElectricItemManager, IEdible {
/**
* All instances of this Item Class are listed here.
* This gets used to register the Renderer to all Items of this Type, if useStandardMetaItemRenderer() returns true.
Expand Down Expand Up @@ -273,17 +280,22 @@ public final EnumAction getItemUseAction(ItemStack aStack) {
IFoodStat tStat = mFoodStats.get((short)getDamage(aStack));
return tStat == null ? EnumAction.none : tStat.getFoodAction(this, aStack);
}
@Override

@Override
public final ItemStack onEaten(ItemStack aStack, World aWorld, EntityPlayer aPlayer) {
IFoodStat tStat = mFoodStats.get((short)getDamage(aStack));
if (tStat != null) {
aPlayer.getFoodStats().addStats(tStat.getFoodLevel(this, aStack, aPlayer), tStat.getSaturation(this, aStack, aPlayer));
tStat.onEaten(this, aStack, aPlayer);
}
return aStack;
}

IFoodStat tStat = mFoodStats.get((short) getDamage(aStack));
if (tStat != null) {
if (Loader.isModLoaded("AppleCore")) {
aPlayer.getFoodStats()
.func_151686_a(getFoodProxy(this), aStack);
} else {
aPlayer.getFoodStats().addStats(tStat.getFoodLevel(this, aStack, aPlayer), tStat.getSaturation(this, aStack, aPlayer));
}
tStat.onEaten(this, aStack, aPlayer);
}
return aStack;
}

@Override
public final boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ) {
ArrayList<IOnItemClick> tList = mClickBehaviors.get((short)getDamage(aStack));
Expand Down Expand Up @@ -318,7 +330,7 @@ public final IIconContainer getIconContainer(int aMetaData) {
}
return null;
}

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings({ "rawtypes", "unchecked" })
Expand All @@ -336,7 +348,19 @@ public final void getSubItems(Item item, CreativeTabs aCreativeTab, List aList)
}
}
}

@Optional.Method(modid = "AppleCore")
private static ItemFood getFoodProxy(Object edible) {
return new ItemFoodProxy((IEdible) edible);
}

@Override
@Optional.Method(modid = "AppleCore")
public FoodValues getFoodValues(ItemStack aStack) {
IFoodStat tStat = mFoodStats.get((short) getDamage(aStack));
return tStat == null ? null
: new FoodValues(tStat.getFoodLevel(this, aStack, null), tStat.getSaturation(this, aStack, null));
}

@Override
public String getUnlocalizedName(ItemStack aStack) {
return getUnlocalizedName() + "." + getDamage(aStack);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gregtechmod/loaders/preload/GT_ItemLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ public void run() {
GT_Items.Credit_Greg_Neutronium.set( tMetaGenerated.addItem( 7, "credit_iridium" , "item.GregTech_MetaGenerated_Item_01.credit_iridium.tooltip" , null));
GT_Items.Coin_Gold_Ancient.set( tMetaGenerated.addItem( 8, "ancient_coin" , "item.GregTech_MetaGenerated_Item_01.ancient_coin.tooltip" , null));
GT_Items.Coin_Doge.set( tMetaGenerated.addItem( 9, "doge_coin" , "item.GregTech_MetaGenerated_Item_01.doge_coin.tooltip" , null));
GT_Items.Coin_Chocolate.set( tMetaGenerated.addItem( 10, "chocolate_coin" , "item.GregTech_MetaGenerated_Item_01.chocolate_coin.tooltip" , new GT_FoodStat(1, 0.1F, EnumAction.eat, GT_OreDictUnificator.get(OrePrefixes.nugget, Materials.Gold, 1L), true, false, new int[] { Potion.moveSpeed.id, 200, 1, 100 })));
GT_Items.Bottle_Purple_Drink.set( tMetaGenerated.addItem(100, "purple_drink" , "item.GregTech_MetaGenerated_Item_01.purple_drink.tooltip" , new GT_FoodStat(8, 0.2F, EnumAction.drink, GT_OreDictUnificator.get(OrePrefixes.bottle, Materials.Empty, 1L), false, false, new int[] { Potion.moveSlowdown.id, 400, 0, 100 })));
GT_Items.Food_Potato_On_Stick.set( tMetaGenerated.addItem(200, "potato_stick" , "item.GregTech_MetaGenerated_Item_01.potato_stick.tooltip" , new GT_FoodStat(1, 0.3F, EnumAction.eat, new ItemStack(Items.stick, 1), false, false, new int[0])));
GT_Items.Food_Potato_On_Stick_Roasted.set( tMetaGenerated.addItem(201, "roasted_potato_stick" , "item.GregTech_MetaGenerated_Item_01.potato_stick.tooltip" , new GT_FoodStat(6, 0.6F, EnumAction.eat, new ItemStack(Items.stick, 1), false, false, new int[0])));
GT_Items.Coin_Chocolate.set( tMetaGenerated.addItem( 10, "chocolate_coin" , "item.GregTech_MetaGenerated_Item_01.chocolate_coin.tooltip" , new GT_FoodStat(1, 0.1F, EnumAction.eat, GT_OreDictUnificator.get(OrePrefixes.nugget, Materials.Gold, 1L), true, false, Potion.moveSpeed.id, 200, 1, 100)));
GT_Items.Bottle_Purple_Drink.set( tMetaGenerated.addItem(100, "purple_drink" , "item.GregTech_MetaGenerated_Item_01.purple_drink.tooltip" , new GT_FoodStat(8, 0.2F, EnumAction.drink, GT_OreDictUnificator.get(OrePrefixes.bottle, Materials.Empty, 1L), false, false, Potion.moveSlowdown.id, 400, 0, 100)));
GT_Items.Food_Potato_On_Stick.set( tMetaGenerated.addItem(200, "potato_stick" , "item.GregTech_MetaGenerated_Item_01.potato_stick.tooltip" , new GT_FoodStat(1, 0.3F, EnumAction.eat, new ItemStack(Items.stick, 1), false, false)));
GT_Items.Food_Potato_On_Stick_Roasted.set( tMetaGenerated.addItem(201, "roasted_potato_stick" , "item.GregTech_MetaGenerated_Item_01.potato_stick.tooltip" , new GT_FoodStat(6, 0.6F, EnumAction.eat, new ItemStack(Items.stick, 1), false, false)));
GT_Items.Shape_Mold_Plate.set( tMetaGenerated.addItem(301, "mold_plates" , "item.GregTech_MetaGenerated_Item_01.mold_plates.tooltip" , null));
GT_Items.Shape_Mold_Casing.set( tMetaGenerated.addItem(302, "mold_casings" , "item.GregTech_MetaGenerated_Item_01.mold_casings.tooltip" , null));
GT_Items.Shape_Mold_Gear.set( tMetaGenerated.addItem(303, "mold_gears" , "item.GregTech_MetaGenerated_Item_01.mold_gears.tooltip" , null));
Expand Down

0 comments on commit 7e8c62d

Please sign in to comment.