mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-29 13:15:15 +01:00
i think i fixed 1.7 chunks?
This commit is contained in:
parent
770bcc40a9
commit
9fa104a533
@ -46,8 +46,7 @@ fun resolveSrv(address: String, port: Int): Pair<String, Int> {
|
|||||||
val record = (attr.get(0) as String).split(" ")
|
val record = (attr.get(0) as String).split(" ")
|
||||||
return record[3] to record[2].toInt()
|
return record[3] to record[2].toInt()
|
||||||
}
|
}
|
||||||
} catch (ignored: NameNotFoundException) {
|
} catch (ignored: Exception) { // DuckDNS workaround
|
||||||
} catch (ignored: ServiceUnavailableException) { // DuckDNS workaround
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return address to port
|
return address to port
|
||||||
|
@ -41,7 +41,7 @@ class PluginMessage : Packet {
|
|||||||
|
|
||||||
fun writeExtendedForgeShort(buf: ByteBuf, toWrite: Int) {
|
fun writeExtendedForgeShort(buf: ByteBuf, toWrite: Int) {
|
||||||
var low = toWrite and 0x7FFF
|
var low = toWrite and 0x7FFF
|
||||||
val high = toWrite and 0x7F8000 shr 15
|
val high = toWrite.and(0x7F8000).shr(15)
|
||||||
if (high != 0) {
|
if (high != 0) {
|
||||||
low = low or 0x8000
|
low = low or 0x8000
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ class Chunk1_8to1_7_6_10(
|
|||||||
var blockBiomeArray = ByteArray(256)
|
var blockBiomeArray = ByteArray(256)
|
||||||
|
|
||||||
fun filterChunk(storageArray: ExtendedBlockStorage?, i: Int) =
|
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)
|
&& (!groundUp || storageArray.isEmpty)
|
||||||
|
|
||||||
fun get1_8Data(): ByteArray {
|
fun get1_8Data(): ByteArray {
|
||||||
@ -30,14 +30,14 @@ class Chunk1_8to1_7_6_10(
|
|||||||
for (ind in blockIds.indices) {
|
for (ind in blockIds.indices) {
|
||||||
val id = blockIds[ind].toInt() and 255
|
val id = blockIds[ind].toInt() and 255
|
||||||
val px = ind and 15
|
val px = ind and 15
|
||||||
val py = ind shr 8 and 15
|
val py = ind.shr(8).and(15)
|
||||||
val pz = ind shr 4 and 15
|
val pz = ind.shr(4).and(15)
|
||||||
val data = nibblearray[px, py, pz].toInt()
|
val data = nibblearray[px, py, pz].toInt()
|
||||||
|
|
||||||
//data = SpigotDebreakifier.getCorrectedData(id, data);
|
//data = SpigotDebreakifier.getCorrectedData(id, data);
|
||||||
val `val` = (id shl 4 or data).toChar()
|
val `val` = (id shl 4 or data).toChar()
|
||||||
buf.writeByte(`val`.toInt() and 255)
|
buf.writeByte(`val`.toInt() and 255)
|
||||||
buf.writeByte(`val`.toInt() shr 8 and 255)
|
buf.writeByte(`val`.toInt().shr(8).and(255))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filteredChunks.forEach {
|
filteredChunks.forEach {
|
||||||
@ -60,38 +60,40 @@ class Chunk1_8to1_7_6_10(
|
|||||||
init {
|
init {
|
||||||
val input = Unpooled.wrappedBuffer(data)
|
val input = Unpooled.wrappedBuffer(data)
|
||||||
for (i in storageSections.indices) {
|
for (i in storageSections.indices) {
|
||||||
if (primaryBitMask and 1 shl i != 0) {
|
if ((primaryBitMask and (1 shl i)) != 0) {
|
||||||
val storageSection = storageSections.getOrElse(i) {
|
var storageSection = storageSections[i]
|
||||||
ExtendedBlockStorage(i shl 4, skyLight).also { storageSections[i] = it }
|
if (storageSection == null){
|
||||||
}!!
|
storageSection = ExtendedBlockStorage(i shl 4, skyLight)
|
||||||
|
storageSections[i] = storageSection
|
||||||
|
}
|
||||||
storageSection.blockLSBArray = input.readByteArray(4096)
|
storageSection.blockLSBArray = input.readByteArray(4096)
|
||||||
} else if (storageSections[i] != null && groundUp) {
|
} else if (storageSections[i] != null && groundUp) {
|
||||||
storageSections[i] = null
|
storageSections[i] = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i in storageSections.indices) {
|
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)
|
storageSections[i]!!.metadataArray.handle = input.readByteArray(4096 / 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i in storageSections.indices) {
|
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)
|
storageSections[i]!!.blocklightArray.handle = input.readByteArray(4096 / 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (skyLight) {
|
if (skyLight) {
|
||||||
for (i in storageSections.indices) {
|
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)
|
storageSections[i]!!.skylightArray!!.handle = input.readByteArray(4096 / 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i in storageSections.indices) {
|
for (i in storageSections.indices) {
|
||||||
if (addBitMask and 1 shl i != 0) {
|
if (addBitMask.and(1 shl i) != 0) {
|
||||||
if (storageSections[i] == null) {
|
if (storageSections[i] == null) {
|
||||||
input.skipBytes(2048)
|
input.skipBytes(2048)
|
||||||
} else {
|
} else {
|
||||||
var msbArray = storageSections[i]!!.blockMSBArray ?: storageSections[i]!!.createBlockMSBArray()
|
val msbArray = storageSections[i]!!.blockMSBArray ?: storageSections[i]!!.createBlockMSBArray()
|
||||||
msbArray!!.handle = input.readByteArray(4096 / 2)
|
msbArray!!.handle = input.readByteArray(4096 / 2)
|
||||||
}
|
}
|
||||||
} else if (groundUp && storageSections[i] != null && storageSections[i]!!.blockMSBArray != null) {
|
} else if (groundUp && storageSections[i] != null && storageSections[i]!!.blockMSBArray != null) {
|
||||||
|
@ -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.Type
|
||||||
import us.myles.ViaVersion.api.type.types.CustomByteType
|
import us.myles.ViaVersion.api.type.types.CustomByteType
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
|
||||||
import java.util.stream.IntStream
|
import java.util.stream.IntStream
|
||||||
import java.util.zip.DataFormatException
|
import java.util.zip.DataFormatException
|
||||||
import java.util.zip.Inflater
|
import java.util.zip.Inflater
|
||||||
@ -23,14 +22,14 @@ object ChunkPacketTransformer {
|
|||||||
val compressedSize = packetWrapper.read(Type.INT)
|
val compressedSize = packetWrapper.read(Type.INT)
|
||||||
val customByteType = CustomByteType(compressedSize)
|
val customByteType = CustomByteType(compressedSize)
|
||||||
val data = packetWrapper.read(customByteType)
|
val data = packetWrapper.read(customByteType)
|
||||||
var k = 0
|
var countOfPrimary = 0
|
||||||
var l = 0
|
var countOfAdditional = 0
|
||||||
for (j in 0..15) {
|
for (j in 0..15) {
|
||||||
k += primaryBitMask shr j and 1
|
countOfPrimary += primaryBitMask.shr(j).and(1)
|
||||||
l += addBitMask shr j and 1
|
countOfAdditional += addBitMask.shr(j).and(1)
|
||||||
}
|
}
|
||||||
var uncompressedSize = 12288 * k
|
var uncompressedSize = 12288 * countOfPrimary
|
||||||
uncompressedSize += 2048 * l
|
uncompressedSize += 2048 * countOfAdditional
|
||||||
if (groundUp) {
|
if (groundUp) {
|
||||||
uncompressedSize += 256
|
uncompressedSize += 256
|
||||||
}
|
}
|
||||||
@ -39,29 +38,23 @@ object ChunkPacketTransformer {
|
|||||||
inflater.setInput(data, 0, compressedSize)
|
inflater.setInput(data, 0, compressedSize)
|
||||||
try {
|
try {
|
||||||
inflater.inflate(uncompressedData)
|
inflater.inflate(uncompressedData)
|
||||||
} catch (ex: DataFormatException) {
|
|
||||||
throw IOException("Bad compressed data format")
|
|
||||||
} finally {
|
} finally {
|
||||||
inflater.end()
|
inflater.end()
|
||||||
}
|
}
|
||||||
val chunk = Chunk1_8to1_7_6_10(uncompressedData, primaryBitMask, addBitMask, true, groundUp)
|
val chunk = Chunk1_8to1_7_6_10(uncompressedData, primaryBitMask, addBitMask, true, groundUp)
|
||||||
var field = PacketWrapper::class.java.getDeclaredField("packetValues")
|
|
||||||
field.isAccessible = true
|
packetWrapper.clearPacket()
|
||||||
(field[packetWrapper] as MutableList<*>).clear()
|
val field = PacketWrapper::class.java.getDeclaredField("inputBuffer")
|
||||||
field = PacketWrapper::class.java.getDeclaredField("readableObjects")
|
|
||||||
field.isAccessible = true
|
|
||||||
(field[packetWrapper] as LinkedList<*>).clear()
|
|
||||||
field = PacketWrapper::class.java.getDeclaredField("inputBuffer")
|
|
||||||
field.isAccessible = true
|
field.isAccessible = true
|
||||||
val buffer = field[packetWrapper] as ByteBuf
|
val buffer = field[packetWrapper] as ByteBuf
|
||||||
|
|
||||||
buffer.clear()
|
buffer.clear()
|
||||||
buffer.writeInt(chunkX)
|
buffer.writeInt(chunkX)
|
||||||
buffer.writeInt(chunkZ)
|
buffer.writeInt(chunkZ)
|
||||||
buffer.writeBoolean(groundUp)
|
buffer.writeBoolean(groundUp)
|
||||||
buffer.writeShort(primaryBitMask)
|
buffer.writeShort(primaryBitMask)
|
||||||
val finaldata = chunk.get1_8Data()
|
val finalData = chunk.get1_8Data()
|
||||||
Type.VAR_INT.writePrimitive(buffer, finaldata.size)
|
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, finalData)
|
||||||
buffer.writeBytes(finaldata)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
|
@ -2,7 +2,7 @@ package com.github.creeper123123321.viaaas.protocol.id47toid5.chunks
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray
|
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 blockLSBArray: ByteArray = ByteArray(4096)
|
||||||
var blockMSBArray: NibbleArray? = null
|
var blockMSBArray: NibbleArray? = null
|
||||||
var metadataArray: NibbleArray
|
var metadataArray: NibbleArray
|
||||||
@ -52,7 +52,7 @@ class ExtendedBlockStorage(val yLocation: Int, paramBoolean: Boolean) {
|
|||||||
init {
|
init {
|
||||||
metadataArray = NibbleArray(blockLSBArray.size)
|
metadataArray = NibbleArray(blockLSBArray.size)
|
||||||
blocklightArray = NibbleArray(blockLSBArray.size)
|
blocklightArray = NibbleArray(blockLSBArray.size)
|
||||||
if (paramBoolean) {
|
if (hasSkyLight) {
|
||||||
skylightArray = NibbleArray(blockLSBArray.size)
|
skylightArray = NibbleArray(blockLSBArray.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ fun Protocol1_8To1_7_6.registerEntityPackets() {
|
|||||||
if (type.toInt() == 70) {
|
if (type.toInt() == 70) {
|
||||||
val id = data
|
val id = data
|
||||||
val metadata = data shr 16
|
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
|
if (type.toInt() == 50 || type.toInt() == 70 || type.toInt() == 74) y -= 16
|
||||||
packetWrapper.set(Type.INT, 0, x)
|
packetWrapper.set(Type.INT, 0, x)
|
||||||
|
@ -40,7 +40,7 @@ fun Protocol1_8To1_7_6.registerWorldPackets() {
|
|||||||
handler { packetWrapper ->
|
handler { packetWrapper ->
|
||||||
val blockId: Int = packetWrapper.read(Type.VAR_INT)
|
val blockId: Int = packetWrapper.read(Type.VAR_INT)
|
||||||
val meta = packetWrapper.read(Type.UNSIGNED_BYTE).toInt()
|
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
|
} //Block Data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -168,7 +168,7 @@ fun Protocol1_8To1_7_6.registerWorldPackets() {
|
|||||||
packetWrapper.write(Type.BYTE, mapData!!.scale)
|
packetWrapper.write(Type.BYTE, mapData!!.scale)
|
||||||
packetWrapper.write(Type.VAR_INT, mapData!!.mapIcons.size)
|
packetWrapper.write(Type.VAR_INT, mapData!!.mapIcons.size)
|
||||||
for (mapIcon in mapData!!.mapIcons) {
|
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.x)
|
||||||
packetWrapper.write(Type.BYTE, mapIcon.z)
|
packetWrapper.write(Type.BYTE, mapIcon.z)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user