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

158 lines
7.2 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;
import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import net.minecraft.ChatFormatting;
2024-03-02 21:23:08 +01:00
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.util.StringUtil;
import net.minecraft.world.effect.MobEffectInstance;
2024-03-02 21:23:08 +01:00
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.food.FoodProperties;
2024-03-02 21:23:08 +01:00
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.UseAnim;
2024-03-02 21:23:08 +01:00
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeHolder;
2024-03-02 21:23:08 +01:00
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.level.Level;
2024-03-04 20:21:48 +01:00
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
2016-01-05 04:47:35 +01:00
2021-02-26 22:15:48 +01:00
import javax.annotation.Nullable;
import java.util.List;
public class ItemCoffee extends ItemBase {
private static final FoodProperties FOOD = new FoodProperties.Builder().nutrition(8).saturationMod(5.0F).alwaysEat().build();
2016-01-05 04:47:35 +01:00
public ItemCoffee() {
super(ActuallyItems.defaultProps().food(FOOD).durability(3));
2016-01-05 04:47:35 +01:00
}
2019-05-02 09:10:29 +02:00
public static void initIngredients() {
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(Items.MILK_BUCKET)));
// //Pam's Soy Milk (For Jemx because he's lactose intolerant. YER HAPPY NAO!?)
// if (ModList.get().isLoaded("harvestcraft")) {
// Item item = ItemUtil.getItemFromName("harvestcraft:soymilkitem");
// if (item != null) {
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(item)));
// }
// }
//
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.SUGAR), 4, new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 30, 0)));
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.MAGMA_CREAM), 2, new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 20, 0)));
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.PUFFERFISH), 2, new MobEffectInstance(MobEffects.WATER_BREATHING, 10, 0)));
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GOLDEN_CARROT), 2, new MobEffectInstance(MobEffects.NIGHT_VISION, 30, 0)));
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GHAST_TEAR), 3, new MobEffectInstance(MobEffects.REGENERATION, 5, 0)));
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.BLAZE_POWDER), 4, new MobEffectInstance(MobEffects.DAMAGE_BOOST, 15, 0)));
// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.FERMENTED_SPIDER_EYE), 2, new MobEffectInstance(MobEffects.INVISIBILITY, 25, 0)));
2016-01-05 04:47:35 +01:00
}
@Nullable
public static RecipeHolder<CoffeeIngredientRecipe> getIngredientRecipeFromStack(ItemStack stack) {
for (RecipeHolder<CoffeeIngredientRecipe> recipeHolder : ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS) {
if (recipeHolder.value().getIngredient().test(stack)) {
return recipeHolder;
2021-02-26 22:15:48 +01:00
}
2016-01-05 04:47:35 +01:00
}
return null;
}
public static void applyPotionEffectsFromStack(ItemStack stack, LivingEntity player) {
MobEffectInstance[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
2019-05-02 09:10:29 +02:00
if (effects != null && effects.length > 0) {
for (MobEffectInstance effect : effects) {
player.addEffect(new MobEffectInstance(effect.getEffect(), effect.getDuration() * 20, effect.getAmplifier()));
2016-02-01 20:39:11 +01:00
}
}
}
@Override
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livingEntity) {
2016-01-05 04:47:35 +01:00
ItemStack theStack = stack.copy();
super.finishUsingItem(stack, level, livingEntity);
applyPotionEffectsFromStack(stack, livingEntity);
theStack.setDamageValue(theStack.getDamageValue() + 1);
if (theStack.getMaxDamage() - theStack.getDamageValue() < 0) {
2024-03-15 02:40:07 +01:00
return new ItemStack(ActuallyItems.EMPTY_CUP.get());
} else {
return theStack;
}
2016-01-05 04:47:35 +01:00
}
@Override
public UseAnim getUseAnimation(ItemStack pStack) {
return UseAnim.DRINK;
}
2021-12-30 18:30:01 +01:00
@OnlyIn(Dist.CLIENT)
2016-01-05 04:47:35 +01:00
@Override
2024-03-02 21:23:08 +01:00
public void appendHoverText(ItemStack stack, @Nullable Level playerIn, List<Component> tooltip, TooltipFlag advanced) {
MobEffectInstance[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack);
if (effects != null) {
for (MobEffectInstance effect : effects) {
tooltip.add(Component.translatable(effect.getDescriptionId())
.append(" " + (effect.getAmplifier() + 1) + ", " + StringUtil.formatTickDuration(effect.getDuration(), 1))
.withStyle(ChatFormatting.GRAY));
}
} else {
tooltip.add(Component.translatable("tooltip." + ActuallyAdditions.MODID + ".coffeeCup.noEffect").withStyle(ChatFormatting.GRAY));
}
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() {
return I18n.get("jei." + ActuallyAdditions.MODID + ".coffee.extra.milk");
2016-01-05 04:47:35 +01:00
}
}
2021-02-26 22:15:48 +01:00
}