Compare commits
2 Commits
a33b27e57d
...
00929dd17a
Author | SHA1 | Date |
---|---|---|
Johannes Frohnmeyer | 00929dd17a | |
Johannes Frohnmeyer | 1109f9e610 |
|
@ -1,4 +1,5 @@
|
|||
import io.gitlab.jfronny.scripts.deployDebug
|
||||
import io.gitlab.jfronny.scripts.deployRelease
|
||||
|
||||
plugins {
|
||||
`java-platform`
|
||||
|
@ -14,6 +15,7 @@ publishing {
|
|||
}
|
||||
tasks.publish { dependsOn(tasks.build) }
|
||||
tasks.deployDebug.dependsOn(tasks.publish)
|
||||
tasks.deployRelease.dependsOn(tasks.deployDebug)
|
||||
|
||||
tasks.withType(GenerateModuleMetadata::class) {
|
||||
enabled = true
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import io.gitlab.jfronny.scripts.deployDebug
|
||||
import io.gitlab.jfronny.scripts.deployRelease
|
||||
|
||||
plugins {
|
||||
`version-catalog`
|
||||
|
@ -14,6 +15,7 @@ publishing {
|
|||
}
|
||||
tasks.publish { dependsOn(tasks.build) }
|
||||
tasks.deployDebug.dependsOn(tasks.publish)
|
||||
tasks.deployRelease.dependsOn(tasks.deployDebug)
|
||||
|
||||
tasks.withType(GenerateModuleMetadata::class) {
|
||||
enabled = true
|
||||
|
|
|
@ -4,19 +4,11 @@ import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public record ConfigurationCompletePacket() implements CustomPayload {
|
||||
public static final CustomPayload.Id<ConfigurationCompletePacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":handshake_complete");
|
||||
public static final PacketCodec<ByteBuf, ConfigurationCompletePacket> CODEC = new PacketCodec<>() {
|
||||
@Override
|
||||
public ConfigurationCompletePacket decode(ByteBuf buf) {
|
||||
return new ConfigurationCompletePacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ConfigurationCompletePacket value) {
|
||||
}
|
||||
};
|
||||
public static final CustomPayload.Id<ConfigurationCompletePacket> ID = new CustomPayload.Id<>(new Identifier(RequestRouter.MOD_ID, "handshake_complete"));
|
||||
public static final PacketCodec<ByteBuf, ConfigurationCompletePacket> CODEC = PacketCodec.unit(new ConfigurationCompletePacket());
|
||||
|
||||
@Override
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
|
|
|
@ -5,9 +5,10 @@ import io.netty.buffer.ByteBuf;
|
|||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public record ConfigurationPacket(int version) implements CustomPayload {
|
||||
public static final CustomPayload.Id<ConfigurationPacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":handshake");
|
||||
public static final CustomPayload.Id<ConfigurationPacket> ID = new CustomPayload.Id<>(new Identifier(RequestRouter.MOD_ID, "handshake"));
|
||||
public static final PacketCodec<ByteBuf, ConfigurationPacket> CODEC = PacketCodecs.INTEGER.xmap(ConfigurationPacket::new, ConfigurationPacket::version);
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,27 +4,30 @@ import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
|||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
public record RequestPacket(long request, @Nullable Long parent, String name, PacketByteBuf aux) implements CustomPayload {
|
||||
public static final Id<RequestPacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":request");
|
||||
public static final PacketCodec<PacketByteBuf, RequestPacket> CODEC = PacketCodec.of(
|
||||
(value, buf) -> {
|
||||
buf.writeLong(value.request);
|
||||
buf.writeBoolean(value.parent != null);
|
||||
if (value.parent != null) buf.writeLong(value.parent);
|
||||
buf.writeString(value.name);
|
||||
buf.writeBytes(value.aux);
|
||||
},
|
||||
buf -> {
|
||||
long request = buf.readLong();
|
||||
Long parent = buf.readBoolean() ? buf.readLong() : null;
|
||||
String name = buf.readString();
|
||||
PacketByteBuf aux = PacketByteBufs.copy(buf);
|
||||
return new RequestPacket(request, parent, name, aux);
|
||||
}
|
||||
);
|
||||
public static final Id<RequestPacket> ID = new CustomPayload.Id<>(new Identifier(RequestRouter.MOD_ID, "request"));
|
||||
public static final PacketCodec<PacketByteBuf, RequestPacket> CODEC = PacketCodec.tuple(
|
||||
PacketCodecs.VAR_LONG, RequestPacket::request,
|
||||
PacketCodecs.optional(PacketCodecs.VAR_LONG), RequestPacket::optionalParent,
|
||||
PacketCodecs.STRING, RequestPacket::name,
|
||||
PacketCodec.of(PacketByteBuf::writeBytes, PacketByteBufs::copy), RequestPacket::aux,
|
||||
RequestPacket::new);
|
||||
|
||||
private RequestPacket(long request, Optional<Long> parent, String name, PacketByteBuf aux) {
|
||||
this(request, parent.orElse(null), name, aux);
|
||||
}
|
||||
|
||||
private Optional<Long> optionalParent() {
|
||||
return Optional.ofNullable(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
|
|
|
@ -4,21 +4,17 @@ import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
|||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public record ResponsePacket(long request, int status, PacketByteBuf aux) implements CustomPayload {
|
||||
public static final CustomPayload.Id<ResponsePacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":response");
|
||||
public static final PacketCodec<PacketByteBuf, ResponsePacket> CODEC = PacketCodec.of(
|
||||
(value, buf) -> {
|
||||
buf.writeLong(value.request());
|
||||
buf.writeInt(value.status());
|
||||
buf.writeBytes(value.aux());
|
||||
},
|
||||
buf -> {
|
||||
long request = buf.readLong();
|
||||
int status = buf.readInt();
|
||||
return new ResponsePacket(request, status, PacketByteBufs.copy(buf));
|
||||
}
|
||||
public static final CustomPayload.Id<ResponsePacket> ID = new CustomPayload.Id<>(new Identifier(RequestRouter.MOD_ID, "response"));
|
||||
public static final PacketCodec<PacketByteBuf, ResponsePacket> CODEC = PacketCodec.tuple(
|
||||
PacketCodecs.VAR_LONG, ResponsePacket::request,
|
||||
PacketCodecs.INTEGER, ResponsePacket::status,
|
||||
PacketCodec.of(PacketByteBuf::writeBytes, PacketByteBufs::copy), ResponsePacket::aux,
|
||||
ResponsePacket::new
|
||||
);
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue