|
|
0 ~# a! p0 I# X* h/ u
行,这个怎么样! }/ M9 {' B0 n- k
- package com.xhg78999.mtrfac.render;4 }" x8 Z* {) U" V6 J& T1 S
- * i: A2 V3 A& |. P1 c
- import com.mojang.blaze3d.vertex.PoseStack;! s3 F9 W9 \2 u" ]; c$ c8 o5 ^8 e
- import com.mojang.blaze3d.vertex.VertexConsumer;0 p% |6 W/ J9 ^
- import net.minecraft.client.renderer.RenderType;4 d4 [* Y) C: C) f; i" r4 P# o, l
- import net.minecraft.resources.ResourceLocation;
' ^. r9 S/ g4 W" g$ P$ i2 g- P - $ p0 O2 }/ Y. H) K! V# I7 }
- import java.util.*;
- ]) u/ z/ \) N7 L
' P/ N5 N4 Q% B* N. p- D, K4 X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, U* l3 h- P5 @' | - ! N5 g! y% r7 ]+ O
- public class LineRender{$ p1 l4 W* }( j. w. n; F" Y) R
- private final PoseStack pose;
" k+ y7 R; d: K( {: R - private final MultiBufferSource source; R9 c. ]" M' U# e$ B- _
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 y* g3 q/ D8 x8 Q. t0 }
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" |5 \5 l+ w( S7 Z7 _$ l1 W! v5 T
R/ O" W8 M" c- * P+ s7 F2 z/ D4 N! u' K; w2 I
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
" L- u) C% h7 a5 r, i - if(x1 == x2 && y1 == y2 && z1 == z2){. w( Q1 f0 A/ h
- return;/ t4 L2 Q/ Y( [0 x/ v
- }
: k4 A' H! A/ j5 d - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ T, a" \ k8 t, h) D1 `
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% Z# P$ Y. A7 y
- }# K- k4 M6 t* a( O4 E- ]4 j
- pose.pushPose();$ z" i2 b! v1 q- C8 D2 H7 s% y) u& \
- final int newLight = convertLight(6);" _6 c8 A: G0 g( M
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ W- E& S D( c* @! r2 V2 ~9 v: o$ W
- final float lineHeightSmall = (y2 - y1);0 R6 K1 F# E( F, {1 U' J
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# c# l1 v/ O8 j# S# y6 i9 _ - pose.popPose();# Q/ W9 v6 w8 Z* b6 t
- }
; J5 n Z# b/ Y I) g - . }3 w. Y' b& F6 _4 M' D
- private RenderType getLayers(String texture, int light) {/ [- N+ Z4 t- j- N
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
8 ]" z* T6 z- ?9 @, y9 _, X6 B: s - }
& q4 Y B' S: V6 N: Z0 H& Q- j9 r, v - , H0 P n% Q2 T$ [8 x
- private RenderType getLightTexture(ResourceLocation texture) {6 @" i7 F) d& W. h2 b0 Z" `
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# h& z) ^# W7 @& q* ? - }
8 P+ e$ ^9 `" K; @! V( F8 S - 4 \' i/ }2 j) t( m' E4 P
- private RenderType getTexture(ResourceLocation texture) {
5 ^2 `9 f3 h6 r6 @+ H4 Q - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
9 ~6 Z1 A/ D5 n7 F - }
+ Z& I4 Y9 z2 {- n# r% ~
0 f0 t+ g, T$ J) n3 @- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {) d* `" Z6 U- s4 n
- if (cache.containsKey(identifier)) {: q* r- p: N+ v" e2 y, _* q
- return cache.get(identifier);: E& f a- m1 I% [/ J3 y
- } else {& N! N0 l/ R- @5 P2 ]$ z" Y8 V! z* W
- final RenderType renderLayer = supplier.get();" {: C! u5 T8 J. }: Q( T E7 l
- cache.put(identifier, renderLayer);7 b% F+ R; ^0 t, y" C+ U, U/ ?" K7 C7 _
- return renderLayer;* c- d* t$ }$ V* ]0 ^ O
- }2 S0 L( P& ~& y+ S4 ?
- }3 [4 o) `# {* P2 r( n
- }
复制代码 |
|