Skip to content

Commit

Permalink
feat: allow players to reset computers via commands
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <[email protected]>
  • Loading branch information
Octol1ttle committed Nov 20, 2023
1 parent 1393cf8 commit f02e94d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/ru/octol1ttle/flightassistant/FlightAssistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.octol1ttle.flightassistant.alerts.ECAMSoundData;
import ru.octol1ttle.flightassistant.commands.ResetAllComputersCommand;
import ru.octol1ttle.flightassistant.commands.ResetFaultedComputersCommand;
import ru.octol1ttle.flightassistant.commands.SetAutoThrustSpeedCommand;
import ru.octol1ttle.flightassistant.commands.SwitchDisplayModeCommand;
import ru.octol1ttle.flightassistant.computers.ComputerHost;
Expand Down Expand Up @@ -100,6 +102,14 @@ private static void setupCommand() {
.then(literal("speed")
.then(argument("targetSpeed", IntegerArgumentType.integer(10, 30))
.executes(new SetAutoThrustSpeedCommand())))
.then(literal("reset")
.then(literal("computers")
.then(literal("all")
.executes(new ResetAllComputersCommand()))
.then(literal("faulted")
.executes(new ResetFaultedComputersCommand()))
)
)
);
dispatcher.register(literal("flas").redirect(node));
dispatcher.register(literal("fhud").redirect(node));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.octol1ttle.flightassistant.commands;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import ru.octol1ttle.flightassistant.HudRenderer;

public class ResetAllComputersCommand implements Command<FabricClientCommandSource> {
@Override
public int run(CommandContext<FabricClientCommandSource> context) {
if (HudRenderer.getHost() != null) {
HudRenderer.getHost().resetAll();
}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.octol1ttle.flightassistant.commands;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import ru.octol1ttle.flightassistant.HudRenderer;

public class ResetFaultedComputersCommand implements Command<FabricClientCommandSource> {
@Override
public int run(CommandContext<FabricClientCommandSource> context) {
if (HudRenderer.getHost() != null) {
HudRenderer.getHost().resetFaulted();
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void reset() {
flightHeading = 0.0f;
roll = 0.0f;
altitude = 0.0f;
voidLevel = 0;
voidLevel = Integer.MIN_VALUE;
groundLevel = 0;
distanceFromGround = 0.0f;
elytraHealth = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,31 @@ public void render() {
}
}
}

public void resetAll() {
for (ITickableComputer tickable : tickables) {
tickable.reset();
}
for (IRenderTickableComputer renderTickable : renderTickables) {
renderTickable.reset();
}
resetFaulted();
}

public void resetFaulted() {
for (IComputer computer : faulted) {
faulted.remove(computer);
computer.reset();
if (computer instanceof ITickableComputer tickable) {
tickables.add(tickable);
return;
}
if (computer instanceof IRenderTickableComputer renderTickable) {
renderTickables.add(renderTickable);
return;
}

throw new RuntimeException("Unknown computer type for " + computer);
}
}
}

0 comments on commit f02e94d

Please sign in to comment.