mirror of
https://github.com/XevianLight/Aphelion.git
synced 2026-05-11 10:00:54 +01:00
RocketEntites can now launch to a specified dimension and position. Added /aphelion rocket (entity) destination, launch, and launchTo
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user