Skip to content

Commit

Permalink
Changed: Modified the description of fakeAirPocket config item & th…
Browse files Browse the repository at this point in the history
…e rendering is still not completed
  • Loading branch information
xiewuzhiying committed Nov 14, 2024
1 parent e0d2de0 commit 03e622d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ object VSAdditionConfig {
val experimental = EXPERIMENTAL()

class EXPERIMENTAL {
@JsonSchema(description = "FAKE")
@JsonSchema(description = "Enable fake air pocket. This feature may frequently change, potentially causing damage to your old save files. Please consider enabling it with caution.")
var fakeAirPocket = false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.xiewuzhiying.vs_addition.context.airpocket

import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.DefaultVertexFormat
import com.mojang.blaze3d.vertex.PoseStack
import com.mojang.blaze3d.vertex.VertexConsumer
Expand All @@ -14,10 +15,9 @@ import io.netty.util.collection.LongObjectHashMap
import io.netty.util.collection.LongObjectMap
import net.minecraft.client.Camera
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.LevelRenderer
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.RenderStateShard
import net.minecraft.client.renderer.RenderType
import net.minecraft.client.renderer.*
import net.minecraft.client.renderer.texture.OverlayTexture
import net.minecraft.client.resources.model.ModelBakery
import net.minecraft.commands.CommandBuildContext
import net.minecraft.network.chat.Component
import net.minecraft.world.phys.AABB
Expand Down Expand Up @@ -177,10 +177,22 @@ object FakeAirPocketClient {
.createCompositeState(false)
)

/*private val WATER_SURFACE: RenderType.CompositeRenderType = RenderType.create(
"water_surface_triangles",
DefaultVertexFormat.BLOCK,
VertexFormat.Mode.TRIANGLES,
2097152,
true,
true,
RenderType.translucentState(RenderStateShard.RENDERTYPE_TRANSLUCENT_SHADER)
)*/

@JvmStatic
fun render(ms: PoseStack, camera: Camera, bufferSource: MultiBufferSource?) {
if (!(VSAdditionConfig.COMMON.experimental.fakeAirPocket && VSAdditionConfig.CLIENT.experimental.cullWaterSurfaceInFakeAirPocket)) return
val waterMaskConsumer = bufferSource?.getBuffer(WATER_MASK) ?: return
/*val waterFaceConsumer = bufferSource.getBuffer(WATER_SURFACE)
val mc = Minecraft.getInstance()*/
val shipClientWorld = ((Minecraft.getInstance() as? IShipObjectWorldClientProvider)?.shipObjectWorld as? ShipObjectClientWorld) ?: return
val cameraPosition = camera.position.toJOML()
val loadedShips = shipClientWorld.loadedShips
Expand All @@ -201,8 +213,8 @@ object FakeAirPocketClient {
}
}

/*val section = aabb2.toPoints().filter { it.isBehindPlane(plane) }.toMutableList()
mask.forEach { section.add(it) }*/
val section = aabb2.toPoints().filter { it.isBehindPlane(plane) }.toMutableList()
mask.forEach { section.add(it) }

val cameraPosition2 = transform.worldToShip.transformPosition(Vector3d(cameraPosition)).sub(aabb.center(Vector3d()))

Expand All @@ -216,17 +228,22 @@ object FakeAirPocketClient {
}
}
.forEach { face ->
renderMask2(ms, transform, cameraPosition, aabb.center(Vector3d()), sortVertices(face.first, face.second), waterSurfaceConsumer, cameraPosition2.isInFrontOfPlane(face.third))
val center = aabb.center(Vector3d())
renderWaterSurface(waterFaceConsumer, ms, transform, cameraPosition, center, sortVertices(face.first, face.second), cameraPosition2.isInFrontOfPlane(face.third), BiomeColors.getAverageWaterColor(mc.level, center.toBlockPos))
}*/

renderMask(ms, transform, cameraPosition, aabb.center(Vector3d()), sortVertices(mask, plane.normal), waterMaskConsumer, cameraPosition2.isInFrontOfPlane(plane))
}
}
}

