-
Notifications
You must be signed in to change notification settings - Fork 754
/
TinkerWeaponry.java
354 lines (306 loc) · 18.5 KB
/
TinkerWeaponry.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package tconstruct.weaponry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import mantle.pulsar.pulse.Handler;
import mantle.pulsar.pulse.Pulse;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.*;
import tconstruct.library.tools.DynamicToolPart;
import tconstruct.library.tools.FletchlingLeafMaterial;
import tconstruct.library.util.IPattern;
import tconstruct.library.util.IToolPart;
import tconstruct.modifiers.tools.ModWindup;
import tconstruct.modifiers.tools.ModAmmoRestock;
import tconstruct.smeltery.TinkerSmeltery;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.items.Bowstring;
import tconstruct.tools.items.Fletching;
import tconstruct.tools.items.Pattern;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.ammo.BoltAmmo;
import tconstruct.library.tools.DualMaterialToolPart;
import tconstruct.weaponry.items.GlassArrows;
import tconstruct.weaponry.items.WeaponryPattern;
import tconstruct.library.weaponry.AmmoItem;
import tconstruct.library.weaponry.AmmoWeapon;
import tconstruct.library.weaponry.ArrowShaftMaterial;
import tconstruct.library.weaponry.ProjectileWeapon;
import tconstruct.weaponry.weapons.*;
import tconstruct.world.TinkerWorld;
import java.util.Map;
import java.util.Random;
import static tconstruct.tools.TinkerTools.MaterialID;
@GameRegistry.ObjectHolder(TConstruct.modID)
@Pulse(id = "Tinkers' Weaponry", description = "The main core of the mod! All of the tools, the tables, and the patterns are here.", pulsesRequired="Tinkers' Tools")
public class TinkerWeaponry {
@SidedProxy(clientSide = "tconstruct.weaponry.WeaponryClientProxy", serverSide = "tconstruct.weaponry.WeaponryCommonProxy")
public static WeaponryCommonProxy proxy;
// Throwing Weapons
public static AmmoWeapon shuriken;
public static AmmoWeapon throwingknife;
public static AmmoWeapon javelin;
// Projectile Weapons
public static ProjectileWeapon shortbow;
public static ProjectileWeapon longbow;
public static ProjectileWeapon crossbow;
// Ammo
public static AmmoItem arrowAmmo;
public static AmmoItem boltAmmo;
// Tool Parts
public static Item bowstring;
public static DynamicToolPart arrowhead;
public static Item fletching;
public static DynamicToolPart partShuriken;
public static DynamicToolPart partArrowShaft; // not craftable, used internally
public static DynamicToolPart partBowLimb;
public static DynamicToolPart partCrossbowLimb;
public static DynamicToolPart partCrossbowBody;
public static DualMaterialToolPart partBolt;
// patterns/casts
public static Pattern woodPattern;
public static Pattern metalPattern;
// other stuff
public static Random random = new Random();
@Handler
public void preInit(FMLPreInitializationEvent event)
{
registerItems();
registerLegendaries();
registerMaterials();
}
@Handler
public void init(FMLInitializationEvent event)
{
addPartRecipies();
addWeaponRecipies();
registerBoltCasting();
setupCreativeTab();
ItemStack redstoneItem = new ItemStack(Items.redstone);
ItemStack redstoneBlock = new ItemStack(Blocks.redstone_block);
ModifyBuilder.registerModifier(new ModWindup(2, new ItemStack[] { redstoneItem, redstoneBlock }, new int[] { 1, 9 }));
ModifyBuilder.registerModifier(new ModAmmoRestock());
TConstructRegistry.registerActiveToolMod(new WeaponryActiveToolMod());
}
@Handler
public void postInit(FMLPostInitializationEvent event)
{
// this handler takes care that ammo weapons get ammo.
WeaponryHandler weaponryHandler = new WeaponryHandler();
MinecraftForge.EVENT_BUS.register(weaponryHandler);
FMLCommonHandler.instance().bus().register(weaponryHandler);
proxy.init();
}
private void registerItems()
{
// create tool part
TinkerTools.bowstring = bowstring = new Bowstring().setUnlocalizedName("tconstruct.Bowstring");
TinkerTools.arrowhead = arrowhead = new DynamicToolPart("_arrowhead", "ArrowHead");
TinkerTools.fletching = fletching = new Fletching().setUnlocalizedName("tconstruct.Fletching");
partShuriken = new DynamicToolPart("_shuriken", "Shuriken");
partArrowShaft = new DynamicToolPart("_arrow_shaft", "Shaft");
partBowLimb = new DynamicToolPart("_bow_limb", "BowLimb");
partCrossbowLimb = new DynamicToolPart("_crossbow_limb", "CrossbowLimb");
partCrossbowBody = new DynamicToolPart("_crossbow_body", "CrossbowBody");
partBolt = new DualMaterialToolPart("_bolt", "Bolt");
// create throwing weapons
shuriken = new Shuriken();
throwingknife = new ThrowingKnife();
javelin = new Javelin();
// create projectile weapons
TinkerTools.shortbow = shortbow = new ShortBow();
longbow = new LongBow();
crossbow = new Crossbow();
// create ammo
arrowAmmo = new ArrowAmmo();
boltAmmo = new BoltAmmo();
woodPattern = new WeaponryPattern("pattern_", "Pattern");
metalPattern = new WeaponryPattern("cast_", "MetalPattern");
// register tool parts
GameRegistry.registerItem(bowstring, "bowstring"); // 1.8 todo: rename properly?
GameRegistry.registerItem(arrowhead, "arrowhead");
GameRegistry.registerItem(fletching, "fletching");
GameRegistry.registerItem(partShuriken, "ShurikenPart");
GameRegistry.registerItem(partBowLimb, "BowLimbPart");
GameRegistry.registerItem(partCrossbowLimb, "CrossbowLimbPart");
GameRegistry.registerItem(partCrossbowBody, "CrossbowBodyPart");
GameRegistry.registerItem(partBolt, "BoltPart");
// register throwing weapons
GameRegistry.registerItem(shuriken, "Shuriken");
GameRegistry.registerItem(throwingknife, "ThrowingKnife");
GameRegistry.registerItem(javelin, "Javelin");
// register projectile weapons
GameRegistry.registerItem(shortbow, "ShortBow");
GameRegistry.registerItem(longbow, "LongBow");
GameRegistry.registerItem(crossbow, "Crossbow");
// register ammo
GameRegistry.registerItem(arrowAmmo, "ArrowAmmo");
GameRegistry.registerItem(boltAmmo, "BoltAmmo");
// register patterns/casts
GameRegistry.registerItem(woodPattern, "Pattern");
GameRegistry.registerItem(metalPattern, "Cast");
}
private void addPartRecipies()
{
StencilBuilder.registerStencil(21, TinkerTools.woodPattern, 25); // arrow head
StencilBuilder.registerStencil(22, TinkerTools.woodPattern, 24); // fletchling
StencilBuilder.registerStencil(23, TinkerTools.woodPattern, 23); // bowstring
StencilBuilder.registerStencil(24, woodPattern, 0);
StencilBuilder.registerStencil(25, woodPattern, 1);
StencilBuilder.registerStencil(26, woodPattern, 2);
StencilBuilder.registerStencil(27, woodPattern, 3);
PatternBuilder.instance.addToolPattern(woodPattern);
// todo: integrate into tcon
int[] nonMetals = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 17 };
int[] liquidDamage = new int[] { 2, 13, 10, 11, 12, 14, 15, 6, 16, 18 };
Item[] patternOutputs = new Item[] { partShuriken, partCrossbowLimb, partCrossbowBody, partBowLimb };
// register part crafting
for (int m = 0; m < patternOutputs.length; m++)
for (int nonMetal : nonMetals)
TConstructRegistry.addPartMapping(woodPattern, m, nonMetal, new ItemStack(patternOutputs[m], 1, nonMetal));
// register part casting
LiquidCasting tableCasting = TConstructRegistry.getTableCasting();
for(int i = 0; i < patternOutputs.length; i++)
{
ItemStack cast = new ItemStack(metalPattern, 1, i);
tableCasting.addCastingRecipe(cast, new FluidStack(TinkerSmeltery.moltenAlubrassFluid, TConstruct.ingotLiquidValue), new ItemStack(patternOutputs[i], 1, Short.MAX_VALUE), false, 50);
tableCasting.addCastingRecipe(cast, new FluidStack(TinkerSmeltery.moltenGoldFluid, TConstruct.ingotLiquidValue * 2), new ItemStack(patternOutputs[i], 1, Short.MAX_VALUE), false, 50);
for (int iterTwo = 0; iterTwo < TinkerSmeltery.liquids.length; iterTwo++)
{
Fluid fs = TinkerSmeltery.liquids[iterTwo].getFluid();
int fluidAmount = ((IPattern) TinkerSmeltery.metalPattern).getPatternCost(cast) * TConstruct.ingotLiquidValue / 2;
ItemStack metalCast = new ItemStack(patternOutputs[i], 1, liquidDamage[iterTwo]);
tableCasting.addCastingRecipe(metalCast, new FluidStack(fs, fluidAmount), cast, 50);
Smeltery.addMelting(FluidType.getFluidType(fs), metalCast, 0, fluidAmount);
}
}
}
private void registerLegendaries()
{
GameRegistry.registerItem(new GlassArrows(), "GlassArrows");
}
private void registerMaterials()
{
// Bow Materials: Material ID, durability, drawspeed, arrow speed
// speed 3.0 == exactly the vanilla bow if 2 parts of speed 3 are used
// Wooden stuff is flexible, therefore good. Reference.
TConstructRegistry.addBowMaterial(MaterialID.Wood, 18, 3.0f); // Wood
// other organic materials also are good
TConstructRegistry.addBowMaterial(MaterialID.Cactus, 20, 2.4f); // Cactus
TConstructRegistry.addBowMaterial(MaterialID.Bone, 38, 2.0f); // Bone
TConstructRegistry.addBowMaterial(MaterialID.Slime, 28, 4.0f); // Slime
TConstructRegistry.addBowMaterial(MaterialID.BlueSlime, 21, 4.0f); // Blue Slime
TConstructRegistry.addBowMaterial(MaterialID.Paper, 25, 2.3f); // Paper
// Metal stuff has a lot of POW, but takes LONG to wind up since it's so hard
TConstructRegistry.addBowMaterial(MaterialID.Iron, 40, 5.2f); // Iron
TConstructRegistry.addBowMaterial(MaterialID.Steel, 50, 5.5f); // Steel
TConstructRegistry.addBowMaterial(MaterialID.PigIron, 30, 5.2f); // Pig Iron - it's meat!
TConstructRegistry.addBowMaterial(MaterialID.Ardite, 50, 4.5f); // Ardite
TConstructRegistry.addBowMaterial(MaterialID.Cobalt, 35, 5.2f); // Cobalt
TConstructRegistry.addBowMaterial(MaterialID.Manyullyn, 45, 4.5f); // Manyullyn
TConstructRegistry.addBowMaterial(MaterialID.Copper, 30, 5.1f); // Copper
TConstructRegistry.addBowMaterial(MaterialID.Bronze, 35, 5.2f); // Bronze
TConstructRegistry.addBowMaterial(MaterialID.Alumite, 35, 4.8f); // Alumite - a bit stone-ish since it has obsidian
// Stone doesn't bend. takes forever, has no pow. WHY WOULD YOU DO THAT
TConstructRegistry.addBowMaterial(MaterialID.Stone, 80, 1.0f); // Stone
TConstructRegistry.addBowMaterial(MaterialID.Flint, 80, 1.0f); // Flint
TConstructRegistry.addBowMaterial(MaterialID.Obsidian, 99, 1.0f); // Obsidian
TConstructRegistry.addBowMaterial(MaterialID.Netherrack, 70, 1.0f); // Netherrack
// Arrow Head Materials: Material ID, mass, fragility
TConstructRegistry.addArrowMaterial(MaterialID.Wood, 0.69F, 1.0F); //Wood
TConstructRegistry.addArrowMaterial(MaterialID.Stone, 2.05F, 5.0F); //Stone
TConstructRegistry.addArrowMaterial(MaterialID.Iron, 3.6F, 0.5F); //Iron
TConstructRegistry.addArrowMaterial(MaterialID.Flint, 1.325F, 1.0F); //Flint
TConstructRegistry.addArrowMaterial(MaterialID.Cactus, 0.76F, 1.0F); //Cactus
TConstructRegistry.addArrowMaterial(MaterialID.Bone, 0.69F, 1.0F); //Bone
TConstructRegistry.addArrowMaterial(MaterialID.Obsidian, 2.4F, 1.0F); //Obsidian
TConstructRegistry.addArrowMaterial(MaterialID.Netherrack, 1.5F, 1.0F); //Netherrack
TConstructRegistry.addArrowMaterial(MaterialID.Slime, 0.22F, 0.0F); //Slime
TConstructRegistry.addArrowMaterial(MaterialID.Paper, 0.69F, 3.0F); //Paper
TConstructRegistry.addArrowMaterial(MaterialID.Cobalt, 3.0F, 0.25f); //Cobalt
TConstructRegistry.addArrowMaterial(MaterialID.Ardite, 1.25F, 0.25f); //Ardite
TConstructRegistry.addArrowMaterial(MaterialID.Manyullyn, 2.25F, 0.1F); //Manyullyn
TConstructRegistry.addArrowMaterial(MaterialID.Copper, 2.7F, 0.5F); //Copper
TConstructRegistry.addArrowMaterial(MaterialID.Bronze, 3.6F, 0.25f); //Bronze
TConstructRegistry.addArrowMaterial(MaterialID.Alumite, 1.1F, 0.25f); //Alumite
TConstructRegistry.addArrowMaterial(MaterialID.Steel, 3.6F, 0.25f); //Steel
TConstructRegistry.addArrowMaterial(MaterialID.BlueSlime, 0.22F, 0.0F); //Blue Slime
TConstructRegistry.addArrowMaterial(MaterialID.PigIron, 3.6F, 0.5F); //Pigiron
// Arrow Shaft Materials: Material ID, crafting item, durability-medifier, mass, fragility
TConstructRegistry.addCustomMaterial(ArrowShaftMaterial.createMaterial(0, Items.stick, 1.0f, 1.0f, 0.15f, 0x866526)); // wood: reference material, 10% break chance
TConstructRegistry.addCustomMaterial(ArrowShaftMaterial.createMaterial(1, Items.bone, 0.95f, 1.4f, 0.02f, 0xede6bf)); // bone: heavier, but durable
TConstructRegistry.addCustomMaterial(ArrowShaftMaterial.createMaterial(2, Items.reeds, 1.5f, 0.5f, 0.66f, 0xc7ff87)); // reed: light, but less durable
TConstructRegistry.addCustomMaterial(ArrowShaftMaterial.createMaterial(3, Items.blaze_rod, 1.2f, 0.9f, 0.08f, 0xfff32d)); // blaze: tad lighter, tad more durable, fieryyyy
// also add the tool rod variants, same stats
TConstructRegistry.addCustomMaterial(ArrowShaftMaterial.createMaterial(0, TinkerTools.toolRod, MaterialID.Wood, 1.0f, 1.0f, 0.15f, 0x866526)); // wood: reference material, 10% break chance
TConstructRegistry.addCustomMaterial(ArrowShaftMaterial.createMaterial(1, TinkerTools.toolRod, MaterialID.Bone, 0.95f, 1.2f, 0.01f, 0xede6bf)); // bone: heavier, but durable
// Arrow Fletching Materials
TConstructRegistry.addFletchingMaterial(0, 2, new ItemStack(Items.feather), new ItemStack(TinkerWeaponry.fletching, 1, 0), 95F, 0.05F, 1.0f, 0xffffff); // Feather
TConstructRegistry.addCustomMaterial(new FletchlingLeafMaterial(1, 2, "treeLeaves", new ItemStack(TinkerWeaponry.fletching, 1, 1), 75F, 0F, 2.5f)); // all vanilla and oredicted leaves. and all leaves in general.
TConstructRegistry.addFletchingMaterial(2, 2, new ItemStack(TinkerTools.materials, 1, 1), new ItemStack(TinkerWeaponry.fletching, 1, 2), 100F, 0.005F, 0.8f, 0x82c873); // Slime
TConstructRegistry.addFletchingMaterial(3, 2, new ItemStack(TinkerTools.materials, 1, 17), new ItemStack(TinkerWeaponry.fletching, 1, 3), 100F, 0.005F, 0.8f, 0x74c8c7); // BlueSlime
TConstructRegistry.addFletchingMaterial(4, 2, new ItemStack(TinkerWorld.slimeLeaves, 1, 0), new ItemStack(TinkerWeaponry.fletching, 1, 4), 98F, 0.02F, 1.4F, 0x74e8c7); // Slime leaves
// Bowstring Materials
TConstructRegistry.addBowstringMaterial(0, 2, new ItemStack(Items.string), new ItemStack(TinkerWeaponry.bowstring, 1, 0), 1F, 1F, 1f, 0xeeeeee); // String
}
private void addWeaponRecipies()
{
TConstructRegistry.addToolRecipe(shuriken, partShuriken, partShuriken, partShuriken, partShuriken);
TConstructRegistry.addToolRecipe(throwingknife, TinkerTools.knifeBlade, TinkerTools.toolRod);
TConstructRegistry.addToolRecipe(javelin, arrowhead, TinkerTools.toughRod, TinkerTools.toughRod);
TConstructRegistry.addToolRecipe(shortbow, partBowLimb, bowstring, partBowLimb);
TConstructRegistry.addToolRecipe(longbow, partBowLimb, bowstring, partBowLimb, TinkerTools.largePlate);
TConstructRegistry.addToolRecipe(crossbow, partCrossbowLimb, partCrossbowBody, bowstring, TinkerTools.toughBinding);
TConstructRegistry.addToolRecipe(arrowAmmo, arrowhead, partArrowShaft, fletching);
TConstructRegistry.addToolRecipe(boltAmmo, partBolt, partBolt, fletching);
}
private void registerBoltCasting()
{
LiquidCasting tb = TConstructRegistry.getTableCasting();
// any fluid that is a toolpart material can be used
for(Map.Entry<String, FluidType> entry : FluidType.fluidTypes.entrySet()) {
// is tool material?
if(!entry.getValue().isToolpart)
continue;
// get a casting recipe for it D:
FluidStack liquid = new FluidStack(entry.getValue().fluid, TConstruct.ingotLiquidValue);
CastingRecipe recipe = tb.getCastingRecipe(liquid, new ItemStack(TinkerSmeltery.metalPattern, 1, 2)); // pickaxe
// no recipe found
if(recipe == null)
continue;
// material id for the pickaxe head == material id for the fluid! such hack. wow.
int matID = recipe.getResult().getItemDamage();
// register our casting stuff
for(Integer id : TConstructRegistry.toolMaterials.keySet()) {
ItemStack rod = new ItemStack(TinkerTools.toolRod, 1, id);
if(((IToolPart)TinkerTools.toolRod).getMaterialID(rod) == -1)
continue;
tb.addCastingRecipe(DualMaterialToolPart.createDualMaterial(partBolt, id, matID), liquid, rod, true, 150);
}
}
}
private void setupCreativeTab()
{
ItemStack tool = new ItemStack(TinkerWeaponry.longbow, 1, 0);
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("InfiTool", new NBTTagCompound());
compound.getCompoundTag("InfiTool").setInteger("RenderHead", 0);
compound.getCompoundTag("InfiTool").setInteger("RenderHandle", 0);
compound.getCompoundTag("InfiTool").setInteger("RenderAccessory", 0);
compound.getCompoundTag("InfiTool").setInteger("RenderExtra", 1);
tool.setTagCompound(compound);
TConstructRegistry.weaponryTab.init(tool);
}
}