generated from MrSphay/codex-agent-repository-kit
Restore intro screen and visible crater test behavior
All checks were successful
Build / build (push) Successful in 9m37s
All checks were successful
Build / build (push) Successful in 9m37s
This commit is contained in:
@@ -1,14 +1,44 @@
|
||||
package com.vinlanx.explosionoverhaul;
|
||||
|
||||
import com.vinlanx.explosionoverhaul.api.IExplosionPower;
|
||||
import com.vinlanx.explosionoverhaul.mixinhelper.ExplosionAccessor;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class ServerExplosionHandler {
|
||||
public static void handleExplosion(ServerLevel level, Explosion explosion, List<BlockPos> affectedBlocks) {
|
||||
if (!((Boolean)Config.COMMON.enableCraterDestruction.get()).booleanValue()) {
|
||||
affectedBlocks.clear();
|
||||
return;
|
||||
}
|
||||
float power = 4.0f;
|
||||
if (explosion instanceof IExplosionPower explosionPower) {
|
||||
power = Math.max(1.0f, explosionPower.getPower());
|
||||
}
|
||||
Vec3 center = explosion instanceof ExplosionAccessor accessor ? accessor.explosionoverhaul$getCenter() : Vec3.ZERO;
|
||||
int radius = Math.max(5, Math.min(18, Math.round(power * 2.0f * ((Double)Config.COMMON.craterSizeMultiplier.get()).floatValue())));
|
||||
Set<BlockPos> existing = new HashSet<>(affectedBlocks);
|
||||
BlockPos origin = BlockPos.containing(center);
|
||||
double radiusSq = radius * radius;
|
||||
for (BlockPos pos : BlockPos.betweenClosed(origin.offset(-radius, -radius, -radius), origin.offset(radius, radius, radius))) {
|
||||
double distanceSq = pos.distToCenterSqr(center);
|
||||
if (distanceSq > radiusSq) {
|
||||
continue;
|
||||
}
|
||||
BlockState state = level.getBlockState(pos);
|
||||
if (state.isAir() || state.getDestroySpeed(level, pos) < 0.0f) {
|
||||
continue;
|
||||
}
|
||||
BlockPos immutable = pos.immutable();
|
||||
if (existing.add(immutable)) {
|
||||
affectedBlocks.add(immutable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user