Add FluidStack support to the Forge packet buffer. (#6353) (#6485)

This commit is contained in:
Richard Freimer 2020-02-03 15:46:14 -05:00 committed by GitHub
parent 7bac75f370
commit 1f46169e1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -22,6 +22,7 @@ package net.minecraftforge.common.extensions;
import com.google.common.base.Preconditions;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
@ -126,4 +127,28 @@ public interface IForgePacketBuffer
throw new IllegalArgumentException("Attempted to read an registryValue of the wrong type from the Buffer!");
return value;
}
/**
* Writes a FluidStack to the packet buffer, easy enough. If EMPTY, writes a FALSE.
* This behavior provides parity with the ItemStack method in PacketBuffer.
*
* @param stack FluidStack to be written to the packet buffer.
*/
default void writeFluidStack(FluidStack stack)
{
if (stack.isEmpty()) {
getBuffer().writeBoolean(false);
} else {
getBuffer().writeBoolean(true);
stack.writeToPacket(getBuffer());
}
}
/**
* Reads a FluidStack from this buffer.
*/
default FluidStack readFluidStack()
{
return !getBuffer().readBoolean() ? FluidStack.EMPTY : FluidStack.readFromPacket(getBuffer());
}
}