-
Notifications
You must be signed in to change notification settings - Fork 754
/
AmmoWeapon.java
147 lines (118 loc) · 4.55 KB
/
AmmoWeapon.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
package tconstruct.library.weaponry;
import tconstruct.weaponry.client.CrosshairType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* Throwing weapons that utilize the ammo system on themselves.
* Throwing knifes etc.
*/
public abstract class AmmoWeapon extends AmmoItem implements IAccuracy, IWindup {
public AmmoWeapon(int baseDamage, String name) {
super(baseDamage, name);
}
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
return EnumAction.none;
} // we use custom animation renderiiing!
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
return 72000;
}
@Override
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
return stack;
}
@Override
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float clickX, float clickY, float clickZ)
{
return false;
}
/**
* How long it takes to "ready" the weapon. To reach the point, where holding the right mouse button any longer doesn't have an impact.
*/
@Override
public int getWindupTime(ItemStack itemStack) { return 0; }
@Override
public float getMinWindupProgress(ItemStack itemStack) {
return 0;
}
public float getWindupProgress(ItemStack itemStack, int timeInUse)
{
float time = (float) timeInUse;
float windup = getWindupTime(itemStack);
if(time > windup)
time = windup;
return time/windup;
}
public float minAccuracy(ItemStack itemStack) { return 0.5f; }
public float maxAccuracy(ItemStack itemStack) { return 0.5f; }
public float getWindupProgress(ItemStack itemStack, EntityPlayer player)
{
// what are you doing!
if(player.inventory.getCurrentItem() != itemStack)
return 0f;
// are we using it?
if(player.getItemInUse() == null)
return 0f;
return getWindupProgress(itemStack, getMaxItemUseDuration(itemStack) - player.getItemInUseCount());
}
public float getAccuracy(ItemStack itemStack, EntityPlayer player)
{
float dif = minAccuracy(itemStack) - maxAccuracy(itemStack);
return minAccuracy(itemStack) - dif * getWindupProgress(itemStack, player);
}
@Override
public String[] getTraits() {
return new String[] {"weapon", "throwing", "ammo", "windup"};
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int durationLeft) {
int time = this.getMaxItemUseDuration(stack) - durationLeft;
if(getWindupProgress(stack, time) >= getMinWindupProgress(stack))
launchProjectile(stack, world, player);
}
protected void launchProjectile(ItemStack stack, World world, EntityPlayer player) {
// spawn projectile on server
if(!world.isRemote) {
ItemStack reference = stack.copy();
reference.stackSize = 1;
reference.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", 1);
Entity projectile = createProjectile(reference, world, player, getAccuracy(stack, player));
world.spawnEntityInWorld(projectile);
}
// reduce ammo
if(!player.capabilities.isCreativeMode)
this.consumeAmmo(1, stack);
}
protected abstract Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy);
@Override
public void registerPartPaths(int index, String[] location) {
}
@Override
public void registerAlternatePartPaths(int index, String[] location) {
headStrings.put(index, location[0]);
brokenPartStrings.put(index, location[1]);
handleStrings.put(index, location[2]);
if (location.length > 3)
accessoryStrings.put(index, location[3]);
if (location.length > 4)
extraStrings.put(index, location[4]);
}
@SideOnly(Side.CLIENT)
public CrosshairType getCrosshairType() { return CrosshairType.SQUARE; }
@Override
public boolean zoomOnWindup(ItemStack itemStack) {
return false;
}
@Override
public float getZoom(ItemStack itemStack) {
return 1.0f;
}
}