|
|
2 b6 \* [5 G. n- q# S& G: I4 \" U8 u行,这个怎么样
9 t* r: w0 I! h7 ]) U- package com.xhg78999.mtrfac.render;0 g! w4 P$ j' b L
/ \1 K, Z; q2 y6 f6 G+ E9 G. Q- import com.mojang.blaze3d.vertex.PoseStack;5 h' C' B& c5 I" E) p9 g
- import com.mojang.blaze3d.vertex.VertexConsumer;! q" R# M! j2 |5 b* E
- import net.minecraft.client.renderer.RenderType;4 P3 d, {* }) F; U
- import net.minecraft.resources.ResourceLocation;
- z7 m6 @* B6 B- p/ [7 f5 y \
9 U, n' B: b3 x) {6 B/ a& c- import java.util.*;
1 O$ G: \4 B `; j+ f8 w - : V) G0 {$ l5 r/ |
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 {) O) i# r$ y1 i
8 p# V; G! J0 _- public class LineRender{
+ L/ Y% g- C% {6 l - private final PoseStack pose;
6 U5 \: I! |" K - private final MultiBufferSource source;+ x; Q9 @. e/ r4 D
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ j# K& P5 G$ H - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); \7 s% K' I) z Y: @) X3 w
/ d1 W5 A& ?( U/ Y- , m% o( E3 @/ D& k3 }
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
% T% `) W/ }/ m9 B: L/ U - if(x1 == x2 && y1 == y2 && z1 == z2){
7 ]; r3 |8 F8 C h3 _# ~ - return;& a- ], ?7 i% s6 b* _8 _1 X. O; t
- }/ d# p) {1 @, q8 ?; _ P
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, _% ^* Q% Q4 w" Z. X% u* i- J- G
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 U# U, h; g' p( R - }( U+ Q2 \2 \) Y5 p! m
- pose.pushPose();, P1 N# q6 r2 E' C8 G3 W
- final int newLight = convertLight(6);7 j5 d, d: R: s3 j! O' U
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 Q, ~2 ?3 I6 o - final float lineHeightSmall = (y2 - y1);% l; D2 j+ N+ _4 c3 n
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- J1 a/ d7 u5 j7 g5 \2 x - pose.popPose();9 |1 Q9 \% W' C3 _3 D0 Q: i
- } Q9 C6 @5 `5 b
$ F7 v* ^' v. } J) c. s% ?* Q* Y. n- private RenderType getLayers(String texture, int light) {/ _; f# y2 F% [2 y% r# d+ T( |
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
& u8 ~' {5 k9 k4 g F2 i8 b; F2 c - }
9 r; h/ q( A* M) K# Y - A& M/ g( \& g" l" u r, C/ Q1 `
- private RenderType getLightTexture(ResourceLocation texture) {
' u8 n' l$ g( y6 a - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ K+ T1 \/ e0 o: K: @ - }
, q6 W5 {: N) k( A3 ]$ u' X
% \' C5 U& G6 N; V, C6 y6 P. G# }- private RenderType getTexture(ResourceLocation texture) { s3 M: L, ~9 q1 i' R0 H5 V
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);3 z" N3 z" E! Z: ?, H' z( d3 }3 l
- }3 i! ~+ Y3 ] z" P6 T+ N' f6 p; g
; A% C1 p- R* @. _, `7 k& S. z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ u7 G$ w' k$ P( k7 n
- if (cache.containsKey(identifier)) {0 f, }, R; g6 k0 D3 v+ d: o
- return cache.get(identifier);
( w8 u( [- g% _& g+ c, m - } else {8 e, w2 ^$ M# W0 L
- final RenderType renderLayer = supplier.get();
, d+ U9 m+ B; e c1 }8 R - cache.put(identifier, renderLayer);
0 E3 b+ m( U7 U& o: E( U - return renderLayer;5 Q' G# [1 f7 D) m9 d& `: {
- }, Z! ]7 e- ]* i; k9 g8 _
- }$ k' p+ ?+ |. K0 U6 @" T6 T
- }
复制代码 |
|