/
EntityMyRock.java
103 lines (88 loc) · 3.66 KB
/
EntityMyRock.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
package net.wildbill22.draco.entities;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.wildbill22.draco.items.ItemMyRock;
import net.wildbill22.draco.items.ModItems;
public class EntityMyRock extends EntityThrowable {
public Entity shootingEntity;
/** 1 if the player can pick up the rock */
public int canBePickedUp;
public EntityMyRock(World world, double p_i1778_2_, double p_i1778_4_, double p_i1778_6_) {
super(world, p_i1778_2_, p_i1778_4_, p_i1778_6_);
}
public EntityMyRock(World par1World, EntityLivingBase par2EntityLivingBase) {
super(par1World, par2EntityLivingBase);
}
public EntityMyRock(World par1World) {
super(par1World);
}
// Added for attack from EntityAISpearAttack
public EntityMyRock(World world, EntityLivingBase attacker, EntityLivingBase target, float p_i1755_4_, float p_i1755_5_)
{
super(world);
this.renderDistanceWeight = 10.0D;
this.shootingEntity = attacker;
if (attacker instanceof EntityPlayer) {
this.canBePickedUp = 1;
}
this.posY = attacker.posY + (double)attacker.getEyeHeight() - 0.10000000149011612D;
double d0 = target.posX - attacker.posX;
double d1 = target.boundingBox.minY + (double)(target.height / 3.0F) - this.posY;
double d2 = target.posZ - attacker.posZ;
double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
if (d3 >= 1.0E-7D)
{
float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI));
double d4 = d0 / d3;
double d5 = d2 / d3;
this.setLocationAndAngles(attacker.posX + d4, this.posY, attacker.posZ + d5, f2, f3);
this.yOffset = 0.0F;
float f4 = (float)d3 * 0.2F;
this.setThrowableHeading(d0, d1 + (double)f4, d2, p_i1755_4_, p_i1755_5_);
}
}
@Override
protected void onImpact(MovingObjectPosition movObjPos) {
// if (!this.worldObj.isRemote)
// LogHelper.info("EntityRock landed!");
if (movObjPos != null) {
if (movObjPos.entityHit instanceof Entity) {
movObjPos.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float) ItemMyRock.rockDamage);
}
else {
// Do something for instance if it hits a tree
}
}
for (int i = 0; i < 4; ++i) {
this.worldObj.spawnParticle("crit", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
// Get rid of the used rock
if (!this.worldObj.isRemote)
this.setDead();
}
/**
* Called by a player entity when they collide with an entity
*/
public void onCollideWithPlayer(EntityPlayer player) {
// if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0)
if (!this.worldObj.isRemote && this.inGround) {
boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && player.capabilities.isCreativeMode;
if (this.canBePickedUp == 1 && !player.inventory.addItemStackToInventory(new ItemStack(ModItems.spear, 1))) {
flag = false;
}
if (flag) {
this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.onItemPickup(this, 1);
this.setDead();
}
}
}
}