diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.kt b/src/main/java/de/bixilon/minosoft/data/world/World.kt index e1f01f051..b47cdee14 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/World.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/World.kt @@ -40,6 +40,8 @@ class World : BiomeAccessor { val worldLightAccessor = WorldLightAccessor(this) var hashedSeed = 0L var biomeAccessor: BiomeAccessor = NullBiomeAccessor + var time = 0L + var age = 0L fun getBlockState(blockPosition: Vec3i): BlockState? { val chunkLocation = blockPosition.chunkPosition diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/shader/Shader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/shader/Shader.kt index 8e2e3dbc1..f3a099940 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/shader/Shader.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/shader/Shader.kt @@ -44,7 +44,7 @@ class Shader( fun load(assetsManager: AssetsManager = Minosoft.MINOSOFT_ASSETS_MANAGER): Int { val uniforms: MutableList = mutableListOf() - val pathPrefix = resourceLocation.namespace + ":rendering/shader/" + resourceLocation.path + "/" + resourceLocation.path.replace("/", "_") + val pathPrefix = """${resourceLocation.namespace}:rendering/shader/${resourceLocation.path}/${resourceLocation.path.replace("/", "_")}""" val vertexShader = createShader(assetsManager, ResourceLocation("$pathPrefix.vsh"), GL_VERTEX_SHADER_ARB, defines, uniforms)!! val geometryShader = createShader(assetsManager, ResourceLocation("$pathPrefix.gsh"), GL_GEOMETRY_SHADER_ARB, defines, uniforms) val fragmentShader = createShader(assetsManager, ResourceLocation("$pathPrefix.fsh"), GL_FRAGMENT_SHADER_ARB, defines, uniforms)!! @@ -165,9 +165,25 @@ class Shader( } for (line in lines) { + val reader = CommandStringReader(line) + when { + line.startsWith("#include ") -> { + val includeResourceLocation = ResourceLocation(line.removePrefix("#include ").removePrefix("\"").removeSuffix("\"").replace("\\\"", "\"")) + total.append("\n") + total.append(assetsManager.readStringAsset(if (includeResourceLocation.path.contains(".glsl")) { + includeResourceLocation + } else { + ResourceLocation(includeResourceLocation.namespace, "rendering/shader/includes/${includeResourceLocation.path}.glsl") + })) + + total.append("\n") + continue + } + } + total.append(line) total.append('\n') - val reader = CommandStringReader(line) + when { line.startsWith("#version") -> { // add all defines diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java index 91b908f46..1c75d65dd 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java @@ -28,8 +28,8 @@ public class TimeChangeEvent extends CancelableEvent { public TimeChangeEvent(PlayConnection connection, WorldTimeSetS2CP pkg) { super(connection); - this.worldAge = pkg.getWorldAge(); - this.timeOfDay = pkg.getTimeOfDay(); + this.worldAge = pkg.getAge(); + this.timeOfDay = pkg.getTime(); } public long getWorldAge() { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldTimeSetS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldTimeSetS2CP.kt index 42ef7233c..5d7d209bb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldTimeSetS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldTimeSetS2CP.kt @@ -21,17 +21,19 @@ import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class WorldTimeSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { - val worldAge: Long = buffer.readLong() - val timeOfDay: Long = buffer.readLong() + val age = buffer.readLong() + val time = buffer.readLong() override fun handle(connection: PlayConnection) { if (connection.fireEvent(TimeChangeEvent(connection, this))) { return } + connection.world.age = age + connection.world.time = time } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "World time set (worldAge=$worldAge, timeOfDay=$timeOfDay)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "World time set (age=$age, time=$time)" } } } diff --git a/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh b/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh index ee33d1797..b3709d3f8 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh @@ -23,20 +23,7 @@ in float passInterpolateBetweenTextures; in vec4 passTintColor; -uniform sampler2DArray textureArray[7]; - -vec4 getTexture(uint textureId, vec3 textureCoordinates){ - switch (textureId){ - case 0u : return texture(textureArray[0], textureCoordinates); - case 1u: return texture(textureArray[1], textureCoordinates); - case 2u: return texture(textureArray[2], textureCoordinates); - case 3u: return texture(textureArray[3], textureCoordinates); - case 4u: return texture(textureArray[4], textureCoordinates); - case 5u: return texture(textureArray[5], textureCoordinates); - case 6u: return texture(textureArray[6], textureCoordinates); - } - return texture(textureArray[0], textureCoordinates); -} +#include "minosoft:texture" void main() { vec4 firstTexelColor = getTexture(passFirstTextureIdIndex, passFirstTextureCoordinates); diff --git a/src/main/resources/assets/minosoft/rendering/shader/hud/hud.fsh b/src/main/resources/assets/minosoft/rendering/shader/hud/hud.fsh index 3e6b8b04e..533b9bf44 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/hud/hud.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/hud/hud.fsh @@ -19,23 +19,7 @@ flat in uint passTextureIdIndex; in vec3 passTextureCoordinates; in vec4 passTintColor; - -uniform sampler2DArray textureArray[7]; - - -vec4 getTexture(uint textureId, vec3 textureCoordinates) { // ToDo: This method is just stupid, @see chunk_fragment.glsl - switch (textureId){ - case 0u : return texture(textureArray[0], textureCoordinates); - case 1u: return texture(textureArray[1], textureCoordinates); - case 2u: return texture(textureArray[2], textureCoordinates); - case 3u: return texture(textureArray[3], textureCoordinates); - case 4u: return texture(textureArray[4], textureCoordinates); - case 5u: return texture(textureArray[5], textureCoordinates); - case 6u: return texture(textureArray[6], textureCoordinates); - } - return texture(textureArray[0], textureCoordinates); -} - +#include "minosoft:texture" void main() { vec4 texelColor = getTexture(passTextureIdIndex, passTextureCoordinates); diff --git a/src/main/resources/assets/minosoft/rendering/shader/includes/texture.glsl b/src/main/resources/assets/minosoft/rendering/shader/includes/texture.glsl new file mode 100644 index 000000000..e65c8d211 --- /dev/null +++ b/src/main/resources/assets/minosoft/rendering/shader/includes/texture.glsl @@ -0,0 +1,28 @@ +/* + * Minosoft + * Copyright (C) 2020 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + + +uniform sampler2DArray textureArray[7]; + +vec4 getTexture(uint textureId, vec3 textureCoordinates) { // ToDo: This method is just stupid and workarounds a opengl crash with mesa drivers + switch (textureId){ + case 0u : return texture(textureArray[0], textureCoordinates); + case 1u: return texture(textureArray[1], textureCoordinates); + case 2u: return texture(textureArray[2], textureCoordinates); + case 3u: return texture(textureArray[3], textureCoordinates); + case 4u: return texture(textureArray[4], textureCoordinates); + case 5u: return texture(textureArray[5], textureCoordinates); + case 6u: return texture(textureArray[6], textureCoordinates); + } + return texture(textureArray[0], textureCoordinates); +}