diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt index 97314bcd0..a560a2513 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt @@ -225,8 +225,6 @@ class RenderWindow( connection.fireEvent(ResizeWindowEvent(previousSize = Vec2i(0, 0), size = window.size)) - Log.log(LogMessageType.RENDERING_LOADING) { "Unloading assets manager" } - connection.assetsManager.unload() Log.log(LogMessageType.RENDERING_LOADING) { "Rendering is fully prepared in ${stopwatch.totalTime()}" } initialized = true latch.dec() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/WeightedBakedModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/WeightedBakedModel.kt index bd8d54004..424a14086 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/WeightedBakedModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/WeightedBakedModel.kt @@ -35,15 +35,17 @@ class WeightedBakedModel( totalWeight += weight } - check(totalWeight > 0) { "Weight must be >= 1" } this.totalWeight = totalWeight } override fun getTouchingFaceProperties(random: Random, direction: Directions): Array { - return getModel(random).getTouchingFaceProperties(random, direction) + return getModel(random)?.getTouchingFaceProperties(random, direction) ?: arrayOf() } - private fun getModel(random: Random): BakedBlockModel { + private fun getModel(random: Random): BakedBlockModel? { + if (models.isEmpty()) { + return null + } var weightLeft = abs(random.nextLong() % totalWeight) for ((model, weight) in models) { @@ -57,12 +59,12 @@ class WeightedBakedModel( } override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean { - return getModel(random).singleRender(position, mesh, random, blockState, neighbours, light, ambientLight, tints) + return getModel(random)?.singleRender(position, mesh, random, blockState, neighbours, light, ambientLight, tints) ?: false } override fun getParticleTexture(random: Random, blockPosition: Vec3i): AbstractTexture? { random.setSeed(VecUtil.generatePositionHash(blockPosition.x, blockPosition.y, blockPosition.z)) - return getModel(random).getParticleTexture(random, blockPosition) + return getModel(random)?.getParticleTexture(random, blockPosition) } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundData.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundData.kt index 2d70a2d7e..28d81d47f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundData.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundData.kt @@ -45,7 +45,10 @@ class SoundData( companion object { operator fun invoke(assetsManager: AssetsManager, sound: Sound): SoundData { - val buffer = ByteBuffer.wrap(assetsManager[sound.path].readAllBytes()) + val vorbisData = assetsManager[sound.path].readAllBytes() + val buffer = BufferUtils.createByteBuffer(vorbisData.size) + buffer.put(vorbisData) + buffer.rewind() val error = BufferUtils.createIntBuffer(1) val vorbis = stb_vorbis_open_memory(buffer, error, null) @@ -73,7 +76,7 @@ class SoundData( channels = channels, sampleRate = sampleRate, samplesLength = samplesLength, - sampleSeconds = sampleSeconds + sampleSeconds = sampleSeconds, ) } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundType.kt index 46ee10367..27e1c4a37 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/sounds/SoundType.kt @@ -32,11 +32,13 @@ data class SoundType( totalWeight += sound.weight } - check(totalWeight >= 1) { "Weight must be >= 1" } this.totalWeight = totalWeight } - fun getSound(random: Random): Sound { + fun getSound(random: Random): Sound? { + if (sounds.isEmpty()) { + return null + } var weightLeft = abs(random.nextLong() % totalWeight) for (sound in sounds) { diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/PlayConnection.kt b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/PlayConnection.kt index 923257268..14001dc70 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/PlayConnection.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/PlayConnection.kt @@ -204,6 +204,7 @@ class PlayConnection( if (this::randomTickTask.isInitialized) { TimeWorker.removeTask(randomTickTask) } + assetsManager.unload() state = PlayConnectionStates.DISCONNECTED ACTIVE_CONNECTIONS -= this }