|
|
$ g A- i" E2 O, F7 F
行,这个怎么样7 c% j1 I3 l% y, d, R1 X( H- }
- package com.xhg78999.mtrfac.render;
& e4 L1 W ~( V" k- P2 z1 V) W - 3 z% e6 r6 j& J6 f: h, i5 f) b
- import com.mojang.blaze3d.vertex.PoseStack;: ]' @* X# {9 @1 Y1 f9 q
- import com.mojang.blaze3d.vertex.VertexConsumer;
- f( s' ]$ K5 D$ w - import net.minecraft.client.renderer.RenderType;
8 S% G; \" ^- }" R9 N - import net.minecraft.resources.ResourceLocation;" g+ K; g0 l" R( V0 v
9 d: P) Z! r) u$ Q$ p" ^! Y2 z- import java.util.*;
9 x& s: Z& f5 P+ d9 G8 D. y - 2 M0 ~# P% i% |( [/ v4 W
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& j' u% y% d2 g) D2 ` - ! m4 @3 q" p F5 H) b$ T: x, _/ g
- public class LineRender{, I% T& I) G+ i, o7 p
- private final PoseStack pose;
: D. t p9 f3 l3 F" ~ - private final MultiBufferSource source;4 g: K$ I1 g+ W1 z1 f5 S
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& e4 ?4 b% S2 a( ~) ~. ? - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ v4 b" M! V9 a$ u" K
5 M" M9 t, c" u! l& U* V$ K) b7 N
2 X4 g, I% {; s+ ~2 _2 C+ G- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
( W& O' e) P5 n( C - if(x1 == x2 && y1 == y2 && z1 == z2){! p8 N$ A4 g+ a% R
- return;8 \$ F+ G; h! |- Z' N
- }+ z: \, t. ?, q# Q( Y
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 B" a- X2 t% z4 ~$ M
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 j' s& W! N- u; K6 S8 a
- }+ |3 r* T! R H' \2 D6 Q4 i
- pose.pushPose();/ U5 `' A+ O% o3 g
- final int newLight = convertLight(6);, A: E+ X8 W6 d& i# ]7 b4 _
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! W% A* O4 b$ ^( M9 r: Z - final float lineHeightSmall = (y2 - y1);
/ z$ Y! c6 k* u9 Z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 T& n# O k7 p7 F- D V! K1 t! { W
- pose.popPose();: S# }) p8 H' y% O. Y8 {+ z4 H7 H
- }
( e, ^( I! a* e z - 9 P3 I# i" N K" Q
- private RenderType getLayers(String texture, int light) {
$ z) b0 L7 S# _0 I. Z - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 G! e! y- {* F' P - }
0 |* n% ~, b$ o/ G. H' C
+ R8 i8 Z/ T7 a- }0 ~ M# y2 F- private RenderType getLightTexture(ResourceLocation texture) {
4 Z+ K& v f- V& ?! Z% f" P - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 H2 l1 G- {/ F# r# v" _. f6 P - }! U, e/ j7 R3 \! ~+ V/ C7 A6 i
) i3 T3 e4 f. I- private RenderType getTexture(ResourceLocation texture) {
1 e* q6 u% ^* @, I& ?8 ?5 n$ l - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 S/ y% i4 X) b [* N$ G D - }
, j% |& x( k- w1 I4 S c- O8 Q
! M1 O% N9 D3 k3 [8 L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; V. B' Q1 L3 [& ] - if (cache.containsKey(identifier)) {
$ y$ X7 p/ J4 v; C: N2 f$ q/ e - return cache.get(identifier);
, M5 ^. M/ j& q' l- N) W+ J+ v - } else {4 z% s) u# e. [6 b0 N
- final RenderType renderLayer = supplier.get();
, x8 m9 O* c7 ?$ r0 M3 B- B+ i - cache.put(identifier, renderLayer);- {9 L1 ~ i0 ~! n$ F( b
- return renderLayer;
" }, x7 e6 z4 e, a* A6 ]# ~* z - }& m5 N! U: u! T* t
- }
0 O5 C: w$ V% Q+ ~. S - }
复制代码 |
|