|
|
! [7 t4 y5 a9 s: f A! N
行,这个怎么样
4 }2 R# m& [. M5 p) A- package com.xhg78999.mtrfac.render;
5 Y* `( i* O$ J; d% b
+ F- {6 P2 ?8 k9 I' O- import com.mojang.blaze3d.vertex.PoseStack;7 w% Y( K1 K k1 r
- import com.mojang.blaze3d.vertex.VertexConsumer;
: Q* D& S- \8 j2 }! t1 s5 P - import net.minecraft.client.renderer.RenderType;6 G7 v. \) p( F4 n
- import net.minecraft.resources.ResourceLocation;
( @) p1 T0 V; I- T" l2 B - . L5 R6 P* X T' U
- import java.util.*;! {: o: Q! X! Y' ]* c1 G$ ^/ c$ N
0 T: d. k/ R, n4 n( n& p- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( i7 m. m& o: o - 8 v4 G0 Y9 u# y* ~* x! l- C
- public class LineRender{
# V" e8 G) {) r& A+ c! G; W% R - private final PoseStack pose;7 N+ q9 Q# Y) b
- private final MultiBufferSource source;" [7 k' X% |3 g5 D- x G2 N1 k E
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% F+ Q& l* [. k# }1 d: ~ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 R% k7 J; m2 f" }
- x% o* M# E5 l8 ~
- ) _ b- K: b w- ]* o$ G
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) J C7 ]1 d9 }+ z' c% @0 \' k0 W - if(x1 == x2 && y1 == y2 && z1 == z2){
) T: X6 Q7 u& { - return;( Y6 c5 w! D2 c+ c1 w" u4 ]
- }% |" ]- _( W8 ~) f5 V& `/ f& L
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){5 q/ I; V2 P1 k3 n: w
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( _6 H+ ^; G7 W6 p1 o5 @2 F
- }
/ k" h. j8 A# ?% p- g. i( G/ } - pose.pushPose();8 G+ N/ I% K' ?, [' b4 k
- final int newLight = convertLight(6);
$ x! L' ]/ B4 e6 w+ L1 k - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));' ^7 E$ p% r3 P6 `4 T8 u& k' @& i
- final float lineHeightSmall = (y2 - y1);
- g, G+ ^" ]) x. Z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
2 ^7 c& E# P8 c& o4 s - pose.popPose();
, e; i( G+ ?8 ^3 l& y2 v, A8 _ - }
n0 N% J4 z6 c$ W4 ?- [ - % ^, F1 t: d7 F9 q; O) u+ o x
- private RenderType getLayers(String texture, int light) {+ K# Z2 ?' e2 p0 A0 ^: p5 h6 A
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
: l D: N: Y8 v" ^+ q - }2 [9 I |9 L/ e8 u, ?: Z
- 3 d5 S$ u/ |) b3 U
- private RenderType getLightTexture(ResourceLocation texture) {
3 ^% F9 `# K' k4 |8 p3 d# j- b; Z5 \ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: X) M, p- f# |
- }- \6 L' N i# Y
- ; @% C8 N2 m5 b: a9 g! Z% T
- private RenderType getTexture(ResourceLocation texture) {0 D$ d) V1 S1 R% J% m9 L5 N5 ?+ a: x
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. z5 r9 s) C0 {# G& ? - }
2 E9 e7 {0 N& i. H& r6 _3 ?
9 j$ x" A8 ` N% ]8 S) \/ `/ g0 b1 Q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
% p1 V' A4 \8 V - if (cache.containsKey(identifier)) {* r, A- }" N7 d- `, I9 Y/ L
- return cache.get(identifier);4 u8 h8 H. v9 k7 p3 j/ U6 y. d1 w
- } else {# f5 j* ^6 F7 U$ L# |
- final RenderType renderLayer = supplier.get();; q7 q* F: D" ~7 d- V
- cache.put(identifier, renderLayer);- J4 Z0 e+ ?& h+ |
- return renderLayer;
. m% C y9 {( o: `1 M0 Q! X - }# s) ?1 W, [! Z7 p# l9 c
- }
* Z: R: F( {# z) y% T' [ - }
复制代码 |
|