|
|
( I, q5 u, O! [$ e% B- A/ h行,这个怎么样
" J" f! v4 ]' z K" ]- package com.xhg78999.mtrfac.render;
; u1 Q8 r |1 \) [9 z4 } - 9 \. Y) }* j- N' r9 R4 J" g, _- I
- import com.mojang.blaze3d.vertex.PoseStack;: Z* U( d6 N/ U+ M; m* _ e, L
- import com.mojang.blaze3d.vertex.VertexConsumer;
! t3 w8 A( k6 b8 K4 j. R# S8 [ - import net.minecraft.client.renderer.RenderType;1 {5 v( @9 P; \( D
- import net.minecraft.resources.ResourceLocation;+ N$ y' o3 }1 S' k6 @
- p$ b, Z3 Z3 `3 ]; R) ^- N* \- import java.util.*;
- ~4 D7 H8 E/ g8 T1 K0 H5 ^, Q% d
- d; s. y( I# I- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! B, \ F' I) d. h6 I5 A
- + `8 q9 y3 e) j; L" i J8 Y
- public class LineRender{" L2 e* x. G: |6 y. O
- private final PoseStack pose;
+ n9 p5 B( v1 r8 L - private final MultiBufferSource source;/ D1 ~* r+ S; M
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" |+ H; T) I0 o/ B
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 l6 L' W/ i( Y9 B4 Z
( D+ x+ I# ?2 p+ Y- 5 e) v) z# S8 v# s. t8 t: u; h$ Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 F _6 E( [2 x3 Y1 o" S$ i, V( M# H( M
- if(x1 == x2 && y1 == y2 && z1 == z2){
, w4 Y& q( `7 b! |, ]0 B2 u - return;
/ ~/ o( X: y d$ t - }) V- a L+ w5 }( S s
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 E0 \7 V* ]! s$ U) P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& O. H) b% w/ z8 @
- }
@* B* I4 s- L8 U ]' C - pose.pushPose();, E( K' O B4 G' x* {
- final int newLight = convertLight(6);
" |- E! O/ o) t7 [. S - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- G) a& U. M" X$ w i& D0 f - final float lineHeightSmall = (y2 - y1);
1 }2 n& \+ k) @0 [) i - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) D' f2 n2 m) T" b8 z0 K2 }
- pose.popPose();
) A/ H1 v2 Y& I - }0 R/ d5 }2 G m6 Z* L
- ( i5 ?0 J3 e; k
- private RenderType getLayers(String texture, int light) {! l; A8 V; _" g7 b$ W' d1 K d* G
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
1 H; P" ~1 E8 n6 M8 g& i - }
+ O# |0 G3 a, _' v' C0 u - 0 C8 D' w& n% {+ k$ A' l
- private RenderType getLightTexture(ResourceLocation texture) {, J# r& V) ]9 ?. p
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 o5 A9 i: H& e& O4 Q' h, D - }
) h( [- I8 X1 P" N# W% y5 ^
( h+ f2 u5 l9 i/ J. u. I- private RenderType getTexture(ResourceLocation texture) {
$ ]+ l }+ {9 ?& f9 ^ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);' q( R# t/ b" P; v6 ^4 p
- }
/ Q3 `; U) R9 J- c - ( Z* Y1 n# ?/ y, ]& J
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
0 S& |9 T5 H1 n' X9 G7 u - if (cache.containsKey(identifier)) {
7 i" G) e5 ~8 ?4 p) v* |6 } - return cache.get(identifier);6 a- Y: O6 P. r) b
- } else {
" N- E5 m0 M. W G0 e - final RenderType renderLayer = supplier.get();
+ i/ x* n- r o/ J- h$ R6 I8 b - cache.put(identifier, renderLayer);
4 s! r! c% w( `2 A! F) J5 K- Z) l - return renderLayer;
0 Z- ~; @2 h& l3 S, Q; R: h - }
* v, B* b/ u' A8 w# t, { - }
$ L2 h v9 C, c; `) J8 | - }
复制代码 |
|