-
Notifications
You must be signed in to change notification settings - Fork 38
/
ArrowFireEntity.java
74 lines (64 loc) · 2.97 KB
/
ArrowFireEntity.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
package com.teammetallurgy.atum.entity.projectile.arrow;
import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.init.AtumEntities;
import com.teammetallurgy.atum.init.AtumParticles;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import javax.annotation.Nonnull;
public class ArrowFireEntity extends CustomArrow {
public ArrowFireEntity(EntityType<? extends ArrowFireEntity> entityType, Level level) {
super(entityType, level);
}
public ArrowFireEntity(Level level, LivingEntity shooter) {
super(AtumEntities.FIRE_ARROW.get(), level, shooter);
}
@Override
protected void onHitEntity(@Nonnull EntityHitResult rayTraceResult) {
super.onHitEntity(rayTraceResult);
Entity hitEntity = rayTraceResult.getEntity();
if (hitEntity instanceof LivingEntity) {
if (!hitEntity.fireImmune()) {
if (hitEntity.getRemainingFireTicks() > 0) { //Extra damage, if target is already on fire
this.setBaseDamage(this.getBaseDamage() * 1.5D);
this.playSound(SoundEvents.FIRECHARGE_USE, 1.0F, 1.0F);
}
hitEntity.setSecondsOnFire(5);
}
}
}
@Override
protected void onHitBlock(@Nonnull BlockHitResult rayTraceResult) {
super.onHitBlock(rayTraceResult);
Entity shooter = this.getOwner();
if (shooter instanceof Player) {
BlockPos pos = rayTraceResult.getBlockPos().relative(rayTraceResult.getDirection());
Player player = (Player) shooter;
if (player.mayUseItemAt(pos, rayTraceResult.getDirection(), player.getItemInHand(player.getUsedItemHand())) && this.level().getBlockState(pos).isAir()) {
this.level().setBlockAndUpdate(pos, Blocks.FIRE.defaultBlockState());
}
}
}
@Override
public void tick() {
super.tick();
if (this.isCritArrow()) {
if (this.level() instanceof ServerLevel serverLevel) {
serverLevel.sendParticles(AtumParticles.RA_FIRE.get(), this.getX() + (this.level().random.nextDouble() - 0.5D) * (double) this.getBbWidth(), this.getY() + this.level().random.nextDouble() * (double) this.getBbHeight(), this.getZ() + (this.level().random.nextDouble() - 0.5D) * (double) this.getBbWidth(), 2, 0.0D, 0.0D, 0.0D, 0.01D);
}
}
}
@Override
public ResourceLocation getTexture() {
return new ResourceLocation(Atum.MOD_ID, "textures/arrow/arrow_fire.png");
}
}