38 lines
816 B
Kotlin
38 lines
816 B
Kotlin
package net.shadowfacts.phycon.util
|
|
|
|
import net.minecraft.item.Item
|
|
import net.minecraft.item.ItemStack
|
|
import net.minecraft.nbt.CompoundTag
|
|
import net.minecraft.network.PacketByteBuf
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
fun PacketByteBuf.writeItemStackWithoutCount(stack: ItemStack) {
|
|
if (stack.isEmpty) {
|
|
writeBoolean(false)
|
|
} else {
|
|
writeBoolean(true)
|
|
writeVarInt(Item.getRawId(stack.item))
|
|
val tag: CompoundTag? =
|
|
if (stack.item.isDamageable || stack.item.shouldSyncTagToClient()) {
|
|
stack.tag
|
|
} else {
|
|
null
|
|
}
|
|
writeCompoundTag(tag)
|
|
}
|
|
}
|
|
|
|
fun PacketByteBuf.readItemStackWithoutCount(): ItemStack {
|
|
return if (!readBoolean()) {
|
|
ItemStack.EMPTY
|
|
} else {
|
|
val id = readVarInt()
|
|
val count = 1
|
|
val stack = ItemStack(Item.byRawId(id), count)
|
|
stack.tag = readCompoundTag()
|
|
stack
|
|
}
|
|
}
|