-
Notifications
You must be signed in to change notification settings - Fork 755
/
TActiveOmniMod.java
313 lines (279 loc) · 12.3 KB
/
TActiveOmniMod.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
package tconstruct.tools;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.entity.item.*;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.*;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.tools.*;
import tconstruct.library.weaponry.IAmmo;
import tconstruct.util.config.PHConstruct;
import tconstruct.world.TinkerWorld;
import tconstruct.world.entity.BlueSlime;
public class TActiveOmniMod extends ActiveToolMod
{
Random random = new Random();
/* Updating */
@Override
public void updateTool (ToolCore tool, ItemStack stack, World world, Entity entity)
{
if (!world.isRemote && entity instanceof EntityLivingBase && !((EntityLivingBase) entity).isSwingInProgress && stack.getTagCompound() != null)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey("Moss"))
{
int chance = tags.getInteger("Moss");
int check = world.canBlockSeeTheSky((int) entity.posX, (int) entity.posY, (int) entity.posZ) ? 350 : 1150;
// REGROWING AMMO :OOoo
if(tool instanceof IAmmo && random.nextInt(check*3) < chance) // ammo regenerates at a much slower rate
{
IAmmo ammothing = (IAmmo)tool;
if(ammothing.getAmmoCount(stack) > 0) // must have ammo
ammothing.addAmmo(1, stack);
}
// selfrepairing tool. LAAAAAME
else if (random.nextInt(check) < chance)
{
AbilityHelper.healTool(stack, 1, (EntityLivingBase) entity, true);
}
}
}
}
/* Harvesting */
@Override
public boolean beforeBlockBreak (ToolCore tool, ItemStack stack, int x, int y, int z, EntityLivingBase entity)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
baconator(tool, stack, entity, tags);
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode)
return false;
TinkerTools.modLapis.midStreamModify(stack, tool);
if (autoSmelt(tool, tags, stack, x, y, z, entity))
return true;
return false;
}
@Override
public void afterBlockBreak(ToolCore tool, ItemStack stack, Block block, int x, int y, int z, EntityLivingBase entity) {
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
slimify(tool, tags, block, x,y,z, entity.worldObj);
}
private boolean autoSmelt (ToolCore tool, NBTTagCompound tags, ItemStack stack, int x, int y, int z, EntityLivingBase entity)
{
World world = entity.worldObj;
Block block = world.getBlock(x, y, z);
if (block == null)
return false;
int blockMeta = world.getBlockMetadata(x, y, z);
if(block.getMaterial().isToolNotRequired()) {
// only if effective tool
if(tool instanceof HarvestTool) {
if (!((HarvestTool) tool).isEffective(block, blockMeta))
return false;
}
else
return false;
}
else if(!ForgeHooks.canToolHarvestBlock(block, blockMeta, stack))
return false;
if (tags.getBoolean("Lava") && block.quantityDropped(blockMeta, 0, random) > 0)
{
int itemMeta = block.damageDropped(blockMeta);
int amount = block.quantityDropped(random);
Item item = block.getItemDropped(blockMeta, random, EnchantmentHelper.getFortuneModifier(entity));
// apparently some things that don't drop blocks (like glass panes without silktouch) return null.
if (item == null)
return false;
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(item, amount, itemMeta));
if (result != null)
{
world.setBlockToAir(x, y, z);
if (entity instanceof EntityPlayer && !((EntityPlayer) entity).capabilities.isCreativeMode)
tool.onBlockDestroyed(stack, world, block, x, y, z, entity);
if (!world.isRemote)
{
ItemStack spawnme = new ItemStack(result.getItem(), amount * result.stackSize, result.getItemDamage());
if (result.hasTagCompound())
spawnme.setTagCompound(result.getTagCompound());
if (!(result.getItem() instanceof ItemBlock) && PHConstruct.lavaFortuneInteraction)
{
int loot = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack);
if (loot > 0)
{
spawnme.stackSize *= (random.nextInt(loot + 1) + 1);
}
}
EntityItem entityitem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, spawnme);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (blockMeta << 12));
int i = spawnme.stackSize;
float f = FurnaceRecipes.smelting().func_151398_b(spawnme);
int j;
if (f == 0.0F)
{
i = 0;
}
else if (f < 1.0F)
{
j = MathHelper.floor_float((float) i * f);
if (j < MathHelper.ceiling_float_int((float) i * f) && (float) Math.random() < (float) i * f - (float) j)
{
++j;
}
i = j;
}
while (i > 0)
{
j = EntityXPOrb.getXPSplit(i);
i -= j;
entity.worldObj.spawnEntityInWorld(new EntityXPOrb(world, x, y + 0.5, z, j));
}
}
for (int i = 0; i < 5; i++)
{
float f = (float) x + random.nextFloat();
float f1 = (float) y + random.nextFloat();
float f2 = (float) z + random.nextFloat();
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
}
return true;
}
}
return false;
}
/* Attacking */
@Override
public int baseAttackDamage (int earlyModDamage, int damage, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
TinkerTools.modLapis.midStreamModify(stack, tool);
baconator(tool, stack, player, tags);
return 0;
}
private void baconator (ToolCore tool, ItemStack stack, EntityLivingBase entity, NBTTagCompound tags)
{
final int pigiron = TinkerTools.MaterialID.PigIron;
int bacon = 0;
bacon += tags.getInteger("Head") == pigiron ? 1 : 0;
bacon += tags.getInteger("Handle") == pigiron ? 1 : 0;
bacon += tags.getInteger("Accessory") == pigiron ? 1 : 0;
bacon += tags.getInteger("Extra") == pigiron ? 1 : 0;
int chance = tool.getPartAmount() * 100;
if (random.nextInt(chance) < bacon)
{
if (entity instanceof EntityPlayer)
AbilityHelper.spawnItemAtPlayer((EntityPlayer) entity, new ItemStack(TinkerWorld.strangeFood, 1, 2));
else
AbilityHelper.spawnItemAtEntity(entity, new ItemStack(TinkerWorld.strangeFood, 1, 2), 0);
}
}
private void slimify(ToolCore tool, NBTTagCompound tags, Block block, int x, int y, int z, World world)
{
if (world.isRemote)
return;
int chance = tool.getPartAmount() * 100;
int count = 0;
int slimeMat = TinkerTools.MaterialID.Slime;
// regular slime
if(tags.getInteger("Head") == slimeMat)
count++;
if(tags.getInteger("Handle") == slimeMat)
count++;
if(tags.getInteger("Accessory") == slimeMat)
count++;
if(tags.getInteger("Extra") == slimeMat)
count++;
if(random.nextInt(chance) < count) {
EntitySlime entity = new EntitySlime(world);
entity.setPosition(x+0.5,y,z+0.5);
entity.setSlimeSize(1); // minislime!
world.spawnEntityInWorld(entity);
entity.playLivingSound();
}
// blueslime
slimeMat = TinkerTools.MaterialID.BlueSlime;
count = 0;
if(tags.getInteger("Head") == slimeMat)
count++;
if(tags.getInteger("Handle") == slimeMat)
count++;
if(tags.getInteger("Accessory") == slimeMat)
count++;
if(tags.getInteger("Extra") == slimeMat)
count++;
if(random.nextInt(chance) < count) {
BlueSlime entity = new BlueSlime(world);
entity.setPosition(x+0.5,y,z+0.5);
entity.setSlimeSize(1); // minislime!
world.spawnEntityInWorld(entity);
entity.playLivingSound();
}
}
@Override
public int attackDamage (int modDamage, int currentDamage, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
int bonus = modDamage;
if (entity instanceof EntityLivingBase)
{
EnumCreatureAttribute attribute = ((EntityLivingBase) entity).getCreatureAttribute();
if (attribute == EnumCreatureAttribute.UNDEAD)
{
if (tool == TinkerTools.hammer)
{
int level = 2;
bonus += random.nextInt(level * 2 + 1) + level * 2;
}
if (toolTags.hasKey("ModSmite"))
{
int[] array = toolTags.getIntArray("ModSmite");
int base = array[0] / 18;
bonus += 1 + base + random.nextInt(base + 1);
}
}
if (attribute == EnumCreatureAttribute.ARTHROPOD)
{
if (toolTags.hasKey("ModAntiSpider"))
{
int[] array = toolTags.getIntArray("ModAntiSpider");
int base = array[0] / 2;
bonus += 1 + base + random.nextInt(base + 1);
}
}
}
return bonus;
}
@Override
public float knockback (float modKnockback, float currentKnockback, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
float bonus = modKnockback;
if (toolTags.hasKey("Knockback"))
{
float level = toolTags.getFloat("Knockback");
bonus += level;
}
return bonus;
}
@Override
public boolean doesCriticalHit (ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
if (tool == TinkerTools.cutlass && random.nextInt(10) == 0)
return true;
return false;
}
}