use of net.minecraft.world.damagesource.CombatEntry in project SpongeCommon by SpongePowered.
the class EntityPerformingDropsTransaction method captureState.
@Override
protected void captureState() {
super.captureState();
final Entity entity = this.destroyingEntity;
this.worldSupplier = VolumeStreamUtils.createWeaklyReferencedSupplier((ServerLevel) entity.level, "ServerLevel");
final CompoundTag tag = new CompoundTag();
entity.saveWithoutId(tag);
this.entityTag = tag;
@Nullable final DamageSource lastAttacker;
if (entity instanceof LivingEntity) {
final CombatEntry entry = ((CombatTrackerAccessor) ((LivingEntity) entity).getCombatTracker()).invoker$getMostSignificantFall();
if (entry != null) {
lastAttacker = ((CombatEntryAccessor) entry).accessor$source();
} else {
lastAttacker = null;
}
} else {
lastAttacker = null;
}
final WeakReference<@Nullable DamageSource> ref = new WeakReference<>(lastAttacker);
this.lastAttacker = () -> {
@Nullable final DamageSource damageSource = ref.get();
// Yes, I know, we're effectively
if (damageSource == null) {
return Optional.empty();
}
return Optional.of(damageSource);
};
}
Aggregations