More old patch work, cleaned up static methods added to ItemStack, and various networking functions.

This commit is contained in:
LexManos committed 2019-01-28 16:25:49 -08:00
1 parent 0067d3edce
commit b40e2cc59e
44 files changed
+507 -1170

No files matched your search

@@ -1,58 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.util;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
public class PacketUtil
{
private PacketUtil() {}
/**
* Most ItemStack serialization is Server to Client, and must go through PacketBuffer.writeItemStack which uses Item.getNBTShareTag.
* One exception is items from the creative menu, which must be sent from Client to Server with their full NBT.
* <br/>
* This method matches PacketBuffer.writeItemStack but without the Item.getNBTShareTag patch.
* It is compatible with PacketBuffer.readItemStack.
*/
public static void writeItemStackFromClientToServer(PacketBuffer buffer, ItemStack stack)
{
if (stack.isEmpty())
{
buffer.writeShort(-1);
}
else
{
buffer.writeShort(Item.getIdFromItem(stack.getItem()));
buffer.writeByte(stack.getCount());
NBTTagCompound nbttagcompound = null;
if (stack.getItem().isDamageable() || stack.getItem().getShareTag())
{
nbttagcompound = stack.getTag();
}
buffer.writeCompoundTag(nbttagcompound);
}
}
}