Skip to content

Commit

Permalink
Make CodecPacket use nbt instead of json
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftschurli committed Feb 2, 2024
1 parent aa93e23 commit 0e2a7be
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.minecraftschurlimods.simplenetlib;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DynamicOps;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

Expand Down Expand Up @@ -29,12 +32,12 @@ public CodecPacket(ResourceLocation id, T data) {
*/
public CodecPacket(ResourceLocation id, FriendlyByteBuf buf) {
this.id = id;
this.data = buf.readJsonWithCodec(this.codec());
this.data = buf.readWithCodec(this.ops(), this.codec());
}

@Override
public void serialize(FriendlyByteBuf buf) {
buf.writeJsonWithCodec(this.codec(), this.data);
buf.writeWithCodec(this.ops(), this.codec(), this.data);
}

@Override
Expand All @@ -48,4 +51,8 @@ public ResourceLocation id() {
* @return the codec to encode and decode the data.
*/
protected abstract Codec<T> codec();

protected DynamicOps<Tag> ops() {
return NbtOps.INSTANCE;
}
}

0 comments on commit 0e2a7be

Please sign in to comment.