|
|
; W8 F/ y2 Q! q8 L6 B a0 @/ Y行,这个怎么样/ S e T4 O6 d4 P/ @" z2 F
- package com.xhg78999.mtrfac.render;8 z5 T( |( O+ k! f! m0 A
5 g# ^1 S& [1 v% B! V6 U- import com.mojang.blaze3d.vertex.PoseStack;: G9 I# V1 b$ P, G2 ?
- import com.mojang.blaze3d.vertex.VertexConsumer;' J7 L* d; V3 K) t
- import net.minecraft.client.renderer.RenderType;
: y4 [ e* ]9 G4 R - import net.minecraft.resources.ResourceLocation;; U" g4 H* h( f5 z: i& k
- . k# d$ _; {1 b t( x
- import java.util.*;
$ i7 l1 X3 k9 N& j - ) h% R7 O) |, U7 t! Z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) p/ {$ a- c9 L. I* _, J9 t - 4 b* ]+ ^" G! ^! c
- public class LineRender{ p1 g0 p7 b- I+ H$ b
- private final PoseStack pose;
$ T4 U' h% f/ ?. s# i6 B( B9 Z - private final MultiBufferSource source;
; D& }" }) L5 p: N( o) ]' w! a - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# z* B C( }; c* x$ m: ~ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
2 r. V! ?, }: N6 w: s# t9 N+ u
; \* K. x! a1 M8 Z+ A% @- * {; r& h" y4 M2 H. F" z# T3 |
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- N+ M& z7 m/ N( r7 U. \8 } - if(x1 == x2 && y1 == y2 && z1 == z2){
6 B* Y6 F" c, z% N" z6 D - return;. g6 C) P0 M' w8 P" {! Y: V4 g/ \: s
- }2 \/ P8 \- F$ D! _7 U
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! T: e/ t# [5 u1 J3 {8 i P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% n Y& d8 S* O) P" ~! A
- }* @. _0 u) Y' s. i* ^4 V! f
- pose.pushPose();" n9 F5 o0 L; {, N7 Y
- final int newLight = convertLight(6);1 A& }$ }% T {6 }1 I7 D, A9 X( |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));" ~- U5 u, R A2 q9 x# G' c* H
- final float lineHeightSmall = (y2 - y1);: }( U* b% \9 P- }9 v5 g/ X
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; x4 d2 t: f; W$ g2 S" d4 C0 V - pose.popPose();
) E2 \& M9 u- D2 G) I% H" H - }2 X: B( O2 k* W" {
- 4 P; }0 S& y% \1 H- R
- private RenderType getLayers(String texture, int light) {
* \) w1 V0 R* r9 b - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' a* g9 N3 P) t% S - }; f$ C' W" M& o! I0 X
- ! |0 F6 K% s7 n" ~5 ^) S) {
- private RenderType getLightTexture(ResourceLocation texture) {6 B7 Z" t* [' d
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ N$ d( C% j+ Y( y+ B - }, M1 M# Q* K8 C+ @+ y& E
- 7 p Q! v$ R; f% o n1 \; i2 U: X
- private RenderType getTexture(ResourceLocation texture) {) c1 F: \- w. u( ? z
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 Z- ]4 ~) q0 ?! E8 |# } - }
* H9 c v0 ]/ o. K5 W7 m
$ N/ O) O W" n; q2 n- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 E' B# v" q m- r$ Q1 J
- if (cache.containsKey(identifier)) {
- M1 U0 r& m$ N( l& I - return cache.get(identifier);
. S: r: J- S& n& x. Z - } else {* |- B4 t3 a. M }0 c/ E
- final RenderType renderLayer = supplier.get();; ]" y5 O& G |
- cache.put(identifier, renderLayer);
3 D4 s" ^/ r |5 D7 U; x - return renderLayer;
5 I" \7 M7 I, Z) J - }
7 Y& T5 C, \- O# h1 c/ v - } D/ Y; `* E# J l+ m
- }
复制代码 |
|