|
| 1 | +package me.nk0.rcu.client.render |
| 2 | + |
| 3 | +import net.minecraft.client.render.* |
| 4 | +import net.minecraft.client.render.VertexFormat.DrawMode |
| 5 | +import net.minecraft.client.util.math.MatrixStack |
| 6 | +import net.minecraft.util.Identifier |
| 7 | +import net.minecraft.util.math.BlockPos |
| 8 | +import net.minecraft.util.math.Vec3d |
| 9 | +import net.minecraft.util.math.Vec3i |
| 10 | +import org.joml.Matrix4f |
| 11 | +import org.joml.Vector4f |
| 12 | + |
| 13 | +object Color { |
| 14 | + val DEFAULT: Vector4f = Vector4f(0f, 0.823f, 1f, 0.3f) |
| 15 | + val POWERED: Vector4f = Vector4f(1f, 0.251f, 0f, 0.3f) |
| 16 | + val SELECTED: Vector4f = Vector4f(0f, 0.823f, 1f, 0.7f) |
| 17 | + val SELECTED_POWERED: Vector4f = Vector4f(1f, 0.251f, 0f, 0.7f) |
| 18 | + val SELECTED_OUTLINE: Vector4f = Vector4f(1f, 1f, 1f, 1f) |
| 19 | + val SELECTED_POWERED_OUTLINE: Vector4f = Vector4f(0.384f, 0.878f, 1f, 1f) |
| 20 | + |
| 21 | + fun getFill(selected: Boolean, powered: Boolean): Vector4f = when (Pair(selected, powered)) { |
| 22 | + Pair(true, true) -> { |
| 23 | + SELECTED_POWERED |
| 24 | + } |
| 25 | + |
| 26 | + Pair(true, false) -> { |
| 27 | + SELECTED |
| 28 | + } |
| 29 | + |
| 30 | + Pair(false, true) -> { |
| 31 | + POWERED |
| 32 | + } |
| 33 | + |
| 34 | + else -> { |
| 35 | + DEFAULT |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + fun getOutline(powered: Boolean): Vector4f = if (powered) { |
| 40 | + SELECTED_POWERED_OUTLINE |
| 41 | + } else { |
| 42 | + SELECTED_OUTLINE |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +object RcuRenderLayer { |
| 47 | + val DEFAULT = RenderLayer.of( |
| 48 | + "rcu_default", |
| 49 | + VertexFormats.POSITION_COLOR, |
| 50 | + DrawMode.TRIANGLE_STRIP, |
| 51 | + 131072, |
| 52 | + RenderLayer.MultiPhaseParameters.builder().program(RenderPhase.COLOR_PROGRAM) |
| 53 | + .layering(RenderPhase.VIEW_OFFSET_Z_LAYERING).transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY) |
| 54 | + .build(false), |
| 55 | + ) as RenderLayer |
| 56 | + val SELECTED = RenderLayer.of( |
| 57 | + "rcu_selected", |
| 58 | + VertexFormats.POSITION_COLOR, |
| 59 | + DrawMode.TRIANGLE_STRIP, |
| 60 | + 131072, |
| 61 | + RenderLayer.MultiPhaseParameters.builder().program(RenderPhase.COLOR_PROGRAM) |
| 62 | + .layering(RenderPhase.VIEW_OFFSET_Z_LAYERING).transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY) |
| 63 | + .depthTest(RenderPhase.ALWAYS_DEPTH_TEST).target(RenderPhase.OUTLINE_TARGET).build(true), |
| 64 | + ) as RenderLayer |
| 65 | + val OUTLINE = RenderLayer.of( |
| 66 | + "outline", |
| 67 | + VertexFormats.POSITION_COLOR_TEXTURE, |
| 68 | + DrawMode.QUADS, |
| 69 | + 256, |
| 70 | + RenderLayer.MultiPhaseParameters.builder().program(RenderPhase.OUTLINE_PROGRAM) |
| 71 | + .texture(RenderPhase.Texture(Identifier("minecraft", "textures/entity/shulker/shulker.png"), false, false)) |
| 72 | + .cull(RenderPhase.DISABLE_CULLING).depthTest(RenderPhase.ALWAYS_DEPTH_TEST) |
| 73 | + .target(RenderPhase.OUTLINE_TARGET).build(RenderLayer.OutlineMode.IS_OUTLINE), |
| 74 | + ) |
| 75 | + |
| 76 | + fun getFill(selected: Boolean): RenderLayer = if (selected) { |
| 77 | + SELECTED |
| 78 | + } else { |
| 79 | + DEFAULT |
| 80 | + } |
| 81 | + |
| 82 | + fun getOutline(selected: Boolean): RenderLayer = OUTLINE |
| 83 | +} |
| 84 | + |
| 85 | +fun MatrixStack.translate(vec: Vec3d) = this.translate(vec.x, vec.y, vec.z) |
| 86 | + |
| 87 | +fun MatrixStack.translate(vec: Vec3i) = this.translate(vec.x.toDouble(), vec.y.toDouble(), vec.z.toDouble()) |
| 88 | + |
| 89 | +fun drawBoxFilledAtBlock(matrix: MatrixStack, buffer: VertexConsumer, pos: BlockPos, color: Vector4f) = |
| 90 | + WorldRenderer.method_49041( |
| 91 | + matrix, |
| 92 | + buffer, |
| 93 | + pos.x.toFloat(), |
| 94 | + pos.y.toFloat(), |
| 95 | + pos.z.toFloat(), |
| 96 | + (pos.x + 1).toFloat(), |
| 97 | + (pos.y + 1).toFloat(), |
| 98 | + (pos.z + 1).toFloat(), |
| 99 | + color.x, |
| 100 | + color.y, |
| 101 | + color.z, |
| 102 | + color.w, |
| 103 | + ) |
| 104 | + |
| 105 | +fun drawBoxOutline( |
| 106 | + matrix: MatrixStack, buffer: VertexConsumer, |
| 107 | + x1: Float, |
| 108 | + y1: Float, |
| 109 | + z1: Float, |
| 110 | + x2: Float, |
| 111 | + y2: Float, |
| 112 | + z2: Float, |
| 113 | +) { |
| 114 | + val matrix: Matrix4f? = matrix.peek().getPositionMatrix() |
| 115 | + |
| 116 | + buffer.vertex(matrix, x1, y1, z1).next() |
| 117 | + buffer.vertex(matrix, x1, y1, z2).next() |
| 118 | + buffer.vertex(matrix, x1, y2, z2).next() |
| 119 | + buffer.vertex(matrix, x1, y2, z1).next() |
| 120 | + |
| 121 | + buffer.vertex(matrix, x2, y1, z1).next() |
| 122 | + buffer.vertex(matrix, x2, y2, z1).next() |
| 123 | + buffer.vertex(matrix, x2, y2, z2).next() |
| 124 | + buffer.vertex(matrix, x2, y1, z2).next() |
| 125 | + |
| 126 | + buffer.vertex(matrix, x1, y1, z1).next() |
| 127 | + buffer.vertex(matrix, x2, y1, z1).next() |
| 128 | + buffer.vertex(matrix, x2, y1, z2).next() |
| 129 | + buffer.vertex(matrix, x1, y1, z2).next() |
| 130 | + |
| 131 | + buffer.vertex(matrix, x1, y2, z1).next() |
| 132 | + buffer.vertex(matrix, x1, y2, z2).next() |
| 133 | + buffer.vertex(matrix, x2, y2, z2).next() |
| 134 | + buffer.vertex(matrix, x2, y2, z1).next() |
| 135 | + |
| 136 | + buffer.vertex(matrix, x1, y1, z1).next() |
| 137 | + buffer.vertex(matrix, x1, y2, z1).next() |
| 138 | + buffer.vertex(matrix, x2, y2, z1).next() |
| 139 | + buffer.vertex(matrix, x2, y1, z1).next() |
| 140 | + |
| 141 | + buffer.vertex(matrix, x1, y1, z2).next() |
| 142 | + buffer.vertex(matrix, x2, y1, z2).next() |
| 143 | + buffer.vertex(matrix, x2, y2, z2).next() |
| 144 | + buffer.vertex(matrix, x1, y2, z2).next() |
| 145 | +} |
| 146 | + |
| 147 | +fun drawBoxOutlineAtBlock( |
| 148 | + matrix: MatrixStack, buffer: VertexConsumer, pos: BlockPos, |
| 149 | +) = drawBoxOutline( |
| 150 | + matrix, buffer, |
| 151 | + pos.x.toFloat(), |
| 152 | + pos.y.toFloat(), |
| 153 | + pos.z.toFloat(), |
| 154 | + (pos.x + 1).toFloat(), |
| 155 | + (pos.y + 1).toFloat(), |
| 156 | + (pos.z + 1).toFloat(), |
| 157 | +) |
0 commit comments