Skip to content

Commit

Permalink
a few final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZoidMaster committed Nov 12, 2024
1 parent 47533e3 commit 02c33c0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 13 deletions.
35 changes: 28 additions & 7 deletions src/main/java/astrinox/stellum/command/StellumDebugCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,8 +70,26 @@ public static void register(CommandDispatcher<ServerCommandSource> 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",
Expand All @@ -85,8 +101,9 @@ public static void register(CommandDispatcher<ServerCommandSource> serverCommand
.then(argument("noiseMultiplier",
FloatArgumentType
.floatArg())
.executes(
StellumDebugCommand::executeBurnzone))))))));
.then(argument("doFire", BoolArgumentType.bool())
.executes(
StellumDebugCommand::executeBurnzone)))))))));
}

public static int executeScreenshake(CommandContext<ServerCommandSource> context)
Expand Down Expand Up @@ -145,7 +162,11 @@ public static int executeExplosion(CommandContext<ServerCommandSource> 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);

Expand Down
28 changes: 23 additions & 5 deletions src/main/java/astrinox/stellum/handlers/explosion/BurnZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +21,7 @@ public class BurnZone {
private float noiseMultiplier = 100;
private Burnmap burnMap;
private Function<Double, Double> falloffFunction = EasingHelper::easeInSine;
private boolean doFire = true;

public BurnZone setPos(BlockPos pos) {
this.pos = pos;
Expand Down Expand Up @@ -54,6 +58,11 @@ public BurnZone setFalloffFunction(Function<Double, Double> 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;
Expand All @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +26,12 @@ public class ExplosionHandler {
private boolean burnBlocks = false;
private Burnmap burnMap;
private int burnSize;
private boolean burnDoFire;
private Function<Double, Double> 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;
Expand Down Expand Up @@ -81,6 +88,31 @@ public ExplosionHandler setBurnFalloffFunction(Function<Double, Double> 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();
Expand Down Expand Up @@ -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));
}

}
}

0 comments on commit 02c33c0

Please sign in to comment.