RocketEntites can now launch to a specified dimension and position. Added /aphelion rocket (entity) destination, launch, and launchTo

This commit is contained in:
XevianLight
2026-01-25 19:56:43 -07:00
parent 59062724ff
commit 5e512cae1c
14 changed files with 757 additions and 110 deletions

View File

@@ -0,0 +1,28 @@
package net.xevianlight.aphelion.network;
import net.minecraft.client.Minecraft;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.entites.vehicles.RocketEntity;
import net.xevianlight.aphelion.network.packet.RocketLaunchPayload;
import net.xevianlight.aphelion.client.AphelionClient;
@EventBusSubscriber(modid = Aphelion.MOD_ID)
public final class KeyNetwork {
@SubscribeEvent
public static void onClientTick(ClientTickEvent.Post event) {
Minecraft mc = Minecraft.getInstance();
if (mc.player == null) return;
// consumeClick makes it fire once per press, not every tick held
if (AphelionClient.ROCKET_LAUNCH_KEY.consumeClick() && mc.player.getVehicle() instanceof RocketEntity rocket) {
PacketDistributor.sendToServer(new RocketLaunchPayload(rocket.getId()));
}
}
}

View File

@@ -0,0 +1,32 @@
package net.xevianlight.aphelion.network;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.entites.vehicles.RocketEntity;
import net.xevianlight.aphelion.network.packet.RocketLaunchPayload;
public final class RocketPayloadHandlers {
public static void handleRocketLaunch(final RocketLaunchPayload payload, final IPayloadContext ctx) {
Aphelion.LOGGER.info("Rocket launch command received");
// Ensure we run on the server thread
ctx.enqueueWork(() -> {
if (!(ctx.player() instanceof ServerPlayer sp)) return;
var level = sp.serverLevel();
var e = level.getEntity(payload.rocketEntityId());
if (!(e instanceof RocketEntity rocket)) return;
// Security: only allow if the sender is actually riding this rocket
if (sp.getVehicle() != rocket) return;
// Start launch
if (rocket.getPhase() == RocketEntity.FlightPhase.IDLE
|| rocket.getPhase() == RocketEntity.FlightPhase.LANDED) {
rocket.launch();
}
});
}
}

View File

@@ -0,0 +1,24 @@
package net.xevianlight.aphelion.network.packet;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
public record RocketLaunchPayload(int rocketEntityId) implements CustomPacketPayload {
public static final Type<RocketLaunchPayload> TYPE =
new Type<>(ResourceLocation.fromNamespaceAndPath("aphelion", "rocket_launch"));
public static final StreamCodec<ByteBuf, RocketLaunchPayload> STREAM_CODEC =
StreamCodec.composite(
ByteBufCodecs.VAR_INT, RocketLaunchPayload::rocketEntityId,
RocketLaunchPayload::new
);
@Override
public Type<? extends CustomPacketPayload> type() {
return TYPE;
}
}