|
|
* g5 n; H" |. Q: v/ A行,这个怎么样* q2 e! q* S" I4 G8 n1 X
- package com.xhg78999.mtrfac.render;
' w! E( h5 | t) S
* p% M3 x4 e8 `: y1 b6 G- import com.mojang.blaze3d.vertex.PoseStack;) c; p- u6 T- u! ~* p5 J* ]
- import com.mojang.blaze3d.vertex.VertexConsumer;( v$ K- B2 ]' W/ ~$ N
- import net.minecraft.client.renderer.RenderType;
6 P" J* F5 u6 x" c0 Y/ ~) ] - import net.minecraft.resources.ResourceLocation;
- l5 G* o' x" D# _! R6 a( m2 B
" g, \, [6 T) h0 q7 m6 W- import java.util.*;
- l( p, A7 a" P4 T0 N - r5 z/ h# D5 @4 w
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; W9 ]& D+ g1 ~6 c, ?( }3 i5 e
, [% G8 w1 ?9 A5 i# ~5 L+ t* U- public class LineRender{6 b6 z& A, _5 O, O4 p5 G
- private final PoseStack pose;. Y" n$ B; i, B6 Q
- private final MultiBufferSource source;' c! v! r4 r5 F7 j) _& J1 z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, s' o8 t/ J2 v% H7 `, W3 e$ ` - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 i" s8 H4 J* p+ [& }2 i* _
. [6 n7 B6 J7 X& K* a e1 C; Z8 o
: X1 w* M8 w1 |0 {% b L/ P- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; o! |* v) G* ~3 ^0 l9 K5 X+ z - if(x1 == x2 && y1 == y2 && z1 == z2){" |- k$ R/ n7 s9 J4 u
- return;
5 i3 v( X& p/ B# A% u d - }* |4 O3 R% _* |) Q8 b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){. M2 J4 V& k# b) U9 O: U
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 N' w' B( n! d5 e
- }
& N3 D& ~4 ^7 Y4 q. @3 b - pose.pushPose();+ E" D% |( @& V6 \0 {
- final int newLight = convertLight(6);
9 g; p1 W, z# I1 b - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ f! d4 T3 s$ U6 O4 U/ @ - final float lineHeightSmall = (y2 - y1);
( Z* f% n9 a U9 ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
L" L O& q4 q/ r, J+ x1 c! O6 _ - pose.popPose();! k2 l1 p6 M U
- }7 N/ z$ R# \% P
; w, v3 C( B' r6 Q* O( B6 A5 s6 r7 y- private RenderType getLayers(String texture, int light) {1 o: _0 t0 u) k( Z/ m6 L
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 C8 ?) j; B& y8 U- | - }
! k! y+ n1 h2 {* K8 d
. T7 }. W# X1 r- F- private RenderType getLightTexture(ResourceLocation texture) {7 T% n! m6 Z1 M0 Q) i
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
0 }7 d- _; L) g" R- ]7 ] - }0 s3 ]; e0 y1 y9 r
- 1 q+ A+ X7 |0 b. P3 ?
- private RenderType getTexture(ResourceLocation texture) {1 ~. Z7 i5 B3 j: l, k7 N$ ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
* K3 z7 |. m o2 U; p8 ^( F - }+ B* \3 C( B9 d6 v. Z
' [! N# W# ]/ y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# m, _+ m8 x( \5 ] - if (cache.containsKey(identifier)) {
0 h5 _- b: I8 `+ T* I9 N5 N - return cache.get(identifier);
* y" ]* z% N+ m' G/ O; { - } else {' {% Y. Q8 X$ [7 T, _ G5 c8 j
- final RenderType renderLayer = supplier.get();6 R! B8 a) ]% Y0 Q. d* m6 J6 y) F
- cache.put(identifier, renderLayer);
8 p! ~. T q! { - return renderLayer;
' O, ?; a7 [9 u+ z8 A3 n1 [ - }1 g4 T! w1 ?2 D; R
- }' \! o7 z5 _0 M- c
- }
复制代码 |
|