Skip to content

Commit db80789

Browse files
committed
更新LICENSE
1 parent 6a5e78e commit db80789

File tree

7 files changed

+796
-176
lines changed

7 files changed

+796
-176
lines changed

LICENSE

Lines changed: 674 additions & 121 deletions
Large diffs are not rendered by default.

src/main/kotlin/cn/coostack/usefulmagic/entity/custom/formation/FormationCoreEntity.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class FormationCoreEntity(type: EntityType<*>, world: World) : Entity(type, worl
6868

6969
override fun tick() {
7070
assertFormationCoreEntity()
71-
setPosition(core.up(3).toCenterPos())
71+
// setPosition(core.up(3).toCenterPos())
7272
super.tick()
7373
}
7474

@@ -77,25 +77,25 @@ class FormationCoreEntity(type: EntityType<*>, world: World) : Entity(type, worl
7777
* 如果方块中心不是目标BlockEntity 则直接死亡
7878
*/
7979
private fun assertFormationCoreEntity() {
80-
val entity = world.getBlockEntity(core) ?: let {
81-
kill()
82-
return
83-
}
84-
85-
if (entity !is FormationCoreBlockEntity) {
86-
kill()
87-
return
88-
}
89-
90-
if (!entity.formation.isActiveFormation()) {
91-
kill()
92-
return
93-
}
94-
// 强制设置距离
95-
// 如果距离大于16 则判定是不正常的实体生成
96-
if (pos.distanceTo(entity.pos.toCenterPos()) > 16) {
97-
kill()
98-
return
99-
}
80+
// val entity = world.getBlockEntity(core) ?: let {
81+
// kill()
82+
// return
83+
// }
84+
//
85+
// if (entity !is FormationCoreBlockEntity) {
86+
// kill()
87+
// return
88+
// }
89+
//
90+
// if (!entity.formation.isActiveFormation()) {
91+
// kill()
92+
// return
93+
// }
94+
// // 强制设置距离
95+
// // 如果距离大于16 则判定是不正常的实体生成
96+
// if (pos.distanceTo(entity.pos.toCenterPos()) > 16) {
97+
// kill()
98+
// return
99+
// }
100100
}
101101
}

src/main/kotlin/cn/coostack/usefulmagic/entity/custom/renderer/FormationCoreRenderer.kt

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
package cn.coostack.usefulmagic.entity.custom.renderer
22

33
import cn.coostack.usefulmagic.UsefulMagic
4-
import cn.coostack.usefulmagic.blocks.UsefulMagicBlocks
54
import cn.coostack.usefulmagic.entity.custom.formation.FormationCoreEntity
5+
import cn.coostack.usefulmagic.items.UsefulMagicItems
66
import cn.coostack.usefulmagic.renderer.shader.TestShader
7-
import com.mojang.blaze3d.platform.GlStateManager
7+
import com.mojang.blaze3d.platform.GlConst.GL_TRIANGLES
88
import net.minecraft.client.MinecraftClient
9+
import net.minecraft.client.render.LightmapTextureManager
910
import net.minecraft.client.render.RenderLayers
11+
import net.minecraft.client.render.RenderPhase
12+
import net.minecraft.client.render.TexturedRenderLayers
13+
import net.minecraft.client.render.VertexConsumer
1014
import net.minecraft.client.render.VertexConsumerProvider
1115
import net.minecraft.client.render.entity.EntityRenderer
1216
import net.minecraft.client.render.entity.EntityRendererFactory
1317
import net.minecraft.client.util.math.MatrixStack
1418
import net.minecraft.util.Identifier
15-
import org.lwjgl.opengl.GL20
19+
import org.joml.Matrix4f
20+
import org.lwjgl.BufferUtils
21+
import org.lwjgl.opengl.GL33
1622

1723

1824
class FormationCoreRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<FormationCoreEntity>(ctx) {
1925
val shader = TestShader()
2026
.apply {
21-
// this.vertexShader = Identifier.of(UsefulMagic.MOD_ID, "shaders/test/test_vertex.vsh")
27+
this.vertexShader = Identifier.of(UsefulMagic.MOD_ID, "shaders/test/test_vertex.vsh")
2228
this.fragmentShader = Identifier.of(UsefulMagic.MOD_ID, "shaders/test/test_frag.fsh")
2329
}
2430

@@ -36,20 +42,45 @@ class FormationCoreRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer
3642
) {
3743
val renderer = MinecraftClient.getInstance().gameRenderer
3844
val camera = renderer.camera
39-
4045
shader.bind()
41-
val timeLocation = shader.getUniformLocation("u_time")
42-
GL20.glUniform1f(timeLocation, System.currentTimeMillis() / 1000f)
43-
val pos = entity.pos.toVector3f()
44-
val entityPosLocation = shader.getUniformLocation("u_pos")
45-
GL20.glUniform3f(entityPosLocation, pos.x, pos.y, pos.z)
46-
val cameraLocation = shader.getUniformLocation("u_camera")
47-
val cameraPos = camera.pos.toVector3f()
48-
GL20.glUniform3f(cameraLocation, cameraPos.x, cameraPos.y, cameraPos.z)
46+
val transform = matrices.peek().positionMatrix
47+
val transLoc = shader.getUniformLocation("transform")
48+
val p = entity.pos.toVector3f()
49+
GL33.glUniformMatrix4fv(transLoc, false, transform.get(BufferUtils.createFloatBuffer(16)))
50+
val modelViewMat = Matrix4f().translate(-p.x, -p.y, -p.z).get(BufferUtils.createFloatBuffer(16))
51+
val viewMatLoc = shader.getUniformLocation("ModelViewMat")
52+
GL33.glUniformMatrix4fv(viewMatLoc, false, modelViewMat)
53+
val consumer =
54+
vertexConsumers.getBuffer(RenderLayers.getItemLayer(UsefulMagicItems.WOODEN_WAND.defaultStack, false))
55+
vertex(consumer, -0.5f, -0.5f, 0f, 0f, 0f)
56+
vertex(consumer, 0.5f, -0.5f, 0f, 1f, 0f)
57+
vertex(consumer, -0.5f, 0.5f, 0f, 0f, 1f)
58+
vertex(consumer, 0.5f, -0.5f, 0f, 1f, 0f)
59+
vertex(consumer, -0.5f, 0.5f, 0f, 0f, 1f)
60+
vertex(consumer, 0.5f, 0.5f, 0f, 1f, 1f)
61+
62+
GL33.glEnable(GL33.GL_DEPTH_TEST)
63+
GL33.glDepthFunc(GL33.GL_LEQUAL)
4964
shader.unbind()
5065
super.render(entity, yaw, tickDelta, matrices, vertexConsumers, light)
5166
}
5267

68+
private fun vertex(consumer: VertexConsumer, x: Float, y: Float, z: Float, u: Float, v: Float) {
69+
consumer.vertex(
70+
x,
71+
y,
72+
z,
73+
0xFFFFFFFFU.toInt(),
74+
u,
75+
v,
76+
1,
77+
LightmapTextureManager.MAX_LIGHT_COORDINATE,
78+
1f,
79+
1f,
80+
1f
81+
)
82+
}
83+
5384
override fun getTexture(entity: FormationCoreEntity?): Identifier? {
5485
return null
5586
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cn.coostack.usefulmagic.magic
2+
3+
class PlayerMagic {
4+
5+
fun useOnClient() {
6+
7+
}
8+
9+
fun useOnServer() {
10+
11+
}
12+
}

src/main/kotlin/cn/coostack/usefulmagic/renderer/shader/TestShader.kt

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@ import com.mojang.blaze3d.platform.GlStateManager
44
import net.minecraft.client.gl.GlProgramManager
55
import net.minecraft.client.gl.GlUniform
66
import net.minecraft.util.Identifier
7-
import org.lwjgl.opengl.GL11
8-
import org.lwjgl.opengl.GL12
9-
import org.lwjgl.opengl.GL20
10-
import org.spongepowered.asm.launch.GlobalProperties
7+
import org.lwjgl.opengl.GL33
8+
import org.lwjgl.opengl.GL33.*
119

1210
class TestShader {
1311
var vertexShader: Identifier? = null
1412
var fragmentShader: Identifier? = null
1513
var programID = 0
1614
var vertexShaderID = 0
1715
var fragmentShaderID = 0
16+
17+
var vao = 0
18+
var vbo = 0
19+
1820
fun bind() {
21+
glBindVertexArray(vao)
1922
GlProgramManager.useProgram(programID)
2023
}
2124

2225
fun unbind() {
26+
glBindBuffer(GL_ARRAY_BUFFER, 0)
27+
glBindVertexArray(0)
2328
GlProgramManager.useProgram(0)
2429
}
2530

@@ -30,11 +35,32 @@ class TestShader {
3035

3136
fun loadShader() {
3237
programID = GlStateManager.glCreateProgram()
33-
vertexShaderID = compileShader(GL20.GL_VERTEX_SHADER, vertexShader)
34-
fragmentShaderID = compileShader(GL20.GL_FRAGMENT_SHADER, fragmentShader)
38+
vertexShaderID = compileShader(GL_VERTEX_SHADER, vertexShader)
39+
fragmentShaderID = compileShader(GL_FRAGMENT_SHADER, fragmentShader)
3540
GlStateManager.glAttachShader(programID, vertexShaderID)
3641
GlStateManager.glAttachShader(programID, fragmentShaderID)
3742
GlStateManager.glLinkProgram(programID)
43+
44+
vao = glGenVertexArrays()
45+
vbo = glGenBuffers()
46+
glBindVertexArray(vao)
47+
glBindBuffer(GL_ARRAY_BUFFER, vbo)
48+
val w = 0.5f
49+
val h = 0.5f
50+
glBufferData(
51+
GL_ARRAY_BUFFER, floatArrayOf(
52+
-w, h, 0F,
53+
w, h, 0F,
54+
-w, -h, 0F,
55+
w, h, 0F,
56+
-w, -h, 0F,
57+
w, -h, 0F
58+
), GL_STATIC_DRAW
59+
)
60+
61+
glVertexAttribPointer(0, 3, GL_FLOAT, false, 3 * Float.SIZE_BYTES, 0)
62+
glEnableVertexAttribArray(0)
63+
3864
checkProgram()
3965
}
4066

@@ -57,14 +83,14 @@ class TestShader {
5783
}
5884

5985
private fun checkShader(id: Int) {
60-
if (GlStateManager.glGetShaderi(id, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
61-
throw RuntimeException("Shader compilation failed: " + GL20.glGetShaderInfoLog(id))
86+
if (GlStateManager.glGetShaderi(id, GL33.GL_COMPILE_STATUS) == GL33.GL_FALSE) {
87+
throw RuntimeException("Shader compilation failed: " + GL33.glGetShaderInfoLog(id))
6288
}
6389
}
6490

6591
private fun checkProgram() {
66-
if (GlStateManager.glGetProgrami(programID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
67-
throw RuntimeException("Program compilation failed: " + GL20.glGetProgramInfoLog(programID))
92+
if (GlStateManager.glGetProgrami(programID, GL33.GL_LINK_STATUS) == GL33.GL_FALSE) {
93+
throw RuntimeException("Program compilation failed: " + GL33.glGetProgramInfoLog(programID))
6894
}
6995
}
7096
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#version 150 core
1+
#version 330 core
22

3-
uniform float u_time;
4-
uniform vec3 u_pos;
5-
uniform vec3 u_camera;
63

4+
5+
out vec4 FragColor;
76
void main(){
8-
float d = distance(u_pos, u_camera);
9-
float step = smoothstep(0., 1., d);
10-
vec4 ball = vec4(0.5, 0.5, 0.5, 1.);
7+
FragColor = vec4(1.);
118
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#version 150 core
2-
uniform float u_time;
3-
uniform vec3 u_pos;
1+
#version 330 core
2+
uniform mat4 transform;
43
uniform mat4 ModelViewMat;
5-
uniform mat4 ProjMat;
4+
layout (location = 0) in vec3 pos;
5+
66
void main() {
7+
gl_Position = ModelViewMat * transform * vec4(pos, 1.);
78
}

0 commit comments

Comments
 (0)