Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.theviolentsquirrels.questsystem.item;
- import net.minecraft.enchantment.Enchantment;
- import net.minecraft.enchantment.EnchantmentHelper;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.projectile.EntityArrow;
- import net.minecraft.init.Items;
- import net.minecraft.item.EnumAction;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemArmor;
- import net.minecraft.item.ItemStack;
- import net.minecraft.stats.StatList;
- import net.minecraft.world.World;
- import net.minecraftforge.common.MinecraftForge;
- import net.minecraftforge.event.entity.player.ArrowLooseEvent;
- import net.minecraftforge.event.entity.player.ArrowNockEvent;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import net.theviolentsquirrels.questsystem.Main;
- public class ItemBow extends Item {
- public static final String[] bowPullIconNameArray = new String[] { "questsystem:pulling_0", "questsystem:pulling_1", "questsystem:pulling_2" };
- private final int renderIndex;
- private final float damageCoefficient;
- private final float velocityCoefficient;
- private final BowMaterial material;
- public ItemBow(String unlocalizedName, BowMaterial material, int renderIndex) {
- this.setUnlocalizedName(unlocalizedName);
- this.setMaxStackSize(1);
- this.setMaxDamage(material.getBaseDurability());
- this.setCreativeTab(Main.tab);
- this.renderIndex = renderIndex;
- this.damageCoefficient = material.getDamageCoefficient();
- this.velocityCoefficient = material.getVelocityCoefficient();
- this.material = material;
- }
- /**
- * Called when the player stops using an Item (stops holding the right mouse button).
- */
- @Override
- public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft) {
- boolean creativeflag;
- creativeflag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
- if (creativeflag || playerIn.inventory.hasItem(Items.arrow)) {
- int bowCharge = this.getMaxItemUseDuration(stack) - timeLeft;
- ArrowLooseEvent event = new ArrowLooseEvent(playerIn, stack, bowCharge);
- if (MinecraftForge.EVENT_BUS.post(event)) return;
- bowCharge = event.charge;
- float velocity = (float) bowCharge / 20.0F;
- velocity = (velocity * velocity + velocity * 2.0F) / 3.0F;
- if ((double) velocity < 0.1D) return;
- if (velocity > 1.0F) velocity = 1.0F;
- EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, velocity * 2.0F);
- if (velocity == 1.0F) entityarrow.setIsCritical(true);
- int powerEnchantmentLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
- if (powerEnchantmentLevel > 0)
- entityarrow.setDamage(entityarrow.getDamage() + (double) powerEnchantmentLevel * 0.5D + 0.5D);
- int punchEnchantmentLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
- if (punchEnchantmentLevel > 0)
- entityarrow.setKnockbackStrength(punchEnchantmentLevel);
- if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
- entityarrow.setFire(100);
- stack.damageItem(1, playerIn);
- worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + velocity * 0.5F);
- if (creativeflag)
- entityarrow.canBePickedUp = 2;
- else
- playerIn.inventory.consumeInventoryItem(Items.arrow);
- playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
- if (!worldIn.isRemote)
- worldIn.spawnEntityInWorld(entityarrow);
- }
- }
- /**
- * Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
- * the Item before the action is complete.
- */
- @Override
- public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn) {
- return (stack);
- }
- /**
- * How long it takes to use or consume an item
- */
- @Override
- public int getMaxItemUseDuration(ItemStack stack) {
- return (72000);
- }
- /**
- * returns the action that specifies what animation to play when the items is being used
- */
- @Override
- public EnumAction getItemUseAction(ItemStack stack) {
- return (EnumAction.BOW);
- }
- /**
- * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
- */
- @Override
- public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
- ArrowNockEvent event = new ArrowNockEvent(playerIn, itemStackIn);
- if (MinecraftForge.EVENT_BUS.post(event)) return (event.result);
- if (playerIn.capabilities.isCreativeMode || playerIn.inventory.hasItem(Items.arrow))
- playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
- return (itemStackIn);
- }
- /**
- * Return the enchantability factor of the item, most of the time is based on material.
- */
- @Override
- public int getItemEnchantability() {
- return (1);
- }
- /**
- * Return whether this item is repairable in an anvil.
- * TVS-NOTE : taken from {@link net.minecraft.item.ItemBow#getIsRepairable(ItemStack, ItemStack)} !
- */
- @Override
- public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
- return (this.material.getRepairItem() == repair.getItem() || super.getIsRepairable(toRepair, repair));
- }
- public enum BowMaterial {
- BASE("wood", 3, 0.4f, 2),
- IRON("iron", 4, 0.7f, 2),
- GOLD("gold", 5, 1.0f, 2),
- DIAMOND("diamond", 6, 1.3f, 2);
- private final String materialName;
- private final int baseDurability;
- private final float damageCoefficient;
- private final float velocityCoefficient;
- public Item customCraftingMaterial = null;
- BowMaterial(String name, int durability, float damageCoeff, int velocity) {
- this.materialName = name;
- this.baseDurability = durability;
- this.damageCoefficient = damageCoeff;
- this.velocityCoefficient = velocity;
- }
- @SideOnly(Side.CLIENT)
- public String getName() {
- return (this.materialName);
- }
- public int getBaseDurability() {
- return (this.baseDurability);
- }
- public float getVelocityCoefficient() {
- return (this.velocityCoefficient);
- }
- public float getDamageCoefficient() {
- return (this.damageCoefficient);
- }
- /**
- * Get a main crafting component of this Armor Material (example is Items.iron_ingot)
- * TVS-NOTE : taken from {@link ItemArmor.ArmorMaterial#getRepairItem()} !
- */
- public Item getRepairItem() {
- switch (this) {
- case IRON: return (Items.iron_ingot);
- case GOLD: return (Items.gold_ingot);
- case DIAMOND: return (Items.diamond);
- default: return (this.customCraftingMaterial);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement