Appearance
Networking and aiming
Packets
NetApi (server and common) and NetClientApi (client) register and send packets the same way on every loader. Register packets from your common init.
On Minecraft 1.21.11 and 26.3 you use the game's own payload types:
java
NetApi.toClient(MyPayload.TYPE, MyPayload.CODEC);
NetApi.toServer(CastPayload.TYPE, CastPayload.CODEC);
NetApi.receive(CastPayload.TYPE, (payload, context) -> {
ServerPlayer player = context.player();
});
NetApi.send(player, new MyPayload(1));On Minecraft 1.20.1 and 1.21.1 you make a packet kind first:
java
RimuPacket<MyPayload> kind = NetApi.packet(id, MyPayload.class, MyPayload::write, MyPayload::read);
NetApi.toClient(kind);
NetApi.send(player, new MyPayload(1));Use canSend to check that the other side has your packet.
On the client:
java
NetClientApi.receive(MyPayload.TYPE, (payload, context) -> {
// Handle it here
});
NetClientApi.send(new CastPayload(0));Aiming
AimApi finds what a player is pointing at, on the server.
java
// The ground under the crosshair
Vec3 spot = AimApi.ground(player, 256.0, 64.0);
// The living entity under the crosshair, or null
LivingEntity target = AimApi.creature(player, 256.0);ground takes a range and a fallback distance. When the player looks at the sky, it lands that many blocks out in the direction they face. A creature under the crosshair takes priority over the block behind it.
