158 lines
4.4 KiB
Java
Executable file
158 lines
4.4 KiB
Java
Executable file
package game.item;
|
|
|
|
import java.util.List;
|
|
|
|
import game.enchantment.Enchantment;
|
|
import game.enchantment.EnchantmentHelper;
|
|
import game.entity.npc.EntityNPC;
|
|
import game.entity.projectile.EntityArrow;
|
|
import game.init.Items;
|
|
import game.init.SoundEvent;
|
|
import game.renderer.blockmodel.ModelBlock;
|
|
import game.renderer.blockmodel.Transforms;
|
|
import game.world.World;
|
|
|
|
public class ItemBow extends Item
|
|
{
|
|
public ItemBow()
|
|
{
|
|
this.maxStackSize = 1;
|
|
this.setMaxDamage(384);
|
|
this.setTab(CheatTab.tabCombat);
|
|
}
|
|
|
|
/**
|
|
* Called when the player stops using an Item (stops holding the right mouse button).
|
|
*/
|
|
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityNPC playerIn, int timeLeft)
|
|
{
|
|
boolean flag = /* playerIn.creative || */ EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
|
|
|
|
if (flag || playerIn.inventory.hasItem(Items.arrow))
|
|
{
|
|
int i = this.getMaxItemUseDuration(stack) - timeLeft;
|
|
float f = (float)i / 20.0F;
|
|
f = (f * f + f * 2.0F) / 3.0F;
|
|
|
|
if ((double)f < 0.1D)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (f > 1.0F)
|
|
{
|
|
f = 1.0F;
|
|
}
|
|
|
|
EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, f * 2.0F);
|
|
|
|
if (f == 1.0F)
|
|
{
|
|
entityarrow.setIsCritical(true);
|
|
}
|
|
|
|
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
|
|
|
|
if (j > 0)
|
|
{
|
|
entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
|
|
}
|
|
|
|
int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
|
|
|
|
if (k > 0)
|
|
{
|
|
entityarrow.setKnockbackStrength(k);
|
|
}
|
|
|
|
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
|
|
{
|
|
entityarrow.setFire(100);
|
|
}
|
|
|
|
stack.damageItem(1, playerIn);
|
|
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 1.0F);
|
|
|
|
if (flag)
|
|
{
|
|
entityarrow.canBePickedUp = 2;
|
|
}
|
|
else
|
|
{
|
|
playerIn.inventory.consumeInventoryItem(Items.arrow);
|
|
}
|
|
|
|
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
|
|
|
if (!worldIn.client)
|
|
{
|
|
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.
|
|
*/
|
|
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn)
|
|
{
|
|
return stack;
|
|
}
|
|
|
|
/**
|
|
* How long it takes to use or consume an item
|
|
*/
|
|
public int getMaxItemUseDuration(ItemStack stack)
|
|
{
|
|
return 72000;
|
|
}
|
|
|
|
/**
|
|
* returns the action that specifies what animation to play when the items is being used
|
|
*/
|
|
public ItemAction getItemUseAction(ItemStack stack)
|
|
{
|
|
return ItemAction.AIM;
|
|
}
|
|
|
|
/**
|
|
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
|
*/
|
|
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
|
{
|
|
if (/* playerIn.creative || */ 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.
|
|
*/
|
|
public int getItemEnchantability()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
|
subItems.add(new ItemStack(itemIn, 1, 0));
|
|
for(int z = 0; z < 3; z++) {
|
|
subItems.add(new ItemStack(itemIn, 1, 1 + z));
|
|
}
|
|
}
|
|
|
|
public Transforms getTransform() {
|
|
return Transforms.RANGED;
|
|
}
|
|
|
|
public ModelBlock getModel(String name, int meta) {
|
|
return new ModelBlock(this.getTransform(), meta == 0 ? "bow" : ("bow_pulling_" + (meta - 1)));
|
|
}
|
|
|
|
public boolean canBeWielded() {
|
|
return true;
|
|
}
|
|
}
|