|
3 x5 v+ F: }" Q% c% b1 H: c: K行,这个怎么样
7 |+ _5 g% ]% u2 \8 @) _- package com.xhg78999.mtrfac.render;
# y4 _9 w; \1 P8 A* A. B - 2 r; r# ^% O( [2 U* U% {7 s+ x
- import com.mojang.blaze3d.vertex.PoseStack;
# y$ `1 u* D+ P+ K6 j - import com.mojang.blaze3d.vertex.VertexConsumer;+ R* p6 Q- X# G/ F1 E
- import net.minecraft.client.renderer.RenderType;
9 E% A' K- u g9 { - import net.minecraft.resources.ResourceLocation;
6 H" C' U `! [: m) T; U
- l' A1 V) G7 c( x3 T" Y3 ]- import java.util.*;" |' E9 Y. a7 T$ M
- 3 ]# B% Q# x _- \" _
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, i7 c Z8 @& B" ]$ Q1 n' P. W
- 8 v4 m; b( I, n3 ^9 l# K
- public class LineRender{6 M9 [) ^2 |/ ^* N q% v
- private final PoseStack pose;
( X4 A3 D% z" v, X - private final MultiBufferSource source;( e# Q; a* D8 b; N- z9 O: I$ e! F8 J
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();, T. N. p% ^% I. z/ o# X/ k5 O
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, J$ r Q! O# t& a
3 `6 o4 H1 e! p9 T$ N; S0 t- + F: ?+ h) B/ }2 z, n% W" A
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
8 y% s! i+ q E - if(x1 == x2 && y1 == y2 && z1 == z2){
( A! u$ t; G/ [* ^ - return;
' B3 }3 `7 g9 Q* T8 u+ P - }$ R8 a5 C; q' \
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
' C/ D/ \ x" @; W3 X3 J: i - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
; F* \( {" m% E+ }6 \/ k6 r- X - }8 G0 M+ `7 }0 `. }5 @6 Z0 P
- pose.pushPose();0 M& u2 U' d- S1 r; u' @
- final int newLight = convertLight(6);- B& a. S; e, W& S1 X# h6 p1 j/ Y% p4 J
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));* t% K4 G2 U7 @0 N
- final float lineHeightSmall = (y2 - y1);8 r* K/ n1 o, W; c G
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& b* j3 y6 j2 l - pose.popPose();- b9 I4 n+ a. |
- }( j* j% b$ u7 ^* H' v1 `$ x
- 5 m" f7 M# f# H- F; \' u
- private RenderType getLayers(String texture, int light) {
* [7 x7 X( a& w' R* k* a - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));5 [ M/ V4 D6 u1 F" X1 I! s9 T' u
- }: X- k" w; z- e& R6 [5 f
- ( W; I6 _$ \. I8 B$ O/ l) W
- private RenderType getLightTexture(ResourceLocation texture) {
) F- C9 _3 ^3 T/ v. h5 V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);0 h5 Q3 [8 G% a
- }; x f/ J( ^; C
3 B1 i3 j9 M" X! T2 D3 g- private RenderType getTexture(ResourceLocation texture) {
0 x6 Z* `& ^% p3 U; c; U - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
$ H; _0 T2 d L2 C - }
* ^& [; Y. T$ l, H- R8 _4 ?
/ C. T5 t' d( m6 x( p3 K7 N" t& ~5 L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 m3 |' ?) c F - if (cache.containsKey(identifier)) {1 y8 Y% R' O( u j. l K
- return cache.get(identifier);8 j+ u V2 V2 ^/ A
- } else {! u2 a) E) z0 a2 Z& P5 T# U
- final RenderType renderLayer = supplier.get();
2 V2 h" r- Z) ]& n/ U. H - cache.put(identifier, renderLayer);
9 P; h. g6 @5 g - return renderLayer;( M* H* g6 R+ \. f( ^: @
- }
" C4 j2 k2 p% F: I, U T2 P - }
. e* t1 C: }# j9 ]" t" z+ c - }
复制代码 |
|