i think i fixed 1.7 chunks?

This commit is contained in:
creeper123123321 2021-03-31 20:41:59 -03:00
parent 770bcc40a9
commit 9fa104a533
7 changed files with 35 additions and 41 deletions

View File

@ -46,8 +46,7 @@ fun resolveSrv(address: String, port: Int): Pair<String, Int> {
val record = (attr.get(0) as String).split(" ")
return record[3] to record[2].toInt()
}
} catch (ignored: NameNotFoundException) {
} catch (ignored: ServiceUnavailableException) { // DuckDNS workaround
} catch (ignored: Exception) { // DuckDNS workaround
}
}
return address to port
@ -171,4 +170,4 @@ fun generateServerId() = ByteArray(13).let {
// https://developer.mozilla.org/en-US/docs/Glossary/Base64 133% of original
}
fun Int.parseProtocol() = ProtocolVersion.getProtocol(this)
fun Int.parseProtocol() = ProtocolVersion.getProtocol(this)

View File

@ -41,7 +41,7 @@ class PluginMessage : Packet {
fun writeExtendedForgeShort(buf: ByteBuf, toWrite: Int) {
var low = toWrite and 0x7FFF
val high = toWrite and 0x7F8000 shr 15
val high = toWrite.and(0x7F8000).shr(15)
if (high != 0) {
low = low or 0x8000
}

View File

@ -16,7 +16,7 @@ class Chunk1_8to1_7_6_10(
var blockBiomeArray = ByteArray(256)
fun filterChunk(storageArray: ExtendedBlockStorage?, i: Int) =
storageArray != null && primaryBitMask and 1 shl i != 0
storageArray != null && (primaryBitMask.and(1 shl i) != 0)
&& (!groundUp || storageArray.isEmpty)
fun get1_8Data(): ByteArray {
@ -30,14 +30,14 @@ class Chunk1_8to1_7_6_10(
for (ind in blockIds.indices) {
val id = blockIds[ind].toInt() and 255
val px = ind and 15
val py = ind shr 8 and 15
val pz = ind shr 4 and 15
val py = ind.shr(8).and(15)
val pz = ind.shr(4).and(15)
val data = nibblearray[px, py, pz].toInt()
//data = SpigotDebreakifier.getCorrectedData(id, data);
val `val` = (id shl 4 or data).toChar()
buf.writeByte(`val`.toInt() and 255)
buf.writeByte(`val`.toInt() shr 8 and 255)
buf.writeByte(`val`.toInt().shr(8).and(255))
}
}
filteredChunks.forEach {
@ -60,38 +60,40 @@ class Chunk1_8to1_7_6_10(
init {
val input = Unpooled.wrappedBuffer(data)
for (i in storageSections.indices) {
if (primaryBitMask and 1 shl i != 0) {
val storageSection = storageSections.getOrElse(i) {
ExtendedBlockStorage(i shl 4, skyLight).also { storageSections[i] = it }
}!!
if ((primaryBitMask and (1 shl i)) != 0) {
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 (primaryBitMask and 1 shl i != 0 && storageSections[i] != null) {
if (primaryBitMask.and(1 shl i) != 0 && storageSections[i] != null) {
storageSections[i]!!.metadataArray.handle = input.readByteArray(4096 / 2)
}
}
for (i in storageSections.indices) {
if (primaryBitMask and 1 shl i != 0 && storageSections[i] != null) {
if (primaryBitMask.and(1 shl i) != 0 && storageSections[i] != null) {
storageSections[i]!!.blocklightArray.handle = input.readByteArray(4096 / 2)
}
}
if (skyLight) {
for (i in storageSections.indices) {
if (primaryBitMask and 1 shl i != 0 && storageSections[i] != null) {
if (primaryBitMask.and(1 shl i) != 0 && storageSections[i] != null) {
storageSections[i]!!.skylightArray!!.handle = input.readByteArray(4096 / 2)
}
}
}
for (i in storageSections.indices) {
if (addBitMask and 1 shl i != 0) {
if (addBitMask.and(1 shl i) != 0) {
if (storageSections[i] == null) {
input.skipBytes(2048)
} else {
var msbArray = storageSections[i]!!.blockMSBArray ?: storageSections[i]!!.createBlockMSBArray()
val msbArray = storageSections[i]!!.blockMSBArray ?: storageSections[i]!!.createBlockMSBArray()
msbArray!!.handle = input.readByteArray(4096 / 2)
}
} else if (groundUp && storageSections[i] != null && storageSections[i]!!.blockMSBArray != null) {

View File

@ -6,7 +6,6 @@ import us.myles.ViaVersion.api.minecraft.BlockChangeRecord1_8
import us.myles.ViaVersion.api.type.Type
import us.myles.ViaVersion.api.type.types.CustomByteType
import java.io.IOException
import java.util.*
import java.util.stream.IntStream
import java.util.zip.DataFormatException
import java.util.zip.Inflater
@ -23,14 +22,14 @@ object ChunkPacketTransformer {
val compressedSize = packetWrapper.read(Type.INT)
val customByteType = CustomByteType(compressedSize)
val data = packetWrapper.read(customByteType)
var k = 0
var l = 0
var countOfPrimary = 0
var countOfAdditional = 0
for (j in 0..15) {
k += primaryBitMask shr j and 1
l += addBitMask shr j and 1
countOfPrimary += primaryBitMask.shr(j).and(1)
countOfAdditional += addBitMask.shr(j).and(1)
}
var uncompressedSize = 12288 * k
uncompressedSize += 2048 * l
var uncompressedSize = 12288 * countOfPrimary
uncompressedSize += 2048 * countOfAdditional
if (groundUp) {
uncompressedSize += 256
}
@ -39,29 +38,23 @@ object ChunkPacketTransformer {
inflater.setInput(data, 0, compressedSize)
try {
inflater.inflate(uncompressedData)
} catch (ex: DataFormatException) {
throw IOException("Bad compressed data format")
} finally {
inflater.end()
}
val chunk = Chunk1_8to1_7_6_10(uncompressedData, primaryBitMask, addBitMask, true, groundUp)
var field = PacketWrapper::class.java.getDeclaredField("packetValues")
field.isAccessible = true
(field[packetWrapper] as MutableList<*>).clear()
field = PacketWrapper::class.java.getDeclaredField("readableObjects")
field.isAccessible = true
(field[packetWrapper] as LinkedList<*>).clear()
field = PacketWrapper::class.java.getDeclaredField("inputBuffer")
packetWrapper.clearPacket()
val field = PacketWrapper::class.java.getDeclaredField("inputBuffer")
field.isAccessible = true
val buffer = field[packetWrapper] as ByteBuf
buffer.clear()
buffer.writeInt(chunkX)
buffer.writeInt(chunkZ)
buffer.writeBoolean(groundUp)
buffer.writeShort(primaryBitMask)
val finaldata = chunk.get1_8Data()
Type.VAR_INT.writePrimitive(buffer, finaldata.size)
buffer.writeBytes(finaldata)
val finalData = chunk.get1_8Data()
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, finalData)
}
@Throws(Exception::class)

View File

@ -2,7 +2,7 @@ package com.github.creeper123123321.viaaas.protocol.id47toid5.chunks
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray
class ExtendedBlockStorage(val yLocation: Int, paramBoolean: Boolean) {
class ExtendedBlockStorage(val yLocation: Int, hasSkyLight: Boolean) {
var blockLSBArray: ByteArray = ByteArray(4096)
var blockMSBArray: NibbleArray? = null
var metadataArray: NibbleArray
@ -52,7 +52,7 @@ class ExtendedBlockStorage(val yLocation: Int, paramBoolean: Boolean) {
init {
metadataArray = NibbleArray(blockLSBArray.size)
blocklightArray = NibbleArray(blockLSBArray.size)
if (paramBoolean) {
if (hasSkyLight) {
skylightArray = NibbleArray(blockLSBArray.size)
}
}

View File

@ -96,7 +96,7 @@ fun Protocol1_8To1_7_6.registerEntityPackets() {
if (type.toInt() == 70) {
val id = data
val metadata = data shr 16
data = id or metadata shl 12
data = id.or(metadata shl 12)
}
if (type.toInt() == 50 || type.toInt() == 70 || type.toInt() == 74) y -= 16
packetWrapper.set(Type.INT, 0, x)

View File

@ -40,7 +40,7 @@ fun Protocol1_8To1_7_6.registerWorldPackets() {
handler { packetWrapper ->
val blockId: Int = 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))
packetWrapper.write(Type.VAR_INT, blockId.shl(4).or(meta and 15))
} //Block Data
}
})
@ -168,7 +168,7 @@ 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)
}