Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.androbean.zcp.items;
- import mod.akrivus.kagic.entity.EntityGem;
- import mod.akrivus.kagic.init.ModCreativeTabs;
- import mod.akrivus.kagic.util.PoofDamage;
- import net.minecraft.enchantment.Enchantment;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.IItemPropertyGetter;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.ActionResult;
- import net.minecraft.util.EnumActionResult;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class ItemGemRejuvenator extends Item {
- public ItemGemRejuvenator() {
- super();
- this.setCreativeTab(ModCreativeTabs.CREATIVE_TAB_OTHER);
- this.setUnlocalizedName("gem_rejuvenator");
- this.setMaxStackSize(1);
- this.addPropertyOverride(new ResourceLocation("primed"), new IItemPropertyGetter() {
- @Override
- @SideOnly(Side.CLIENT)
- public float apply(ItemStack stack, World world, EntityLivingBase entity) {
- if (stack.hasTagCompound()) {
- return stack.getTagCompound().getBoolean("Primed") ? 1.0F : 0.0F;
- }
- return 0.0F;
- }
- });
- }
- @Override
- public int getMaxItemUseDuration(ItemStack stack) {
- return 40;
- }
- @Override
- public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entity, int timeLeft) {
- if (!world.isRemote && entity instanceof EntityPlayer) {
- EntityPlayer player = (EntityPlayer) entity;
- player.getCooldownTracker().setCooldown(this, 0);
- }
- }
- @Override
- public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entity) {
- NBTTagCompound compound = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
- compound.setBoolean("Primed", true);
- stack.setTagCompound(compound);
- return stack;
- }
- @Override
- public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
- ItemStack stack = player.getHeldItem(hand);
- player.setActiveHand(hand);
- if (!stack.hasTagCompound() || !stack.getTagCompound().getBoolean("Primed")) {
- player.getCooldownTracker().setCooldown(this, 60);
- }
- return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
- }
- @Override
- public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
- if (stack.hasTagCompound()) {
- if (target instanceof EntityGem) {
- if (stack.getTagCompound().getBoolean("Primed")) {
- ((EntityGem) target).setOwnerId("0");
- target.attackEntityFrom(new PoofDamage(), target.getMaxHealth());
- this.Rejuvenate((EntityGem) target);
- stack.getTagCompound().setBoolean("Primed", false);
- }
- }
- return true;
- }
- return false;
- }
- public void Rejuvenate(EntityGem gem){
- gem.setGemId(MathHelper.getRandomUUID());
- gem.setUniformColor(gem.nativeColor);
- gem.setServitude(EntityGem.SERVE_NONE);
- gem.fallbackServitude = -1;
- gem.setAttackAI();
- }
- @Override
- public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
- return false;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public boolean isFull3D() {
- return true;
- }
- }
Add Comment
Please, Sign In to add comment