summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java
blob: 5235b7d72b3f4d10dd0ed89696e7c2e6ff024941 (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
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
package darkknight.jewelrycraft.effects;

import java.util.Iterator;
import java.util.List;

import darkknight.jewelrycraft.api.ModifierEffects;
import darkknight.jewelrycraft.damage.DamageSourceList;
import darkknight.jewelrycraft.item.ItemBracelet;
import darkknight.jewelrycraft.item.ItemEarrings;
import darkknight.jewelrycraft.item.ItemNecklace;
import darkknight.jewelrycraft.item.ItemRing;
import darkknight.jewelrycraft.potions.PotionList;
import darkknight.jewelrycraft.util.JewelryNBT;
import darkknight.jewelrycraft.util.Variables;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;

public class EffectFeather extends ModifierEffects {
	public EffectFeather() {
		super(new ItemStack(Items.feather));
	}

	@Override
	public void action(ItemStack item, EntityPlayer player,
			Item jewelry) {
		// Positive earrings
		if (jewelry instanceof ItemEarrings) {
			AxisAlignedBB axisalignedbb = player.boundingBox
					.expand(1.0D, 1.0D, 1.0D);
			List<?> list = player.worldObj
					.getEntitiesWithinAABB(
							EntityArrow.class,
							axisalignedbb);
			if (!player.worldObj.isRemote && list != null
					&& !list.isEmpty()) {
				Iterator<?> iterator = list.iterator();
				while (iterator.hasNext()) {
					EntityArrow arrow = (EntityArrow) iterator
							.next();
					if ((arrow.shootingEntity == null
							|| !(arrow.shootingEntity
									.equals(player))
							|| arrow.canBePickedUp == 0)
							&& rand.nextInt(2
									+ JewelryNBT.numberOfModifiers(
											item)) == 0)
						arrow.setDead();
				}
			}
		}
		if (jewelry instanceof ItemBracelet) {
			// Positive bracelet
			if (player.motionY < 0)
				player.motionY *= (0.6D + (JewelryNBT
						.numberOfModifiers(item)
						- 1) * 0.03D);
			if (rand.nextInt(JewelryNBT
					.numberOfModifiers(item)) == 0)
				player.fallDistance = 0F;
			// Negative bracelet
			if (!player.isPotionActive(Potion.moveSlowdown)
					|| player.getActivePotionEffect(
							Potion.moveSlowdown)
							.getDuration() < 30)
				player.addPotionEffect(new PotionEffect(
						Potion.moveSlowdown.id,
						80 + JewelryNBT.numberOfModifiers(
								item) * 10,
						1 + JewelryNBT.numberOfModifiers(
								item)
								/ 4));
		}
	}

	@Override
	public boolean onEntityAttackedCancellable(ItemStack item,
			EntityPlayer player, Entity target, Item jewelry,
			float amount) {
		NBTTagCompound enemyData = target.getEntityData();
		if (jewelry instanceof ItemRing
				&& !player.worldObj.isRemote) {
			if (enemyData.getInteger("reAttacked") == 0) {
				// Negative ring
				enemyData.setInteger("reAttacked",
						enemyData.getInteger(
								"reAttacked")
								+ 1);
				target.attackEntityFrom(DamageSource
						.causePlayerDamage(player),
						amount / (2F + (JewelryNBT
								.numberOfModifiers(
										item)
								- 1)
								* 0.3F));
				// Positive ring
				if (rand.nextInt(2) == 0
						&& target instanceof EntityLivingBase)
					((EntityLivingBase) target)
							.addPotionEffect(
									new PotionEffect(
											PotionList.stun.id,
											(51 - JewelryNBT.numberOfModifiers(
													item))
													* 2,
											0,
											false));
				return true;
			}
			enemyData.setInteger("reAttacked", 0);
		}
		return false;
	}

	@Override
	public boolean onPlayerAttackedCancellable(ItemStack item,
			EntityPlayer player, DamageSource source,
			Item jewelry, float amount) {
		// Positive necklace
		if (jewelry instanceof ItemNecklace && rand.nextInt(3
				+ JewelryNBT.numberOfModifiers(item)) == 0
				&& source != DamageSourceList.weak
				&& source != DamageSource.inFire
				&& source != DamageSource.onFire
				&& source != DamageSource.lava) {
			player.addChatComponentMessage(
					new ChatComponentText(
							EnumChatFormatting.GRAY
									+ StatCollector.translateToLocal(
											"chatmessage." + Variables.MODID
													+ ".effect.feather")));
			return true;
		}
		// Negative necklace
		if (jewelry instanceof ItemNecklace
				&& (source == DamageSource.inFire
						|| source == DamageSource.onFire
						|| source == DamageSource.lava)
				&& source != DamageSourceList.weak)
			player.attackEntityFrom(DamageSourceList.weak,
					amount * (3F + (JewelryNBT
							.numberOfModifiers(
									item)
							- 1) * 0.1F));
		// Negative earrings
		if (jewelry instanceof ItemEarrings
				&& source.damageType.equals("arrow"))
			player.attackEntityFrom(DamageSourceList.weak,
					amount * (2F + (JewelryNBT
							.numberOfModifiers(
									item)
							- 1) * 0.1F));
		return false;
	}
}