73 lines
2.5 KiB
Java
73 lines
2.5 KiB
Java
package net.minecraft.item;
|
|
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.block.BlockDispenser;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.EntityLiving;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Items;
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.EnumActionResult;
|
|
import net.minecraft.util.EnumHand;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class ItemElytra extends Item
|
|
{
|
|
public ItemElytra()
|
|
{
|
|
this.maxStackSize = 1;
|
|
this.setMaxDamage(432);
|
|
this.setCreativeTab(CreativeTabs.TRANSPORTATION);
|
|
this.addPropertyOverride(new ResourceLocation("broken"), new IItemPropertyGetter()
|
|
{
|
|
@SideOnly(Side.CLIENT)
|
|
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
|
{
|
|
return ItemElytra.isUsable(stack) ? 0.0F : 1.0F;
|
|
}
|
|
});
|
|
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, ItemArmor.DISPENSER_BEHAVIOR);
|
|
}
|
|
|
|
public static boolean isUsable(ItemStack stack)
|
|
{
|
|
return stack.getItemDamage() < stack.getMaxDamage() - 1;
|
|
}
|
|
|
|
/**
|
|
* Return whether this item is repairable in an anvil.
|
|
*
|
|
* @param toRepair the {@code ItemStack} being repaired
|
|
* @param repair the {@code ItemStack} being used to perform the repair
|
|
*/
|
|
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
|
{
|
|
return repair.getItem() == Items.LEATHER;
|
|
}
|
|
|
|
/**
|
|
* Called when the equipped item is right clicked.
|
|
*/
|
|
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
|
{
|
|
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
|
EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);
|
|
ItemStack itemstack1 = playerIn.getItemStackFromSlot(entityequipmentslot);
|
|
|
|
if (itemstack1.isEmpty())
|
|
{
|
|
playerIn.setItemStackToSlot(entityequipmentslot, itemstack.copy());
|
|
itemstack.setCount(0);
|
|
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
|
}
|
|
else
|
|
{
|
|
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
|
}
|
|
}
|
|
} |