63 lines
2.3 KiB
Java
63 lines
2.3 KiB
Java
package com.jenny.enhancedexplosives.entities.tnt;
|
|
|
|
import com.jenny.enhancedexplosives.blocks.blocks;
|
|
import com.jenny.enhancedexplosives.entities.entities;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Explosion;
|
|
import net.minecraft.world.level.ExplosionDamageCalculator;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.Objects;
|
|
|
|
public class bedrockPrimedTNT extends basePrimedTNT {
|
|
static class noExplosionCalculator extends ExplosionDamageCalculator {
|
|
public boolean shouldBlockExplode(@NotNull Explosion pExplosion, @NotNull BlockGetter pReader, @NotNull BlockPos pPos, @NotNull BlockState pState, float pPower) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bedrockPrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
|
|
super(entities.TNT_BEDROCK.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
|
|
}
|
|
|
|
public bedrockPrimedTNT(EntityType<bedrockPrimedTNT> entityType, Level level) {
|
|
super(entityType, level);
|
|
}
|
|
@Override
|
|
protected void explode() {
|
|
noExplosionCalculator dmgCalc = new noExplosionCalculator();
|
|
this.level().explode(this, DamageSource.explosion(getOwner()), dmgCalc, getX(), getY(), getZ(), getPower(), false, Explosion.BlockInteraction.BREAK);
|
|
explodeBelow();
|
|
}
|
|
|
|
public BlockPos getBlockBelow() {
|
|
return new BlockPos((int) Math.floor(getX()), (int) Math.floor(getY()) - 1, (int) Math.floor(getZ()));
|
|
}
|
|
|
|
public String getBlock() {
|
|
return level().getBlockState(getBlockBelow()).getBlock().toString();
|
|
}
|
|
|
|
private void explodeBelow()
|
|
{
|
|
if (Objects.equals(getBlock(), Blocks.BEDROCK.toString())) {
|
|
level().destroyBlock(getBlockBelow(), false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Block renderBlock() {
|
|
return blocks.TNT_BEDROCK.get();
|
|
}
|
|
}
|