|
|
& y, p+ v+ R0 d2 p. h
行,这个怎么样- B% a6 A/ q5 S! f# r* H8 T
- package com.xhg78999.mtrfac.render;
6 r5 Z, }; p$ `2 X& k
6 t& u! l6 a* A; q9 Z+ @- import com.mojang.blaze3d.vertex.PoseStack;
" R, h, |8 @, Z - import com.mojang.blaze3d.vertex.VertexConsumer;
( G3 X# i0 s3 L4 J: ?' p1 N - import net.minecraft.client.renderer.RenderType;' x% Q# k9 c: M6 o2 X! \- y% U
- import net.minecraft.resources.ResourceLocation;2 k; U) q6 z8 M9 q$ N k( `
- 2 z8 q5 t! Z; L9 M9 R3 L
- import java.util.*;
' f# L1 E1 _- h* X - . m& V f' A6 [0 ^% D+ h
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& p9 d, |8 f) I
- 4 e2 K1 ^3 J4 N- B6 ~4 h& n; i
- public class LineRender{! ~+ b" ^, L( q! W; @
- private final PoseStack pose;
7 p) x' Q) W4 g, z! l6 B - private final MultiBufferSource source;' h8 f6 s' p) J9 {
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) D- f! g5 S) M. Z3 k - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) ~, W* ?8 k. t- P3 L ?
/ a* p" h: m9 d9 b" V' o- 9 f3 C) C9 w# Q/ {* ]/ B
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 S# R! M4 z6 @& O - if(x1 == x2 && y1 == y2 && z1 == z2){
. b5 D; W1 U2 Y4 t+ i - return;
9 g- J; v- K m4 v/ } - }
* r8 E4 x; F" N- ?0 \; M6 p - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 m- k% u: K* P/ _& n3 n5 p# |
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 s" W! d0 Q, v+ C" s: d- X+ n
- }
+ ^& C P0 W) y9 N - pose.pushPose();7 u% P( ]3 {! c5 \' y% ]* H) z: z
- final int newLight = convertLight(6); f0 f, Q% w/ c
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 E9 g, I) f4 X9 }; S5 h
- final float lineHeightSmall = (y2 - y1);0 k. ~7 Q" j% c& [$ G$ l
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" Z# T6 ^/ p5 C' |# R' S1 R( V9 ]) F) O0 B - pose.popPose();
, W1 G' h3 S4 B1 Y# {0 x - }, B/ q2 Z/ o, E- w6 \0 h$ i: C
- 1 D( G; B4 `6 v8 j7 ^1 h
- private RenderType getLayers(String texture, int light) {# F( `# n6 o7 K" U% q# g
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ H9 H) c; e4 G k - }3 q N. Y) V3 a* _2 E7 C' B' \
- 3 E" q1 u8 T! }7 ~0 _3 t& }0 w
- private RenderType getLightTexture(ResourceLocation texture) {
% `0 k$ Y/ `1 O& g" G8 G+ T, V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 [5 ]5 ]2 |9 a4 f% K" p
- }( | }7 w W' K; p2 T3 V$ b
/ L" d9 E- j; Z' L" N- C( V; n- private RenderType getTexture(ResourceLocation texture) {) E7 I4 l# y( W% V6 J: G
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 \; W8 N& g, W- B8 z
- }
7 _" J5 ^" Q% G; C
7 x' L \2 W, f- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" T. E* B. }; ]' V
- if (cache.containsKey(identifier)) {
( u! t% B3 P0 N- q- @ - return cache.get(identifier);
2 `4 i% X e7 J3 [' T - } else {
; G. p5 M$ s( Q, U/ u0 g - final RenderType renderLayer = supplier.get();
5 \( J3 k2 z1 p. b: c - cache.put(identifier, renderLayer);% G4 P/ \, R+ m
- return renderLayer;0 p. T: }6 r1 l" f& g3 _
- }
u" a0 c1 Z4 r$ n1 i/ c - }
& w# b4 j5 V' @4 ?4 q1 I7 W [ - }
复制代码 |
|