remove some code warnings

This commit is contained in:
Bixilon 2021-04-01 22:18:34 +02:00
parent 046c9b3b4b
commit 7452020727
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
17 changed files with 31 additions and 34 deletions

View File

@ -126,6 +126,8 @@ class MinecraftAssetsManager(
) )
), hash, false) ), hash, false)
} }
else -> {
}
} }
} }

View File

@ -96,8 +96,8 @@ class Camera(
lastMouseY = yPos lastMouseY = yPos
xOffset *= mouseSensitivity xOffset *= mouseSensitivity
yOffset *= mouseSensitivity yOffset *= mouseSensitivity
var yaw = xOffset.toFloat() + (playerEntity.rotation?.headYaw ?: 0f) var yaw = xOffset.toFloat() + playerEntity.rotation.headYaw
var pitch = yOffset.toFloat() + (playerEntity.rotation?.pitch ?: 0f) var pitch = yOffset.toFloat() + playerEntity.rotation.pitch
// make sure that when pitch is out of bounds, screen doesn't get flipped // make sure that when pitch is out of bounds, screen doesn't get flipped
if (pitch > 89.9) { if (pitch > 89.9) {

View File

@ -50,7 +50,7 @@ object RenderConstants {
const val MAXIMUM_CALLS_PER_FRAME = 10 const val MAXIMUM_CALLS_PER_FRAME = 10
const val DISABLE_LIGHTING = true const val DISABLE_LIGHTING = false
const val RENDER_BLOCKS = true const val RENDER_BLOCKS = true
const val RENDER_FLUIDS = true const val RENDER_FLUIDS = true

View File

@ -250,7 +250,7 @@ class RenderWindow(
textures.preLoad(connection.version.assetsManager) textures.preLoad(connection.version.assetsManager)
font.loadAtlas(textures) font.loadAtlas()
textures.load() textures.load()

View File

@ -48,7 +48,7 @@ class Font {
preLoaded = true preLoaded = true
} }
fun loadAtlas(textureArray: TextureArray) { fun loadAtlas() {
check(!loaded) { "Font has already a atlas texture!" } check(!loaded) { "Font has already a atlas texture!" }
check(preLoaded) { "Font hasn't been preloaded!" } check(preLoaded) { "Font hasn't been preloaded!" }

View File

@ -52,7 +52,7 @@ class HUDRenderer(val connection: Connection, val renderWindow: RenderWindow) :
override fun init() { override fun init() {
hudShader.load(Minosoft.MINOSOFT_ASSETS_MANAGER) hudShader.load(Minosoft.MINOSOFT_ASSETS_MANAGER)
val hudImages = HUDAtlasElement.deserialize(Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "mapping/atlas.json")).toResourceLocationMap(), connection.version.versionId) val hudImages = HUDAtlasElement.deserialize(Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "mapping/atlas.json")).toResourceLocationMap())
this.hudAtlasElements = hudImages.second this.hudAtlasElements = hudImages.second
renderWindow.textures.allTextures.addAll(hudImages.first.toList()) renderWindow.textures.allTextures.addAll(hudImages.first.toList())

View File

@ -41,16 +41,16 @@ data class HUDAtlasElement(
private val UV_START_ADD = Vec2(0, 0.000015f) // ToDo: This fixes the "half pixel bug" private val UV_START_ADD = Vec2(0, 0.000015f) // ToDo: This fixes the "half pixel bug"
fun deserialize(json: Map<ResourceLocation, JsonObject>, versionId: Int): Pair<Collection<Texture>, Map<ResourceLocation, HUDAtlasElement>> { fun deserialize(json: Map<ResourceLocation, JsonObject>): Pair<Collection<Texture>, Map<ResourceLocation, HUDAtlasElement>> {
val textures: MutableMap<ResourceLocation, Texture> = mutableMapOf() val textures: MutableMap<ResourceLocation, Texture> = mutableMapOf()
val ret: MutableMap<ResourceLocation, HUDAtlasElement> = mutableMapOf() val ret: MutableMap<ResourceLocation, HUDAtlasElement> = mutableMapOf()
for ((resourceLocation, data) in json) { for ((resourceLocation, data) in json) {
ret[resourceLocation] = deserialize(data, textures, versionId) ret[resourceLocation] = deserialize(data, textures)
} }
return Pair(textures.values, ret) return Pair(textures.values, ret)
} }
fun deserialize(json: JsonObject, textures: MutableMap<ResourceLocation, Texture>, versionId: Int): HUDAtlasElement { fun deserialize(json: JsonObject, textures: MutableMap<ResourceLocation, Texture>): HUDAtlasElement {
val keys: MutableSet<Int> = mutableSetOf() val keys: MutableSet<Int> = mutableSetOf()
var textureResourceLocation: ResourceLocation? = json["texture"]?.asString?.let { ResourceLocation(it) } var textureResourceLocation: ResourceLocation? = json["texture"]?.asString?.let { ResourceLocation(it) }
for (key in json["versions"].asJsonObject.keySet()) { for (key in json["versions"].asJsonObject.keySet()) {

View File

@ -107,8 +107,7 @@ class HUDWorldDebugElement(hudRenderer: HUDRenderer) : DebugScreen(hudRenderer)
private fun getPosition(): String { private fun getPosition(): String {
return "${formatCoordinate(camera.cameraPosition.x)} / ${formatCoordinate(camera.cameraPosition.y)} / ${formatCoordinate(camera.cameraPosition.z)}" return "${formatCoordinate(camera.playerEntity.position.x)} / ${formatCoordinate(camera.playerEntity.position.y)} / ${formatCoordinate(camera.playerEntity.position.z)}"
return "${formatCoordinate(camera.playerEntity.position?.x!!)} / ${formatCoordinate(camera.playerEntity.position?.y!!)} / ${formatCoordinate(camera.playerEntity.position?.z!!)}"
} }
private fun getBlockPosition(): String { private fun getBlockPosition(): String {
@ -120,8 +119,8 @@ class HUDWorldDebugElement(hudRenderer: HUDRenderer) : DebugScreen(hudRenderer)
} }
private fun getFacing(): String { private fun getFacing(): String {
val yaw = hudRenderer.renderWindow.camera.playerEntity.rotation?.yaw!! val yaw = hudRenderer.renderWindow.camera.playerEntity.rotation.yaw
val pitch = hudRenderer.renderWindow.camera.playerEntity.rotation?.pitch!! val pitch = hudRenderer.renderWindow.camera.playerEntity.rotation.pitch
val direction = Directions.byDirection(camera.cameraFront) val direction = Directions.byDirection(camera.cameraFront)
return "${Directions.byDirection(camera.cameraFront).name.toLowerCase()} ${direction.directionVector} (${formatRotation(yaw.toDouble())} / ${formatRotation(pitch.toDouble())})" return "${Directions.byDirection(camera.cameraFront).name.toLowerCase()} ${direction.directionVector} (${formatRotation(yaw.toDouble())} / ${formatRotation(pitch.toDouble())})"
} }

View File

@ -41,7 +41,8 @@ class PacketMultiBlockChange() : ClientboundPacket() {
buffer.readChunkPosition() buffer.readChunkPosition()
} }
val count = buffer.readShort() val count = buffer.readShort()
val dataSize = buffer.readInt() // should be count * 4 val dataSize = buffer.readInt()
check(dataSize == count * 4) { "MultiBlockChangePacket needs 4 bytes per block change!" }
for (i in 0 until count) { for (i in 0 until count) {
val raw = buffer.readInt() val raw = buffer.readInt()
val meta = (raw and 0xF) val meta = (raw and 0xF)

View File

@ -40,22 +40,20 @@ class PacketUpdateLight(buffer: InByteBuffer) : ClientboundPacket() {
val skyLightMask: BitSet val skyLightMask: BitSet
val blockLightMask: BitSet val blockLightMask: BitSet
val emptySkyLightMask: BitSet
val emptyBlockLightMask: BitSet
if (buffer.versionId < ProtocolVersions.V_20W49A) { if (buffer.versionId < ProtocolVersions.V_20W49A) {
skyLightMask = KUtil.bitSetOf(buffer.readVarLong()) skyLightMask = KUtil.bitSetOf(buffer.readVarLong())
blockLightMask = KUtil.bitSetOf(buffer.readVarLong()) blockLightMask = KUtil.bitSetOf(buffer.readVarLong())
emptyBlockLightMask = KUtil.bitSetOf(buffer.readVarLong()) buffer.readVarLong() // emptyBlockLightMask
emptySkyLightMask = KUtil.bitSetOf(buffer.readVarLong()) buffer.readVarLong() // emptySkyLightMask
} else { } else {
skyLightMask = BitSet.valueOf(buffer.readLongArray()) skyLightMask = BitSet.valueOf(buffer.readLongArray())
blockLightMask = BitSet.valueOf(buffer.readLongArray()) blockLightMask = BitSet.valueOf(buffer.readLongArray())
emptySkyLightMask = BitSet.valueOf(buffer.readLongArray()) buffer.readLongArray() // emptySkyLightMask
emptyBlockLightMask = BitSet.valueOf(buffer.readLongArray()) buffer.readLongArray() // emptyBlockLightMask
} }
lightAccessor = readLightPacket(buffer, skyLightMask, blockLightMask, emptyBlockLightMask, emptySkyLightMask, buffer.connection.world.dimension!!) lightAccessor = readLightPacket(buffer, skyLightMask, blockLightMask, buffer.connection.world.dimension!!)
} }
override fun log() { override fun log() {

View File

@ -22,9 +22,9 @@ object CombatEventPacketFactory {
fun createPacket(buffer: InByteBuffer): ClientboundPacket { fun createPacket(buffer: InByteBuffer): ClientboundPacket {
return when (CombatEvents.VALUES[buffer.readVarInt()]) { return when (CombatEvents.VALUES[buffer.readVarInt()]) {
CombatEvents.ENTER_COMBAT -> EnterCombatEventPacket(buffer) CombatEvents.ENTER_COMBAT -> EnterCombatEventPacket()
CombatEvents.END_COMBAT -> EnterCombatEventPacket(buffer) CombatEvents.END_COMBAT -> EnterCombatEventPacket()
CombatEvents.ENTITY_DEATH -> EnterCombatEventPacket(buffer) CombatEvents.ENTITY_DEATH -> EnterCombatEventPacket()
} }
} }

View File

@ -14,10 +14,9 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play.combat package de.bixilon.minosoft.protocol.packets.clientbound.play.combat
import de.bixilon.minosoft.protocol.packets.ClientboundPacket import de.bixilon.minosoft.protocol.packets.ClientboundPacket
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.Log
class EnterCombatEventPacket(buffer: InByteBuffer) : ClientboundPacket() { class EnterCombatEventPacket : ClientboundPacket() {
override fun log() { override fun log() {
Log.protocol("[IN] Received enter combat event") Log.protocol("[IN] Received enter combat event")

View File

@ -14,10 +14,9 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play.title package de.bixilon.minosoft.protocol.packets.clientbound.play.title
import de.bixilon.minosoft.protocol.packets.ClientboundPacket import de.bixilon.minosoft.protocol.packets.ClientboundPacket
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.Log
class HideTitlePacket(buffer: InByteBuffer) : ClientboundPacket() { class HideTitlePacket : ClientboundPacket() {
override fun log() { override fun log() {
Log.protocol("[IN] Received hide title") Log.protocol("[IN] Received hide title")

View File

@ -14,10 +14,9 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play.title package de.bixilon.minosoft.protocol.packets.clientbound.play.title
import de.bixilon.minosoft.protocol.packets.ClientboundPacket import de.bixilon.minosoft.protocol.packets.ClientboundPacket
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.Log
class ResetTitlePacket(buffer: InByteBuffer) : ClientboundPacket() { class ResetTitlePacket : ClientboundPacket() {
override fun log() { override fun log() {
Log.protocol("[IN] Received reset title") Log.protocol("[IN] Received reset title")

View File

@ -26,8 +26,8 @@ object TitlePacketFactory {
TitleActions.SET_SUBTITLE -> SetSubTitlePacket(buffer) TitleActions.SET_SUBTITLE -> SetSubTitlePacket(buffer)
TitleActions.SET_ACTION_BAR -> SetActionBarTextPacket(buffer) TitleActions.SET_ACTION_BAR -> SetActionBarTextPacket(buffer)
TitleActions.SET_TIMES_AND_DISPLAY -> SetTimesAndDisplayPacket(buffer) TitleActions.SET_TIMES_AND_DISPLAY -> SetTimesAndDisplayPacket(buffer)
TitleActions.HIDE -> HideTitlePacket(buffer) TitleActions.HIDE -> HideTitlePacket()
TitleActions.RESET -> ResetTitlePacket(buffer) TitleActions.RESET -> ResetTitlePacket()
} }
} }

View File

@ -68,7 +68,7 @@ object ChunkUtil {
for (blockNumber in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) { for (blockNumber in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) {
var blockId = (blockData[arrayPosition].toInt() and 0xFF) shl 4 var blockId = (blockData[arrayPosition].toInt() and 0xFF) shl 4
var blockMeta = 0 var blockMeta: Int
// get block meta and shift and add (merge) id if needed // get block meta and shift and add (merge) id if needed
if (arrayPosition % 2 == 0) { if (arrayPosition % 2 == 0) {
// high bits // high bits

View File

@ -22,7 +22,7 @@ import java.util.*
object LightUtil { object LightUtil {
fun readLightPacket(buffer: InByteBuffer, skyLightMask: BitSet, blockLightMask: BitSet, emptyBlockLightMask: BitSet, emptySkyLightMask: BitSet, dimension: Dimension): LightAccessor { fun readLightPacket(buffer: InByteBuffer, skyLightMask: BitSet, blockLightMask: BitSet, dimension: Dimension): LightAccessor {
// ToDo // ToDo
val skyLight = if (dimension.hasSkyLight) { val skyLight = if (dimension.hasSkyLight) {
readLightArray(buffer, skyLightMask, dimension) readLightArray(buffer, skyLightMask, dimension)