|
|
# f& T0 P* R% R8 |) s: T
行,这个怎么样4 ?( @# P/ g8 M& t' x
- package com.xhg78999.mtrfac.render;5 n: Y8 E+ E5 Q/ G3 q* I$ s; v
( N% |3 A* _7 T4 X* t) J- import com.mojang.blaze3d.vertex.PoseStack;: S3 ^9 y, {$ |2 Y, a
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 v3 Q# H- x; Y; r - import net.minecraft.client.renderer.RenderType;
2 J/ S, c$ P$ n; C; ]0 [( c. F - import net.minecraft.resources.ResourceLocation;# F8 ^" [$ ~7 |
/ X# d. F% ^' w! [6 w9 c! F- import java.util.*;
, m9 \( i( j* R) H, B. ^- Q
$ @7 x% `& Z$ i8 Z6 H4 B- |1 D- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
r3 r, K: j2 P' w! p) m
0 }5 }* ~# @% N# n2 D& r. \* f) |: R& L- public class LineRender{
, s( L) _5 i2 `* n" l& I - private final PoseStack pose;8 l( n& ?& Y' ^3 L& E+ K5 Y! o' Z
- private final MultiBufferSource source;7 K e! d& }4 W" w5 o* ]" q" u1 F+ w
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" c3 U. h. a. C3 ~
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 f: G: g# `. j8 i1 S( T# H
8 W1 o v& [& ?2 p- ) T* z* ^, a, u2 E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){- Q; C8 _# \ e$ {0 j
- if(x1 == x2 && y1 == y2 && z1 == z2){* v- ]3 f* M7 }4 [ `6 q
- return;. C) q( F: U5 r; w% V( E
- }/ p- Q7 X2 L# [- B
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" k+ ~$ G0 J. X% P+ |* ?
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, c7 O5 Q! l+ `, ~5 k7 f3 P: ~
- }
( B# B) N1 q- T9 L - pose.pushPose();) g0 y6 u* ~3 b8 l, N Q
- final int newLight = convertLight(6);
- \' C5 B) F: w% {9 w6 o - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ p5 f9 {; D6 w! [2 L8 V$ E
- final float lineHeightSmall = (y2 - y1);9 V) T r9 D' ?+ }% O
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) _5 D+ `' l- i( D: e8 f x
- pose.popPose();* [4 t( c9 y1 \' R0 j
- }* q2 ?9 O: j$ L2 S) J7 I
$ r2 v3 L$ Y5 t. c- i" Z- private RenderType getLayers(String texture, int light) {; A( [( {5 ?$ I3 x a" ?
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% O6 ?" z' \* i* L! U
- }4 R7 q) W9 z$ u2 }$ H7 a
, e1 k. n) B" C$ s+ g( h- |4 B- private RenderType getLightTexture(ResourceLocation texture) {
; e% v% v* s4 B - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 x: t0 [6 E/ e! M8 l - }- o' ^+ _' s$ N
& Q4 o4 D, X5 S' o1 r. W( O- private RenderType getTexture(ResourceLocation texture) {# z& ~1 T' w0 i* F
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 L1 p* [8 t# w9 I3 V- ^
- }' @- w5 D+ U* C0 i5 I
- ; T8 u8 ~7 Q: k B) M5 U, }* h4 {: I
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# S& ^" ^( c% u# w! X/ o
- if (cache.containsKey(identifier)) {6 g9 L/ y( g0 b: Q' ~: @ e
- return cache.get(identifier);
% ]0 M9 f7 ?3 x' `/ M; S2 z0 M - } else {
( u; D: p% s: r6 N% i9 M - final RenderType renderLayer = supplier.get();) B6 n% w: M* {6 d8 b1 a$ C
- cache.put(identifier, renderLayer);! C+ ~$ `# M. G7 i- h% d5 H1 ~
- return renderLayer;
& o& r- U# X+ w9 W+ @" o9 C - }
3 s' D& P" C2 {* t/ ?& Q O/ C - }
9 a! k# T) S+ }0 B. c" J @ - }
复制代码 |
|