mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
network: improve pre flattening item meta writing
This commit is contained in:
parent
78b8daabf8
commit
c8150e5fb5
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -134,7 +134,7 @@ when (os) {
|
|||||||
Architectures.ARM -> {
|
Architectures.ARM -> {
|
||||||
lwjglNatives += "-arm64"
|
lwjglNatives += "-arm64"
|
||||||
zstdNatives += "-amd64"
|
zstdNatives += "-amd64"
|
||||||
// TODO: javafx for Windows on arm is not yet supported: https://github.com/luben/zstd-jni/issues/277
|
// TODO: javafx for Windows on arm is not yet supported
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -22,4 +22,9 @@ interface DurableItem : ItemWithMeta {
|
|||||||
override fun setMeta(stack: ItemStack, meta: Int) {
|
override fun setMeta(stack: ItemStack, meta: Int) {
|
||||||
stack.durability.durability = maxDurability - meta // in <1.13 its damage not durability
|
stack.durability.durability = maxDurability - meta // in <1.13 its damage not durability
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getMeta(id: Int, stack: ItemStack): Int {
|
||||||
|
val durability = stack._durability ?: return 0
|
||||||
|
return maxDurability - durability.durability
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -14,8 +14,12 @@
|
|||||||
package de.bixilon.minosoft.data.registries.item.items.legacy
|
package de.bixilon.minosoft.data.registries.item.items.legacy
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.container.stack.ItemStack
|
import de.bixilon.minosoft.data.container.stack.ItemStack
|
||||||
|
import de.bixilon.minosoft.data.registries.registries.registry.MetaTypes
|
||||||
|
|
||||||
interface ItemWithMeta {
|
interface ItemWithMeta {
|
||||||
|
|
||||||
fun setMeta(stack: ItemStack, meta: Int)
|
fun setMeta(stack: ItemStack, meta: Int)
|
||||||
|
fun getMeta(id: Int, stack: ItemStack): Int {
|
||||||
|
return id and MetaTypes.ITEM.mask
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -19,9 +19,9 @@ enum class MetaTypes(val bits: Int) {
|
|||||||
ITEM(16),
|
ITEM(16),
|
||||||
;
|
;
|
||||||
|
|
||||||
private val metaMask = (1 shl bits) - 1
|
val mask = (1 shl bits) - 1
|
||||||
|
|
||||||
fun modify(id: Int, meta: Int): Int {
|
fun modify(id: Int, meta: Int): Int {
|
||||||
return (id shl bits) or (meta and metaMask)
|
return (id shl bits) or (meta and mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -18,6 +18,8 @@ import de.bixilon.minosoft.data.chat.signature.ChatSignatureProperties
|
|||||||
import de.bixilon.minosoft.data.chat.signature.LastSeenMessageList
|
import de.bixilon.minosoft.data.chat.signature.LastSeenMessageList
|
||||||
import de.bixilon.minosoft.data.chat.signature.lastSeen.MessageSignatureData
|
import de.bixilon.minosoft.data.chat.signature.lastSeen.MessageSignatureData
|
||||||
import de.bixilon.minosoft.data.container.stack.ItemStack
|
import de.bixilon.minosoft.data.container.stack.ItemStack
|
||||||
|
import de.bixilon.minosoft.data.registries.item.items.legacy.ItemWithMeta
|
||||||
|
import de.bixilon.minosoft.data.registries.registries.registry.MetaTypes
|
||||||
import de.bixilon.minosoft.protocol.PlayerPublicKey
|
import de.bixilon.minosoft.protocol.PlayerPublicKey
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
||||||
@ -48,17 +50,22 @@ class PlayOutByteBuffer(val connection: PlayConnection) : OutByteBuffer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun writeLegacyItemStack(stack: ItemStack?) {
|
||||||
|
if (stack == null || !stack._valid) {
|
||||||
|
writeShort(-1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val item = stack.item.item
|
||||||
|
val id = connection.registries.item.getId(item)
|
||||||
|
writeShort(id shr MetaTypes.ITEM.bits)
|
||||||
|
writeByte(stack.item.count)
|
||||||
|
writeShort(if (item is ItemWithMeta) item.getMeta(id, stack) else 0)
|
||||||
|
writeNBT(stack.getNBT())
|
||||||
|
}
|
||||||
|
|
||||||
fun writeItemStack(stack: ItemStack?) {
|
fun writeItemStack(stack: ItemStack?) {
|
||||||
if (versionId < ProtocolVersions.V_1_13_2_PRE1) {
|
if (versionId < ProtocolVersions.V_1_13_2_PRE1) {
|
||||||
if (stack == null || !stack._valid) {
|
return writeLegacyItemStack(stack)
|
||||||
writeShort(-1)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
writeShort(connection.registries.item.getId(stack.item.item))
|
|
||||||
writeByte(stack.item.count)
|
|
||||||
writeShort(stack._durability?.durability ?: 0) // ToDo: This is meta in general and not just durability
|
|
||||||
writeNBT(stack.getNBT())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
val valid = stack != null && stack._valid
|
val valid = stack != null && stack._valid
|
||||||
writeBoolean(valid)
|
writeBoolean(valid)
|
||||||
@ -80,6 +87,7 @@ class PlayOutByteBuffer(val connection: PlayConnection) : OutByteBuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun writeNBT(nbt: Any?) {
|
fun writeNBT(nbt: Any?) {
|
||||||
|
if (nbt is Map<*, *> && nbt.isEmpty()) return writeNBT(null)
|
||||||
return writeNBT(nbt, versionId < ProtocolVersions.V_14W28B, versionId < V_23W31A)
|
return writeNBT(nbt, versionId < ProtocolVersions.V_14W28B, versionId < V_23W31A)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user