mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-21 11:55:15 +01:00
basic implementation of vialegacy
This commit is contained in:
parent
6b406d2a90
commit
df5f4c67c8
@ -61,15 +61,16 @@ dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
implementation(kotlin("reflect"))
|
||||
|
||||
val vvVer = "4.7.0-23w14a-SNAPSHOT"
|
||||
val vbVer = "4.7.0-23w14a-SNAPSHOT"
|
||||
val vrVer = "2e7dc6b"
|
||||
val vvVer = "4.7.0-23w16a-SNAPSHOT"
|
||||
val vbVer = "4.7.0-23w16a-SNAPSHOT"
|
||||
val vrVer = "5f7fdc5"
|
||||
implementation("com.viaversion:viaversion:$vvVer") { isTransitive = false }
|
||||
implementation("com.viaversion:viabackwards:$vbVer") { isTransitive = false }
|
||||
implementation("com.github.ViaVersion.ViaRewind:viarewind-all:$vrVer") { isTransitive = false }
|
||||
implementation("net.raphimc:ViaAprilFools:2.0.6")
|
||||
implementation("net.raphimc:ViaLegacy:2.2.15")
|
||||
|
||||
val nettyVer = "4.1.89.Final"
|
||||
val nettyVer = "4.1.91.Final"
|
||||
implementation("io.netty:netty-handler-proxy:$nettyVer")
|
||||
implementation("io.netty:netty-resolver-dns:$nettyVer")
|
||||
implementation("io.netty:netty-transport-native-epoll:$nettyVer:linux-aarch_64")
|
||||
@ -96,7 +97,7 @@ dependencies {
|
||||
implementation("org.jline:jline-terminal-jansi:3.23.0")
|
||||
implementation("org.slf4j:slf4j-api:$slf4jVer")
|
||||
|
||||
val ktorVersion = "2.2.4"
|
||||
val ktorVersion = "2.3.0"
|
||||
implementation("io.ktor:ktor-network-tls-certificates-jvm:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-websockets:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-netty-jvm:$ktorVersion")
|
||||
|
23
src/main/java/com/viaversion/aas/platform/AspirinLegacy.java
Normal file
23
src/main/java/com/viaversion/aas/platform/AspirinLegacy.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.viaversion.aas.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.raphimc.vialegacy.platform.ViaLegacyPlatform;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AspirinLegacy implements ViaLegacyPlatform {
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return Via.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return Via.getPlatform().getDataFolder();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
init(getDataFolder());
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package com.viaversion.aas.platform;
|
||||
|
||||
import com.viaversion.aas.provider.AspirinCompressionProvider;
|
||||
import com.viaversion.aas.provider.AspirinEncryptionProvider;
|
||||
import com.viaversion.aas.provider.AspirinProfileProvider;
|
||||
import com.viaversion.aas.provider.AspirinVersionProvider;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
|
||||
@ -8,6 +10,8 @@ import com.viaversion.viaversion.api.protocol.version.VersionProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
import com.viaversion.viaversion.velocity.providers.VelocityMovementTransmitter;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
|
||||
|
||||
public class AspirinLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
@ -15,6 +19,10 @@ public class AspirinLoader implements ViaPlatformLoader {
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new AspirinVersionProvider());
|
||||
Via.getManager().getProviders().use(CompressionProvider.class, new AspirinCompressionProvider());
|
||||
|
||||
//ViaLegacy
|
||||
Via.getManager().getProviders().use(GameProfileFetcher.class, new AspirinProfileProvider());
|
||||
Via.getManager().getProviders().use(EncryptionProvider.class, new AspirinEncryptionProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.viaversion.aas.provider;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider;
|
||||
|
||||
public class AspirinEncryptionProvider extends EncryptionProvider {
|
||||
@Override
|
||||
public void enableDecryption(UserConnection user) {
|
||||
throw new UnsupportedOperationException("todo"); // todo implement this
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.viaversion.aas.provider;
|
||||
|
||||
import com.viaversion.aas.UtilKt;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameProfile;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
// todo implement an api without blocking
|
||||
public class AspirinProfileProvider extends GameProfileFetcher {
|
||||
@Override
|
||||
public UUID loadMojangUUID(String playerName) {
|
||||
return UtilKt.generateOfflinePlayerUuid(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile loadGameProfile(UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.viaversion.aas
|
||||
import com.viaversion.aas.command.VIAaaSConsole
|
||||
import com.viaversion.aas.platform.AspirinAprilFools
|
||||
import com.viaversion.aas.platform.AspirinBackwards
|
||||
import com.viaversion.aas.platform.AspirinLegacy
|
||||
import com.viaversion.aas.platform.AspirinPlatform
|
||||
import com.viaversion.aas.platform.AspirinRewind
|
||||
import com.viaversion.aas.protocol.registerAspirinProtocols
|
||||
@ -54,10 +55,11 @@ private fun printSplash() {
|
||||
|
||||
private fun initVia() {
|
||||
AspirinPlatform.initVia {
|
||||
AspirinRewind().init()
|
||||
AspirinBackwards().init()
|
||||
AspirinAprilFools().init()
|
||||
AspirinLegacy().init()
|
||||
}
|
||||
AspirinRewind().init()
|
||||
|
||||
ProtocolVersion.register(-2, "AUTO")
|
||||
registerAspirinProtocols()
|
||||
|
@ -2,11 +2,15 @@ package com.viaversion.aas.handler
|
||||
|
||||
import com.viaversion.aas.codec.FrameCodec
|
||||
import com.viaversion.aas.codec.MinecraftCodec
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
|
||||
import com.viaversion.viaversion.connection.UserConnectionImpl
|
||||
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl
|
||||
import io.netty.channel.Channel
|
||||
import io.netty.channel.ChannelInitializer
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion
|
||||
import net.raphimc.vialegacy.netty.PreNettyLengthCodec
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.baseprotocols.PreNettyBaseProtocol
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.URI
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -15,8 +19,17 @@ class BackEndInit(val connectionData: ConnectionData, val proxyUri: URI?, val pr
|
||||
ChannelInitializer<Channel>() {
|
||||
override fun initChannel(ch: Channel) {
|
||||
val user = UserConnectionImpl(ch, true)
|
||||
ProtocolPipelineImpl(user)
|
||||
ch.pipeline().also { addProxyHandler(it, proxyUri, proxyAddress) }
|
||||
val pipeline = ProtocolPipelineImpl(user)
|
||||
val version = connectionData.backServerVer!!
|
||||
val isLegacy = LegacyProtocolVersion.protocolCompare(version, ProtocolVersion.v_1_6_4.version) <= 0
|
||||
|
||||
if (isLegacy) {
|
||||
pipeline.add(PreNettyBaseProtocol.INSTANCE)
|
||||
}
|
||||
|
||||
ch.pipeline()
|
||||
.also { addProxyHandler(it, proxyUri, proxyAddress) }
|
||||
.also { if (isLegacy) it.addLast("vl-prenetty", PreNettyLengthCodec(user)) }
|
||||
// "crypto"
|
||||
.addLast("frame", FrameCodec())
|
||||
// compress
|
||||
|
@ -182,6 +182,7 @@ class LoginState : ConnectionState {
|
||||
"Session req: {} ({} {}) {}",
|
||||
handler.data.frontHandler.endRemoteAddress, playerId, frontName, backName
|
||||
)
|
||||
// todo change this for viaproxy
|
||||
val pluginReauthed = reauthMessage(handler, backName!!, backHash).await()
|
||||
if (!pluginReauthed) {
|
||||
AspirinServer.viaWebServer.requestSessionJoin(
|
||||
|
@ -35,6 +35,8 @@ private suspend fun createBackChannel(
|
||||
proxyUri: URI?,
|
||||
proxyAddress: InetSocketAddress?
|
||||
): Channel {
|
||||
autoDetectVersion(handler, socketAddr)
|
||||
|
||||
val loop = handler.data.frontChannel.eventLoop()
|
||||
val channel = Bootstrap()
|
||||
.handler(BackEndInit(handler.data, proxyUri, proxyAddress))
|
||||
@ -58,8 +60,6 @@ private suspend fun createBackChannel(
|
||||
}
|
||||
handler.data.backChannel = channel as SocketChannel
|
||||
|
||||
autoDetectVersion(handler, socketAddr)
|
||||
|
||||
val packet = Handshake()
|
||||
packet.nextState = state
|
||||
packet.protocolId = handler.data.frontVer!!
|
||||
|
@ -1,16 +1,15 @@
|
||||
package com.viaversion.aas.protocol
|
||||
|
||||
import com.viaversion.aas.protocol.id47toid5.Protocol1_8To1_7_6
|
||||
import com.viaversion.viaversion.api.Via
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
|
||||
import com.viaversion.viaversion.protocol.ProtocolManagerImpl
|
||||
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion
|
||||
|
||||
// cursed 1.7 -> 1.8 from https://github.com/Gerrygames/ClientViaVersion
|
||||
// + https://github.com/creeper123123321/ViaRewind/tree/17to18
|
||||
|
||||
val sharewareVersion = AprilFoolsProtocolVersion.s3d_shareware
|
||||
fun registerAspirinProtocols() {
|
||||
// todo fix version checks for shareware
|
||||
Via.getManager().protocolManager.maxPathDeltaIncrease = -1 // shareware id is weird
|
||||
Via.getManager().protocolManager.registerProtocol(Protocol1_8To1_7_6, ProtocolVersion.v1_8, ProtocolVersion.v1_7_6)
|
||||
|
||||
// for ViaLegacy
|
||||
Via.getManager().protocolManager.maxProtocolPathSize = Int.MAX_VALUE
|
||||
Via.getManager().protocolManager.maxPathDeltaIncrease = -1
|
||||
(Via.getManager().protocolManager as ProtocolManagerImpl).refreshVersions()
|
||||
}
|
||||
|
@ -1,122 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5
|
||||
|
||||
import com.viaversion.aas.protocol.id47toid5.packets.*
|
||||
import com.viaversion.aas.protocol.id47toid5.storage.*
|
||||
import com.viaversion.viaversion.api.connection.UserConnection
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ServerboundPackets1_7
|
||||
|
||||
// Based on https://github.com/Gerrygames/ClientViaVersion
|
||||
object Protocol1_8To1_7_6 : AbstractProtocol<ClientboundPackets1_7, ClientboundPackets1_8,
|
||||
ServerboundPackets1_7, ServerboundPackets1_8>(
|
||||
ClientboundPackets1_7::class.java, ClientboundPackets1_8::class.java,
|
||||
ServerboundPackets1_7::class.java, ServerboundPackets1_8::class.java
|
||||
) {
|
||||
private val placeable = hashSetOf<Int>()
|
||||
|
||||
init {
|
||||
placeable.add(6)
|
||||
placeable.add(27)
|
||||
placeable.add(28)
|
||||
placeable.add(30)
|
||||
placeable.add(31)
|
||||
placeable.add(32)
|
||||
placeable.add(37)
|
||||
placeable.add(38)
|
||||
placeable.add(39)
|
||||
placeable.add(40)
|
||||
placeable.add(50)
|
||||
placeable.add(65)
|
||||
placeable.add(66)
|
||||
placeable.add(69)
|
||||
placeable.add(70)
|
||||
placeable.add(72)
|
||||
placeable.add(76)
|
||||
placeable.add(77)
|
||||
placeable.add(96)
|
||||
placeable.add(106)
|
||||
placeable.add(111)
|
||||
placeable.add(131)
|
||||
placeable.add(143)
|
||||
placeable.add(147)
|
||||
placeable.add(148)
|
||||
placeable.add(157)
|
||||
placeable.add(167)
|
||||
placeable.add(175)
|
||||
for (i in 256..378) placeable.add(i)
|
||||
for (i in 381..396) placeable.add(i)
|
||||
for (i in 398..452) placeable.add(i)
|
||||
for (i in 2256..2267) placeable.add(i)
|
||||
}
|
||||
|
||||
override fun registerPackets() {
|
||||
this.registerPlayerPackets()
|
||||
this.registerEntityPackets()
|
||||
this.registerWorldPackets()
|
||||
this.registerLoginPackets()
|
||||
this.registerInventoryPackets()
|
||||
}
|
||||
|
||||
override fun init(userConnection: UserConnection) {
|
||||
userConnection.put(Tablist(userConnection))
|
||||
userConnection.put(Windows(userConnection))
|
||||
userConnection.put(Scoreboard(userConnection))
|
||||
userConnection.put(EntityTracker(userConnection))
|
||||
userConnection.put(MapStorage(userConnection))
|
||||
}
|
||||
|
||||
fun isPlayerInsideBlock(x: Long, y: Long, z: Long, direction: Short): Boolean {
|
||||
//switch (direction) {
|
||||
// case 0: {
|
||||
// y--;
|
||||
// break;
|
||||
// }
|
||||
// case 1: {
|
||||
// y++;
|
||||
// break;
|
||||
// }
|
||||
// case 2: {
|
||||
// z--;
|
||||
// break;
|
||||
// }
|
||||
// case 3: {
|
||||
// z++;
|
||||
// break;
|
||||
// }
|
||||
// case 4: {
|
||||
// x--;
|
||||
// break;
|
||||
// }
|
||||
// case 5: {
|
||||
// x++;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
//return Math.abs(The5zigAPI.getAPI().getPlayerPosX() - (x + 0.5)) < 0.8 && Math.abs(The5zigAPI.getAPI().getPlayerPosZ() - (z + 0.5)) < 0.8 && Math.abs((The5zigAPI.getAPI().getPlayerPosY() + 0.9) - (y + 0.5)) < 1.4;
|
||||
return false
|
||||
}
|
||||
|
||||
fun isPlaceable(id: Int): Boolean {
|
||||
return placeable.contains(id)
|
||||
}
|
||||
|
||||
fun getInventoryString(b: Int): String {
|
||||
return when (b) {
|
||||
1 -> "minecraft:crafting_table"
|
||||
2 -> "minecraft:furnace"
|
||||
3 -> "minecraft:dispenser"
|
||||
4 -> "minecraft:enchanting_table"
|
||||
5 -> "minecraft:brewing_stand"
|
||||
6 -> "minecraft:villager"
|
||||
7 -> "minecraft:beacon"
|
||||
8 -> "minecraft:anvil"
|
||||
9 -> "minecraft:hopper"
|
||||
10 -> "minecraft:dropper"
|
||||
11 -> "EntityHorse"
|
||||
else -> "minecraft:chest"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.chunks
|
||||
|
||||
import com.viaversion.aas.readByteArray
|
||||
import com.viaversion.aas.readRemainingBytes
|
||||
import io.netty.buffer.ByteBufAllocator
|
||||
import io.netty.buffer.Unpooled
|
||||
|
||||
class Chunk1_8to1_7_6_10(
|
||||
data: ByteArray,
|
||||
private val primaryBitMask: Int,
|
||||
additionalBitMask: Int,
|
||||
private val skyLight: Boolean,
|
||||
private val groundUp: Boolean
|
||||
) {
|
||||
var storageSections = arrayOfNulls<ExtendedBlockStorage>(16)
|
||||
var blockBiomeArray = ByteArray(256)
|
||||
|
||||
fun filterChunk(storageArray: ExtendedBlockStorage?, i: Int) =
|
||||
storageArray != null && (primaryBitMask.and(1 shl i) != 0)
|
||||
&& (!groundUp || storageArray.isEmpty)
|
||||
|
||||
fun get1_8Data(): ByteArray {
|
||||
val buf = ByteBufAllocator.DEFAULT.buffer()
|
||||
try {
|
||||
val filteredChunks = storageSections.filterIndexed { i, value -> filterChunk(value, i) }.filterNotNull()
|
||||
filteredChunks.forEach {
|
||||
val blockIds = it.blockLSBArray
|
||||
val nibblearray = it.metadataArray
|
||||
for (iBlock in blockIds.indices) {
|
||||
val id = blockIds[iBlock].toInt() and 0xFF
|
||||
val x = iBlock and 0xF
|
||||
val y = iBlock.shr(8).and(0xF)
|
||||
val z = iBlock.shr(4).and(0xF)
|
||||
val data = nibblearray[x, y, z].toInt()
|
||||
|
||||
//data = SpigotDebreakifier.getCorrectedData(id, data);
|
||||
buf.writeShortLE(id.shl(4).or(data))
|
||||
}
|
||||
}
|
||||
filteredChunks.forEach {
|
||||
buf.writeBytes(it.blocklightArray.handle)
|
||||
}
|
||||
if (skyLight) {
|
||||
filteredChunks.forEach {
|
||||
buf.writeBytes(it.skylightArray!!.handle)
|
||||
}
|
||||
}
|
||||
if (groundUp) {
|
||||
buf.writeBytes(blockBiomeArray)
|
||||
}
|
||||
return readRemainingBytes(buf)
|
||||
} finally {
|
||||
buf.release()
|
||||
}
|
||||
}
|
||||
|
||||
fun filterBitmask(bitmask: Int, i: Int) = (bitmask and (1 shl i)) != 0
|
||||
|
||||
init {
|
||||
val input = Unpooled.wrappedBuffer(data)
|
||||
for (i in storageSections.indices) {
|
||||
if (filterBitmask(primaryBitMask, i)) {
|
||||
var storageSection = storageSections[i]
|
||||
if (storageSection == null) {
|
||||
storageSection = ExtendedBlockStorage(i shl 4, skyLight)
|
||||
storageSections[i] = storageSection
|
||||
}
|
||||
storageSection.blockLSBArray = input.readByteArray(4096)
|
||||
} else if (storageSections[i] != null && groundUp) {
|
||||
storageSections[i] = null
|
||||
}
|
||||
}
|
||||
for (i in storageSections.indices) {
|
||||
if (filterBitmask(primaryBitMask, i) && storageSections[i] != null) {
|
||||
storageSections[i]!!.metadataArray.handle = input.readByteArray(4096 / 2)
|
||||
}
|
||||
}
|
||||
for (i in storageSections.indices) {
|
||||
if (filterBitmask(primaryBitMask, i) && storageSections[i] != null) {
|
||||
storageSections[i]!!.blocklightArray.handle = input.readByteArray(4096 / 2)
|
||||
}
|
||||
}
|
||||
if (skyLight) {
|
||||
for (i in storageSections.indices) {
|
||||
if (filterBitmask(primaryBitMask, i) && storageSections[i] != null) {
|
||||
storageSections[i]!!.skylightArray!!.handle = input.readByteArray(4096 / 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i in storageSections.indices) {
|
||||
if (filterBitmask(additionalBitMask, i)) {
|
||||
if (storageSections[i] == null) {
|
||||
input.skipBytes(2048)
|
||||
} else {
|
||||
val msbArray = storageSections[i]!!.blockMSBArray ?: storageSections[i]!!.createBlockMSBArray()
|
||||
msbArray.handle = input.readByteArray(4096 / 2)
|
||||
}
|
||||
} else if (groundUp && storageSections[i] != null && storageSections[i]!!.blockMSBArray != null) {
|
||||
storageSections[i]!!.clearMSBArray()
|
||||
}
|
||||
}
|
||||
if (groundUp) {
|
||||
blockBiomeArray = input.readByteArray(256)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.chunks
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
import com.viaversion.viaversion.api.type.types.CustomByteType
|
||||
import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl
|
||||
import io.netty.buffer.ByteBufAllocator
|
||||
import io.netty.buffer.Unpooled
|
||||
import java.util.stream.IntStream
|
||||
import java.util.zip.Inflater
|
||||
import kotlin.streams.toList
|
||||
|
||||
object ChunkPacketTransformer {
|
||||
@Throws(Exception::class)
|
||||
fun transformChunk(packetWrapper: PacketWrapper) {
|
||||
val chunkX = packetWrapper.read(Type.INT)
|
||||
val chunkZ = packetWrapper.read(Type.INT)
|
||||
val groundUp = packetWrapper.read(Type.BOOLEAN)
|
||||
val primaryBitMask = packetWrapper.read(Type.SHORT).toInt()
|
||||
val addBitMask = packetWrapper.read(Type.SHORT).toInt()
|
||||
val compressedSize = packetWrapper.read(Type.INT)
|
||||
val customByteType = CustomByteType(compressedSize)
|
||||
val data = packetWrapper.read(customByteType)
|
||||
var countOfPrimary = 0
|
||||
var countOfAdditional = 0
|
||||
for (j in 0..15) {
|
||||
countOfPrimary += primaryBitMask.shr(j).and(1)
|
||||
countOfAdditional += addBitMask.shr(j).and(1)
|
||||
}
|
||||
var uncompressedSize = 12288 * countOfPrimary
|
||||
uncompressedSize += 2048 * countOfAdditional
|
||||
if (groundUp) {
|
||||
uncompressedSize += 256
|
||||
}
|
||||
val uncompressedData = ByteArray(uncompressedSize)
|
||||
val inflater = Inflater()
|
||||
inflater.setInput(data, 0, compressedSize)
|
||||
try {
|
||||
inflater.inflate(uncompressedData)
|
||||
} finally {
|
||||
inflater.end()
|
||||
}
|
||||
val chunk = Chunk1_8to1_7_6_10(uncompressedData, primaryBitMask, addBitMask, true, groundUp)
|
||||
|
||||
packetWrapper.clearPacket()
|
||||
val buffer = (packetWrapper as PacketWrapperImpl).inputBuffer!!
|
||||
|
||||
buffer.clear()
|
||||
buffer.writeInt(chunkX)
|
||||
buffer.writeInt(chunkZ)
|
||||
buffer.writeBoolean(groundUp)
|
||||
buffer.writeShort(primaryBitMask)
|
||||
val finalData = chunk.get1_8Data()
|
||||
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, finalData)
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun transformChunkBulk(packetWrapper: PacketWrapper) {
|
||||
val columnCount = packetWrapper.read(Type.SHORT).toInt()
|
||||
val compressedSize = packetWrapper.read(Type.INT)
|
||||
val skyLightSent = packetWrapper.read(Type.BOOLEAN)
|
||||
val chunkX = IntArray(columnCount)
|
||||
val chunkZ = IntArray(columnCount)
|
||||
val primaryBitMask = IntArray(columnCount)
|
||||
val compressedData = packetWrapper.read(CustomByteType(compressedSize))
|
||||
|
||||
val decompressedData = ByteArray(196864 * columnCount)
|
||||
val inflater = Inflater()
|
||||
try {
|
||||
inflater.setInput(compressedData)
|
||||
inflater.inflate(decompressedData)
|
||||
} finally {
|
||||
inflater.end()
|
||||
}
|
||||
|
||||
val decompressedBuf = Unpooled.wrappedBuffer(decompressedData)
|
||||
|
||||
val chunks = arrayOfNulls<Chunk1_8to1_7_6_10>(columnCount)
|
||||
|
||||
for (column in 0 until columnCount) {
|
||||
chunkX[column] = packetWrapper.read(Type.INT)
|
||||
chunkZ[column] = packetWrapper.read(Type.INT)
|
||||
primaryBitMask[column] = packetWrapper.read(Type.SHORT).toInt()
|
||||
val addBitMask = packetWrapper.read(Type.SHORT).toInt()
|
||||
|
||||
var primaryCount = 0
|
||||
var secondaryCount = 0
|
||||
for (chunkY in 0 until 16) {
|
||||
primaryCount += primaryBitMask[column].shr(chunkY).and(1)
|
||||
secondaryCount += addBitMask.shr(chunkY).and(1)
|
||||
}
|
||||
|
||||
var copySize = 8192 * primaryCount + 256
|
||||
copySize += 2048 * secondaryCount
|
||||
if (skyLightSent) {
|
||||
copySize += 2048 * primaryCount
|
||||
}
|
||||
|
||||
val columnData = ByteArray(copySize)
|
||||
decompressedBuf.readBytes(columnData)
|
||||
|
||||
chunks[column] = Chunk1_8to1_7_6_10(
|
||||
columnData, primaryBitMask[column],
|
||||
addBitMask, skyLightSent, true
|
||||
)
|
||||
}
|
||||
|
||||
packetWrapper.write(Type.BOOLEAN, skyLightSent)
|
||||
packetWrapper.write(Type.VAR_INT, columnCount)
|
||||
|
||||
for (column in 0 until columnCount) {
|
||||
packetWrapper.write(Type.INT, chunkX[column])
|
||||
packetWrapper.write(Type.INT, chunkZ[column])
|
||||
packetWrapper.write(Type.UNSIGNED_SHORT, primaryBitMask[column])
|
||||
}
|
||||
|
||||
for (column in 0 until columnCount) {
|
||||
val columnData = chunks[column]!!.get1_8Data()
|
||||
packetWrapper.write(CustomByteType(columnData.size), columnData)
|
||||
}
|
||||
|
||||
val buffer = ByteBufAllocator.DEFAULT.buffer()
|
||||
try {
|
||||
packetWrapper.writeToBuffer(buffer)
|
||||
Type.VAR_INT.readPrimitive(buffer) // packet id
|
||||
packetWrapper.clearPacket()
|
||||
|
||||
(packetWrapper as PacketWrapperImpl).inputBuffer!!.writeBytes(buffer)
|
||||
} finally {
|
||||
buffer.release()
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun transformMultiBlockChange(packetWrapper: PacketWrapper) {
|
||||
val chunkX = packetWrapper.read(Type.INT)
|
||||
val chunkZ = packetWrapper.read(Type.INT)
|
||||
val size = packetWrapper.read(Type.SHORT).toInt()
|
||||
packetWrapper.read(Type.INT)
|
||||
val blocks = ShortArray(size)
|
||||
val positions = ShortArray(size)
|
||||
for (i in 0 until size) {
|
||||
positions[i] = packetWrapper.read(Type.SHORT)
|
||||
blocks[i] = packetWrapper.read(Type.SHORT)
|
||||
}
|
||||
packetWrapper.write(Type.INT, chunkX)
|
||||
packetWrapper.write(Type.INT, chunkZ)
|
||||
packetWrapper.write(
|
||||
Type.BLOCK_CHANGE_RECORD_ARRAY, IntStream.range(0, size)
|
||||
.mapToObj {
|
||||
val encodedPos = (positions[it].toInt())
|
||||
val x = encodedPos.ushr(12).and(0xF)
|
||||
val y = encodedPos.and(0xFF)
|
||||
val z = encodedPos.ushr(8).and(0xF)
|
||||
BlockChangeRecord1_8(x, y, z, blocks[it].toInt())
|
||||
}.toList().toTypedArray()
|
||||
)
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.chunks
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.NibbleArray
|
||||
|
||||
class ExtendedBlockStorage(val yLocation: Int, hasSkyLight: Boolean) {
|
||||
var blockLSBArray: ByteArray = ByteArray(4096)
|
||||
var blockMSBArray: NibbleArray? = null
|
||||
var metadataArray: NibbleArray
|
||||
private set
|
||||
var blocklightArray: NibbleArray
|
||||
var skylightArray: NibbleArray? = null
|
||||
fun getExtBlockMetadata(paramInt1: Int, paramInt2: Int, paramInt3: Int): Int {
|
||||
return metadataArray[paramInt1, paramInt2, paramInt3].toInt()
|
||||
}
|
||||
|
||||
fun setExtBlockMetadata(paramInt1: Int, paramInt2: Int, paramInt3: Int, paramInt4: Int) {
|
||||
metadataArray[paramInt1, paramInt2, paramInt3] = paramInt4
|
||||
}
|
||||
|
||||
fun setExtSkylightValue(paramInt1: Int, paramInt2: Int, paramInt3: Int, paramInt4: Int) {
|
||||
skylightArray!![paramInt1, paramInt2, paramInt3] = paramInt4
|
||||
}
|
||||
|
||||
fun getExtSkylightValue(paramInt1: Int, paramInt2: Int, paramInt3: Int): Int {
|
||||
return skylightArray!![paramInt1, paramInt2, paramInt3].toInt()
|
||||
}
|
||||
|
||||
fun setExtBlocklightValue(paramInt1: Int, paramInt2: Int, paramInt3: Int, paramInt4: Int) {
|
||||
blocklightArray[paramInt1, paramInt2, paramInt3] = paramInt4
|
||||
}
|
||||
|
||||
fun getExtBlocklightValue(paramInt1: Int, paramInt2: Int, paramInt3: Int): Int {
|
||||
return blocklightArray[paramInt1, paramInt2, paramInt3].toInt()
|
||||
}
|
||||
|
||||
val isEmpty: Boolean
|
||||
get() = blockMSBArray == null
|
||||
|
||||
fun clearMSBArray() {
|
||||
blockMSBArray = null
|
||||
}
|
||||
|
||||
fun setBlockMetadataArray(paramNibbleArray: NibbleArray) {
|
||||
metadataArray = paramNibbleArray
|
||||
}
|
||||
|
||||
fun createBlockMSBArray(): NibbleArray {
|
||||
blockMSBArray = NibbleArray(blockLSBArray.size)
|
||||
return blockMSBArray!!
|
||||
}
|
||||
|
||||
init {
|
||||
metadataArray = NibbleArray(blockLSBArray.size)
|
||||
blocklightArray = NibbleArray(blockLSBArray.size)
|
||||
if (hasSkyLight) {
|
||||
skylightArray = NibbleArray(blockLSBArray.size)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.data
|
||||
|
||||
enum class Particle1_8to1_7 constructor(val identifier: String, val extra: Int = 0) {
|
||||
EXPLOSION_NORMAL("explode"),
|
||||
EXPLOSION_LARGE("largeexplode"),
|
||||
EXPLOSION_HUGE("hugeexplosion"),
|
||||
FIREWORKS_SPARK("fireworksSpark"),
|
||||
WATER_BUBBLE("bubble"),
|
||||
WATER_SPLASH("splash"),
|
||||
WATER_WAKE("wake"),
|
||||
SUSPENDED("suspended"),
|
||||
SUSPENDED_DEPTH("depthsuspend"),
|
||||
CRIT("crit"),
|
||||
CRIT_MAGIC("magicCrit"),
|
||||
SMOKE_NORMAL("smoke"),
|
||||
SMOKE_LARGE("largesmoke"),
|
||||
SPELL("spell"),
|
||||
SPELL_INSTANT("instantSpell"),
|
||||
SPELL_MOB("mobSpell"),
|
||||
SPELL_MOB_AMBIENT("mobSpellAmbient"),
|
||||
SPELL_WITCH("witchMagic"),
|
||||
DRIP_WATER("dripWater"),
|
||||
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");
|
||||
|
||||
companion object {
|
||||
private val particleMap = HashMap<String, Particle1_8to1_7>()
|
||||
fun find(part: String): Particle1_8to1_7? {
|
||||
return particleMap[part]
|
||||
}
|
||||
|
||||
init {
|
||||
val particles = values()
|
||||
particles.forEach { particle ->
|
||||
particleMap[particle.identifier] = particle
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.metadata
|
||||
|
||||
import com.viaversion.viaversion.api.Via
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8
|
||||
import de.gerrygames.viarewind.protocol.protocol1_8to1_7_6_10.metadata.MetaIndex1_8to1_7_6_10
|
||||
|
||||
object MetadataRewriter {
|
||||
fun transform(type: Entity1_10Types.EntityType?, list: MutableList<Metadata>) {
|
||||
for (entry in ArrayList(list)) {
|
||||
try {
|
||||
val oldValue = entry.value
|
||||
val metaIndex = MetaIndex1_8to1_7_6_10.searchIndex(type, entry.id())
|
||||
|
||||
if (metaIndex == null || metaIndex.newType == MetaType1_8.NonExistent) {
|
||||
list.remove(entry)
|
||||
continue
|
||||
}
|
||||
|
||||
entry.setId(metaIndex.newIndex)
|
||||
val newValue = when (metaIndex.newType) {
|
||||
MetaType1_8.Byte -> {
|
||||
var byteValue = (oldValue as Number).toByte()
|
||||
|
||||
if (metaIndex == MetaIndex1_8to1_7_6_10.HUMAN_SKIN_FLAGS) {
|
||||
val cape = byteValue.toInt() == 2
|
||||
byteValue = (if (cape) 127 else 125).toByte()
|
||||
}
|
||||
byteValue
|
||||
}
|
||||
MetaType1_8.Int -> (oldValue as Number).toInt()
|
||||
MetaType1_8.Short -> (oldValue as Number).toShort()
|
||||
MetaType1_8.Float -> (oldValue as Number).toFloat()
|
||||
MetaType1_8.String -> oldValue.toString()
|
||||
MetaType1_8.Slot, MetaType1_8.Position, MetaType1_8.Rotation -> oldValue
|
||||
else -> throw Exception("unknown metatype ${metaIndex.newType}")
|
||||
}
|
||||
entry.setTypeAndValue(metaIndex.newType, newValue)
|
||||
} catch (e: Exception) {
|
||||
if (!Via.getPlatform().conf.isSuppressMetadataErrors) {
|
||||
Via.getPlatform().logger.warning("Metadata Exception: $e $list")
|
||||
}
|
||||
list.remove(entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,373 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.packets
|
||||
|
||||
import com.viaversion.aas.protocol.id47toid5.Protocol1_8To1_7_6
|
||||
import com.viaversion.aas.protocol.id47toid5.metadata.MetadataRewriter
|
||||
import com.viaversion.aas.protocol.id47toid5.storage.EntityTracker
|
||||
import com.viaversion.aas.protocol.id47toid5.type.CustomIntType
|
||||
import com.viaversion.aas.protocol.xyzToPosition
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper
|
||||
import com.viaversion.viaversion.api.protocol.remapper.TypeRemapper
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_8
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10
|
||||
import kotlin.experimental.and
|
||||
|
||||
fun Protocol1_8To1_7_6.registerEntityPackets() {
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_EQUIPMENT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.SHORT) //Slot
|
||||
map(Types1_7_6_10.COMPRESSED_NBT_ITEM, Type.ITEM) //Item
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_ANIMATION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val entityId = packetWrapper.read(Type.VAR_INT) //Entity Id
|
||||
val animation = packetWrapper.read(Type.UNSIGNED_BYTE) //Animation
|
||||
packetWrapper.clearInputBuffer()
|
||||
if (animation.toInt() == 104 || animation.toInt() == 105) {
|
||||
packetWrapper.packetType = ClientboundPackets1_8.ENTITY_METADATA
|
||||
packetWrapper.write(Type.VAR_INT, entityId) //Entity Id
|
||||
packetWrapper.write(Type.UNSIGNED_BYTE, 0.toShort()) //Index
|
||||
packetWrapper.write(Type.UNSIGNED_BYTE, 0.toShort()) //Type
|
||||
packetWrapper.write(
|
||||
Type.BYTE,
|
||||
(if (animation.toInt() == 104) 0x02 else 0x00).toByte()
|
||||
) //Value (sneaking/not sneaking)
|
||||
packetWrapper.write(Type.UNSIGNED_BYTE, 255.toShort()) //end
|
||||
} else {
|
||||
packetWrapper.write(Type.VAR_INT, entityId) //Entity Id
|
||||
packetWrapper.write(Type.UNSIGNED_BYTE, animation) //Animation
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.COLLECT_ITEM, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Collected Entity ID
|
||||
map(Type.INT, Type.VAR_INT) //Collector Entity ID
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_ENTITY, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT) // id
|
||||
map(Type.BYTE) // type
|
||||
map(Type.INT) // x
|
||||
map(Type.INT) // y
|
||||
map(Type.INT) // z
|
||||
map(Type.BYTE) // pitch
|
||||
map(Type.BYTE) // yaw
|
||||
map(Type.INT) // data
|
||||
handler { packetWrapper ->
|
||||
val type = packetWrapper.get(Type.BYTE, 0)
|
||||
var x = packetWrapper.get(Type.INT, 0)
|
||||
var y = packetWrapper.get(Type.INT, 1)
|
||||
var z = packetWrapper.get(Type.INT, 2)
|
||||
var yaw = packetWrapper.get(Type.BYTE, 2)
|
||||
var data = packetWrapper.get(Type.INT, 3)
|
||||
if (type.toInt() == 71) {
|
||||
when (data) {
|
||||
0 -> {
|
||||
z += 32
|
||||
yaw = 0
|
||||
}
|
||||
1 -> {
|
||||
x -= 32
|
||||
yaw = 64.toByte()
|
||||
}
|
||||
2 -> {
|
||||
z -= 32
|
||||
yaw = 128.toByte()
|
||||
}
|
||||
3 -> {
|
||||
x += 32
|
||||
yaw = 192.toByte()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type.toInt() == 70) {
|
||||
val id = data
|
||||
val metadata = data shr 16
|
||||
data = id.or(metadata shl 12)
|
||||
}
|
||||
if (type.toInt() == 50 || type.toInt() == 70 || type.toInt() == 74) y -= 16
|
||||
packetWrapper.set(Type.INT, 0, x)
|
||||
packetWrapper.set(Type.INT, 1, y)
|
||||
packetWrapper.set(Type.INT, 2, z)
|
||||
packetWrapper.set(Type.BYTE, 2, yaw)
|
||||
packetWrapper.set(Type.INT, 3, data)
|
||||
}
|
||||
handler { packetWrapper ->
|
||||
val entityID = packetWrapper.get(Type.VAR_INT, 0)
|
||||
val typeID = packetWrapper.get(Type.BYTE, 0).toInt()
|
||||
val tracker = packetWrapper.user().get(EntityTracker::class.java)!!
|
||||
val type: Entity1_10Types.EntityType = Entity1_10Types.getTypeFromId(typeID, true)
|
||||
tracker.addEntity(entityID, type)
|
||||
tracker.flushMetadataBuffer(entityID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_MOB, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT)
|
||||
map(Type.UNSIGNED_BYTE)
|
||||
map(Type.INT)
|
||||
map(Type.INT)
|
||||
map(Type.INT)
|
||||
map(Type.BYTE)
|
||||
map(Type.BYTE)
|
||||
map(Type.BYTE)
|
||||
map(Type.SHORT)
|
||||
map(Type.SHORT)
|
||||
map(Type.SHORT)
|
||||
map(Types1_7_6_10.METADATA_LIST, Types1_8.METADATA_LIST)
|
||||
handler { packetWrapper ->
|
||||
val entityID: Int = packetWrapper.get(Type.VAR_INT, 0)
|
||||
val typeID = packetWrapper.get(Type.UNSIGNED_BYTE, 0).toInt()
|
||||
val tracker = packetWrapper.user().get(EntityTracker::class.java)!!
|
||||
tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, false))
|
||||
tracker.flushMetadataBuffer(entityID)
|
||||
|
||||
val metadataList = packetWrapper.get(Types1_8.METADATA_LIST, 0)
|
||||
MetadataRewriter.transform(tracker.getType(entityID), metadataList)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_PAINTING, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT) //Entity Id
|
||||
map(Type.STRING) //Title
|
||||
map(xyzToPosition, TypeRemapper(Type.POSITION)) //Position
|
||||
map(Type.INT, Type.BYTE) //Rotation
|
||||
handler { packetWrapper ->
|
||||
val entityID = packetWrapper.get(Type.VAR_INT, 0)
|
||||
val tracker = packetWrapper.user().get(EntityTracker::class.java)!!
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.PAINTING)
|
||||
tracker.flushMetadataBuffer(entityID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_EXPERIENCE_ORB, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT)
|
||||
map(Type.INT)
|
||||
map(Type.INT)
|
||||
map(Type.INT)
|
||||
map(Type.SHORT)
|
||||
handler { packetWrapper ->
|
||||
val entityID: Int = packetWrapper.get(Type.VAR_INT, 0)
|
||||
val tracker = packetWrapper.user().get(EntityTracker::class.java)!!
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.EXPERIENCE_ORB)
|
||||
tracker.flushMetadataBuffer(entityID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_VELOCITY, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.SHORT) //velX
|
||||
map(Type.SHORT) //velY
|
||||
map(Type.SHORT) //velZ
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.DESTROY_ENTITIES, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val amount = packetWrapper.read(Type.BYTE).toInt()
|
||||
val customIntType = CustomIntType(amount)
|
||||
val entityIds = packetWrapper.read(customIntType)
|
||||
packetWrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, entityIds)
|
||||
} //Entity Id Array
|
||||
handler { packetWrapper ->
|
||||
val tracker = packetWrapper.user().get(EntityTracker::class.java)!!
|
||||
for (entityId in packetWrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0)) tracker.removeEntity(entityId)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_MOVEMENT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_POSITION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.BYTE) //x
|
||||
map(Type.BYTE) //y
|
||||
map(Type.BYTE) //z
|
||||
create(Type.BOOLEAN, true) //OnGround
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_ROTATION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.BYTE) //yaw
|
||||
map(Type.BYTE) //pitch
|
||||
create(Type.BOOLEAN, true) //OnGround
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_POSITION_AND_ROTATION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.BYTE) //x
|
||||
map(Type.BYTE) //y
|
||||
map(Type.BYTE) //z
|
||||
map(Type.BYTE) //yaw
|
||||
map(Type.BYTE) //pitch
|
||||
create(Type.BOOLEAN, true) //OnGround
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_TELEPORT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.INT) //x
|
||||
map(Type.INT) //y
|
||||
map(Type.INT) //z
|
||||
map(Type.BYTE) //yaw
|
||||
map(Type.BYTE) //pitch
|
||||
create(Type.BOOLEAN, true) //OnGround
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_HEAD_LOOK, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.BYTE) //Head yaw
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_METADATA, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Types1_7_6_10.METADATA_LIST, Types1_8.METADATA_LIST) //MetadataType
|
||||
handler { wrapper ->
|
||||
val metadataList = wrapper.get(Types1_8.METADATA_LIST, 0)
|
||||
val entityID: Int = wrapper.get(Type.VAR_INT, 0)
|
||||
val tracker = wrapper.user().get(EntityTracker::class.java)!!
|
||||
if (tracker.hasEntity(entityID)) {
|
||||
MetadataRewriter.transform(tracker.getType(entityID), metadataList)
|
||||
if (metadataList.isEmpty()) wrapper.cancel()
|
||||
} else {
|
||||
tracker.addMetadataToBuffer(entityID, metadataList)
|
||||
wrapper.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_EFFECT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.BYTE) //Effect Id
|
||||
map(Type.BYTE) //Amplifier
|
||||
map(Type.SHORT, Type.VAR_INT) //Duration
|
||||
create(Type.BOOLEAN, false) //Hide Particles
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.REMOVE_ENTITY_EFFECT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(Type.BYTE) //Effect Id
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.ENTITY_PROPERTIES, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
handler { packetWrapper ->
|
||||
val amount: Int = packetWrapper.read(Type.INT)
|
||||
packetWrapper.write(Type.INT, amount)
|
||||
for (i in 0 until amount) {
|
||||
packetWrapper.passthrough(Type.STRING)
|
||||
packetWrapper.passthrough(Type.DOUBLE)
|
||||
val modifierlength = packetWrapper.read(Type.SHORT).toInt()
|
||||
packetWrapper.write(Type.VAR_INT, modifierlength)
|
||||
for (j in 0 until modifierlength) {
|
||||
packetWrapper.passthrough(Type.UUID)
|
||||
packetWrapper.passthrough(Type.DOUBLE)
|
||||
packetWrapper.passthrough(Type.BYTE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_GLOBAL_ENTITY, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT)
|
||||
map(Type.BYTE)
|
||||
map(Type.INT)
|
||||
map(Type.INT)
|
||||
map(Type.INT)
|
||||
handler { packetWrapper ->
|
||||
val entityID: Int = packetWrapper.get(Type.VAR_INT, 0)
|
||||
val tracker = packetWrapper.user().get(EntityTracker::class.java)!!
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.LIGHTNING)
|
||||
tracker.flushMetadataBuffer(entityID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.INTERACT_ENTITY, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT, Type.INT)
|
||||
handler { packetWrapper ->
|
||||
val mode: Int = packetWrapper.read(Type.VAR_INT)
|
||||
if (mode == 2) {
|
||||
packetWrapper.write(Type.BYTE, 0.toByte())
|
||||
packetWrapper.read(Type.FLOAT)
|
||||
packetWrapper.read(Type.FLOAT)
|
||||
packetWrapper.read(Type.FLOAT)
|
||||
} else {
|
||||
packetWrapper.write(Type.BYTE, mode.toByte())
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.ENTITY_ACTION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT, Type.INT) //Entity Id
|
||||
handler { packetWrapper ->
|
||||
packetWrapper.write(
|
||||
Type.BYTE,
|
||||
(packetWrapper.read(Type.VAR_INT) + 1).toByte()
|
||||
)
|
||||
} //Action Id
|
||||
map(Type.VAR_INT, Type.INT) //Action Paramter
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.STEER_VEHICLE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.FLOAT) //Sideways
|
||||
map(Type.FLOAT) //Forwards
|
||||
handler { packetWrapper ->
|
||||
val flags = packetWrapper.read(Type.UNSIGNED_BYTE)
|
||||
packetWrapper.write(Type.BOOLEAN, flags and 1 == 1.toShort()) //Jump
|
||||
packetWrapper.write(Type.BOOLEAN, flags and 2 == 2.toShort()) //Unmount
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.packets
|
||||
|
||||
import com.viaversion.aas.protocol.id47toid5.Protocol1_8To1_7_6
|
||||
import com.viaversion.aas.protocol.id47toid5.storage.Windows
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.Component
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10
|
||||
|
||||
fun Protocol1_8To1_7_6.registerInventoryPackets() {
|
||||
this.registerClientbound(ClientboundPackets1_7.OPEN_WINDOW, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.UNSIGNED_BYTE)
|
||||
handler { packetWrapper ->
|
||||
val windowId = packetWrapper.get(Type.UNSIGNED_BYTE, 0)
|
||||
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
|
||||
val title = packetWrapper.read(Type.STRING) //Title
|
||||
val slots = packetWrapper.read(Type.UNSIGNED_BYTE)
|
||||
val useProvidedWindowTitle = packetWrapper.read(Type.BOOLEAN) //Use provided window title
|
||||
val convertedTitle = GsonComponentSerializer.gson().serialize(
|
||||
if (useProvidedWindowTitle) {
|
||||
LegacyComponentSerializer.legacySection().deserialize(title)
|
||||
} else {
|
||||
Component.translatable(title) // todo
|
||||
}
|
||||
)
|
||||
packetWrapper.write(Type.STRING, convertedTitle) //Window title
|
||||
packetWrapper.write(Type.UNSIGNED_BYTE, slots)
|
||||
if (windowType == 11.toShort()) packetWrapper.passthrough(Type.INT) //Entity Id
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SET_SLOT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.UNSIGNED_BYTE) // window id
|
||||
map(Type.SHORT) // window type
|
||||
handler { packetWrapper ->
|
||||
val windowId = packetWrapper.get(Type.UNSIGNED_BYTE, 0) //Window Id
|
||||
val windowType = packetWrapper.user().get(Windows::class.java)!!.get(windowId)
|
||||
val slot = packetWrapper.get(Type.SHORT, 0).toInt()
|
||||
if (windowType.toInt() == 4 && slot >= 1) {
|
||||
packetWrapper.set(Type.SHORT, 0, (slot + 1).toShort())
|
||||
}
|
||||
}
|
||||
map(Types1_7_6_10.COMPRESSED_NBT_ITEM, Type.ITEM) //Item
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.WINDOW_ITEMS, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.UNSIGNED_BYTE) //Window Id
|
||||
handler { packetWrapper ->
|
||||
val windowId = packetWrapper.get(Type.UNSIGNED_BYTE, 0)
|
||||
val windowType = packetWrapper.user().get(Windows::class.java)!![windowId]
|
||||
var items = packetWrapper.read(Types1_7_6_10.COMPRESSED_NBT_ITEM_ARRAY)
|
||||
if (windowType.toInt() == 4) {
|
||||
val old = items
|
||||
items = arrayOfNulls(old.size + 1)
|
||||
items[0] = old[0]
|
||||
System.arraycopy(old, 1, items, 2, old.size - 1)
|
||||
items[1] = DataItem(351, 3.toByte(), 4.toShort(), null)
|
||||
}
|
||||
packetWrapper.write(Type.ITEM_ARRAY, items) //Items
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.CLICK_WINDOW, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val windowId = packetWrapper.read(Type.UNSIGNED_BYTE) //Window Id
|
||||
packetWrapper.write(Type.BYTE, windowId.toByte())
|
||||
val windowType = packetWrapper.user().get(Windows::class.java)!![windowId]
|
||||
var slot = packetWrapper.read(Type.SHORT).toInt()
|
||||
if (windowType.toInt() == 4) {
|
||||
if (slot == 1) {
|
||||
packetWrapper.cancel()
|
||||
} else if (slot > 1) {
|
||||
slot -= 1
|
||||
}
|
||||
}
|
||||
packetWrapper.write(Type.SHORT, slot.toShort()) //Slot
|
||||
}
|
||||
map(Type.BYTE) //Button
|
||||
map(Type.SHORT) //Action Number
|
||||
map(Type.BYTE) //Mode
|
||||
map(Type.ITEM, Types1_7_6_10.COMPRESSED_NBT_ITEM)
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.CREATIVE_INVENTORY_ACTION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.SHORT) //Slot
|
||||
map(Type.ITEM, Types1_7_6_10.COMPRESSED_NBT_ITEM) //Item
|
||||
}
|
||||
})
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.packets
|
||||
|
||||
import com.viaversion.aas.protocol.id47toid5.Protocol1_8To1_7_6
|
||||
import com.viaversion.viaversion.api.protocol.packet.State
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
|
||||
fun Protocol1_8To1_7_6.registerLoginPackets() {
|
||||
//Encryption Request
|
||||
this.registerClientbound(State.LOGIN, 0x01, 0x01, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.STRING) //Server ID
|
||||
map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE)
|
||||
map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE)
|
||||
}
|
||||
})
|
||||
|
||||
//Encryption Response
|
||||
this.registerServerbound(State.LOGIN, 0x01, 0x01, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.BYTE_ARRAY_PRIMITIVE, Type.SHORT_BYTE_ARRAY)
|
||||
map(Type.BYTE_ARRAY_PRIMITIVE, Type.SHORT_BYTE_ARRAY)
|
||||
}
|
||||
})
|
||||
}
|
@ -1,474 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.packets
|
||||
|
||||
import com.google.common.base.Charsets
|
||||
import com.viaversion.aas.generateOfflinePlayerUuid
|
||||
import com.viaversion.aas.protocol.id47toid5.Protocol1_8To1_7_6
|
||||
import com.viaversion.aas.protocol.id47toid5.metadata.MetadataRewriter
|
||||
import com.viaversion.aas.protocol.id47toid5.storage.EntityTracker
|
||||
import com.viaversion.aas.protocol.id47toid5.storage.Scoreboard
|
||||
import com.viaversion.aas.protocol.id47toid5.storage.Tablist
|
||||
import com.viaversion.aas.protocol.xyzToPosition
|
||||
import com.viaversion.aas.protocol.xyzUBytePos
|
||||
import com.viaversion.aas.util.SignableProperty
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper
|
||||
import com.viaversion.viaversion.api.protocol.remapper.TypeRemapper
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
import com.viaversion.viaversion.api.type.types.CustomByteType
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_8
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8
|
||||
import com.viaversion.viaversion.util.ChatColorUtil
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.CustomStringType
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10
|
||||
import de.gerrygames.viarewind.utils.ChatUtil
|
||||
import io.netty.buffer.Unpooled
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.*
|
||||
import kotlin.experimental.and
|
||||
|
||||
fun Protocol1_8To1_7_6.registerPlayerPackets() {
|
||||
this.registerClientbound(ClientboundPackets1_7.KEEP_ALIVE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT)
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.JOIN_GAME, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT) //Entiy Id
|
||||
map(Type.UNSIGNED_BYTE) //Gamemode
|
||||
map(Type.BYTE) //Dimension
|
||||
map(Type.UNSIGNED_BYTE) //Difficulty
|
||||
map(Type.UNSIGNED_BYTE) //Max players
|
||||
map(Type.STRING) //Level Type
|
||||
create(Type.BOOLEAN, false) //Reduced Debug Info
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.CHAT_MESSAGE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.STRING) //Chat Message
|
||||
create(Type.BYTE, 0.toByte()) //Position (chat box)
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_POSITION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(xyzToPosition, TypeRemapper(Type.POSITION)) //Position
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.UPDATE_HEALTH, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.FLOAT) //Health
|
||||
map(Type.SHORT, Type.VAR_INT) //Food
|
||||
map(Type.FLOAT) //Food Saturation
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.PLAYER_POSITION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.DOUBLE) //x
|
||||
handler { packetWrapper ->
|
||||
val y = packetWrapper.read(Type.DOUBLE)
|
||||
packetWrapper.write(Type.DOUBLE, y - 1.62) //y - fixed value
|
||||
}
|
||||
map(Type.DOUBLE) //z
|
||||
map(Type.FLOAT) //pitch
|
||||
map(Type.FLOAT) //yaw
|
||||
handler { packetWrapper ->
|
||||
packetWrapper.read(Type.BOOLEAN) //OnGround
|
||||
packetWrapper.write(Type.BYTE, 0.toByte()) //BitMask
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.USE_BED, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT, Type.VAR_INT) //Entity Id
|
||||
map(xyzUBytePos, TypeRemapper(Type.POSITION))
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_PLAYER, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val entityId = packetWrapper.passthrough(Type.VAR_INT) //Entity Id
|
||||
val uuid = UUID.fromString(packetWrapper.read(Type.STRING)) //UUID
|
||||
packetWrapper.write(Type.UUID, uuid)
|
||||
val name = ChatColorUtil.stripColor(packetWrapper.read(Type.STRING)) //Name
|
||||
val dataCount = packetWrapper.read(Type.VAR_INT) //DataCunt
|
||||
val properties = ArrayList<SignableProperty>()
|
||||
for (i in 0 until dataCount) {
|
||||
val key: String = packetWrapper.read(Type.STRING) //Name
|
||||
val value: String = packetWrapper.read(Type.STRING) //Value
|
||||
val signature: String = packetWrapper.read(Type.STRING) //Signature
|
||||
properties.add(SignableProperty(key, value, signature))
|
||||
}
|
||||
val x = packetWrapper.passthrough(Type.INT) //x
|
||||
val y = packetWrapper.passthrough(Type.INT) //y
|
||||
val z = packetWrapper.passthrough(Type.INT) //z
|
||||
val yaw = packetWrapper.passthrough(Type.BYTE) //yaw
|
||||
val pitch = packetWrapper.passthrough(Type.BYTE) //pitch
|
||||
val item = packetWrapper.passthrough(Type.SHORT) //Item in hand
|
||||
val metadata = packetWrapper.read(Types1_7_6_10.METADATA_LIST) //Metadata
|
||||
MetadataRewriter.transform(Entity1_10Types.EntityType.PLAYER, metadata)
|
||||
packetWrapper.write(Types1_8.METADATA_LIST, metadata)
|
||||
val tablist = packetWrapper.user().get(Tablist::class.java)!!
|
||||
var entryByName = tablist.getTabListEntry(name)
|
||||
if (entryByName == null && name.length > 14) entryByName =
|
||||
tablist.getTabListEntry(name.substring(0, 14))
|
||||
val entryByUUID = tablist.getTabListEntry(uuid)
|
||||
if (entryByName == null || entryByUUID == null) {
|
||||
if (entryByName != null || entryByUUID != null) {
|
||||
val remove = PacketWrapper.create(ClientboundPackets1_8.PLAYER_INFO, null, packetWrapper.user())
|
||||
remove.write(Type.VAR_INT, 4)
|
||||
remove.write(Type.VAR_INT, 1)
|
||||
remove.write(Type.UUID, entryByName?.uuid ?: entryByUUID!!.uuid)
|
||||
tablist.remove(entryByName ?: entryByUUID!!)
|
||||
remove.send(Protocol1_8To1_7_6::class.java)
|
||||
}
|
||||
val packetPlayerListItem =
|
||||
PacketWrapper.create(ClientboundPackets1_8.PLAYER_INFO, null, packetWrapper.user())
|
||||
val newentry = Tablist.TabListEntry(name, uuid)
|
||||
if (entryByName != null || entryByUUID != null) {
|
||||
newentry.displayName =
|
||||
if (entryByUUID != null) entryByUUID.displayName else entryByName!!.displayName
|
||||
}
|
||||
newentry.properties = properties
|
||||
tablist.add(newentry)
|
||||
packetPlayerListItem.write(Type.VAR_INT, 0)
|
||||
packetPlayerListItem.write(Type.VAR_INT, 1)
|
||||
packetPlayerListItem.write(Type.UUID, newentry.uuid)
|
||||
packetPlayerListItem.write(Type.STRING, newentry.name)
|
||||
packetPlayerListItem.write(Type.VAR_INT, dataCount)
|
||||
for (property in newentry.properties) {
|
||||
packetPlayerListItem.write(Type.STRING, property.key)
|
||||
packetPlayerListItem.write(Type.STRING, property.value)
|
||||
packetPlayerListItem.write(Type.BOOLEAN, property.signature != null)
|
||||
if (property.signature != null) packetPlayerListItem.write(Type.STRING, property.signature)
|
||||
}
|
||||
packetPlayerListItem.write(Type.VAR_INT, 0)
|
||||
packetPlayerListItem.write(Type.VAR_INT, 0)
|
||||
packetPlayerListItem.write(Type.BOOLEAN, newentry.displayName != null)
|
||||
if (newentry.displayName != null) {
|
||||
packetPlayerListItem.write(Type.STRING, newentry.displayName)
|
||||
}
|
||||
packetPlayerListItem.send(Protocol1_8To1_7_6::class.java)
|
||||
|
||||
packetWrapper.cancel()
|
||||
val delayedPacket =
|
||||
PacketWrapper.create(ClientboundPackets1_8.SPAWN_PLAYER, null, packetWrapper.user())
|
||||
delayedPacket.write(Type.VAR_INT, entityId)
|
||||
delayedPacket.write(Type.UUID, uuid)
|
||||
delayedPacket.write(Type.INT, x)
|
||||
delayedPacket.write(Type.INT, y)
|
||||
delayedPacket.write(Type.INT, z)
|
||||
delayedPacket.write(Type.BYTE, yaw)
|
||||
delayedPacket.write(Type.BYTE, pitch)
|
||||
delayedPacket.write(Type.SHORT, item)
|
||||
delayedPacket.write(Types1_8.METADATA_LIST, metadata)
|
||||
|
||||
delayedPacket.send(Protocol1_8To1_7_6::class.java)
|
||||
} else {
|
||||
entryByUUID.properties = properties
|
||||
}
|
||||
}
|
||||
handler { packetWrapper ->
|
||||
val entityID: Int = packetWrapper.get(Type.VAR_INT, 0)
|
||||
val tracker: EntityTracker = packetWrapper.user().get(EntityTracker::class.java)!!
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.PLAYER)
|
||||
tracker.flushMetadataBuffer(entityID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SET_EXPERIENCE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.FLOAT) //Experience bar
|
||||
map(Type.SHORT, Type.VAR_INT) //Level
|
||||
map(Type.SHORT, Type.VAR_INT) //Total Experience
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.PLAYER_INFO, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val name = packetWrapper.read(Type.STRING)
|
||||
val displayName: String? = null
|
||||
val online = packetWrapper.read(Type.BOOLEAN)
|
||||
val ping = packetWrapper.read(Type.SHORT)
|
||||
val tablist = packetWrapper.user().get(Tablist::class.java)!!
|
||||
var entry = tablist.getTabListEntry(name)
|
||||
if (!online && entry != null) {
|
||||
packetWrapper.write(Type.VAR_INT, 4)
|
||||
packetWrapper.write(Type.VAR_INT, 1)
|
||||
packetWrapper.write(Type.UUID, entry.uuid)
|
||||
tablist.remove(entry)
|
||||
} else if (online && entry == null) {
|
||||
val uuid = if (name == packetWrapper.user().protocolInfo?.username) {
|
||||
packetWrapper.user().protocolInfo!!.uuid!!
|
||||
} else {
|
||||
generateOfflinePlayerUuid(name)
|
||||
|
||||
}
|
||||
entry = Tablist.TabListEntry(name, uuid)
|
||||
entry.displayName = displayName
|
||||
tablist.add(entry)
|
||||
packetWrapper.write(Type.VAR_INT, 0) // Add
|
||||
packetWrapper.write(Type.VAR_INT, 1) // Entries
|
||||
packetWrapper.write(Type.UUID, entry.uuid)
|
||||
packetWrapper.write(Type.STRING, entry.name)
|
||||
packetWrapper.write(Type.VAR_INT, entry.properties.size)
|
||||
for (property in entry.properties) {
|
||||
packetWrapper.write(Type.STRING, property.key)
|
||||
packetWrapper.write(Type.STRING, property.value)
|
||||
packetWrapper.write(Type.BOOLEAN, property.signature != null)
|
||||
if (property.signature != null) packetWrapper.write(Type.STRING, property.signature)
|
||||
}
|
||||
packetWrapper.write(Type.VAR_INT, 0)
|
||||
packetWrapper.write(Type.VAR_INT, ping.toInt())
|
||||
packetWrapper.write(Type.BOOLEAN, entry.displayName != null)
|
||||
if (entry.displayName != null) {
|
||||
packetWrapper.write(Type.STRING, entry.displayName)
|
||||
}
|
||||
} else if (online && Tablist.shouldUpdateDisplayName(entry!!.displayName, displayName)) {
|
||||
entry.displayName = displayName
|
||||
packetWrapper.write(Type.VAR_INT, 3)
|
||||
packetWrapper.write(Type.VAR_INT, 1)
|
||||
packetWrapper.write(Type.UUID, entry.uuid)
|
||||
packetWrapper.write(Type.BOOLEAN, entry.displayName != null)
|
||||
if (entry.displayName != null) {
|
||||
packetWrapper.write(Type.STRING, entry.displayName)
|
||||
}
|
||||
} else if (online) {
|
||||
entry!!.ping = ping.toInt()
|
||||
packetWrapper.write(Type.VAR_INT, 2) // Update ping
|
||||
packetWrapper.write(Type.VAR_INT, 1) // Entries
|
||||
packetWrapper.write(Type.UUID, entry.uuid)
|
||||
packetWrapper.write(Type.VAR_INT, ping.toInt())
|
||||
} else {
|
||||
packetWrapper.write(Type.VAR_INT, 0)
|
||||
packetWrapper.write(Type.VAR_INT, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SCOREBOARD_OBJECTIVE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.STRING) // name
|
||||
handler { packetWrapper ->
|
||||
val value = packetWrapper.read(Type.STRING)
|
||||
val mode = packetWrapper.read(Type.BYTE)
|
||||
packetWrapper.write(Type.BYTE, mode)
|
||||
if (mode.toInt() == 0 || mode.toInt() == 2) {
|
||||
packetWrapper.write(Type.STRING, value)
|
||||
packetWrapper.write(Type.STRING, "integer")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.UPDATE_SCORE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val name = packetWrapper.passthrough(Type.STRING)
|
||||
val mode = packetWrapper.passthrough(Type.BYTE)
|
||||
if (mode.toInt() != 1) {
|
||||
val objective = packetWrapper.passthrough(Type.STRING)
|
||||
packetWrapper.user().get(Scoreboard::class.java)!!.put(name, objective)
|
||||
packetWrapper.write(Type.VAR_INT, packetWrapper.read(Type.INT))
|
||||
} else {
|
||||
val objective = packetWrapper.user().get(Scoreboard::class.java)!!.get(name)
|
||||
packetWrapper.write(Type.STRING, objective)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.TEAMS, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.STRING)
|
||||
handler { packetWrapper ->
|
||||
val mode: Byte = packetWrapper.read(Type.BYTE)
|
||||
packetWrapper.write(Type.BYTE, mode)
|
||||
if (mode.toInt() == 0 || mode.toInt() == 2) {
|
||||
packetWrapper.passthrough(Type.STRING)
|
||||
packetWrapper.passthrough(Type.STRING)
|
||||
packetWrapper.passthrough(Type.STRING)
|
||||
packetWrapper.passthrough(Type.BYTE)
|
||||
packetWrapper.write(Type.STRING, "always")
|
||||
packetWrapper.write(Type.BYTE, 0.toByte())
|
||||
}
|
||||
if (mode.toInt() == 0 || mode.toInt() == 3 || mode.toInt() == 4) {
|
||||
val count = packetWrapper.read(Type.SHORT).toInt()
|
||||
val type = CustomStringType(count)
|
||||
val entries = packetWrapper.read(type)
|
||||
packetWrapper.write(Type.STRING_ARRAY, entries)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.PLUGIN_MESSAGE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.STRING)
|
||||
handler { packetWrapper ->
|
||||
val channel: String = packetWrapper.get(Type.STRING, 0)
|
||||
val length: Short = packetWrapper.read(Type.SHORT)
|
||||
if (channel == "MC|Brand") {
|
||||
val data: ByteArray = packetWrapper.read(CustomByteType(length.toInt()))
|
||||
val brand = String(data, StandardCharsets.UTF_8)
|
||||
packetWrapper.write(Type.STRING, brand)
|
||||
} else if (channel == "MC|AdvCdm") {
|
||||
val type: Byte = packetWrapper.passthrough(Type.BYTE)
|
||||
if (type.toInt() == 0) {
|
||||
packetWrapper.passthrough(Type.INT)
|
||||
packetWrapper.passthrough(Type.INT)
|
||||
packetWrapper.passthrough(Type.INT)
|
||||
packetWrapper.passthrough(Type.STRING)
|
||||
packetWrapper.passthrough(Type.BOOLEAN)
|
||||
} else if (type.toInt() == 1) {
|
||||
packetWrapper.passthrough(Type.INT)
|
||||
packetWrapper.passthrough(Type.STRING)
|
||||
packetWrapper.passthrough(Type.BOOLEAN)
|
||||
}
|
||||
packetWrapper.write(Type.BYTE, 1.toByte())
|
||||
}
|
||||
if (channel.equals("MC|TrList", ignoreCase = true)) {
|
||||
packetWrapper.passthrough(Type.INT) //Window Id
|
||||
val size: Int = packetWrapper.passthrough(Type.UNSIGNED_BYTE).toInt() //Size
|
||||
for (i in 0 until size) {
|
||||
var item: Item = packetWrapper.read(Types1_7_6_10.COMPRESSED_NBT_ITEM)
|
||||
packetWrapper.write(Type.ITEM, item) //Buy Item 1
|
||||
item = packetWrapper.read(Types1_7_6_10.COMPRESSED_NBT_ITEM)
|
||||
packetWrapper.write(Type.ITEM, item) //Buy Item 3
|
||||
val has3Items: Boolean = packetWrapper.passthrough(Type.BOOLEAN)
|
||||
if (has3Items) {
|
||||
item = packetWrapper.read(Types1_7_6_10.COMPRESSED_NBT_ITEM)
|
||||
packetWrapper.write(Type.ITEM, item) //Buy Item 2
|
||||
}
|
||||
packetWrapper.passthrough(Type.BOOLEAN) //Unavailable
|
||||
packetWrapper.write(Type.INT, 0) //Uses
|
||||
packetWrapper.write(Type.INT, 0) //Max Uses
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.KEEP_ALIVE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT, Type.INT)
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.PLUGIN_MESSAGE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.STRING)
|
||||
handler { packetWrapper ->
|
||||
val channel = packetWrapper.get(Type.STRING, 0)
|
||||
when (channel) {
|
||||
"MC|ItemName" -> {
|
||||
val name: ByteArray = packetWrapper.read(Type.STRING).toByteArray(Charsets.UTF_8)
|
||||
packetWrapper.write(Type.REMAINING_BYTES, name)
|
||||
}
|
||||
"MC|BEdit", "MC|BSign" ->{
|
||||
packetWrapper.read(Type.SHORT) //length
|
||||
val book: Item = packetWrapper.read(Types1_7_6_10.COMPRESSED_NBT_ITEM)
|
||||
val tag = book.tag()
|
||||
if (tag != null && tag.contains("pages")) {
|
||||
val pages = tag.get<ListTag>("pages")
|
||||
if (pages != null) {
|
||||
(0 until pages.size()).forEach { i ->
|
||||
val page = pages.get<StringTag>(i)
|
||||
var value: String? = page.value
|
||||
value = ChatUtil.jsonToLegacy(value)
|
||||
page.value = value
|
||||
}
|
||||
}
|
||||
}
|
||||
packetWrapper.write(Type.ITEM, book)
|
||||
}
|
||||
}
|
||||
packetWrapper.cancel()
|
||||
packetWrapper.packetType = null
|
||||
val newPacketBuf = Unpooled.buffer()
|
||||
packetWrapper.writeToBuffer(newPacketBuf)
|
||||
val newWrapper =
|
||||
PacketWrapper.create(ServerboundPackets1_8.PLUGIN_MESSAGE, newPacketBuf, packetWrapper.user())
|
||||
newWrapper.passthrough(Type.STRING)
|
||||
newWrapper.write(Type.SHORT, newPacketBuf.readableBytes().toShort())
|
||||
newWrapper.sendToServer(Protocol1_8To1_7_6::class.java)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.PLAYER_POSITION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.DOUBLE) //X
|
||||
handler { packetWrapper ->
|
||||
val feetY: Double = packetWrapper.passthrough(Type.DOUBLE)
|
||||
packetWrapper.write(Type.DOUBLE, feetY + 1.62) //HeadY
|
||||
}
|
||||
map(Type.DOUBLE) //Z
|
||||
map(Type.BOOLEAN) //OnGround
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.PLAYER_POSITION_AND_ROTATION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.DOUBLE) //X
|
||||
handler { packetWrapper ->
|
||||
val feetY: Double = packetWrapper.passthrough(Type.DOUBLE)
|
||||
packetWrapper.write(Type.DOUBLE, feetY + 1.62) //HeadY
|
||||
}
|
||||
map(Type.DOUBLE) //Z
|
||||
map(Type.FLOAT) //Yaw
|
||||
map(Type.FLOAT) //Pitch
|
||||
map(Type.BOOLEAN) //OnGround
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.ANIMATION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
create(Type.INT, 0) //Entity Id, hopefully 0 is ok
|
||||
create(Type.BYTE, 1.toByte()) //Animation
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.CLIENT_SETTINGS, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.STRING)
|
||||
map(Type.BYTE)
|
||||
map(Type.BYTE)
|
||||
map(Type.BOOLEAN)
|
||||
create(Type.BYTE, 0.toByte())
|
||||
handler { packetWrapper ->
|
||||
val flags = packetWrapper.read(Type.UNSIGNED_BYTE)
|
||||
packetWrapper.write(Type.BOOLEAN, flags and 1 == 1.toShort())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.TAB_COMPLETE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val text = packetWrapper.read(Type.STRING)
|
||||
packetWrapper.clearInputBuffer()
|
||||
packetWrapper.write(Type.STRING, text)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.cancelServerbound(ServerboundPackets1_8.SPECTATE)
|
||||
this.cancelServerbound(ServerboundPackets1_8.RESOURCE_PACK_STATUS)
|
||||
}
|
@ -1,243 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.packets
|
||||
|
||||
import com.viaversion.aas.protocol.*
|
||||
import com.viaversion.aas.protocol.id47toid5.Protocol1_8To1_7_6
|
||||
import com.viaversion.aas.protocol.id47toid5.chunks.ChunkPacketTransformer
|
||||
import com.viaversion.aas.protocol.id47toid5.data.Particle1_8to1_7
|
||||
import com.viaversion.aas.protocol.id47toid5.storage.MapStorage
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper
|
||||
import com.viaversion.viaversion.api.protocol.remapper.TypeRemapper
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10
|
||||
import kotlin.experimental.and
|
||||
|
||||
fun Protocol1_8To1_7_6.registerWorldPackets() {
|
||||
this.registerClientbound(ClientboundPackets1_7.CHUNK_DATA) { packetWrapper ->
|
||||
ChunkPacketTransformer.transformChunk(packetWrapper)
|
||||
}
|
||||
|
||||
//Multi Block Change
|
||||
this.registerClientbound(ClientboundPackets1_7.MULTI_BLOCK_CHANGE) { packetWrapper ->
|
||||
ChunkPacketTransformer.transformMultiBlockChange(packetWrapper)
|
||||
}
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.BLOCK_CHANGE, object : PacketHandlers() {
|
||||
override fun register() {
|
||||
map(xyzUBytePos, TypeRemapper(Type.POSITION)) //Position
|
||||
handler { packetWrapper ->
|
||||
val blockId = packetWrapper.read(Type.VAR_INT)
|
||||
val meta = packetWrapper.read(Type.UNSIGNED_BYTE).toInt()
|
||||
packetWrapper.write(Type.VAR_INT, blockId.shl(4).or(meta and 15))
|
||||
} //Block Data
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.BLOCK_ACTION, object : PacketHandlers() {
|
||||
override fun register() {
|
||||
map(xyzShortPos, TypeRemapper(Type.POSITION)) //Position
|
||||
map(Type.UNSIGNED_BYTE)
|
||||
map(Type.UNSIGNED_BYTE)
|
||||
map(Type.VAR_INT)
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.BLOCK_BREAK_ANIMATION, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT) //Entity Id
|
||||
map(xyzToPosition, TypeRemapper(Type.POSITION)) //Position
|
||||
map(Type.BYTE) //Progress
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.MAP_BULK_CHUNK) { packetWrapper ->
|
||||
ChunkPacketTransformer.transformChunkBulk(packetWrapper)
|
||||
}
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.EFFECT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.INT) // id
|
||||
map(xyzUBytePos, TypeRemapper(Type.POSITION))
|
||||
map(Type.INT) // data
|
||||
map(Type.BOOLEAN) // relative volume
|
||||
handler { packetWrapper ->
|
||||
if (packetWrapper.get(Type.INT, 0) == 2006) { // id
|
||||
packetWrapper.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.SPAWN_PARTICLE, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
handler { packetWrapper ->
|
||||
val parts = packetWrapper.read(Type.STRING).split("_").toTypedArray()
|
||||
var particle = Particle1_8to1_7.find(parts[0])
|
||||
if (particle == null) particle = Particle1_8to1_7.CRIT
|
||||
packetWrapper.write(Type.INT, particle.ordinal)
|
||||
packetWrapper.write(Type.BOOLEAN, false)
|
||||
packetWrapper.passthrough(Type.FLOAT)
|
||||
packetWrapper.passthrough(Type.FLOAT)
|
||||
packetWrapper.passthrough(Type.FLOAT)
|
||||
packetWrapper.passthrough(Type.FLOAT)
|
||||
packetWrapper.passthrough(Type.FLOAT)
|
||||
packetWrapper.passthrough(Type.FLOAT)
|
||||
packetWrapper.passthrough(Type.FLOAT)
|
||||
packetWrapper.passthrough(Type.INT)
|
||||
var i = 0
|
||||
while (i < particle.extra) {
|
||||
var toWrite = 0
|
||||
if (parts.size - 1 > i) {
|
||||
try {
|
||||
toWrite = parts[i + 1].toInt()
|
||||
if (particle.extra == 1 && parts.size == 3) {
|
||||
i++
|
||||
toWrite = toWrite or (parts[i + 1].toInt() shl 12)
|
||||
}
|
||||
} catch (ignored: NumberFormatException) {
|
||||
}
|
||||
}
|
||||
packetWrapper.write(Type.VAR_INT, toWrite)
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.UPDATE_SIGN, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(xyzShortPos, TypeRemapper(Type.POSITION)) //Position
|
||||
handler { packetWrapper ->
|
||||
for (i in 0..3) {
|
||||
packetWrapper.write(
|
||||
Type.STRING,
|
||||
Protocol1_9To1_8.fixJson(packetWrapper.read(Type.STRING)).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.BLOCK_ENTITY_DATA, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(xyzShortPos, TypeRemapper(Type.POSITION)) //Position
|
||||
map(Type.UNSIGNED_BYTE) //Action
|
||||
map(Types1_7_6_10.COMPRESSED_NBT, Type.NBT)
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.MAP_DATA, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT)
|
||||
handler { packetWrapper ->
|
||||
val id = packetWrapper.get(Type.VAR_INT, 0)
|
||||
val data = packetWrapper.read(Type.SHORT_BYTE_ARRAY)
|
||||
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]
|
||||
)
|
||||
}
|
||||
} else if (data[0] == 2.toByte()) {
|
||||
mapData!!.scale = data[1]
|
||||
}
|
||||
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.x)
|
||||
packetWrapper.write(Type.BYTE, mapIcon.z)
|
||||
}
|
||||
if (data[0] == 0.toByte()) {
|
||||
val x = data[1]
|
||||
val z = data[2]
|
||||
val rows = data.size - 3
|
||||
packetWrapper.write(Type.BYTE, 1.toByte())
|
||||
packetWrapper.write(Type.BYTE, rows.toByte())
|
||||
packetWrapper.write(Type.BYTE, x)
|
||||
packetWrapper.write(Type.BYTE, z)
|
||||
val newData = ByteArray(rows)
|
||||
for (i in 0 until rows) {
|
||||
newData[i] = data[i + 3]
|
||||
}
|
||||
packetWrapper.write(Type.BYTE_ARRAY_PRIMITIVE, newData)
|
||||
} else {
|
||||
packetWrapper.write(Type.BYTE, 0.toByte())
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7.OPEN_SIGN_EDITOR, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(xyzToPosition, TypeRemapper(Type.POSITION)) //Position
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.PLAYER_DIGGING, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(Type.VAR_INT) //Status
|
||||
map(TypeRemapper(Type.POSITION), xyzUBytePosWriter)
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.PLAYER_BLOCK_PLACEMENT, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
map(TypeRemapper(Type.POSITION), xyzUBytePosWriter)
|
||||
map(Type.UNSIGNED_BYTE)
|
||||
map(Type.ITEM, Types1_7_6_10.COMPRESSED_NBT_ITEM)
|
||||
handler { packetWrapper ->
|
||||
val x = packetWrapper.get(Type.INT, 0)
|
||||
val y = packetWrapper.get(Type.UNSIGNED_BYTE, 0)
|
||||
val z = packetWrapper.get(Type.INT, 1)
|
||||
// https://github.com/ViaVersion/ViaVersion/pull/1379
|
||||
val direction = packetWrapper.get(Type.UNSIGNED_BYTE, 0) //Direction
|
||||
val item = packetWrapper.get(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0)
|
||||
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)
|
||||
} else {
|
||||
val cursor = packetWrapper.read(Type.UNSIGNED_BYTE)
|
||||
packetWrapper.write(Type.BYTE, cursor.toByte())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_8.UPDATE_SIGN, object : PacketRemapper() {
|
||||
override fun registerMap() {
|
||||
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)))
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.storage
|
||||
|
||||
import com.viaversion.aas.protocol.id47toid5.Protocol1_8To1_7_6
|
||||
import com.viaversion.aas.protocol.id47toid5.metadata.MetadataRewriter
|
||||
import com.viaversion.viaversion.api.connection.StoredObject
|
||||
import com.viaversion.viaversion.api.connection.UserConnection
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_8
|
||||
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
|
||||
|
||||
class EntityTracker(user: UserConnection) : StoredObject(user) {
|
||||
private val clientEntityTypes = HashMap<Int, Entity1_10Types.EntityType>()
|
||||
private val metadataBuffer = HashMap<Int, MutableList<Metadata>>()
|
||||
fun removeEntity(entityId: Int) {
|
||||
clientEntityTypes.remove(entityId)
|
||||
metadataBuffer.remove(entityId)
|
||||
}
|
||||
|
||||
fun getType(entityId: Int) = clientEntityTypes[entityId]
|
||||
|
||||
fun addEntity(entityId: Int, type: Entity1_10Types.EntityType) {
|
||||
clientEntityTypes[entityId] = type
|
||||
}
|
||||
|
||||
fun hasEntity(entityId: Int) = clientEntityTypes.containsKey(entityId)
|
||||
|
||||
fun addMetadataToBuffer(entityID: Int, metadataList: MutableList<Metadata>) {
|
||||
metadataBuffer.computeIfAbsent(entityID) { mutableListOf() }.addAll(metadataList)
|
||||
}
|
||||
|
||||
fun flushMetadataBuffer(entityId: Int) {
|
||||
val buffer = metadataBuffer[entityId] ?: return
|
||||
|
||||
val wrapper = PacketWrapper.create(ClientboundPackets1_7.ENTITY_METADATA, null, this.user)
|
||||
wrapper.write(Type.VAR_INT, entityId)
|
||||
wrapper.write(Types1_8.METADATA_LIST, buffer)
|
||||
|
||||
MetadataRewriter.transform(clientEntityTypes[entityId], buffer)
|
||||
|
||||
if (buffer.isNotEmpty()) {
|
||||
try {
|
||||
wrapper.scheduleSend(Protocol1_8To1_7_6::class.java)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
metadataBuffer.remove(entityId)
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.storage
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject
|
||||
import com.viaversion.viaversion.api.connection.UserConnection
|
||||
|
||||
class MapStorage(user: UserConnection) : StoredObject(user) {
|
||||
private val maps: MutableMap<Int, MapData> = HashMap()
|
||||
fun getMapData(id: Int): MapData? {
|
||||
return maps[id]
|
||||
}
|
||||
|
||||
fun putMapData(id: Int, mapData: MapData) {
|
||||
maps[id] = mapData
|
||||
}
|
||||
|
||||
class MapData {
|
||||
var scale: Byte = 0
|
||||
var mapIcons = emptyArray<MapIcon>()
|
||||
}
|
||||
|
||||
class MapIcon(var direction: Byte, var type: Byte, var x: Byte, var z: Byte)
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.storage
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject
|
||||
import com.viaversion.viaversion.api.connection.UserConnection
|
||||
|
||||
class Scoreboard(user: UserConnection) : StoredObject(user) {
|
||||
private val objectives = HashMap<String, String>()
|
||||
fun put(name: String, objective: String) {
|
||||
objectives[name] = objective
|
||||
}
|
||||
|
||||
operator fun get(name: String): String {
|
||||
return objectives.getOrDefault(name, "null")
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.storage
|
||||
|
||||
import com.viaversion.aas.util.SignableProperty
|
||||
import com.viaversion.viaversion.api.connection.StoredObject
|
||||
import com.viaversion.viaversion.api.connection.UserConnection
|
||||
import java.util.*
|
||||
|
||||
class Tablist(user: UserConnection?) : StoredObject(user) {
|
||||
private val tablist = ArrayList<TabListEntry>()
|
||||
fun getTabListEntry(name: String): TabListEntry? {
|
||||
for (entry in tablist) if (name == entry.name) return entry
|
||||
return null
|
||||
}
|
||||
|
||||
fun getTabListEntry(uuid: UUID): TabListEntry? {
|
||||
for (entry in tablist) if (uuid == entry.uuid) return entry
|
||||
return null
|
||||
}
|
||||
|
||||
fun remove(entry: TabListEntry) {
|
||||
tablist.remove(entry)
|
||||
}
|
||||
|
||||
fun add(entry: TabListEntry) {
|
||||
tablist.add(entry)
|
||||
}
|
||||
|
||||
class TabListEntry(var name: String, var uuid: UUID) {
|
||||
var displayName: String? = null
|
||||
var ping = 0
|
||||
var properties = mutableListOf<SignableProperty>()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun shouldUpdateDisplayName(oldName: String?, newName: String?): Boolean {
|
||||
return oldName == null && newName != null || oldName != null && newName == null || oldName != null && oldName != newName
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.storage
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject
|
||||
import com.viaversion.viaversion.api.connection.UserConnection
|
||||
|
||||
class Windows(user: UserConnection?) : StoredObject(user) {
|
||||
var types = mutableMapOf<Short, Short>()
|
||||
operator fun get(windowId: Short): Short = types.getOrDefault(windowId, (-1).toShort())
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.viaversion.aas.protocol.id47toid5.type
|
||||
|
||||
import com.viaversion.viaversion.api.type.PartialType
|
||||
import io.netty.buffer.ByteBuf
|
||||
|
||||
class CustomIntType(amount: Int) : PartialType<IntArray, Int>(amount, IntArray::class.java) {
|
||||
override fun read(p0: ByteBuf, p1: Int): IntArray {
|
||||
return IntArray(p1) { p0.readInt() }
|
||||
}
|
||||
|
||||
override fun write(p0: ByteBuf, p1: Int, p2: IntArray) {
|
||||
p2.forEach { p0.writeInt(it) }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user