private fun renderMask(ms: PoseStack, transform: ShipTransform, camera: Vector3dc, offset: Vector3dc, vertices: List<Vector3dc>, maskConsumer: VertexConsumer, bl: Boolean) {
if (vertices.size < 3) return
/*val textureAtlasSprite = ModelBakery.WATER_FLOW.sprite()
val u1 = textureAtlasSprite.getU(0.0)
val u2 = textureAtlasSprite.getU(16.0)
val v1 = textureAtlasSprite.getV(0.0)
val v2 = textureAtlasSprite.getV(16.0)
fun renderWaterSurface(waterFaceConsumer: VertexConsumer, ms: PoseStack, transform: ShipTransform, camera: Vector3dc, offset: Vector3dc, vertices: List<Vector3dc>, bl: Boolean, color: Int) {
ms.pushPose()
VSClientGameUtils.transformRenderWithShip(
transform,
Expand All @@ -238,8 +255,21 @@ object FakeAirPocketClient {
camera.y(),
camera.z()
)
renderTriangle(maskConsumer, ms.last().pose(), vertices, true)
val matrix4f: Matrix4f = ms.last().pose()
RenderSystem.setShaderTexture(0, textureAtlasSprite.atlasLocation())
RenderSystem.setShader { GameRenderer.getRendertypeTranslucentShader() }
*//*RenderSystem.enableBlend()
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)*//*
RenderSystem.enableDepthTest()
renderTriangle2(waterFaceConsumer, matrix4f, vertices, bl, color)
ms.popPose()
}*/

private fun renderMask(ms: PoseStack, transform: ShipTransform, camera: Vector3dc, offset: Vector3dc, vertices: List<Vector3dc>, maskConsumer: VertexConsumer, bl: Boolean) {
if (vertices.size < 3) return

ms.pushPose()
VSClientGameUtils.transformRenderWithShip(
Expand All @@ -249,10 +279,10 @@ object FakeAirPocketClient {
offset.y(),
offset.z(),
camera.x(),
camera.y() + ZFIGHT,
camera.y() + if (bl) 0.0 else ZFIGHT,
camera.z()
)
renderTriangle(maskConsumer, ms.last().pose(), vertices, false)
renderTriangle(maskConsumer, ms.last().pose(), vertices, bl)
ms.popPose()
}

Expand All @@ -265,21 +295,57 @@ object FakeAirPocketClient {
}
consumer
.vertex(matrix, vertices[first].x().toFloat(), vertices[first].y().toFloat(), vertices[first].z().toFloat())
.uv(0f, 0f)
.endVertex()

consumer
.vertex(matrix, vertices[i].x().toFloat(), vertices[i].y().toFloat(), vertices[i].z().toFloat())
.uv(0f, 1f)
.endVertex()

consumer
.vertex(matrix, vertices[finally].x().toFloat(), vertices[finally].y().toFloat(), vertices[finally].z().toFloat())
.uv(1f, 0f)
.endVertex()
}
}

/*private fun renderTriangle2(consumer: VertexConsumer, matrix: Matrix4f, vertices: List<Vector3dc>, order: Boolean, color: Int) {
val r: Float = (color shr 16 and 255).toFloat() / 255.0f
val g: Float = (color shr 8 and 255).toFloat() / 255.0f
val b: Float = (color and 255).toFloat() / 255.0f
for (i in 1 until vertices.size - 1) {
val (first, finally) = if (order) {
Pair(i+1, 0)
} else {
Pair(0, i+1)
}
consumer
.vertex(matrix, vertices[first].x().toFloat(), vertices[first].y().toFloat(), vertices[first].z().toFloat())
.uv(u1, v1)
.color(r, g, b, 1f)
.uv2(LightTexture.FULL_BRIGHT)
.overlayCoords(OverlayTexture.NO_OVERLAY)
.normal(0f, 1f, 0f)
.endVertex()
consumer
.vertex(matrix, vertices[i].x().toFloat(), vertices[i].y().toFloat(), vertices[i].z().toFloat())
.uv(u1, v2)
.color(r, g, b, 1f)
.uv2(LightTexture.FULL_BRIGHT)
.overlayCoords(OverlayTexture.NO_OVERLAY)
.normal(0f, 1f, 0f)
.endVertex()
consumer
.vertex(matrix, vertices[finally].x().toFloat(), vertices[finally].y().toFloat(), vertices[finally].z().toFloat())
.uv(u2, v1)
.color(r, g, b, 1f)
.uv2(LightTexture.FULL_BRIGHT)
.overlayCoords(OverlayTexture.NO_OVERLAY)
.normal(0f, 1f, 0f)
.endVertex()
}
}*/

private fun sortVertices(vertices: List<Vector3dc>, planeNormal: Vector3dc): List<Vector3dc> {
if (vertices.size < 3) return vertices

Expand Down

0 comments on commit 03e622d

Please sign in to comment.