generated from MrSphay/codex-agent-repository-kit
40 lines
1.6 KiB
Java
40 lines
1.6 KiB
Java
package com.vinlanx.explosionoverhaul;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class DripstoneEffects {
|
|
public static void handleDripstoneFall(ServerLevel level, BlockPos center, int explosionPower, RandomSource random) {
|
|
if (!((Boolean)Config.COMMON.enableDripstoneFalling.get()).booleanValue()) {
|
|
return;
|
|
}
|
|
int radius = Math.min((Integer)Config.COMMON.dripstoneFallingSearchRadius.get(), Math.max(8, explosionPower * 4));
|
|
int fallPercent = getFallPercent(explosionPower);
|
|
int changed = 0;
|
|
for (BlockPos pos : BlockPos.betweenClosed(center.offset(-radius, -radius, -radius), center.offset(radius, radius, radius))) {
|
|
if (changed >= 400) {
|
|
break;
|
|
}
|
|
BlockState state = level.getBlockState(pos);
|
|
if (!state.is(Blocks.POINTED_DRIPSTONE) || random.nextInt(100) >= fallPercent) {
|
|
continue;
|
|
}
|
|
BlockPos immutable = pos.immutable();
|
|
level.levelEvent(2001, immutable, Block.getId(state));
|
|
level.setBlock(immutable, Blocks.AIR.defaultBlockState(), 3);
|
|
++changed;
|
|
}
|
|
}
|
|
|
|
public static void onServerTick(ServerLevel level) {
|
|
}
|
|
|
|
public static int getFallPercent(int explosionPower) {
|
|
return Math.max(10, Math.min(90, explosionPower * 7));
|
|
}
|
|
}
|