-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
ThrownNitraEntity.java
77 lines (67 loc) · 2.91 KB
/
ThrownNitraEntity.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
package net.id.paradiselost.entities.projectile;
import net.id.paradiselost.ParadiseLost;
import net.id.paradiselost.entities.ParadiseLostEntityTypes;
import net.id.paradiselost.items.ParadiseLostItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.BlazeEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.thrown.SnowballEntity;
import net.minecraft.entity.projectile.thrown.ThrownEntity;
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
import net.minecraft.item.Item;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
public class ThrownNitraEntity extends ThrownItemEntity {
public ThrownNitraEntity(EntityType<? extends ThrownNitraEntity> entityType, World world) {
super(entityType, world);
}
public ThrownNitraEntity(World world, LivingEntity owner) {
super(ParadiseLostEntityTypes.THROWN_NITRA, owner, world);
}
protected void onEntityHit(EntityHitResult entityHitResult) {
super.onEntityHit(entityHitResult);
doDamage();
}
protected void onCollision(HitResult hitResult) {
super.onCollision(hitResult);
doDamage();
if (!this.world.isClient) {
this.world.sendEntityStatus(this, (byte)3);
this.discard();
}
}
public void handleStatus(byte status) {
if (status == 3) {
for (int i = 0; i < 4; i++) {
this.world.addParticle(ParticleTypes.EXPLOSION,
this.getX() + this.random.nextDouble() - 0.5, this.getY() + this.random.nextDouble() - 0.5, this.getZ() + this.random.nextDouble() - 0.5,
0.0, 0.0, 0.0
);
}
this.world.playSound(this.getX(), this.getY(), this.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.NEUTRAL, 1.0F, 1.1F + this.random.nextFloat() * 0.4F, false);
}
}
private void doDamage() {
var hit = this.world.getOtherEntities(this, new Box(this.getX()-1.5, this.getY()-1.5, this.getZ()-1.5, this.getX()+1.5, this.getY()+1.5, this.getZ()+1.5));
for (Entity e : hit) {
Vec3d diff = this.getPos().subtract(e.getPos()).negate().normalize();
e.addVelocity(diff.x, diff.y, diff.z);
e.damage(DamageSource.explosion((LivingEntity) null), 2);
}
}
@Override
protected Item getDefaultItem() {
return ParadiseLostItems.NITRA_BULB;
}
}