generated from TechTastic/VS-Addon-Template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adc473e
commit 2562b5d
Showing
6 changed files
with
243 additions
and
5 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
common/src/main/java/io/github/priestoffern/vs_ship_assembler/mixin/GameRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.priestoffern.vs_ship_assembler.mixin; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import io.github.priestoffern.vs_ship_assembler.rendering.Renderer; | ||
import net.minecraft.client.Camera; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import org.objectweb.asm.Opcodes; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import static io.github.priestoffern.vs_ship_assembler.rendering.RendererKt.renderData; | ||
|
||
|
||
@Mixin(GameRenderer.class) | ||
public abstract class GameRendererMixin { | ||
@Shadow @Final private Camera mainCamera; | ||
@Shadow @Final private Minecraft minecraft; | ||
|
||
@Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GameRenderer;renderHand:Z", opcode = Opcodes.GETFIELD, ordinal = 0 )) | ||
void vsshipassembler_postWorldRender(float partialTicks, long finishTimeNano, PoseStack matrixStack, CallbackInfo ci) { | ||
minecraft.getProfiler().push("vsshipassembler_rendering_phase"); | ||
renderData(matrixStack, mainCamera); | ||
minecraft.getProfiler().pop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
common/src/main/kotlin/io/github/priestoffern/vs_ship_assembler/rendering/Renderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.github.priestoffern.vs_ship_assembler.rendering | ||
|
||
import com.google.common.base.Supplier | ||
import com.mojang.blaze3d.vertex.PoseStack | ||
|
||
import net.minecraft.client.Camera | ||
import net.minecraft.client.Minecraft | ||
|
||
import org.valkyrienskies.mod.common.shipObjectWorld | ||
|
||
|
||
fun renderData(poseStack: PoseStack, camera: Camera) { | ||
|
||
for (data in Renderer.toRender) { | ||
data.renderData(poseStack, camera) | ||
} | ||
} | ||
|
||
object Renderer { | ||
var CurrentId:Long = 0; | ||
val toRender = mutableListOf<RenderingData>() | ||
|
||
fun addRender(renderData: RenderingData): RenderingData { | ||
renderData.Id = CurrentId; | ||
CurrentId++ | ||
|
||
toRender.add(renderData); | ||
return renderData; | ||
} | ||
|
||
fun removeRender(renderData: RenderingData) { | ||
toRender.remove(renderData); | ||
} | ||
} | ||
|
||
|
||
interface RenderingData { | ||
var Id: Long; | ||
fun renderData(poseStack: PoseStack, camera: Camera) | ||
} |
117 changes: 117 additions & 0 deletions
117
...c/main/kotlin/io/github/priestoffern/vs_ship_assembler/rendering/SelectionZoneRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package io.github.priestoffern.vs_ship_assembler.rendering | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem | ||
import com.mojang.blaze3d.vertex.* | ||
import com.mojang.math.Matrix4f | ||
import de.m_marvin.univec.impl.Vec3d | ||
import net.fabricmc.loader.impl.lib.sat4j.core.Vec | ||
import net.minecraft.client.Camera | ||
import net.minecraft.client.Minecraft | ||
import net.minecraft.client.renderer.GameRenderer | ||
import net.minecraft.client.renderer.RenderType | ||
import org.joml.Vector3d | ||
import org.lwjgl.opengl.GL11 | ||
import java.awt.Color | ||
class SelectionZoneRenderer() : RenderingData { | ||
var point0 = Vec3d(); | ||
var point1 = Vec3d(); | ||
var color: Color = Color(0) | ||
override var Id: Long = 0; | ||
constructor( | ||
point0: Vec3d, | ||
point1: Vec3d, | ||
color: Color, | ||
): this() { | ||
this.point0 = point0 | ||
this.point1 = point1 | ||
this.color = color | ||
} | ||
|
||
override fun renderData(poseStack: PoseStack, camera: Camera) { | ||
|
||
|
||
val tesselator = Tesselator.getInstance() | ||
val vBuffer = tesselator.builder | ||
|
||
RenderSystem.enableDepthTest() | ||
RenderSystem.depthFunc(GL11.GL_LEQUAL) | ||
RenderSystem.depthMask(true) | ||
RenderSystem.setShader(GameRenderer::getPositionColorShader) | ||
|
||
// val light = LightTexture.pack(level!!.getBrightness(LightLayer.BLOCK, point1.toBlockPos()), level!!.getBrightness(LightLayer.SKY, point1.toBlockPos())) | ||
|
||
val light = Int.MAX_VALUE | ||
|
||
vBuffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP) | ||
|
||
poseStack.pushPose() | ||
|
||
val cameraPos = camera.position | ||
|
||
val Add1 = Vec3d(if (point0.x>=point1.x) 1.0 else 0.0, if (point0.y>=point1.y) 1.0 else 0.0, if (point0.z>=point1.z) 1.0 else 0.0) | ||
val Add2 = Vec3d(if (point1.x>point0.x) 1.0 else 0.0, if (point1.y>point0.y) 1.0 else 0.0, if (point1.z>point0.z) 1.0 else 0.0) | ||
|
||
val tpos1 = Vec3d(point0.x-cameraPos.x,point0.y-cameraPos.y,point0.z-cameraPos.z).add(Add1) | ||
val tpos2 = Vec3d(point1.x-cameraPos.x,point1.y-cameraPos.y,point1.z-cameraPos.z).add(Add2) | ||
|
||
val matrix = poseStack.last().pose() | ||
makeBox( | ||
vBuffer, matrix, | ||
color.red, color.green, color.blue, color.alpha, light, | ||
tpos1, tpos2 | ||
) | ||
|
||
tesselator.end() | ||
|
||
poseStack.popPose() | ||
|
||
|
||
} | ||
|
||
fun tof(n: Double) = n.toFloat() | ||
fun makeBox(buf: VertexConsumer, matrix: Matrix4f, | ||
r: Int, g: Int, b: Int, a: Int, lightmapUV: Int, | ||
A: Vec3d, B:Vec3d | ||
) { | ||
buf.vertex(matrix, tof(A.x), tof(A.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(A.x), tof(A.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(A.x), tof(A.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(A.x), tof(B.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(A.x), tof(A.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(A.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
|
||
buf.vertex(matrix, tof(A.x), tof(A.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(A.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(A.x), tof(A.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(A.x), tof(B.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(A.x), tof(B.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(B.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
|
||
buf.vertex(matrix, tof(A.x), tof(B.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(A.x), tof(B.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(A.x), tof(B.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(B.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(B.x), tof(B.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(B.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
|
||
buf.vertex(matrix, tof(B.x), tof(A.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(B.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(B.x), tof(A.y), tof(A.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(A.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
|
||
buf.vertex(matrix, tof(B.x), tof(A.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
buf.vertex(matrix, tof(B.x), tof(B.y), tof(B.z)).color(r, g, b, a).uv2(lightmapUV).endVertex() | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters