SimpleExplosionDamageCalculator .java

net.minecraft.world.level.SimpleExplosionDamageCalculator (class, 54 lines): members: damagesEntities, explodesBlocks, getKnockbackMultiplier, block.

net.minecraft.world.levelclass54 linescommonextends ExplosionDamageCalculator2.0 KB

API Surface (4)

Optional<Float> getBlockExplosionResistance(final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState block, final FluidState fluid)
boolean shouldBlockExplode(final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState state, final float power)
boolean shouldDamageEntity(final Explosion explosion, final Entity entity)
float getKnockbackMultiplier(final Entity entity)

Fields & Constants (5)

explodesBlocks
damagesEntities
knockbackMultiplier
immuneBlocks
block

Full Source

SimpleExplosionDamageCalculator.java54 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level;
2
3
import java.util.Optional;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.HolderSet;
6
import net.minecraft.world.entity.Entity;
7
import net.minecraft.world.entity.player.Player;
8
import net.minecraft.world.level.block.Block;
9
import net.minecraft.world.level.block.state.BlockState;
10
import net.minecraft.world.level.material.FluidState;
11
12
public class SimpleExplosionDamageCalculator extends ExplosionDamageCalculator {
13
	private final boolean explodesBlocks;
14
	private final boolean damagesEntities;
15
	private final Optional<Float> knockbackMultiplier;
16
	private final Optional<HolderSet<Block>> immuneBlocks;
17
18
	public SimpleExplosionDamageCalculator(
19
		final boolean explodesBlocks, final boolean damagesEntities, final Optional<Float> knockbackMultiplier, final Optional<HolderSet<Block>> immuneBlocks
20
	) {
21
		this.explodesBlocks = explodesBlocks;
22
		this.damagesEntities = damagesEntities;
23
		this.knockbackMultiplier = knockbackMultiplier;
24
		this.immuneBlocks = immuneBlocks;
25
	}
26
27
	@Override
28
	public Optional<Float> getBlockExplosionResistance(
29
		final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState block, final FluidState fluid
30
	) {
31
		if (this.immuneBlocks.isPresent()) {
32
			return block.is(this.immuneBlocks.get()) ? Optional.of(3600000.0F) : Optional.empty();
33
		} else {
34
			return super.getBlockExplosionResistance(explosion, level, pos, block, fluid);
35
		}
36
	}
37
38
	@Override
39
	public boolean shouldBlockExplode(final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState state, final float power) {
40
		return this.explodesBlocks;
41
	}
42
43
	@Override
44
	public boolean shouldDamageEntity(final Explosion explosion, final Entity entity) {
45
		return this.damagesEntities;
46
	}
47
48
	@Override
49
	public float getKnockbackMultiplier(final Entity entity) {
50
		boolean creativeFlying = entity instanceof Player player && player.getAbilities().flying;
51
		return creativeFlying ? 0.0F : this.knockbackMultiplier.orElseGet(() -> super.getKnockbackMultiplier(entity));
52
	}
53
}
54

Decompiled Minecraft 26.3 source of SimpleExplosionDamageCalculator (net/minecraft/world/level/SimpleExplosionDamageCalculator.java) with Mojang official mappings, stored verbatim on the site.