Fixed spells not syncing

This commit is contained in:
Sollace 2024-10-06 19:17:14 +01:00
parent 58c342442d
commit e9728ec0f7
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 4 additions and 3 deletions

View file

@ -20,6 +20,7 @@ import com.minelittlepony.unicopia.util.serialization.NbtSerialisable;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodecs; import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.registry.RegistryWrapper.WrapperLookup; import net.minecraft.registry.RegistryWrapper.WrapperLookup;
@ -165,7 +166,7 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
@Override @Override
public Optional<? extends ByteBuf> write(Status status, WrapperLookup lookup) { public Optional<? extends ByteBuf> write(Status status, WrapperLookup lookup) {
if (status != Status.DEFAULT) { if (status != Status.DEFAULT) {
ByteBuf buffer = Unpooled.buffer(); ByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
buffer.writeByte(1); buffer.writeByte(1);
PacketCodecs.NBT_COMPOUND.encode(buffer, spell.toNBT(lookup)); PacketCodecs.NBT_COMPOUND.encode(buffer, spell.toNBT(lookup));
return Optional.of(buffer); return Optional.of(buffer);

View file

@ -20,13 +20,13 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
public interface PacketCodecUtils { public interface PacketCodecUtils {
PacketCodec<PacketByteBuf, PacketByteBuf> BUFFER = PacketCodec.of((buffer, bytes) -> { PacketCodec<PacketByteBuf, PacketByteBuf> BUFFER = PacketCodec.of((bytes, buffer) -> {
buffer.writeInt(bytes.writerIndex()); buffer.writeInt(bytes.writerIndex());
buffer.writeBytes(bytes); buffer.writeBytes(bytes);
}, buffer -> new PacketByteBuf(buffer.readBytes(buffer.readInt()))); }, buffer -> new PacketByteBuf(buffer.readBytes(buffer.readInt())));
PacketCodec<PacketByteBuf, Optional<PacketByteBuf>> OPTIONAL_BUFFER = PacketCodecs.optional(BUFFER); PacketCodec<PacketByteBuf, Optional<PacketByteBuf>> OPTIONAL_BUFFER = PacketCodecs.optional(BUFFER);
PacketCodec<RegistryByteBuf, ByteBuf> REGISTRY_BUFFER = PacketCodec.of((buffer, bytes) -> { PacketCodec<RegistryByteBuf, ByteBuf> REGISTRY_BUFFER = PacketCodec.of((bytes, buffer) -> {
buffer.writeInt(bytes.writerIndex()); buffer.writeInt(bytes.writerIndex());
buffer.writeBytes(bytes); buffer.writeBytes(bytes);
}, buffer -> new RegistryByteBuf(buffer.readBytes(buffer.readInt()), buffer.getRegistryManager())); }, buffer -> new RegistryByteBuf(buffer.readBytes(buffer.readInt()), buffer.getRegistryManager()));