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

165 lines
7 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;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.items.base.ItemFoodBase;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
2023-12-02 14:49:10 +01:00
import net.minecraft.client.resources.I18n;
2017-06-17 00:48:49 +02:00
import net.minecraft.client.util.ITooltipFlag;
2019-11-09 21:02:42 +01:00
import net.minecraft.enchantment.Enchantment;
2021-11-14 00:20:29 +01:00
import net.minecraft.entity.LivingEntity;
2016-01-05 04:47:35 +01:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2021-11-14 00:20:29 +01:00
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
2021-02-26 22:15:48 +01:00
import net.minecraft.nbt.CompoundNBT;
2021-11-14 00:20:29 +01:00
import net.minecraft.util.text.ITextComponent;
2016-01-05 04:47:35 +01:00
import net.minecraft.world.World;
2021-12-30 18:30:01 +01:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
2021-11-14 00:20:29 +01:00
import net.minecraftforge.fml.ModList;
2016-01-05 04:47:35 +01:00
2021-02-26 22:15:48 +01:00
import javax.annotation.Nullable;
import java.util.List;
2019-05-02 09:10:29 +02:00
public class ItemCoffee extends ItemFoodBase {
2016-01-05 04:47:35 +01:00
public ItemCoffee() {
2021-11-14 00:20:29 +01:00
super(8, 5.0F, false); //, name);
//this.setMaxDamage(3);
//this.setAlwaysEdible();
//this.setMaxStackSize(1);
//this.setNoRepair();
2016-01-05 04:47:35 +01:00
}
2019-05-02 09:10:29 +02:00
public static void initIngredients() {
2021-11-14 00:20:29 +01:00
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(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!?)
2021-11-14 00:20:29 +01:00
if (ModList.get().isLoaded("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) {
2021-11-14 00:20:29 +01:00
ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(item)));
2016-01-05 04:47:35 +01:00
}
}
2021-11-14 00:20:29 +01:00
//ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.SUGAR), 4, new PotionEffect(MobEffects.SPEED, 30, 0)));
//ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.MAGMA_CREAM), 2, new PotionEffect(MobEffects.FIRE_RESISTANCE, 20, 0)));
//ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(new ItemStack(Items.FISH, 1, 3)), 2, new PotionEffect(MobEffects.WATER_BREATHING, 10, 0)));
//ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GOLDEN_CARROT), 2, new PotionEffect(MobEffects.NIGHT_VISION, 30, 0)));
//ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GHAST_TEAR), 3, new PotionEffect(MobEffects.REGENERATION, 5, 0)));
//ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.BLAZE_POWDER), 4, new PotionEffect(MobEffects.STRENGTH, 15, 0)));
//ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(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) {
2021-11-14 00:20:29 +01:00
if (ingredient.getInput().test(stack)) {
2021-02-26 22:15:48 +01:00
return ingredient;
}
2016-01-05 04:47:35 +01:00
}
return null;
}
2021-11-14 00:20:29 +01:00
public static void applyPotionEffectsFromStack(ItemStack stack, LivingEntity 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
}
}
2021-11-14 00:20:29 +01:00
*/
2016-02-01 20:39:11 +01:00
}
2021-11-14 00:20:29 +01:00
//@Override
public ItemStack onItemUseFinish(ItemStack stack, World world, LivingEntity player) {
2016-01-05 04:47:35 +01:00
ItemStack theStack = stack.copy();
super.finishUsingItem(stack, world, player);
2016-01-05 04:47:35 +01:00
applyPotionEffectsFromStack(stack, player);
2021-11-14 00:20:29 +01:00
//theStack.setItemDamage(theStack.getItemDamage() + 1);
//if (theStack.getMaxDamage() - theStack.getItemDamage() < 0) {
// return new ItemStack(ActuallyItems.COFFEE_CUP.get());
//} else {
// return theStack;
//}
return ItemStack.EMPTY;
2016-01-05 04:47:35 +01:00
}
2021-11-14 00:20:29 +01:00
//@Override
//public EnumAction getItemUseAction(ItemStack stack) {
// return EnumAction.DRINK;
//}
2016-01-05 04:47:35 +01:00
2021-04-19 21:20:23 +02:00
@Nullable
2016-01-05 04:47:35 +01:00
@Override
2021-04-19 21:20:23 +02:00
public CompoundNBT getShareTag(ItemStack stack) {
return super.getShareTag(stack);
2016-01-05 04:47:35 +01:00
}
2021-12-30 18:30:01 +01:00
@OnlyIn(Dist.CLIENT)
2016-01-05 04:47:35 +01:00
@Override
2021-11-14 00:20:29 +01:00
public void appendHoverText(ItemStack stack, @Nullable World playerIn, List<ITextComponent> tooltip, ITooltipFlag advanced) {
//PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
//if (effects != null) {
// for (PotionEffect effect : effects) {
// tooltip.add(StringUtil.localize(effect.getEffectName()) + " " + (effect.getAmplifier() + 1) + ", " + StringUtils.formatTickDuration(effect.getDuration() * 20));
// }
//} else {
// tooltip.add(StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".coffeeCup.noEffect"));
//}
2016-01-05 04:47:35 +01:00
}
2021-02-26 22:15:48 +01:00
2019-11-09 21:02:42 +01:00
@Override
public boolean isEnchantable(ItemStack stack) {
return false;
}
2021-02-26 22:15:48 +01:00
2019-11-09 21:02:42 +01:00
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return false;
}
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) {
2021-11-14 00:20:29 +01:00
//PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
//ArrayList<PotionEffect> effectsNew = new ArrayList<>();
2019-05-02 09:10:29 +02:00
if (effects != null && effects.length > 0) {
2021-11-14 00:20:29 +01:00
/* for (PotionEffect effect : effects) {
2019-05-02 09:10:29 +02:00
if (effect.getAmplifier() > 0) {
effectsNew.add(new PotionEffect(effect.getPotion(), effect.getDuration() + 120, effect.getAmplifier() - 1));
2016-01-05 04:47:35 +01:00
}
}
2021-02-26 22:15:48 +01:00
stack.setTagCompound(new CompoundNBT());
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);
2021-11-14 00:20:29 +01:00
}*/
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() {
2023-12-02 14:49:10 +01:00
return I18n.get("container.nei." + ActuallyAdditions.MODID + ".coffee.extra.milk");
2016-01-05 04:47:35 +01:00
}
}
2021-02-26 22:15:48 +01:00
}