|
|
' y2 o8 A2 X. ^行,这个怎么样; d) W6 @% F6 R$ {4 f& B/ j% @8 m1 }
- package com.xhg78999.mtrfac.render;- j" V( b" A# g- B1 x5 Y+ N/ ?0 c
9 {* K( X3 e/ h: n9 n- import com.mojang.blaze3d.vertex.PoseStack;
b; a7 _2 L% Y7 Y9 G; h - import com.mojang.blaze3d.vertex.VertexConsumer;' R5 j5 I. I$ Q [, C3 ?4 l7 W
- import net.minecraft.client.renderer.RenderType;; P+ _% o+ j" _" P* s/ F0 E
- import net.minecraft.resources.ResourceLocation;7 c# k* U+ H/ Q) D2 H
; l& K9 }5 i# c1 p. V: a3 E- import java.util.*;
" t5 z# C& f% n$ U/ r% F' M - $ j+ }, g, ?; [
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! J% \$ A) u @8 _4 k
# Y' X* J# Z! ?: x( c- z- public class LineRender{9 k: t2 a9 D( ]% L( E9 a
- private final PoseStack pose;
6 ?' S2 t4 h0 C/ ^, B - private final MultiBufferSource source;" G4 r, h6 ~# b0 y" j4 h
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, T! ?. n- z8 Z. H5 A - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
4 U; a( x0 H: F% T
$ H& l0 w- j0 d, y- 1 H; ]# B: T) ~
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 r7 r" @+ f7 Y" x* k - if(x1 == x2 && y1 == y2 && z1 == z2){2 M" Q' U9 n o- {- I
- return;+ @% G8 ?$ P$ h; `/ l
- }( h8 [1 P+ I) p# B9 u
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 m4 f/ q6 W3 A - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 P8 z2 [* t6 w
- }+ i6 y9 B" D% g; p8 w
- pose.pushPose();
; ~; p! p$ W( |' C$ L1 p - final int newLight = convertLight(6); \. n0 K% D P9 u! A& T8 y7 z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) v/ v" S6 g0 C - final float lineHeightSmall = (y2 - y1);
/ F4 s* v, G: E1 [. P$ V6 V. { - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 K e7 \. w8 p L - pose.popPose();
; c" M1 [* r5 f - }# Z% x2 g2 ^ A6 ?. d
- ; k, U, r' l9 I/ z
- private RenderType getLayers(String texture, int light) {6 V+ b6 v4 R, \/ z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 y: A) `0 X$ U( H# J - }
0 a+ O A/ h! [" H& a+ q& ]
( r* ]% `1 j% o. G D- private RenderType getLightTexture(ResourceLocation texture) {! K# i6 I+ }' L8 V
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" Q6 \- s! J! ]' O& q% p1 Y+ }
- }
3 t5 b3 h x ^# F0 R2 k1 x) n3 Q - ! b8 q* p! H# J& ]0 ~7 E; z
- private RenderType getTexture(ResourceLocation texture) {
1 v% M' P: l" J; R% Y$ T% Z5 T - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
5 U6 x* }5 \* P7 } - }
" S. c( f% @! Q& [; C, c& g% |
( h+ B9 T; y. M& O3 L& g- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
/ [% D& k' x) U. s - if (cache.containsKey(identifier)) {
8 j' x5 J. J( S! {, W S* s* I - return cache.get(identifier);& s2 E, W$ }- Y2 ~9 c- w3 [
- } else {2 I- J. e% Z/ c
- final RenderType renderLayer = supplier.get();1 k, A; Z( ?* W
- cache.put(identifier, renderLayer);- V7 b" L' ]- \- z- a. z
- return renderLayer;1 x- I7 W9 F/ F& k& X; s1 W
- }
2 S3 O% d* A% ~$ U3 g f8 G: e4 c7 ] - }
5 {3 S9 ?6 q, G1 u* _ w& f - }
复制代码 |
|