Files
VS--Improved-Aerodynamics/src/main/java/dev/lumareth/improvedAerodynamics/exhaust/NozzleCommands.java
T
richard 70eb237d70 Add vectored afterburner nozzle with afterburner key and exhaust style
- Add vectored afterburner nozzle block with AzureLib model, deflection, throttle and afterburner state
- Drive nozzles from the vehicle control node and map pitch, roll and yaw to differential deflection
- Add afterburner toggle key and packet, linked to the control node
- Replace Warium exhaust effect entities with improved flames, particles and sounds when exhaustStyle is improved
- Add /aero seedgen to measure the air ceiling for the air placeholder
- Upgrade Warium VS to 1.1.7 and make the lift use horizontal speed
2026-11-11 18:00:46 +01:00

71 lines
4.1 KiB
Java

package dev.lumareth.improvedAerodynamics.exhaust;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import java.util.function.Consumer;
/**
* {@code /aero nozzle <pos> ...}: moves a vectored afterburner nozzle by hand, for testing it without the flight system.
* {@code deflection <degrees>}, {@code throttle <0..1>}, {@code afterburner <true|false>} and {@code right <true|false>}.
*/
public final class NozzleCommands {
private NozzleCommands() {
}
public static LiteralArgumentBuilder<CommandSourceStack> node() {
return Commands.literal("nozzle").then(Commands.argument("pos", BlockPosArgument.blockPos())
.executes(context -> status(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos")))
.then(Commands.literal("deflection").then(Commands.argument("degrees", FloatArgumentType.floatArg(-90.0F, 90.0F))
.executes(context -> {
float degrees = FloatArgumentType.getFloat(context, "degrees");
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
nozzle -> nozzle.setDeflectionTarget((float) Math.toRadians(degrees)));
})))
.then(Commands.literal("throttle").then(Commands.argument("throttle", FloatArgumentType.floatArg(0.0F, 1.0F))
.executes(context -> {
float throttle = FloatArgumentType.getFloat(context, "throttle");
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
nozzle -> nozzle.setThrottle(throttle));
})))
.then(Commands.literal("afterburner").then(Commands.argument("on", BoolArgumentType.bool())
.executes(context -> {
boolean on = BoolArgumentType.getBool(context, "on");
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
nozzle -> nozzle.setAfterburner(on));
})))
.then(Commands.literal("right").then(Commands.argument("right", BoolArgumentType.bool())
.executes(context -> {
boolean right = BoolArgumentType.getBool(context, "right");
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
nozzle -> nozzle.setRightEngine(right));
}))));
}
private static int modify(CommandSourceStack source, BlockPos pos, Consumer<NozzleBlockEntity> change) {
if (!(source.getLevel().getBlockEntity(pos) instanceof NozzleBlockEntity nozzle)) {
source.sendFailure(Component.literal("There is no vectored afterburner nozzle at " + pos.toShortString()));
return 0;
}
change.accept(nozzle);
return status(source, pos);
}
private static int status(CommandSourceStack source, BlockPos pos) {
if (!(source.getLevel().getBlockEntity(pos) instanceof NozzleBlockEntity nozzle)) {
source.sendFailure(Component.literal("There is no vectored afterburner nozzle at " + pos.toShortString()));
return 0;
}
source.sendSuccess(() -> Component.literal(String.format("Nozzle at %s: deflection %.1f deg, throttle %.2f, afterburner %s, %s engine",
pos.toShortString(), Math.toDegrees(nozzle.getDeflectionTarget()), nozzle.getThrottle(),
nozzle.isAfterburner() ? "on" : "off", nozzle.isRightEngine() ? "right" : "left")), false);
return 1;
}
}