-
Notifications
You must be signed in to change notification settings - Fork 754
/
Javelin.java
192 lines (157 loc) · 5.11 KB
/
Javelin.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package tconstruct.weaponry.weapons;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.client.CrosshairType;
import tconstruct.weaponry.entity.JavelinEntity;
import tconstruct.library.weaponry.AmmoWeapon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.tools.TinkerTools;
public class Javelin extends AmmoWeapon {
public Javelin() {
super(3, "Javelin");
}
@Override
public boolean onLeftClickEntity (ItemStack stack, EntityPlayer player, Entity entity)
{
// javelin is the only throwing/ammo weapon that hurts on leftclicking
return AbilityHelper.onLeftClickEntity(stack, player, entity, this, 0);
}
@Override
public float getWindupProgress(ItemStack itemStack, EntityPlayer player) {
if(!itemStack.hasTagCompound())
return super.getWindupProgress(itemStack, player);
if(!itemStack.getTagCompound().getCompoundTag("InfiTool").hasKey("Throwing"))
return 0.5f;
float timeleft = itemStack.getTagCompound().getCompoundTag("InfiTool").getInteger("Throwing");
float threshold = getWindupTime(itemStack)/5;
if(timeleft < threshold)
return (threshold-timeleft)/threshold;
else
return 0.5f - 0.25f * ((float)getWindupTime(itemStack)-timeleft)/threshold;
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
// already throwing
if(tags.hasKey("Throwing"))
return stack;
// has ammo?
if(this.getAmmoCount(stack) <= 0)
return stack;
// start throwing
tags.setInteger("Throwing", getWindupTime(stack));
return stack;
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
super.onUpdate(stack, world, entity, par4, par5);
if(!stack.hasTagCompound())
return;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if(!tags.hasKey("Throwing"))
return;
EntityPlayer player = (EntityPlayer) entity;
if(player.inventory.getCurrentItem() != stack)
return;
int timeLeft = tags.getInteger("Throwing");
timeLeft--;
if(timeLeft > 0)
tags.setInteger("Throwing", timeLeft);
else {
onPlayerStoppedUsing(stack, world, player, 0);
tags.removeTag("Throwing");
}
}
@Override
public boolean zoomOnWindup(ItemStack itemStack) {
return true;
}
@Override
public float getZoom(ItemStack itemStack) {
return 1.5f;
}
@Override
public float minAccuracy(ItemStack itemStack) {
return 2.5f;
}
@Override
public float maxAccuracy(ItemStack itemStack) {
return 0.5f;
}
@Override
public int getWindupTime(ItemStack itemStack) {
return 17;
}
@Override
public int getPartAmount() {
return 3;
}
@Override
public String getIconSuffix(int partType) {
switch (partType)
{
case 0:
return "_javelin_head";
case 1:
return "_javelin_head_broken"; // no broken, since it runs out of ammo
case 2:
return "_javelin_handle";
case 3:
return "_javelin_accessory";
default:
return "";
}
}
@Override
public String getEffectSuffix() {
return "_javelin_effect";
}
@Override
public String getDefaultFolder() {
return "javelin";
}
@Override
public float getAmmoModifier() {
return 0.2f;
}
@Override
public float getDurabilityModifier() {
return 0.1f;
}
@Override
public Item getHeadItem() {
return TinkerWeaponry.arrowhead;
}
@Override
public Item getHandleItem() {
return TinkerTools.toughRod;
}
@Override
public Item getAccessoryItem() {
return TinkerTools.toughRod;
}
@Override
public String[] getTraits() {
return new String[] {"weapon", "thrown", "ammo", "windup"};
}
@Override
protected Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy) {
reference.getTagCompound().getCompoundTag("InfiTool").removeTag("Throwing"); // needed so the NBTs are equal
JavelinEntity entity = new JavelinEntity(world, player, getProjectileSpeed(), accuracy, reference);
return entity;
}
@Override
public float getProjectileSpeed() {
return 2.0f;
}
@SideOnly(Side.CLIENT)
@Override
public CrosshairType getCrosshairType() { return CrosshairType.WEIRD; }
}