mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-20 12:09:45 +00:00
Fixed a Digital Miner oversight, fixed Bins losing NBT data and allow Bins to accept items with varying item damage
This commit is contained in:
1 parent
06c66d5fbe
commit
12215490f0
6 files changed
+89
-37
No files matched your search
@@ -61,6 +61,11 @@ import mekanism.common.network.PacketWalkieTalkieState;
|
||||
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTSizeTracker;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
@@ -151,6 +156,14 @@ public class PacketHandler
|
||||
{
|
||||
output.writeByte((Byte)data);
|
||||
}
|
||||
else if(data instanceof ItemStack)
|
||||
{
|
||||
writeStack(output, (ItemStack)data);
|
||||
}
|
||||
else if(data instanceof NBTTagCompound)
|
||||
{
|
||||
writeNBT(output, (NBTTagCompound)data);
|
||||
}
|
||||
else if(data instanceof int[])
|
||||
{
|
||||
for(int i : (int[])data)
|
||||
@@ -187,6 +200,67 @@ public class PacketHandler
|
||||
return new String(input.readBytes(input.readInt()).array());
|
||||
}
|
||||
|
||||
public static void writeStack(ByteBuf output, ItemStack stack)
|
||||
{
|
||||
output.writeInt(stack != null ? Item.getIdFromItem(stack.getItem()) : -1);
|
||||
|
||||
if(stack != null)
|
||||
{
|
||||
output.writeInt(stack.stackSize);
|
||||
output.writeInt(stack.getItemDamage());
|
||||
|
||||
if(stack.getTagCompound() != null && stack.getItem().getShareTag())
|
||||
{
|
||||
output.writeBoolean(true);
|
||||
writeNBT(output, stack.getTagCompound());
|
||||
}
|
||||
else {
|
||||
output.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack readStack(ByteBuf input)
|
||||
{
|
||||
int id = input.readInt();
|
||||
|
||||
if(id >= 0)
|
||||
{
|
||||
ItemStack stack = new ItemStack(Item.getItemById(id), input.readInt(), input.readInt());
|
||||
|
||||
if(input.readBoolean())
|
||||
{
|
||||
stack.setTagCompound(readNBT(input));
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void writeNBT(ByteBuf output, NBTTagCompound nbtTags)
|
||||
{
|
||||
try {
|
||||
byte[] buffer = CompressedStreamTools.compress(nbtTags);
|
||||
|
||||
output.writeInt(buffer.length);
|
||||
output.writeBytes(buffer);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
public static NBTTagCompound readNBT(ByteBuf input)
|
||||
{
|
||||
try {
|
||||
byte[] buffer = new byte[input.readInt()];
|
||||
input.readBytes(buffer);
|
||||
|
||||
return CompressedStreamTools.func_152457_a(buffer, new NBTSizeTracker(2097152L));
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityPlayer getPlayer(MessageContext context)
|
||||
{
|
||||
return Mekanism.proxy.getPlayer(context);
|
||||
|
||||
Reference in new issue
Block a user