/
FusewoodBow.java
96 lines (77 loc) · 2.92 KB
/
FusewoodBow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package mods.natura.items.tools;
import mods.natura.entity.FusewoodArrow;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
public class FusewoodBow extends NaturaBow
{
public FusewoodBow(int id, int damage, String type)
{
super(id, damage, type);
}
public void onPlayerStoppedUsing (ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
{
int j = this.getMaxItemUseDuration(par1ItemStack) - par4;
ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
{
return;
}
j = event.charge;
boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;
if (flag || par3EntityPlayer.inventory.hasItem(Items.arrow))
{
float f = (float) j / 20.0F;
f = (f * f + f * 2.0F) / 3.0F;
if ((double) f < 0.1D)
{
return;
}
if (f > 1.0F)
{
f = 1.0F;
}
FusewoodArrow entityarrow = new FusewoodArrow(par2World, par3EntityPlayer, f * 2.0F);
entityarrow.shootingEntity = par3EntityPlayer;
if (f == 1.0F)
{
entityarrow.setIsCritical(true);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
if (k > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double) k * 0.5D + 0.5D);
}
int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
if (l > 0)
{
entityarrow.setKnockbackStrength(l);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
{
entityarrow.setFire(100);
}
par1ItemStack.damageItem(1, par3EntityPlayer);
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (flag)
{
entityarrow.canBePickedUp = 2;
}
else
{
par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow);
}
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(entityarrow);
}
}
}
}