|
|
0 b2 p/ b* x( D( ]; u" o; p7 I行,这个怎么样' V H/ g( ~* R
- package com.xhg78999.mtrfac.render;
& ?! f9 i) f u: r5 M X
6 p8 U( Y7 X( o$ N. h9 l- import com.mojang.blaze3d.vertex.PoseStack;
# Z0 j* `2 q0 ]! C - import com.mojang.blaze3d.vertex.VertexConsumer;4 @5 @0 h6 B4 Z/ I' j. b% Q
- import net.minecraft.client.renderer.RenderType;
; a4 x8 b6 S/ a9 x4 b4 N7 K - import net.minecraft.resources.ResourceLocation;1 L. T- U1 A) R) u% q4 r
' r7 e" N8 ?' @: e- W( v- import java.util.*;
8 O' `! l# _/ U2 T - F/ t" M. P) r9 J! x
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
* z9 u& ?, I1 D$ J; _8 U - 4 w( j/ N y7 k( D3 Z
- public class LineRender{
+ H6 m4 A/ l; F. Q& r0 I - private final PoseStack pose;
6 d* k0 w& i: q - private final MultiBufferSource source;
1 ~5 u8 i% n0 v. k3 O+ f/ z - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& I0 @. A4 @% D( X! Y1 l - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: x( c' h% h, } - ; j* M6 \3 E9 {$ N
- 3 n: m) ]: ^: S
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
0 r/ Q6 {" z( ~" ^& h - if(x1 == x2 && y1 == y2 && z1 == z2){
. \( S8 A/ Q" ?* K6 ^ - return;
; J! C2 f* Y: |- y' a - }3 N* c7 }% X4 l1 R
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
) g% O" F. X) W/ _& i9 D. ` - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
& C" H2 I% o! g - }
/ N% p- d% [2 V! P* ^ - pose.pushPose();
. V i! G6 s1 p) N; {( n - final int newLight = convertLight(6);1 M1 y6 @; \$ o' l/ `
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 {4 b- c& Q- B* _/ C) @; T3 B, m - final float lineHeightSmall = (y2 - y1);
1 s; E/ Q9 b, ` - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
+ a: s) B/ E, R+ V6 p - pose.popPose(); v* B5 G, t- f' I- a
- }
1 Q. K6 f) X4 `8 E" [, @* v2 f
; t( A8 g: K9 R6 R- private RenderType getLayers(String texture, int light) {
' f8 c; T+ h# j5 A0 ~. O1 m - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 s5 }7 |: G4 \8 `8 X
- }, L/ g/ o% _, A/ f" G
8 G: a% b* j" A; R" T: B* _$ a- private RenderType getLightTexture(ResourceLocation texture) {; w$ f0 H Y: H; ]) z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* `. z5 m3 i0 g- E) [+ `$ h - }
1 @6 ~( G7 r8 @9 F7 y1 i - , u% _0 \2 Y9 a. M
- private RenderType getTexture(ResourceLocation texture) {
2 g. L8 g, X$ I& A( v0 q& K - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& e, k# Q7 G# w - }
* b& ?' O9 s4 `( r. k
+ I1 k* j5 E3 u- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ n3 O0 J/ n$ l
- if (cache.containsKey(identifier)) {/ Z! U( Z3 l2 N: Q
- return cache.get(identifier);, b$ F3 E! I( l Q( F
- } else {
. S- E* a+ U" h, a: o - final RenderType renderLayer = supplier.get();
" e' k3 N; M; {2 J. B: R/ n) S/ B - cache.put(identifier, renderLayer);
9 I# c3 W6 |& t; b& E - return renderLayer;% L! X# C( B# S$ a O; m
- }
+ W( I2 F/ y, z6 s* O8 }, R5 Q - }
4 i5 G# R9 T( F' x2 j( ? - }
复制代码 |
|