| 1 | package net.minecraft.world.level;
|
| 2 |
|
| 3 | import net.minecraft.server.level.ServerLevel;
|
| 4 | import net.minecraft.world.damagesource.DamageSource;
|
| 5 | import net.minecraft.world.entity.Entity;
|
| 6 | import net.minecraft.world.entity.LivingEntity;
|
| 7 | import net.minecraft.world.entity.item.PrimedTnt;
|
| 8 | import net.minecraft.world.entity.projectile.Projectile;
|
| 9 | import net.minecraft.world.phys.Vec3;
|
| 10 | import org.jspecify.annotations.Nullable;
|
| 11 |
|
| 12 | public interface Explosion {
|
| 13 | static DamageSource getDefaultDamageSource(final Level level, final @Nullable Entity source) {
|
| 14 | return level.damageSources().explosion(source, getIndirectSourceEntity(source));
|
| 15 | }
|
| 16 |
|
| 17 | static @Nullable LivingEntity getIndirectSourceEntity(final @Nullable Entity source) {
|
| 18 | return switch (source) {
|
| 19 | case PrimedTnt primedTnt -> primedTnt.getOwner();
|
| 20 | case LivingEntity livingEntity -> livingEntity;
|
| 21 | case Projectile projectile when projectile.getOwner() instanceof LivingEntity livingEntity -> livingEntity;
|
| 22 | case null, default -> null;
|
| 23 | };
|
| 24 | }
|
| 25 |
|
| 26 | ServerLevel level();
|
| 27 |
|
| 28 | Explosion.BlockInteraction getBlockInteraction();
|
| 29 |
|
| 30 | @Nullable LivingEntity getIndirectSourceEntity();
|
| 31 |
|
| 32 | @Nullable Entity getDirectSourceEntity();
|
| 33 |
|
| 34 | float radius();
|
| 35 |
|
| 36 | Vec3 center();
|
| 37 |
|
| 38 | boolean canTriggerBlocks();
|
| 39 |
|
| 40 | boolean shouldAffectBlocklikeEntities();
|
| 41 |
|
| 42 | enum BlockInteraction {
|
| 43 | KEEP(false),
|
| 44 | DESTROY(true),
|
| 45 | DESTROY_WITH_DECAY(true),
|
| 46 | TRIGGER_BLOCK(false);
|
| 47 |
|
| 48 | private final boolean shouldAffectBlocklikeEntities;
|
| 49 |
|
| 50 | BlockInteraction(final boolean shouldAffectBlocklikeEntities) {
|
| 51 | this.shouldAffectBlocklikeEntities = shouldAffectBlocklikeEntities;
|
| 52 | }
|
| 53 |
|
| 54 | public boolean shouldAffectBlocklikeEntities() {
|
| 55 | return this.shouldAffectBlocklikeEntities;
|
| 56 | }
|
| 57 | }
|
| 58 | }
|
| 59 |
|