Search in sources :

Example 1 with IMessageReader

use of com.infinityraider.infinitylib.network.serialization.IMessageReader in project AgriCraft by AgriCraft.

the class MessageTileEntitySeedStorage method getNecessarySerializers.

@Override
protected List<IMessageSerializer> getNecessarySerializers() {
    return ImmutableList.of(new IMessageSerializer<IAgriStat>() {

        @Override
        public boolean accepts(Class<IAgriStat> clazz) {
            return IAgriStat.class.isAssignableFrom(clazz);
        }

        @Override
        public IMessageWriter<IAgriStat> getWriter(Class<IAgriStat> clazz) {
            return (buf, data) -> {
                NBTTagCompound tag = new NBTTagCompound();
                data.writeToNBT(tag);
                ByteBufUtil.writeNBT(buf, tag);
            };
        }

        @Override
        public IMessageReader<IAgriStat> getReader(Class<IAgriStat> clazz) {
            return buf -> AgriApi.getStatRegistry().valueOf(ByteBufUtil.readNBT(buf)).get();
        }
    });
}
Also used : IMessageWriter(com.infinityraider.infinitylib.network.serialization.IMessageWriter) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMessageReader(com.infinityraider.infinitylib.network.serialization.IMessageReader)

Aggregations

IAgriStat (com.infinityraider.agricraft.api.v1.stat.IAgriStat)1 IMessageReader (com.infinityraider.infinitylib.network.serialization.IMessageReader)1 IMessageWriter (com.infinityraider.infinitylib.network.serialization.IMessageWriter)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1