summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java
blob: ebfa48c58ec9977722bacda32e6773c63e19cef0 (plain)
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
package darkknight.jewelrycraft.effects;

import darkknight.jewelrycraft.api.ModifierEffects;
import darkknight.jewelrycraft.item.ItemBracelet;
import darkknight.jewelrycraft.item.ItemEarrings;
import darkknight.jewelrycraft.item.ItemNecklace;
import darkknight.jewelrycraft.item.ItemRing;
import darkknight.jewelrycraft.util.JewelryNBT;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;

public class EffectBlazePowder extends ModifierEffects {
	public EffectBlazePowder() {
		super(new ItemStack(Items.blaze_powder));
	}

	@Override
	public void action(ItemStack item, EntityPlayer player,
			Item jewelry) {
		if (jewelry instanceof ItemNecklace) {
			// Positive for necklace
			if (player.isBurning() && rand.nextInt(JewelryNBT
					.numberOfModifiers(item)) == 0)
				player.extinguish();
			// Negative for necklace
			if (player.isInWater())
				player.attackEntityFrom(DamageSource.drown,
						1f + (JewelryNBT.numberOfModifiers(
								item) - 1)
								* 0.1F);
		}
		// Negative for bracelet
		if (jewelry instanceof ItemBracelet
				&& player.isInWater()) {
			double slowAmount = 0.6D + (JewelryNBT
					.numberOfModifiers(item) - 1)
					* 0.05D;
			player.motionX *= slowAmount;
			player.motionY *= slowAmount;
			player.motionZ *= slowAmount;
			player.motionY -= (0.02D + (JewelryNBT
					.numberOfModifiers(item) - 1)
					* 0.005D);
			if (player.isCollidedHorizontally)
				player.motionY = 0.30000001192092896D;
		}
		// Negative for earrings
		if (jewelry instanceof ItemEarrings) {
			if (player.getAir() >= 300)
				player.setAir(player.getAir() / 2);
			else
				player.setAir(player.getAir() - JewelryNBT
						.numberOfModifiers(item));
		}
	}

	@Override
	public boolean onEntityAttackedCancellable(ItemStack item,
			EntityPlayer player, Entity target, Item jewelry,
			float amount) {
		// Balanced for ring
		if (jewelry instanceof ItemRing && !player.isInWater()
				&& rand.nextInt(JewelryNBT
						.numberOfModifiers(
								item)) == 0)
			target.setFire(2);
		return false;
	}

	@Override
	public boolean onPlayerAttackedCancellable(ItemStack item,
			EntityPlayer player, DamageSource source,
			Item jewelry, float amount) {
		if (jewelry instanceof ItemEarrings && rand.nextInt(4) == 0
				&& source == DamageSource.lava
				|| source == DamageSource.inFire
				|| source == DamageSource.onFire) {
			// Positive for earrings
			int stackSize = JewelryNBT.modifierSize(item,
					modifier);

			player.heal(stackSize * 0.05F - (JewelryNBT
					.numberOfModifiers(item) - 1)
					* 0.01F);

			return true;
		}
		// Positive for bracelet
		if (jewelry instanceof ItemBracelet)
			if (source == DamageSource.inFire
					|| source == DamageSource.onFire
					|| source == DamageSource.lava
							&& player.worldObj
									.isMaterialInBB(AxisAlignedBB
											.getBoundingBox(player.boundingBox.minX,
													player.boundingBox.minY,
													player.boundingBox.minZ,
													player.boundingBox.maxX,
													player.boundingBox.maxY
															- 0.7,
													player.boundingBox.maxZ),
											Material.lava)
							&& !player.worldObj
									.isMaterialInBB(AxisAlignedBB
											.getBoundingBox(player.boundingBox.minX,
													player.boundingBox.minY
															+ 0.9,
													player.boundingBox.minZ,
													player.boundingBox.maxX,
													player.boundingBox.maxY,
													player.boundingBox.maxZ),
											Material.lava)) {
				return true;
			}

		return false;
	}
}