|
! m0 F J0 t6 G2 e9 a, f! \( R行,这个怎么样
* F, t1 q6 H0 a- package com.xhg78999.mtrfac.render;
; I5 M3 I9 J7 D" A# S
' O& s7 `' x$ T1 e- import com.mojang.blaze3d.vertex.PoseStack;4 S9 g, g6 `0 m$ r
- import com.mojang.blaze3d.vertex.VertexConsumer;* o2 j2 v6 r: X0 H5 k# V
- import net.minecraft.client.renderer.RenderType;0 L+ M5 C9 C; U% o
- import net.minecraft.resources.ResourceLocation;& M6 P0 O! w- g) n
- : W9 D% |8 W) a! ?* S8 L
- import java.util.*;& v/ d8 Q/ b! T7 Z3 d5 s
8 q5 V z' l7 q: s" w- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(# L+ K6 |* B& g9 @. q
2 r9 }% }& W3 J6 X! _$ S: o# b- public class LineRender{
; j. A9 A( I& w5 T' U - private final PoseStack pose;
$ f$ \! b. T5 s/ j/ c& m - private final MultiBufferSource source;
4 O- ? Z( m0 k" E7 W1 M6 U4 O - private static final Map<String, RenderType> CACHE_A = new HashMap<>();- j G* Z# p1 ]9 P/ ~; R
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();3 a& K5 t+ q# F" ?1 O2 G: D+ |* q
- 3 E& P9 L9 m. v' C: p
- + T/ w+ n: `$ [7 ]
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 P8 o: A) m1 O; l8 x* F& j! d% ` - if(x1 == x2 && y1 == y2 && z1 == z2){+ s. p& D( S( i! B
- return;+ C6 q' T& C' {0 Y; \
- }
" E9 X5 {/ V; _4 F. R! T - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
/ R) n$ N( d; I: r" J - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& _5 S) D1 H# |4 ?( `
- }7 X8 A2 o4 B! {+ o6 A0 {
- pose.pushPose();' n- { a$ {( }8 I
- final int newLight = convertLight(6);" S, B( @/ C, C+ \9 [9 C2 W4 V: d
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
q# f) T4 G/ k2 z7 ~ - final float lineHeightSmall = (y2 - y1);
Z) B7 F, P- D, @: L# v8 U9 ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' h. n; ^! B) M6 U% U+ b - pose.popPose();- R. I! {9 O: Y3 K7 j0 C- u7 V4 l
- }; w i& a- d: R& [% j
- 4 z8 _$ U" {- O) J. W- R
- private RenderType getLayers(String texture, int light) {1 A4 p9 u! s, {
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( j* v0 A+ b; ]7 V l$ Z+ x* b" V - }
- |' h/ m/ u! C8 z D
9 B. S1 E( a3 m3 K# T1 _$ k* C- private RenderType getLightTexture(ResourceLocation texture) {
# n3 W: a( R0 W9 q, o4 U* X - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
- j+ M9 a7 I5 P( y- {) _! v - }
. g+ k: f) ] X4 C4 E+ c% e0 b - ; v2 V* e( T( N. |# l: g3 n
- private RenderType getTexture(ResourceLocation texture) {" d* J- h0 I, F U5 Q* M
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);* r) n4 T3 H* M- R
- }) ]" h; S' L, ~0 H# s
$ n& h, d/ _/ H) K- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. D' e) s* A, y$ }( w, _ - if (cache.containsKey(identifier)) {
4 }8 z3 ^0 \2 ~" J) r) ^ - return cache.get(identifier);8 g, Q; W/ j+ I A, i6 w
- } else {
1 X u9 q# d0 { - final RenderType renderLayer = supplier.get();4 S+ {: Q0 S: p" h# U s$ a) j+ c
- cache.put(identifier, renderLayer);2 M* a A/ P' B! c% U
- return renderLayer;
4 Y8 J# N! V9 i) I - }
; \6 f0 v6 \+ U. o - } D3 v- A0 f9 ^: V5 h0 |' Q# M! q
- }
复制代码 |
|