|
|
; K$ Q! s; }8 }: t1 O3 b行,这个怎么样
; \9 @: L [6 C$ U5 }1 o- package com.xhg78999.mtrfac.render;: v: S: w1 l1 M- P3 u5 k7 A
- ! X) i* [+ o7 a7 B
- import com.mojang.blaze3d.vertex.PoseStack;
+ K$ i7 o7 }$ K& }2 z - import com.mojang.blaze3d.vertex.VertexConsumer;
" C* C) c; ~ k* s; K) u( R: u - import net.minecraft.client.renderer.RenderType;
2 M' P$ Q' r$ ?+ m: i J% {* @ - import net.minecraft.resources.ResourceLocation;7 Q$ y8 B3 \- v) o1 \- t h0 B
4 }( m0 e- ]7 L. a+ g* M- import java.util.*;7 Q7 t6 Q2 L: Y5 m& Z& `- E
- k- z; Q' U Q. X; F) G1 K
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
9 w. S2 n5 o( N' S) o& w
; S+ P5 ], E* {6 X( U3 S1 H2 h$ |- public class LineRender{
7 R% j% s' n( A4 e! G* ?7 M - private final PoseStack pose;
' O: h6 ]! O$ ~9 G! | - private final MultiBufferSource source;2 Z6 Q. ? p( W) | Z: _5 S
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( X3 i1 o. R7 U7 c' O# U
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
q5 X, D' H( X, b/ | - & }4 S4 O; B' J2 g
6 R0 H8 e3 L7 Y% F x$ Z) ?( O- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
3 P1 H) m; `) e; [0 ~ - if(x1 == x2 && y1 == y2 && z1 == z2){- m/ E/ s- i# v& i4 X- M
- return;6 h6 n+ H1 H" b% V& N
- }
4 v/ P3 O4 D) R0 h - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# H' i) m! i) n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, X4 q; N2 Z* I3 u2 U* _
- }$ g# i( g2 G6 b$ Y. _$ t
- pose.pushPose();
# i' p8 a% g; L* I0 m - final int newLight = convertLight(6);
0 {3 H I% E# o9 \* D( g1 u - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ z" {6 w8 y# f" z
- final float lineHeightSmall = (y2 - y1);
- y: w; p0 U: G - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) {/ B* m- D+ l! [1 {. j
- pose.popPose();% q2 h" G7 j) E
- }* c1 K! b7 N- N4 Y( ^" Z; j
- " ^ \2 p2 [$ R
- private RenderType getLayers(String texture, int light) {
" `$ [! |" R ~3 N' t$ l, Z - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! g3 `% e. r8 y7 B! O
- }4 f: q( V* b3 |% Z, z. ~+ ^
- - e' Z" d, _$ g( e/ Z5 w
- private RenderType getLightTexture(ResourceLocation texture) {
4 G% ^# j( }/ k1 C, i# t - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
" V/ X2 X4 s* s$ e) @ - }* J) Q$ s5 y; x* o* k6 S8 Y
( T7 F( A P, Q6 k) A2 w- private RenderType getTexture(ResourceLocation texture) {/ X# h3 E- \- R7 u
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' I4 Q H) y5 s - }" Z: L+ {5 P$ D5 K
f+ H A3 l1 }& @- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
+ Y3 s$ r% G7 ?- C - if (cache.containsKey(identifier)) {& ~# J* S/ j$ q7 M
- return cache.get(identifier);
! `3 H' T9 ~" | - } else {; J- I' D4 @$ i# l* b# v- b5 M
- final RenderType renderLayer = supplier.get();4 t( @2 T. e# l4 ?6 H4 j
- cache.put(identifier, renderLayer);
8 @6 Z- R- I4 Z Y5 Z* y8 U - return renderLayer;# c; b# G0 D6 D
- }
. ^" [2 k5 ^3 {8 i( V% b - }
( T/ z* f; j/ t7 q0 d j - }
复制代码 |
|