diff --git a/src/main/java/astrinox/stellum/command/StellumDebugCommand.java b/src/main/java/astrinox/stellum/command/StellumDebugCommand.java index 7785031..8a93fe2 100644 --- a/src/main/java/astrinox/stellum/command/StellumDebugCommand.java +++ b/src/main/java/astrinox/stellum/command/StellumDebugCommand.java @@ -18,10 +18,8 @@ import astrinox.stellum.util.PerlinNoiseHelper; import net.minecraft.block.Blocks; import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.registry.tag.BlockTags; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.state.property.Properties; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -72,8 +70,26 @@ public static void register(CommandDispatcher serverCommand .then(argument("burnSize", IntegerArgumentType .integer()) - .executes( - StellumDebugCommand::executeExplosion)))))))) + .then(argument("doScreenshake", + BoolArgumentType.bool()) + .then(argument( + "screenshakeIntensity", + FloatArgumentType + .floatArg()) + .then(argument( + "screenshakeDurationMs", + IntegerArgumentType + .integer()) + .then(argument( + "screenshakeFade", + BoolArgumentType + .bool()) + .then(argument( + "doFire", + BoolArgumentType + .bool()) + .executes( + StellumDebugCommand::executeExplosion))))))))))))) .then(literal("burnzone") .then(argument("size", IntegerArgumentType.integer()) .then(argument("explosionSize", @@ -85,8 +101,9 @@ public static void register(CommandDispatcher serverCommand .then(argument("noiseMultiplier", FloatArgumentType .floatArg()) - .executes( - StellumDebugCommand::executeBurnzone)))))))); + .then(argument("doFire", BoolArgumentType.bool()) + .executes( + StellumDebugCommand::executeBurnzone))))))))); } public static int executeScreenshake(CommandContext context) @@ -145,7 +162,11 @@ public static int executeExplosion(CommandContext context) .setDamage(context.getArgument("damage", float.class)) .setBurnBlocks(context.getArgument("burnBlocks", boolean.class)) .setBurnSize(context.getArgument("burnSize", int.class)) - .setBurnMap(burnMap); + .setBurnMap(burnMap) + .setDoScreenshake(context.getArgument("doScreenshake", boolean.class)) + .setScreenshakeIntensity(context.getArgument("screenshakeIntensity", float.class)) + .setScreenshakeDurationMs(context.getArgument("screenshakeDurationMs", int.class)) + .setBurnDoFire(context.getArgument("doFire", boolean.class)); explosion.trigger(world); diff --git a/src/main/java/astrinox/stellum/handlers/explosion/BurnZone.java b/src/main/java/astrinox/stellum/handlers/explosion/BurnZone.java index f9876ff..bf1e8a0 100644 --- a/src/main/java/astrinox/stellum/handlers/explosion/BurnZone.java +++ b/src/main/java/astrinox/stellum/handlers/explosion/BurnZone.java @@ -3,9 +3,12 @@ import java.util.Random; import java.util.function.Function; +import org.joml.Math; + import astrinox.stellum.util.EasingHelper; import astrinox.stellum.util.MathHelper; import astrinox.stellum.util.PerlinNoiseHelper; +import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.Mutable; import net.minecraft.world.World; @@ -18,6 +21,7 @@ public class BurnZone { private float noiseMultiplier = 100; private Burnmap burnMap; private Function falloffFunction = EasingHelper::easeInSine; + private boolean doFire = true; public BurnZone setPos(BlockPos pos) { this.pos = pos; @@ -54,6 +58,11 @@ public BurnZone setFalloffFunction(Function falloffFunction) { return this; } + public BurnZone setDoFire(boolean doFire) { + this.doFire = doFire; + return this; + } + public void trigger(World world) { int trueSize = size + explosionSize; int trueSizeSquared = trueSize * trueSize; @@ -75,21 +84,30 @@ public void trigger(World world) { if (distanceSquared <= trueSizeSquared + noisePoint) { blockPos.set(x, y, z); if (distanceSquared >= explosionSizeSquared + noisePoint) { - double percent = MathHelper.map(distanceSquared, explosionSizeSquared, trueSizeSquared, 1, - 0); + double percent = MathHelper.map(distanceSquared, explosionSizeSquared, trueSizeSquared, 0, + 1); if (falloffFunction != null) { percent = falloffFunction.apply(percent); } if (Math.random() < percent) { - if (burnMap != null) { - world.setBlockState(blockPos, burnMap.getOutput(world.getBlockState(blockPos)), - 0b01100010); + } else if (burnMap != null) { + world.setBlockState(blockPos, burnMap.getOutput(world.getBlockState(blockPos)), + 0b01100010); + if (world.getBlockState(blockPos.down()).isSolidBlock(world, blockPos) + && world.getBlockState(blockPos.up()).isAir() + && Math.random() < 0.05 && doFire) { + world.setBlockState(blockPos, Blocks.FIRE.getDefaultState(), 0b01100010); } } } else { if (burnMap != null) { world.setBlockState(blockPos, burnMap.getOutput(world.getBlockState(blockPos)), 0b01100010); + if (world.getBlockState(blockPos.down()).isSolidBlock(world, blockPos) + && world.getBlockState(blockPos.up()).isAir() + && Math.random() < 0.05 && doFire) { + world.setBlockState(blockPos, Blocks.FIRE.getDefaultState(), 0b01100010); + } } } } diff --git a/src/main/java/astrinox/stellum/handlers/explosion/ExplosionHandler.java b/src/main/java/astrinox/stellum/handlers/explosion/ExplosionHandler.java index c535636..3867c84 100644 --- a/src/main/java/astrinox/stellum/handlers/explosion/ExplosionHandler.java +++ b/src/main/java/astrinox/stellum/handlers/explosion/ExplosionHandler.java @@ -4,6 +4,8 @@ import java.util.Random; import java.util.function.Function; +import astrinox.stellum.handlers.screenshake.Screenshake; +import astrinox.stellum.handlers.screenshake.ScreenshakeHandler; import astrinox.stellum.util.EasingHelper; import astrinox.stellum.util.PerlinNoiseHelper; import net.minecraft.block.Blocks; @@ -24,7 +26,12 @@ public class ExplosionHandler { private boolean burnBlocks = false; private Burnmap burnMap; private int burnSize; + private boolean burnDoFire; private Function burnFalloffFunction = (Double x) -> EasingHelper.easeInSine(x); + private boolean doScreenshake = true; + private float screenshakeIntensity = 0.5f; + private int screenshakeDurationMs = 1000; + private boolean doScreenshakeFade = true; public ExplosionHandler setPos(BlockPos pos) { this.pos = pos; @@ -81,6 +88,31 @@ public ExplosionHandler setBurnFalloffFunction(Function burnFall return this; } + public ExplosionHandler setDoScreenshake(boolean doScreenshake) { + this.doScreenshake = doScreenshake; + return this; + } + + public ExplosionHandler setScreenshakeIntensity(float screenshakeIntensity) { + this.screenshakeIntensity = screenshakeIntensity; + return this; + } + + public ExplosionHandler setScreenshakeDurationMs(int screenshakeDurationMs) { + this.screenshakeDurationMs = screenshakeDurationMs; + return this; + } + + public ExplosionHandler setDoScreenshakeFade(boolean doScreenshakeFade) { + this.doScreenshakeFade = doScreenshakeFade; + return this; + } + + public ExplosionHandler setBurnDoFire(boolean burnDoFire) { + this.burnDoFire = burnDoFire; + return this; + } + public void trigger(World world) { int sizeSquared = size * size; Mutable blockPos = new Mutable(); @@ -121,10 +153,16 @@ public void trigger(World world) { .setNoiseScale(noiseScale) .setNoiseMultiplier(noiseMultiplier) .setBurnMap(burnMap) - .setFalloffFunction(burnFalloffFunction == null ? EasingHelper::easeInSine : burnFalloffFunction); + .setFalloffFunction(burnFalloffFunction == null ? EasingHelper::easeInSine : burnFalloffFunction) + .setDoFire(burnDoFire); burnZone.trigger(world); } + if (doScreenshake) { + ScreenshakeHandler + .addScreenshake(new Screenshake(screenshakeIntensity, screenshakeDurationMs, doScreenshakeFade)); + } + } }