diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/data/Particle1_8to1_7.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/data/Particle1_8to1_7.kt index 9f99c89..a12af58 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/data/Particle1_8to1_7.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/data/Particle1_8to1_7.kt @@ -23,7 +23,26 @@ enum class Particle1_8to1_7 constructor(val identifier: String, val extra: Int = DRIP_LAVA("dripLava"), VILLAGER_ANGRY("angryVillager"), VILLAGER_HAPPY("happyVillager"), - TOWN_AURA("townaura"), NOTE("note"), PORTAL("portal"), ENCHANTMENT_TABLE("enchantmenttable"), FLAME("flame"), LAVA("lava"), FOOTSTEP("footstep"), CLOUD("cloud"), REDSTONE("reddust"), SNOWBALL("snowballpoof"), SNOW_SHOVEL("snowshovel"), SLIME("slime"), HEART("heart"), BARRIER("barrier"), ICON_CRACK("iconcrack", 2), BLOCK_CRACK("blockcrack", 1), BLOCK_DUST("blockdust", 1), WATER_DROP("droplet"), ITEM_TAKE("take"), MOB_APPEARANCE("mobappearance"); + TOWN_AURA("townaura"), + NOTE("note"), + PORTAL("portal"), + ENCHANTMENT_TABLE("enchantmenttable"), + FLAME("flame"), + LAVA("lava"), + FOOTSTEP("footstep"), + CLOUD("cloud"), + REDSTONE("reddust"), + SNOWBALL("snowballpoof"), + SNOW_SHOVEL("snowshovel"), + SLIME("slime"), + HEART("heart"), + BARRIER("barrier"), + ICON_CRACK("iconcrack", 2), + BLOCK_CRACK("blockcrack", 1), + BLOCK_DUST("blockdust", 1), + WATER_DROP("droplet"), + ITEM_TAKE("take"), + MOB_APPEARANCE("mobappearance"); companion object { private val particleMap = HashMap() diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/InventoryPackets.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/InventoryPackets.kt index d7fe697..9d89331 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/InventoryPackets.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/InventoryPackets.kt @@ -7,8 +7,8 @@ import us.myles.ViaVersion.api.minecraft.item.Item import us.myles.ViaVersion.api.remapper.PacketRemapper import us.myles.ViaVersion.api.type.Type import us.myles.ViaVersion.packets.State -import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8 import us.myles.viaversion.libs.kyori.adventure.text.Component +import us.myles.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer import us.myles.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer fun Protocol1_8To1_7_6.registerInventoryPackets() { @@ -17,20 +17,19 @@ fun Protocol1_8To1_7_6.registerInventoryPackets() { this.registerOutgoing(State.PLAY, 0x2D, 0x2D, object : PacketRemapper() { override fun registerMap() { handler { packetWrapper -> - val windowId: Short = packetWrapper.read(Type.UNSIGNED_BYTE) + val windowId = packetWrapper.read(Type.UNSIGNED_BYTE) packetWrapper.write(Type.UNSIGNED_BYTE, windowId) - val windowType: Short = packetWrapper.read(Type.UNSIGNED_BYTE) + val windowType = packetWrapper.read(Type.UNSIGNED_BYTE) packetWrapper.user().get(Windows::class.java)!!.types[windowId] = windowType packetWrapper.write(Type.STRING, getInventoryString(windowType.toInt())) //Inventory Type - var title: String = packetWrapper.read(Type.STRING) //Title - val slots: Short = packetWrapper.read(Type.UNSIGNED_BYTE) + val title = packetWrapper.read(Type.STRING) //Title + val slots = packetWrapper.read(Type.UNSIGNED_BYTE) val useProvidedWindowTitle: Boolean = packetWrapper.read(Type.BOOLEAN) //Use provided window title - title = if (useProvidedWindowTitle) { - Protocol1_9To1_8.fixJson(title).toString() + packetWrapper.write(Type.STRING, GsonComponentSerializer.gson().serialize(if (useProvidedWindowTitle) { + LegacyComponentSerializer.legacySection().deserialize(title) } else { - LegacyComponentSerializer.legacySection().serialize(Component.translatable(title)) // todo - } - packetWrapper.write(Type.STRING, title) //Window title + Component.translatable(title) // todo + })) //Window title packetWrapper.write(Type.UNSIGNED_BYTE, slots) if (packetWrapper.get(Type.UNSIGNED_BYTE, 0) == 11.toShort()) packetWrapper.passthrough(Type.INT) //Entity Id } diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/PlayerPackets.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/PlayerPackets.kt index 616ae1f..e8f8c0b 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/PlayerPackets.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/PlayerPackets.kt @@ -57,7 +57,7 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() { //Chat Message this.registerOutgoing(State.PLAY, 0x02, 0x02, object : PacketRemapper() { override fun registerMap() { - map(Type.STRING) //Chat Message + map(Type.COMPONENT) //Chat Message create { packetWrapper -> packetWrapper.write(Type.BYTE, 0.toByte()) //Position (chat box) } diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt index 6d8fc8f..0ac39ed 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt @@ -7,7 +7,6 @@ import com.github.creeper123123321.viaaas.protocol.id47toid5.data.Particle1_8to1 import com.github.creeper123123321.viaaas.protocol.id47toid5.storage.MapStorage import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10 import us.myles.ViaVersion.api.minecraft.Position -import us.myles.ViaVersion.api.minecraft.item.Item import us.myles.ViaVersion.api.remapper.PacketRemapper import us.myles.ViaVersion.api.remapper.TypeRemapper import us.myles.ViaVersion.api.type.Type @@ -129,7 +128,8 @@ fun Protocol1_8To1_7_6.registerWorldPackets() { map(xyzShortPos, TypeRemapper(Type.POSITION)) //Position handler { packetWrapper -> for (i in 0..3) { - packetWrapper.write(Type.STRING, + packetWrapper.write( + Type.STRING, Protocol1_9To1_8.fixJson(packetWrapper.read(Type.STRING)).toString() ) } @@ -151,16 +151,21 @@ fun Protocol1_8To1_7_6.registerWorldPackets() { override fun registerMap() { map(Type.VAR_INT) handler { packetWrapper -> - val id: Int = packetWrapper.get(Type.VAR_INT, 0) - val length: Int = packetWrapper.read(Type.SHORT).toInt() - val data: ByteArray = packetWrapper.read(CustomByteType(length)) + val id = packetWrapper.get(Type.VAR_INT, 0) + val length = packetWrapper.read(Type.SHORT).toInt() + val data = packetWrapper.read(CustomByteType(length)) val mapStorage = packetWrapper.user().get(MapStorage::class.java)!! var mapData = mapStorage.getMapData(id) if (mapData == null) mapStorage.putMapData(id, MapStorage.MapData().also { mapData = it }) if (data[0] == 1.toByte()) { val count = (data.size - 1) / 3 mapData!!.mapIcons = Array(count) { i -> - MapStorage.MapIcon((data[i * 3 + 1].toInt() shr 4).toByte(), (data[i * 3 + 1] and 0xF), data[i * 3 + 2], data[i * 3 + 3]) + MapStorage.MapIcon( + (data[i * 3 + 1].toInt() shr 4).toByte(), + (data[i * 3 + 1] and 0xF), + data[i * 3 + 2], + data[i * 3 + 3] + ) } } else if (data[0] == 2.toByte()) { mapData!!.scale = data[1] @@ -168,7 +173,10 @@ fun Protocol1_8To1_7_6.registerWorldPackets() { packetWrapper.write(Type.BYTE, mapData!!.scale) packetWrapper.write(Type.VAR_INT, mapData!!.mapIcons.size) for (mapIcon in mapData!!.mapIcons) { - packetWrapper.write(Type.BYTE, (mapIcon.direction.toInt().shl(4).or(mapIcon.type.toInt() and 0xF)).toByte()) + packetWrapper.write( + Type.BYTE, + (mapIcon.direction.toInt().shl(4).or(mapIcon.type.toInt() and 0xF)).toByte() + ) packetWrapper.write(Type.BYTE, mapIcon.x) packetWrapper.write(Type.BYTE, mapIcon.z) } @@ -221,10 +229,16 @@ fun Protocol1_8To1_7_6.registerWorldPackets() { packetWrapper.write(Type.INT, x) packetWrapper.write(Type.UNSIGNED_BYTE, y) packetWrapper.write(Type.INT, z) - val direction: Byte = packetWrapper.passthrough(Type.BYTE) //Direction - val item: Item = packetWrapper.read(Type.ITEM) + val direction = packetWrapper.passthrough(Type.BYTE) //Direction + val item = packetWrapper.read(Type.ITEM) packetWrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, item) - if (isPlayerInsideBlock(x.toLong(), y.toLong(), z.toLong(), direction) && !isPlaceable(item.identifier)) packetWrapper.cancel() + if (isPlayerInsideBlock( + x.toLong(), + y.toLong(), + z.toLong(), + direction + ) && !isPlaceable(item.identifier) + ) packetWrapper.cancel() for (i in 0..2) { if (packetWrapper.isReadable(Type.BYTE, 0)) { packetWrapper.passthrough(Type.BYTE) @@ -243,8 +257,10 @@ fun Protocol1_8To1_7_6.registerWorldPackets() { map(TypeRemapper(Type.POSITION), xyzShortPosWriter) handler { packetWrapper -> for (i in 0..3) - packetWrapper.write(Type.STRING, LegacyComponentSerializer.legacySection() - .serialize(GsonComponentSerializer.gson().deserialize(packetWrapper.read(Type.STRING)))) + packetWrapper.write( + Type.STRING, LegacyComponentSerializer.legacySection() + .serialize(GsonComponentSerializer.gson().deserialize(packetWrapper.read(Type.STRING))) + ) } } })