|
|
( T" O% t- r- f& l3 Q" @( _8 `行,这个怎么样
E8 L/ X0 f; x1 W- package com.xhg78999.mtrfac.render;, X q r8 c* O. V
- , o# ^9 k- C3 p
- import com.mojang.blaze3d.vertex.PoseStack;( f/ K0 I2 d: j2 Q$ A
- import com.mojang.blaze3d.vertex.VertexConsumer;
" a9 r* P+ K! K9 K - import net.minecraft.client.renderer.RenderType;
( M3 G% N% p* \' M5 E* \9 K9 B ? - import net.minecraft.resources.ResourceLocation;! Y; O a# |, y& E& [: m
' D2 e" I5 v; D4 b" k/ c- import java.util.*;8 @+ V# _: c4 b4 `* S
$ ~- X& ~$ A, Q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ T6 l* Y9 m4 v, [% R( e! X - 2 G, H0 K& n5 A
- public class LineRender{6 H& W9 O1 m+ c/ p) a& X' \ s* O! m
- private final PoseStack pose;# S# W. [ D6 [" |
- private final MultiBufferSource source;. n O! ~- M/ j4 T5 J5 J; x5 Z# y, ~
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# q& o1 y0 O4 f' F: f b! b - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
' ] s, F" @7 O( D, y - 7 v1 ^) B- i f* ]
- 7 k; i0 }: ^# I- f5 {2 F' ?, Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ r( V$ D+ ~( g+ m: I
- if(x1 == x2 && y1 == y2 && z1 == z2){
4 n/ I/ m7 k4 N3 N - return;
$ h4 j8 h1 g- ^/ A - }
* V1 M: w6 p/ i5 r% m( z% m - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 Q+ n- C9 A4 F0 Q5 q8 c. R
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 L; ]* H- @9 m
- }
* P* E( U3 J' V5 M- Z( Z- L - pose.pushPose();; ~$ N$ @5 V! T. \4 I7 l; E% s4 H* p$ I
- final int newLight = convertLight(6);0 F* h& f$ [8 F v& t7 d! M4 V! P
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 A/ z+ w- _- i- _/ r
- final float lineHeightSmall = (y2 - y1);) P9 D& ^: h9 M3 ]1 N; \% v
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 i) p: o% G3 x9 F - pose.popPose();" _" A& h f' B: ~2 E' u7 i; w. e$ \6 k
- }: d. O! T. J. p8 f7 {
& p4 a( c, e2 j1 T0 U- private RenderType getLayers(String texture, int light) {& h1 I6 R8 @0 n5 W
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# I8 {9 b2 U: r& f" e4 Z+ r1 ~) I0 N6 f - }
) s% } Z$ f# v7 ^
+ H/ A9 r( E Y% N1 n }- private RenderType getLightTexture(ResourceLocation texture) {
9 b- ]0 H% a U$ Z) y1 n6 o( P% Z - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 Y3 @# `, F: G# _* j' V; h
- }
9 m* k2 L. x6 ]+ F+ R# p - . d% l' k& x& S" l' y4 _0 C6 G
- private RenderType getTexture(ResourceLocation texture) {
" X* G U0 ?$ Z - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 D5 y* M1 u- B1 ?( h. V1 w
- }/ O" f& D4 m. z$ E4 K/ }2 ?
- % U8 V. h0 U/ J; v3 S* {
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; _% \9 s& a# |4 [1 m( H
- if (cache.containsKey(identifier)) {. C! l- ]" p/ G" g* B
- return cache.get(identifier);
$ d. o t3 u4 d+ |5 u - } else {
$ k- O! J6 R& }& V - final RenderType renderLayer = supplier.get();
" @/ i$ q) V% c, I9 w7 l6 \7 H - cache.put(identifier, renderLayer);
8 a1 S0 A" W" N" m - return renderLayer;
( b% N0 Z. w. O - }
/ J% k/ T7 |6 q$ X$ m8 g - }
# o% H* x1 t; ~ - }
复制代码 |
|