- 1,383
- 115
- 244
Здравствуйте!
Столкнулся с совсем странной, на мой взгляд, проблемой: по какой-то причине spell в projectile становится null.
Код прилагаю:
Может мне кто-нибудь, пожалуйста, объяснить в чём дело? Буду очень благодарен.
Столкнулся с совсем странной, на мой взгляд, проблемой: по какой-то причине spell в projectile становится null.
Код прилагаю:
Java:
public abstract class SpellEntity extends AbstractHurtingProjectile {
private final Spell spell;
public SpellEntity(EntityType<? extends SpellEntity> type, Level level) {
super(type, level);
this.spell = null; //Этот конструктор вызывается только в регистрации EntityType.
}
public SpellEntity(EntityType<? extends SpellBallEntity> type, LivingEntity entity, Spell spell) {
super(type, entity, getSpellVec(entity).x, getSpellVec(entity).y, getSpellVec(entity).z, entity.level());
this.spell = spell;
//Здесь дебаггер показываёт, что со spell всё норм
}
@Override
protected void onHitEntity(EntityHitResult result) {
if(spell != null) {
//... куча кода
}
super.onHitEntity(result);
}
@Override
protected void onHitBlock(BlockHitResult result) {
if(spell != null) { //Здесь дебаггер показывает, что spell == null
//... куча кода
}
super.onHitBlock(result);
}
static Vec3 getSpellVec(LivingEntity entity) {
return new Vec3(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z);
}
Может мне кто-нибудь, пожалуйста, объяснить в чём дело? Буду очень благодарен.