-
Notifications
You must be signed in to change notification settings - Fork 755
/
BowBaseAmmo.java
165 lines (136 loc) · 5.38 KB
/
BowBaseAmmo.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
package tconstruct.library.weaponry;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.BowstringMaterial;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.entity.ArrowEntity;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import tconstruct.library.crafting.ToolBuilder;
import java.util.List;
public abstract class BowBaseAmmo extends ProjectileWeapon {
public BowBaseAmmo(int baseDamage, String name) {
super(baseDamage, name);
}
@Override
public int durabilityTypeAccessory() {
return 2; // head-type
}
@Override
public int durabilityTypeExtra() {
return 1; // handle-type
}
@Override
public boolean zoomOnWindup(ItemStack itemStack) {
return true;
}
@Override
public float getZoom(ItemStack itemStack) {
return 1.2f;
}
@Override
public float getMinWindupProgress(ItemStack itemStack) {
return 0.5f;
}
@Override
public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon)
{
// arrow priority: hotbar > inventory, tinker arrows > regular arrows
ItemStack[] inventory = player.inventory.mainInventory;
// check hotbar for tinker arrows
for(int i = 0; i < InventoryPlayer.getHotbarSize(); i++)
if(checkTinkerArrow(inventory[i]))
return inventory[i];
// check hotbar for vanilla arrows
for(int i = 0; i < InventoryPlayer.getHotbarSize(); i++)
if(checkVanillaArrow(inventory[i]))
return inventory[i];
// check the rest of the inventory for tinker arrows
for(int i = InventoryPlayer.getHotbarSize(); i < inventory.length; i++)
if(checkTinkerArrow(inventory[i]))
return inventory[i];
// check the rest of the inventory for vanilla arrows
for(int i = InventoryPlayer.getHotbarSize(); i < inventory.length; i++)
if(checkVanillaArrow(inventory[i]))
return inventory[i];
// creative mode
if(player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, weapon) > 0)
return new ItemStack(Items.arrow);
return null;
}
private boolean checkTinkerArrow(ItemStack stack)
{
// null
if(stack == null)
return false;
// no tinker arrow
if(!(stack.getItem() instanceof ArrowAmmo))
return false;
// no ammo left
if(((IAmmo) stack.getItem()).getAmmoCount(stack) <= 0)
return false;
return true;
}
private boolean checkVanillaArrow(ItemStack stack)
{
// null
if(stack == null)
return false;
// no arrow
if(!(stack.getItem() == Items.arrow))
return false;
// inventory shouldn't contain stacksize 0 items so we don't have to check that.
return true;
}
@Override
protected Entity createProjectile(ItemStack arrows, World world, EntityPlayer player, float speed, float accuracy) {
EntityArrow arrow;
if(arrows.getItem() == Items.arrow) {
arrow = new EntityArrow(world, player, speed/1.5f); // vanilla arrows internally do x1.5
}
else {
ItemStack reference = arrows.copy();
reference.stackSize = 1;
reference.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", 1);
arrow = new ArrowEntity(world, player, speed, accuracy, reference);
}
if(player.capabilities.isCreativeMode)
arrow.canBePickedUp = 2;
return arrow;
}
@Override
public void playFiringSound(World world, EntityPlayer player, ItemStack weapon, ItemStack ammo, float speed, float accuracy) {
world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + speed * 0.5F);
}
@Override
public void buildTool (int id, String name, List list)
{
// all creative bows use regular bowstring
ItemStack handleStack = new ItemStack(getHandleItem(), 1, 0); // regular bowstring
ItemStack accessoryStack = getPartAmount() > 2 ? new ItemStack(getAccessoryItem(), 1, id) : null;
ItemStack extraStack = getPartAmount() > 3 ? new ItemStack(getExtraItem(), 1, id) : null;
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, id), handleStack, accessoryStack, extraStack, "");
if (tool != null)
{
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
}
}
@Override
protected int getDefaultColor(int renderPass, int materialID) {
// bowstring uses custom material
if(renderPass == 0)
return TConstructRegistry.getCustomMaterial(materialID, BowstringMaterial.class).color;
return super.getDefaultColor(renderPass, materialID);
}
@Override
public String[] getTraits() {
return new String[] {"weapon", "ranged", "bow", "windup"};
}
}