|
|
" Q% j6 U4 e0 l8 e4 l7 l [& e$ A
行,这个怎么样
! S1 E. b8 d; Z- package com.xhg78999.mtrfac.render;
# Q: Q! [# b2 Q. b$ o+ X& @
/ O. ^3 ]" X* m% I- import com.mojang.blaze3d.vertex.PoseStack;
! m+ ^1 y- }6 A! ? - import com.mojang.blaze3d.vertex.VertexConsumer;
4 R( e& ]$ r9 ]9 c- H4 a - import net.minecraft.client.renderer.RenderType;7 H) T3 ?, C. m+ w/ x
- import net.minecraft.resources.ResourceLocation;
# m% i. f% c, ~, ^9 b6 z' s* ~
9 a, P1 ^% R* O- m) k, |/ K% t- import java.util.*;3 F8 }0 w' C) {0 F1 A0 i2 M% k
z) @: m; S7 E" P2 N' g) B- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) J! @" C N4 P6 k4 [ - ( Q, D( z+ u+ R5 h' f- I7 `
- public class LineRender{1 H [: b+ K, X( {# F
- private final PoseStack pose;
0 S9 A" V4 @5 @( W4 F& I4 X - private final MultiBufferSource source;
u3 \2 X4 S" r8 L8 H- c! m5 u - private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 z9 l6 P, n& W
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% |0 {4 P( E+ }: A0 J( X: y - + v2 x8 `3 k s9 L% x' ~; H* s
1 @3 u: A* C6 C0 h' T- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; c$ T: M! [; M0 V - if(x1 == x2 && y1 == y2 && z1 == z2){
1 c/ D% x& k. R7 o" @5 F% L# n2 N - return;7 O, _% Y4 q! J A# |* A7 b! h
- }5 P. Y$ Q) \. \& e/ X
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 V3 R& \3 [9 d2 b) f/ O - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
' ]1 x8 w d/ y2 C3 \ [% j - }* ]3 P( v+ U$ }7 w) @
- pose.pushPose();6 @- X/ _9 I" M1 f
- final int newLight = convertLight(6);3 p5 l: V4 e3 ~* H8 {0 m3 Q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& D- ]; a6 V" i& |4 L$ L
- final float lineHeightSmall = (y2 - y1);6 ~. d1 p3 u; Z3 W. i
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 P p# @7 c8 H/ o1 @) S+ f - pose.popPose();
+ @& P1 l2 i2 s5 z* ]) l - }
7 I$ j% _% E6 e4 m3 p4 E - 4 P; @/ _- N9 X" d9 m0 g- N
- private RenderType getLayers(String texture, int light) {, y2 j; M- A) @; g: K8 J: P
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- n) T* G% q6 T" z' }$ k
- }/ L5 N1 G& h" W4 ]
3 w- P. }9 \1 x* U) w- private RenderType getLightTexture(ResourceLocation texture) {
( B' v2 x. y) t8 ^- B! D - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
0 t& B& u4 v$ u! p2 f* B - }# k, A: P/ ^3 p; E
- 2 [* g/ [4 O; D5 N
- private RenderType getTexture(ResourceLocation texture) {
; b# d+ J+ O5 n9 w) Q8 [8 a7 D - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
9 g( p0 u0 U* u p* x+ _ - }4 t" z @9 P# `; h7 R; J) e& z* p
- y) P( `$ U, R( e# b1 g- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
0 X! q9 I+ `# A: h, M8 P/ O - if (cache.containsKey(identifier)) {
0 @1 k& l1 K9 D8 ? - return cache.get(identifier);, B. P9 [3 v1 r$ m8 X1 B7 I' l) v
- } else {3 U3 G/ X* M- [, V
- final RenderType renderLayer = supplier.get();
l$ i4 k' B8 `: L - cache.put(identifier, renderLayer);
5 D. H) `" c* V, q5 P! v# ~& z* F - return renderLayer;
, R4 S1 f4 z2 M# Q9 F; h, G - }0 o/ u* y1 M) `5 |# E8 ]& B
- }5 f! Z1 Q7 C& w: [7 r0 q i* P
- }
复制代码 |
|