-
Notifications
You must be signed in to change notification settings - Fork 16
/
AbstractRangedAttack.java
83 lines (69 loc) · 2.77 KB
/
AbstractRangedAttack.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
package mod.azure.doom.entity.attack;
import mod.azure.doom.entity.DemonEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public abstract class AbstractRangedAttack implements IRangedAttack {
public DemonEntity parentEntity;
public double xOffSetModifier = 2;
public double entityHeightFraction = 0.5;
public double zOffSetModifier = 2;
public float damage = 1;
public double accuracy = 0.95;
public AbstractRangedAttack(DemonEntity parentEntity) {
this.parentEntity = parentEntity;
}
public AbstractRangedAttack(DemonEntity parentEntity, double xOffSetModifier, double entityHeightFraction,
double zOffSetModifier, float damage) {
this.parentEntity = parentEntity;
this.xOffSetModifier = xOffSetModifier;
this.entityHeightFraction = entityHeightFraction;
this.zOffSetModifier = zOffSetModifier;
this.damage = damage;
}
public AbstractRangedAttack setProjectileOriginOffset(double x, double entityHeightFraction, double z) {
xOffSetModifier = x;
this.entityHeightFraction = entityHeightFraction;
zOffSetModifier = z;
return this;
}
public AbstractRangedAttack setDamage(float damage) {
this.damage = damage;
return this;
}
private AttackSound sound;
public AbstractRangedAttack setSound(AttackSound sound) {
this.sound = sound;
return this;
}
public AbstractRangedAttack setSound(SoundEvent sound, float volume, float pitch) {
this.sound = new AttackSound(sound, volume, pitch);
return this;
}
public AbstractRangedAttack setAccuracy(double accuracy) {
this.accuracy = accuracy;
return this;
}
public double rollAccuracy(double directional) {
return directional + (1.0D - accuracy) * directional * this.parentEntity.getRandom().nextGaussian();
}
public void shoot() {
LivingEntity livingentity = this.parentEntity.getTarget();
World world = this.parentEntity.getEntityWorld();
Vec3d vector3d = this.parentEntity.getRotationVec(1.0F);
double d2 = livingentity.getX() - (this.parentEntity.getX() + vector3d.x * xOffSetModifier);
double d3 = livingentity.getBodyY(0.5D) - (this.parentEntity.getBodyY(entityHeightFraction));
double d4 = livingentity.getZ() - (this.parentEntity.getZ() + vector3d.z * zOffSetModifier);
ProjectileEntity projectile = getProjectile(world, rollAccuracy(d2), rollAccuracy(d3), rollAccuracy(d4));
projectile.updatePosition(this.parentEntity.getX() + vector3d.x * xOffSetModifier,
this.parentEntity.getBodyY(entityHeightFraction),
this.parentEntity.getZ() + vector3d.z * zOffSetModifier);
world.spawnEntity(projectile);
if (sound == null)
getDefaultAttackSound().play(this.parentEntity);
else
sound.play(this.parentEntity);
}
}