64 lines
1.8 KiB
Java
64 lines
1.8 KiB
Java
package net.minecraft.world.level;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.item.PrimedTnt;
|
|
import net.minecraft.world.entity.projectile.Projectile;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public interface Explosion {
|
|
static DamageSource getDefaultDamageSource(Level level, @Nullable Entity source) {
|
|
return level.damageSources().explosion(source, getIndirectSourceEntity(source));
|
|
}
|
|
|
|
@Nullable
|
|
static LivingEntity getIndirectSourceEntity(@Nullable Entity source) {
|
|
return switch (source) {
|
|
case PrimedTnt primedTnt -> primedTnt.getOwner();
|
|
case LivingEntity livingEntity -> livingEntity;
|
|
case Projectile projectile when projectile.getOwner() instanceof LivingEntity livingEntity2 -> livingEntity2;
|
|
case null, default -> null;
|
|
};
|
|
}
|
|
|
|
ServerLevel level();
|
|
|
|
Explosion.BlockInteraction getBlockInteraction();
|
|
|
|
@Nullable
|
|
LivingEntity getIndirectSourceEntity();
|
|
|
|
/**
|
|
* Returns either the entity that placed the explosive block, the entity that caused the explosion or null.
|
|
*/
|
|
@Nullable
|
|
Entity getDirectSourceEntity();
|
|
|
|
float radius();
|
|
|
|
Vec3 center();
|
|
|
|
boolean canTriggerBlocks();
|
|
|
|
boolean shouldAffectBlocklikeEntities();
|
|
|
|
public static enum BlockInteraction {
|
|
KEEP(false),
|
|
DESTROY(true),
|
|
DESTROY_WITH_DECAY(true),
|
|
TRIGGER_BLOCK(false);
|
|
|
|
private final boolean shouldAffectBlocklikeEntities;
|
|
|
|
private BlockInteraction(final boolean shouldAffectBlocklikeEntities) {
|
|
this.shouldAffectBlocklikeEntities = shouldAffectBlocklikeEntities;
|
|
}
|
|
|
|
public boolean shouldAffectBlocklikeEntities() {
|
|
return this.shouldAffectBlocklikeEntities;
|
|
}
|
|
}
|
|
}
|