minecraft-src/net/minecraft/world/entity/projectile/SpectralArrow.java
2025-07-04 03:45:38 +03:00

61 lines
2 KiB
Java

package net.minecraft.world.entity.projectile;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
public class SpectralArrow extends AbstractArrow {
private static final int DEFAULT_DURATION = 200;
private int duration = 200;
public SpectralArrow(EntityType<? extends SpectralArrow> entityType, Level level) {
super(entityType, level);
}
public SpectralArrow(Level level, LivingEntity owner, ItemStack pickupItemStack, @Nullable ItemStack firedFromWeapon) {
super(EntityType.SPECTRAL_ARROW, owner, level, pickupItemStack, firedFromWeapon);
}
public SpectralArrow(Level level, double x, double y, double z, ItemStack pickupItemStack, @Nullable ItemStack firedFromWeapon) {
super(EntityType.SPECTRAL_ARROW, x, y, z, level, pickupItemStack, firedFromWeapon);
}
@Override
public void tick() {
super.tick();
if (this.level().isClientSide && !this.isInGround()) {
this.level().addParticle(ParticleTypes.INSTANT_EFFECT, this.getX(), this.getY(), this.getZ(), 0.0, 0.0, 0.0);
}
}
@Override
protected void doPostHurtEffects(LivingEntity target) {
super.doPostHurtEffects(target);
MobEffectInstance mobEffectInstance = new MobEffectInstance(MobEffects.GLOWING, this.duration, 0);
target.addEffect(mobEffectInstance, this.getEffectSource());
}
@Override
public void readAdditionalSaveData(CompoundTag tag) {
super.readAdditionalSaveData(tag);
this.duration = tag.getIntOr("Duration", 200);
}
@Override
public void addAdditionalSaveData(CompoundTag tag) {
super.addAdditionalSaveData(tag);
tag.putInt("Duration", this.duration);
}
@Override
protected ItemStack getDefaultPickupItem() {
return new ItemStack(Items.SPECTRAL_ARROW);
}
}