|
|
8 `; R, M8 h4 ?" h: ^ a' X2 ?: I
行,这个怎么样
& g: _ s- r: e( ?. _- package com.xhg78999.mtrfac.render;
/ L. {8 N. F" V9 P+ S' Q* n1 ~% }
& o, r" h" p9 I- import com.mojang.blaze3d.vertex.PoseStack;
+ \0 S- |5 U; ~3 E8 Q - import com.mojang.blaze3d.vertex.VertexConsumer;
4 m- O' `) b4 |5 \7 a - import net.minecraft.client.renderer.RenderType;$ z7 e5 }& R4 @2 ~7 U3 Y# h
- import net.minecraft.resources.ResourceLocation;
$ y$ B# X) A! J q+ g - * [# K( X# J' b) w. X
- import java.util.*;* W- B- |0 e2 ^# y' j2 j5 N
& S: Y+ i! `- l& K% Z/ M- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
* D1 V9 b$ F3 k! a' r7 u
) [6 [3 I$ Q( [# [) E% W- public class LineRender{5 S; v) ^" H a# c- z- I/ Z
- private final PoseStack pose;
3 ?& e8 m4 U% i7 X/ v - private final MultiBufferSource source;" x# }& e" H# Q! k
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 x; u* N x( Y0 W, f - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ H0 G4 [( N ]5 R* J. j - 7 X4 b$ w- \% ~9 N. ^- l
- 5 a0 S+ f& |( r) P% F
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 C7 G' }% j. h! \+ S; t1 |/ u - if(x1 == x2 && y1 == y2 && z1 == z2){# ] _/ X. b1 j2 ?& v
- return;
& g, J- K. T# {7 R" w5 _4 ` - }7 z$ ` }$ t5 H) s, B& R
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 l) O" s8 L8 e$ V3 X1 ?- w
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
$ n9 C# |# d1 Y0 X$ K4 | - }
! x/ \4 @4 b( `" \6 N1 z' K9 l% c - pose.pushPose();
9 |; ^) P5 k1 H8 f- _ - final int newLight = convertLight(6);& Z* h$ L; P9 z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
% a7 [8 M; w( t3 K - final float lineHeightSmall = (y2 - y1);
) ~: c5 d+ q8 Q& a7 m& ^) v) k - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ |) j& B2 m8 J$ H5 N$ d8 r" E9 h ~
- pose.popPose();
! |, Y. }4 D5 x9 L2 k, b - }
: [% i+ s# t0 Z6 d$ B1 a/ O B' x+ I
, X: B- K- i' B. x- private RenderType getLayers(String texture, int light) {0 J6 N. H7 Y" u0 T9 O7 @. c
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- E! o6 t) d3 ^. m4 w7 C+ v
- }
$ F* p" f: q3 e9 v' \) z - 8 Q) }9 `0 v5 w
- private RenderType getLightTexture(ResourceLocation texture) {( n }( [. O4 ^0 p
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
" }% b8 D2 P' Z7 c P& ~! X - }3 B+ x) _6 F+ B* r0 i
6 W. T1 u5 W/ a/ e3 C! `1 e1 S8 g+ D- private RenderType getTexture(ResourceLocation texture) {
! d( k9 k' p; J! q: ~& |$ M - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 b1 n9 I2 p- Q! }6 w - }
0 x/ C1 h" J5 k0 @
! \: M' [9 K) l- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 O! o- e. M+ f$ j1 U J* ]0 q
- if (cache.containsKey(identifier)) {9 Z. |- u/ L0 V8 l2 s8 @$ Z
- return cache.get(identifier);0 V( p) P0 s. [3 p: `; ~% }
- } else {
$ z: a& o0 L& H6 ^4 h( | - final RenderType renderLayer = supplier.get();
% a8 I3 Q( c/ ]2 h9 b - cache.put(identifier, renderLayer);$ Y a0 q1 g* s% Q
- return renderLayer;
; p, j2 n$ }7 A8 x; m' B& ` - }6 @, C; w) e8 g9 ~* {3 t! e# w0 c
- }( h. b1 c: N; d; R% r6 ]! G; `
- }
复制代码 |
|