Skip to content

Instantly share code, notes, and snippets.

@capnkirok
Created July 30, 2017 10:04
Show Gist options
  • Save capnkirok/dbdbf524d0136b68c62596e3a3a976b4 to your computer and use it in GitHub Desktop.
Save capnkirok/dbdbf524d0136b68c62596e3a3a976b4 to your computer and use it in GitHub Desktop.
ItemTruffleSoup
package com.animania.common.items;
import java.util.List;
import javax.annotation.Nullable;
import com.animania.Animania;
import com.animania.config.AnimaniaConfig;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class ItemTruffleSoup extends ItemFood
{
private final String name = "truffle_soup";
public ItemTruffleSoup() {
super(10, 10F, true);
this.setAlwaysEdible();
this.setRegistryName(new ResourceLocation(Animania.MODID, this.name));
GameRegistry.register(this);
this.setUnlocalizedName(Animania.MODID + "_" + this.name);
this.setCreativeTab(Animania.TabAnimaniaResources);
this.setMaxStackSize(1);
}
@Override
public EnumAction getItemUseAction(ItemStack itemstack) {
return EnumAction.EAT;
}
@Override
@Nullable
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entityLiving;
if (!worldIn.isRemote && AnimaniaConfig.gameRules.foodsGiveBonusEffects) {
entityplayer.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 1200, 1, false, false));
}
}
if (entityLiving instanceof EntityPlayer && !((EntityPlayer)entityLiving).capabilities.isCreativeMode)
{
stack.shrink(1);
}
if (entityLiving instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)entityLiving;
entityplayer.getFoodStats().addStats(this, stack);
worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
this.onFoodEaten(stack, worldIn, entityplayer);
entityplayer.addStat(StatList.getObjectUseStats(this));
}
return stack.getCount() <= 0 ? new ItemStack(Items.BOWL) : stack;
}
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
playerIn.setActiveHand(hand);
return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
public String getName() {
return this.name;
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4) {
if (AnimaniaConfig.gameRules.foodsGiveBonusEffects)
list.add(TextFormatting.GREEN + I18n.translateToLocal("tooltip.an.regeneration"));
list.add(TextFormatting.GOLD + I18n.translateToLocal("tooltip.an.edibleanytime"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment