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

164 lines
6.9 KiB
Java
Raw Normal View History

2016-01-05 04:47:35 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("ItemCoffee.java") is part of the Actually Additions mod for Minecraft.
2016-01-05 04:47:35 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2016-01-05 04:47:35 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2016-01-05 04:47:35 +01:00
*/
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
2016-05-14 13:51:18 +02:00
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.items.base.ItemFoodBase;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.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.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
2017-06-17 00:48:49 +02:00
import javax.annotation.Nullable;
2016-01-05 04:47:35 +01:00
import java.util.ArrayList;
import java.util.List;
public class ItemCoffee extends ItemFoodBase{
public ItemCoffee(String name){
super(8, 5.0F, false, name);
this.setMaxDamage(3);
this.setAlwaysEdible();
this.setMaxStackSize(1);
this.setNoRepair();
}
public static void initIngredients(){
2016-04-20 21:39:03 +02:00
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(new ItemStack(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!?)
if(Loader.isModLoaded("harvestcraft")){
Item item = ItemUtil.getItemFromName("harvestcraft:soymilkItem");
if(item != null){
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(new ItemStack(item)));
}
}
2016-04-20 21:39:03 +02:00
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.SUGAR), new PotionEffect[]{new PotionEffect(MobEffects.SPEED, 30, 0)}, 4));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.MAGMA_CREAM), new PotionEffect[]{new PotionEffect(MobEffects.FIRE_RESISTANCE, 20, 0)}, 2));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.FISH, 1, 3), new PotionEffect[]{new PotionEffect(MobEffects.WATER_BREATHING, 10, 0)}, 2));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.GOLDEN_CARROT), new PotionEffect[]{new PotionEffect(MobEffects.NIGHT_VISION, 30, 0)}, 2));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.GHAST_TEAR), new PotionEffect[]{new PotionEffect(MobEffects.REGENERATION, 5, 0)}, 3));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.BLAZE_POWDER), new PotionEffect[]{new PotionEffect(MobEffects.STRENGTH, 15, 0)}, 4));
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.FERMENTED_SPIDER_EYE), new PotionEffect[]{new PotionEffect(MobEffects.INVISIBILITY, 25, 0)}, 2));
2016-01-05 04:47:35 +01:00
}
public static CoffeeIngredient getIngredientFromStack(ItemStack stack){
2016-05-19 20:05:12 +02:00
for(CoffeeIngredient ingredient : ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS){
2016-01-05 04:47:35 +01:00
if(ingredient.ingredient.copy().isItemEqual(stack)){
return ingredient;
}
}
return null;
}
2016-03-18 23:47:22 +01:00
public static void applyPotionEffectsFromStack(ItemStack stack, EntityLivingBase player){
2016-05-14 13:51:18 +02:00
PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
2016-02-01 20:39:11 +01:00
if(effects != null && effects.length > 0){
for(PotionEffect effect : effects){
2016-03-18 23:47:22 +01:00
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
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);
theStack.setItemDamage(theStack.getItemDamage()+1);
if(theStack.getMaxDamage()-theStack.getItemDamage() < 0){
return new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CUP.ordinal());
}
else{
return theStack;
}
}
2016-01-05 04:47:35 +01:00
@Override
public EnumAction getItemUseAction(ItemStack stack){
return EnumAction.DRINK;
2016-01-05 04:47:35 +01:00
}
@Override
public int getMetadata(int damage){
return damage;
}
@Override
public boolean getShareTag(){
return true;
}
@Override
2017-06-17 00:48:49 +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);
2016-01-05 04:47:35 +01:00
if(effects != null){
for(PotionEffect effect : effects){
2017-06-17 00:48:49 +02:00
tooltip.add(StringUtil.localize(effect.getEffectName())+" "+(effect.getAmplifier()+1)+", "+StringUtils.ticksToElapsedTime(effect.getDuration()*20));
2016-01-05 04:47:35 +01:00
}
}
else{
2017-06-17 00:48:49 +02:00
tooltip.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".coffeeCup.noEffect"));
2016-01-05 04:47:35 +01:00
}
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE;
2016-01-05 04:47:35 +01:00
}
public static class MilkIngredient extends CoffeeIngredient{
public MilkIngredient(ItemStack ingredient){
super(ingredient, null, 0);
}
@Override
public boolean effect(ItemStack stack){
2016-05-14 13:51:18 +02:00
PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
2016-01-05 04:47:35 +01:00
ArrayList<PotionEffect> effectsNew = new ArrayList<PotionEffect>();
if(effects != null && effects.length > 0){
for(PotionEffect effect : effects){
if(effect.getAmplifier() > 0){
2016-03-18 23:47:22 +01:00
effectsNew.add(new PotionEffect(effect.getPotion(), effect.getDuration()+120, effect.getAmplifier()-1));
2016-01-05 04:47:35 +01:00
}
}
stack.setTagCompound(new NBTTagCompound());
if(effectsNew.size() > 0){
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
public String getExtraText(){
2016-04-20 21:39:03 +02:00
return StringUtil.localize("container.nei."+ModUtil.MOD_ID+".coffee.extra.milk");
2016-01-05 04:47:35 +01:00
}
}
}