mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
fix 3d biome detection, fix some transparency issues
This commit is contained in:
parent
d43c0bddc9
commit
e5c8f43aa9
@ -46,6 +46,8 @@ data class Dimension(
|
|||||||
height / ProtocolDefinition.SECTION_HEIGHT_Y
|
height / ProtocolDefinition.SECTION_HEIGHT_Y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val supports3DBiomes = resourceLocation.full != "minecraft:overworld" // ToDo
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return resourceLocation.toString()
|
return resourceLocation.toString()
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,5 @@ import de.bixilon.minosoft.data.world.BlockPosition
|
|||||||
|
|
||||||
interface BiomeAccessor {
|
interface BiomeAccessor {
|
||||||
|
|
||||||
fun getBiome(position: BlockPosition): Biome?
|
fun getBiome(position: BlockPosition, is3d: Boolean = true): Biome?
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,8 @@ import de.bixilon.minosoft.data.mappings.biomes.Biome
|
|||||||
import de.bixilon.minosoft.data.world.BlockPosition
|
import de.bixilon.minosoft.data.world.BlockPosition
|
||||||
|
|
||||||
class DummyBiomeAccessor(private val biome: Biome) : BiomeAccessor {
|
class DummyBiomeAccessor(private val biome: Biome) : BiomeAccessor {
|
||||||
override fun getBiome(position: BlockPosition): Biome {
|
|
||||||
|
override fun getBiome(position: BlockPosition, is3d: Boolean): Biome {
|
||||||
return biome
|
return biome
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,14 @@ class NoiseBiomeAccessor(
|
|||||||
private val biomes: Array<Biome>,
|
private val biomes: Array<Biome>,
|
||||||
) : BiomeAccessor {
|
) : BiomeAccessor {
|
||||||
|
|
||||||
override fun getBiome(position: BlockPosition): Biome? {
|
override fun getBiome(position: BlockPosition, is3d: Boolean): Biome? {
|
||||||
val inChunk = position.getInChunkSectionPosition()
|
val inChunk = position.getInChunkSectionPosition()
|
||||||
val index = (inChunk.y / 4 * 16 + ((inChunk.z / 4 * 4) + (inChunk.x / 4)))
|
val y = if (is3d) {
|
||||||
|
inChunk.y / 4 * 16
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
val index = (y + ((inChunk.z / 4 * 4) + (inChunk.x / 4)))
|
||||||
if (index < 0 || index > biomes.size) {
|
if (index < 0 || index > biomes.size) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class XZBiomeAccessor(
|
|||||||
private val biomes: Array<Biome>,
|
private val biomes: Array<Biome>,
|
||||||
) : BiomeAccessor {
|
) : BiomeAccessor {
|
||||||
|
|
||||||
override fun getBiome(position: BlockPosition): Biome {
|
override fun getBiome(position: BlockPosition, is3d: Boolean): Biome {
|
||||||
return biomes[(position.x and 0x0F) or ((position.z and 0x0F) shl 4)]
|
return biomes[(position.x and 0x0F) or ((position.z and 0x0F) shl 4)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,14 +206,14 @@ class Camera(
|
|||||||
headLocation = Position(cameraPosition)
|
headLocation = Position(cameraPosition)
|
||||||
feetLocation = Position(headLocation.x, headLocation.y - PLAYER_HEIGHT, headLocation.z)
|
feetLocation = Position(headLocation.x, headLocation.y - PLAYER_HEIGHT, headLocation.z)
|
||||||
blockPosition = feetLocation.toBlockPosition()
|
blockPosition = feetLocation.toBlockPosition()
|
||||||
currentBiome = connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition)
|
currentBiome = connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition, connection.player.world.dimension?.supports3DBiomes ?: false)
|
||||||
chunkPosition = blockPosition.getChunkPosition()
|
chunkPosition = blockPosition.getChunkPosition()
|
||||||
sectionHeight = blockPosition.getSectionHeight()
|
sectionHeight = blockPosition.getSectionHeight()
|
||||||
inChunkSectionPosition = blockPosition.getInChunkSectionPosition()
|
inChunkSectionPosition = blockPosition.getInChunkSectionPosition()
|
||||||
|
|
||||||
// recalculate sky color for current biome
|
// recalculate sky color for current biome
|
||||||
val blockPosition = Position(cameraPosition).toBlockPosition()
|
val blockPosition = Position(cameraPosition).toBlockPosition()
|
||||||
renderWindow.setSkyColor(connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR)
|
renderWindow.setSkyColor(connection.player.world.getChunk(blockPosition.getChunkPosition())?.biomeAccessor?.getBiome(blockPosition, connection.player.world.dimension?.supports3DBiomes ?: false)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR)
|
||||||
connection.renderer.renderWindow.worldRenderer.recalculateFrustum(Frustum(this))
|
connection.renderer.renderWindow.worldRenderer.recalculateFrustum(Frustum(this))
|
||||||
connection.player.world.dimension?.hasSkyLight?.let {
|
connection.player.world.dimension?.hasSkyLight?.let {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
@ -29,6 +29,7 @@ object RenderConstants {
|
|||||||
|
|
||||||
|
|
||||||
val EXPERIENCE_BAR_LEVEL_COLOR = RGBColor("#80ff20")
|
val EXPERIENCE_BAR_LEVEL_COLOR = RGBColor("#80ff20")
|
||||||
|
val HP_TEXT_COLOR = RGBColor("#ff1313")
|
||||||
|
|
||||||
const val COLORMAP_SIZE = 255
|
const val COLORMAP_SIZE = 255
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class WorldRenderer(
|
|||||||
visibleChunks.add(chunkPosition)
|
visibleChunks.add(chunkPosition)
|
||||||
}
|
}
|
||||||
val chunk = world.getChunk(chunkPosition)!!
|
val chunk = world.getChunk(chunkPosition)!!
|
||||||
|
val dimensionSupports3dBiomes = connection.player.world.dimension?.supports3DBiomes ?: false
|
||||||
val mesh = ChunkMesh()
|
val mesh = ChunkMesh()
|
||||||
|
|
||||||
for ((index, blockInfo) in section.blocks.withIndex()) {
|
for ((index, blockInfo) in section.blocks.withIndex()) {
|
||||||
@ -67,7 +67,7 @@ class WorldRenderer(
|
|||||||
neighborBlocks[direction.ordinal] = world.getBlockInfo(blockPosition + direction)
|
neighborBlocks[direction.ordinal] = world.getBlockInfo(blockPosition + direction)
|
||||||
}
|
}
|
||||||
|
|
||||||
val biome = chunk.biomeAccessor!!.getBiome(blockPosition)
|
val biome = chunk.biomeAccessor!!.getBiome(blockPosition, dimensionSupports3dBiomes)
|
||||||
|
|
||||||
var tintColor: RGBColor? = null
|
var tintColor: RGBColor? = null
|
||||||
if (StaticConfiguration.BIOME_DEBUG_MODE) {
|
if (StaticConfiguration.BIOME_DEBUG_MODE) {
|
||||||
@ -106,6 +106,12 @@ class WorldRenderer(
|
|||||||
|
|
||||||
override fun postInit() {
|
override fun postInit() {
|
||||||
renderWindow.textures.use(chunkShader, "textureArray")
|
renderWindow.textures.use(chunkShader, "textureArray")
|
||||||
|
|
||||||
|
for (block in connection.version.mapping.blockStateIdMap.values) {
|
||||||
|
for (model in block.renders) {
|
||||||
|
model.postInit()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun draw() {
|
override fun draw() {
|
||||||
@ -143,6 +149,7 @@ class WorldRenderer(
|
|||||||
return textures
|
return textures
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun prepareChunk(chunkPosition: ChunkPosition, chunk: Chunk? = world.getChunk(chunkPosition), checkQueued: Boolean = true) {
|
fun prepareChunk(chunkPosition: ChunkPosition, chunk: Chunk? = world.getChunk(chunkPosition), checkQueued: Boolean = true) {
|
||||||
if (chunk == null || !chunk.isFullyLoaded) {
|
if (chunk == null || !chunk.isFullyLoaded) {
|
||||||
return
|
return
|
||||||
|
@ -24,6 +24,7 @@ import de.bixilon.minosoft.data.world.light.LightAccessor
|
|||||||
import de.bixilon.minosoft.gui.rendering.chunk.ChunkMesh
|
import de.bixilon.minosoft.gui.rendering.chunk.ChunkMesh
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureTransparencies
|
||||||
import glm_.mat4x4.Mat4
|
import glm_.mat4x4.Mat4
|
||||||
|
|
||||||
class BlockRenderer {
|
class BlockRenderer {
|
||||||
@ -67,18 +68,38 @@ class BlockRenderer {
|
|||||||
textureMapping[key] = texture!!
|
textureMapping[key] = texture!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun postInit() {
|
||||||
for (direction in Directions.DIRECTIONS) {
|
for (direction in Directions.DIRECTIONS) {
|
||||||
|
var directionIsCullface: Boolean? = null
|
||||||
|
var directionIsNotTransparent: Boolean? = null
|
||||||
|
var directionIsFull: Boolean? = null
|
||||||
for (element in elements) {
|
for (element in elements) {
|
||||||
if (element.isCullFace(direction)) {
|
if (element.isCullFace(direction)) {
|
||||||
cullFaces.add(direction)
|
directionIsCullface = true
|
||||||
}
|
}
|
||||||
if (textureMapping[element.getTexture(direction)]?.isTransparent == true) { // THIS IS BROKEN!
|
if (textureMapping[element.getTexture(direction)]?.transparency != TextureTransparencies.OPAQUE) {
|
||||||
transparentFaces.add(direction)
|
if (directionIsNotTransparent == null) {
|
||||||
|
directionIsNotTransparent = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
directionIsNotTransparent = true
|
||||||
}
|
}
|
||||||
if (element.isFullTowards(direction)) {
|
if (element.isFullTowards(direction)) {
|
||||||
fullFaceDirections.add(direction)
|
directionIsFull = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (directionIsCullface == true) {
|
||||||
|
cullFaces.add(direction)
|
||||||
|
}
|
||||||
|
if (directionIsNotTransparent == false) {
|
||||||
|
transparentFaces.add(direction)
|
||||||
|
}
|
||||||
|
if (directionIsFull == true) {
|
||||||
|
fullFaceDirections.add(direction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ class Texture(
|
|||||||
var layer = -1
|
var layer = -1
|
||||||
var width: Int = 0
|
var width: Int = 0
|
||||||
var height: Int = 0
|
var height: Int = 0
|
||||||
var isTransparent: Boolean = false
|
lateinit var transparency: TextureTransparencies
|
||||||
|
private set
|
||||||
lateinit var buffer: ByteBuffer
|
lateinit var buffer: ByteBuffer
|
||||||
var loaded = false
|
var loaded = false
|
||||||
|
|
||||||
@ -49,10 +50,13 @@ class Texture(
|
|||||||
width = decoder.width
|
width = decoder.width
|
||||||
height = decoder.height
|
height = decoder.height
|
||||||
buffer.rewind()
|
buffer.rewind()
|
||||||
|
transparency = TextureTransparencies.OPAQUE
|
||||||
for (i in 0 until buffer.limit() step 4) {
|
for (i in 0 until buffer.limit() step 4) {
|
||||||
val color = RGBColor(buffer.get(), buffer.get(), buffer.get(), buffer.get())
|
val color = RGBColor(buffer.get(), buffer.get(), buffer.get(), buffer.get())
|
||||||
if (color.alpha < 0xFF) {
|
if (color.alpha == 0x00 && transparency != TextureTransparencies.SEMI_TRANSPARENT) {
|
||||||
isTransparent = true
|
transparency = TextureTransparencies.TRANSPARENT
|
||||||
|
} else if (color.alpha < 0xFF) {
|
||||||
|
transparency = TextureTransparencies.SEMI_TRANSPARENT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.flip()
|
buffer.flip()
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program.If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.textures
|
||||||
|
|
||||||
|
enum class TextureTransparencies {
|
||||||
|
OPAQUE,
|
||||||
|
TRANSPARENT,
|
||||||
|
SEMI_TRANSPARENT,
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user