ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/common/items/ItemCoffee.java

151 lines
6.6 KiB
Java
Raw Normal View History

2020-09-09 16:49:01 +02:00
package de.ellpeck.actuallyadditions.common.items;
2016-01-05 04:47:35 +01:00
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
2020-09-09 16:49:01 +02:00
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.items.base.ItemFoodBase;
import de.ellpeck.actuallyadditions.common.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.common.util.ItemUtil;
import de.ellpeck.actuallyadditions.common.util.StringUtil;
2017-06-17 00:48:49 +02:00
import net.minecraft.client.util.ITooltipFlag;
2016-03-18 23:47:22 +01:00
import net.minecraft.entity.EntityLivingBase;
2016-01-05 04:47:35 +01:00
import net.minecraft.init.Items;
2016-03-18 23:47:22 +01:00
import net.minecraft.init.MobEffects;
2016-01-05 04:47:35 +01:00
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
2016-01-05 04:47:35 +01:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StringUtils;
import net.minecraft.world.World;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.common.Loader;
2016-01-05 04:47:35 +01:00
2019-05-02 09:10:29 +02:00
public class ItemCoffee extends ItemFoodBase {
2016-01-05 04:47:35 +01:00
2019-05-02 09:10:29 +02:00
public ItemCoffee(String name) {
2016-01-05 04:47:35 +01:00
super(8, 5.0F, false, name);
this.setMaxDamage(3);
this.setAlwaysEdible();
this.setMaxStackSize(1);
this.setNoRepair();
}
2019-05-02 09:10:29 +02:00
public static void initIngredients() {
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.fromItem(Items.MILK_BUCKET)));
2016-01-05 04:47:35 +01:00
//Pam's Soy Milk (For Jemx because he's lactose intolerant. YER HAPPY NAO!?)
2019-05-02 09:10:29 +02:00
if (Loader.isModLoaded("harvestcraft")) {
2018-06-26 22:25:51 +02:00
Item item = ItemUtil.getItemFromName("harvestcraft:soymilkitem");
2019-05-02 09:10:29 +02:00
if (item != null) {
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.fromItem(item)));
2016-01-05 04:47:35 +01:00
}
}
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.SUGAR), 4, new PotionEffect(MobEffects.SPEED, 30, 0)));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.MAGMA_CREAM), 2, new PotionEffect(MobEffects.FIRE_RESISTANCE, 20, 0)));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromStacks(new ItemStack(Items.FISH, 1, 3)), 2, new PotionEffect(MobEffects.WATER_BREATHING, 10, 0)));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.GOLDEN_CARROT), 2, new PotionEffect(MobEffects.NIGHT_VISION, 30, 0)));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.GHAST_TEAR), 3, new PotionEffect(MobEffects.REGENERATION, 5, 0)));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.BLAZE_POWDER), 4, new PotionEffect(MobEffects.STRENGTH, 15, 0)));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.FERMENTED_SPIDER_EYE), 2, new PotionEffect(MobEffects.INVISIBILITY, 25, 0)));
2016-01-05 04:47:35 +01:00
}
@Nullable
2019-05-02 09:10:29 +02:00
public static CoffeeIngredient getIngredientFromStack(ItemStack stack) {
for (CoffeeIngredient ingredient : ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS) {
if (ingredient.getInput().apply(stack)) return ingredient;
2016-01-05 04:47:35 +01:00
}
return null;
}
2019-05-02 09:10:29 +02:00
public static void applyPotionEffectsFromStack(ItemStack stack, EntityLivingBase player) {
2016-05-14 13:51:18 +02:00
PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
2019-05-02 09:10:29 +02:00
if (effects != null && effects.length > 0) {
for (PotionEffect effect : effects) {
player.addPotionEffect(new PotionEffect(effect.getPotion(), effect.getDuration() * 20, effect.getAmplifier()));
2016-02-01 20:39:11 +01:00
}
}
}
2016-01-05 04:47:35 +01:00
@Override
2019-05-02 09:10:29 +02:00
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase player) {
2016-01-05 04:47:35 +01:00
ItemStack theStack = stack.copy();
super.onItemUseFinish(stack, world, player);
2016-01-05 04:47:35 +01:00
applyPotionEffectsFromStack(stack, player);
2019-05-02 09:10:29 +02:00
theStack.setItemDamage(theStack.getItemDamage() + 1);
if (theStack.getMaxDamage() - theStack.getItemDamage() < 0) {
2016-01-05 04:47:35 +01:00
return new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CUP.ordinal());
2019-05-02 09:10:29 +02:00
} else {
2016-01-05 04:47:35 +01:00
return theStack;
}
}
@Override
2019-05-02 09:10:29 +02:00
public EnumAction getItemUseAction(ItemStack stack) {
return EnumAction.DRINK;
2016-01-05 04:47:35 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public int getMetadata(int damage) {
2016-01-05 04:47:35 +01:00
return damage;
}
@Override
2019-05-02 09:10:29 +02:00
public boolean getShareTag() {
2016-01-05 04:47:35 +01:00
return true;
}
@Override
2019-05-02 09:10:29 +02:00
public void addInformation(ItemStack stack, @Nullable World playerIn, List<String> tooltip, ITooltipFlag advanced) {
2016-05-14 13:51:18 +02:00
PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
2019-05-02 09:10:29 +02:00
if (effects != null) {
for (PotionEffect effect : effects) {
tooltip.add(StringUtil.localize(effect.getEffectName()) + " " + (effect.getAmplifier() + 1) + ", " + StringUtils.ticksToElapsedTime(effect.getDuration() * 20));
2016-01-05 04:47:35 +01:00
}
2019-05-02 09:10:29 +02:00
} else {
tooltip.add(StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".coffeeCup.noEffect"));
2016-01-05 04:47:35 +01:00
}
}
@Override
2019-05-02 09:10:29 +02:00
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.RARE;
2016-01-05 04:47:35 +01:00
}
2019-05-02 09:10:29 +02:00
public static class MilkIngredient extends CoffeeIngredient {
2016-01-05 04:47:35 +01:00
2019-05-02 09:10:29 +02:00
public MilkIngredient(Ingredient ingredient) {
super(ingredient, 0);
2016-01-05 04:47:35 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public boolean effect(ItemStack stack) {
2016-05-14 13:51:18 +02:00
PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
2019-02-27 19:53:05 +01:00
ArrayList<PotionEffect> effectsNew = new ArrayList<>();
2019-05-02 09:10:29 +02:00
if (effects != null && effects.length > 0) {
for (PotionEffect effect : effects) {
if (effect.getAmplifier() > 0) {
effectsNew.add(new PotionEffect(effect.getPotion(), effect.getDuration() + 120, effect.getAmplifier() - 1));
2016-01-05 04:47:35 +01:00
}
}
stack.setTagCompound(new NBTTagCompound());
2019-05-02 09:10:29 +02:00
if (effectsNew.size() > 0) {
2016-01-05 04:47:35 +01:00
this.effects = effectsNew.toArray(new PotionEffect[effectsNew.size()]);
2016-05-14 13:51:18 +02:00
ActuallyAdditionsAPI.methodHandler.addEffectToStack(stack, this);
2016-01-05 04:47:35 +01:00
}
}
this.effects = null;
return true;
}
@Override
2019-05-02 09:10:29 +02:00
public String getExtraText() {
return StringUtil.localize("container.nei." + ActuallyAdditions.MODID + ".coffee.extra.milk");
2016-01-05 04:47:35 +01:00
}
}
}