mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
Wall overlay, overlay fixes
This commit is contained in:
parent
b6d0696cd5
commit
379126a95a
@ -20,4 +20,6 @@ interface Overlay : Drawable {
|
||||
|
||||
fun init() {}
|
||||
fun postInit() {}
|
||||
|
||||
fun update() {}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ class OverlayManager(
|
||||
|
||||
override fun draw() {
|
||||
for (overlay in overlays) {
|
||||
overlay.update()
|
||||
if (!overlay.render) {
|
||||
continue
|
||||
}
|
||||
|
@ -13,10 +13,12 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays.simple.WallOverlay
|
||||
import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays.simple.WaterOverlay
|
||||
|
||||
object DefaultOverlays {
|
||||
val OVERLAYS = listOf(
|
||||
WallOverlay,
|
||||
WaterOverlay,
|
||||
)
|
||||
}
|
||||
|
@ -30,10 +30,8 @@ abstract class SimpleOverlay(
|
||||
protected open val shader: Shader = renderWindow.shaderManager.genericTexture2dShader
|
||||
private var mesh = SimpleTextureMesh(renderWindow)
|
||||
protected var tintColor: RGBColor? = null
|
||||
|
||||
override fun postInit() {
|
||||
updateMesh()
|
||||
}
|
||||
protected open var uvStart = Vec2(0.0f, 0.0f)
|
||||
protected open var uvEnd = Vec2(1.0f, 1.0f)
|
||||
|
||||
|
||||
protected fun updateMesh() {
|
||||
@ -42,13 +40,13 @@ abstract class SimpleOverlay(
|
||||
}
|
||||
mesh = SimpleTextureMesh(renderWindow)
|
||||
|
||||
mesh.addZQuad(Vec2(-1.0f, -1.0f), z, Vec2(+1.0f, +1.0f)) { position, uv -> mesh.addVertex(position, texture, uv, tintColor) }
|
||||
mesh.addZQuad(Vec2(-1.0f, -1.0f), z, Vec2(+1.0f, +1.0f), uvStart, uvEnd) { position, uv -> mesh.addVertex(position, texture, uv, tintColor) }
|
||||
mesh.load()
|
||||
}
|
||||
|
||||
override fun draw() {
|
||||
renderWindow.renderSystem.reset(blending = true)
|
||||
updateMesh()
|
||||
updateMesh() // ToDo: Don't update every time
|
||||
shader.use()
|
||||
mesh.draw()
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 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.framebuffer.world.overlay.overlays.simple
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
||||
import de.bixilon.minosoft.data.abilities.Gamemodes
|
||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.OverlayFactory
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.blockPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY
|
||||
import glm_.vec2.Vec2
|
||||
import glm_.vec3.Vec3i
|
||||
import java.util.*
|
||||
|
||||
class WallOverlay(renderWindow: RenderWindow, z: Float) : SimpleOverlay(renderWindow, z) {
|
||||
private val player = renderWindow.connection.player
|
||||
override var texture: AbstractTexture = unsafeNull()
|
||||
private var blockState: BlockState? = null
|
||||
private var position: Vec3i = Vec3i.EMPTY
|
||||
override val render: Boolean
|
||||
get() {
|
||||
val blockState = blockState
|
||||
return player.gamemode != Gamemodes.SPECTATOR && blockState != null && blockState.block !is FluidBlock
|
||||
}
|
||||
override var uvEnd: Vec2
|
||||
get() = Vec2(0.3f, renderWindow.window.sizef.x / renderWindow.window.sizef.y / 3.0f) // To make pixels squares and make it look more like minecraft
|
||||
set(value) {}
|
||||
private val random = Random()
|
||||
|
||||
override fun update() {
|
||||
position = player.eyePosition.blockPosition
|
||||
blockState = renderWindow.connection.world[position]
|
||||
}
|
||||
|
||||
override fun draw() {
|
||||
random.setSeed(VecUtil.generatePositionHash(position.x, position.y, position.z))
|
||||
texture = blockState?.blockModel?.getParticleTexture(random, position) ?: return
|
||||
|
||||
tintColor = RGBColor(0.1f, 0.1f, 0.1f, 1.0f)
|
||||
|
||||
super.draw()
|
||||
}
|
||||
|
||||
|
||||
companion object : OverlayFactory<WallOverlay> {
|
||||
|
||||
override fun build(renderWindow: RenderWindow, z: Float): WallOverlay {
|
||||
return WallOverlay(renderWindow, z)
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays.simple
|
||||
|
||||
import de.bixilon.minosoft.data.abilities.Gamemodes
|
||||
import de.bixilon.minosoft.data.registries.fluid.water.WaterFluid
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
@ -22,9 +23,10 @@ import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
|
||||
class WaterOverlay(renderWindow: RenderWindow, z: Float) : SimpleOverlay(renderWindow, z) {
|
||||
private val player = renderWindow.connection.player
|
||||
override val texture: AbstractTexture = renderWindow.textureManager.staticTextures.createTexture("minecraft:misc/underwater".toResourceLocation().texture())
|
||||
override val render: Boolean
|
||||
get() = renderWindow.connection.player.submergedFluid is WaterFluid
|
||||
get() = player.gamemode != Gamemodes.SPECTATOR && player.submergedFluid is WaterFluid
|
||||
|
||||
override fun draw() {
|
||||
val brightness = renderWindow.connection.world.getBrightness(renderWindow.connection.player.positionInfo.blockPosition)
|
||||
|
Loading…
x
Reference in New Issue
Block a user