|
|
5 s6 l \! \- f G2 } f行,这个怎么样
/ `2 \4 h: s5 I$ v& u3 g7 v. c, j7 l- package com.xhg78999.mtrfac.render;
" J: ^& r! [' I) `# R7 y - 8 u* [& [* Q6 u# C8 @. R; t
- import com.mojang.blaze3d.vertex.PoseStack;
: a3 d$ _! O: g1 T) C0 ]2 j - import com.mojang.blaze3d.vertex.VertexConsumer;
' `7 u( j: P" o9 n7 ` - import net.minecraft.client.renderer.RenderType; T3 w/ w- s/ `- R3 ~4 I
- import net.minecraft.resources.ResourceLocation;( U" M* T' [* T" A; @/ C2 |3 O
6 \6 n1 P) I6 Y. h/ {# x- S- import java.util.*;; g1 i, g' P, |! b s& |0 L
- $ R+ ~$ `% d9 p
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
R- K. |7 J/ V' H8 V. ] }$ C v
- e& _! v' |6 ~, I! [/ x' a$ ^- public class LineRender{
' P9 |( b7 O7 u; m - private final PoseStack pose;
7 u: p% E6 _* c: ] - private final MultiBufferSource source;# e# y2 g+ P8 n7 j2 X2 w
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
* P9 t \$ A. k Z3 j, ^$ \' u - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 j1 Y2 u5 [7 n; I/ N' m
: w& m! q& J: O5 |- L/ |- ( C7 k1 ^5 C7 M/ A# O
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){7 I* t l) t- k1 L4 q5 c; u. T
- if(x1 == x2 && y1 == y2 && z1 == z2){
: f p; [/ v+ {- V+ [ - return;
" a6 K- s9 Z6 u6 A0 s { - }
6 X- Q8 `- Z" }: ~: O4 B# S - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 Y' ] V) Z! b p7 c
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. x! P; T. ~2 d+ {' W. J - }9 \4 m& m4 a- U! S5 T
- pose.pushPose(); K9 M, [& Y/ N5 g2 v
- final int newLight = convertLight(6);
! T$ ^3 Z: n6 S/ _1 e* H - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));2 U# z4 H, K$ M# p2 O5 ^9 v
- final float lineHeightSmall = (y2 - y1);' L3 O$ x* O0 _) X8 E$ E
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 t$ {" p+ u" Q3 _9 d, j
- pose.popPose();! B. }6 Z& N/ p; Q5 X
- }
" o* C- u. i5 ^' [$ O9 w - # `' Y( e) Q9 O5 G! t
- private RenderType getLayers(String texture, int light) {
# d& x2 s( \9 `" h4 e) t9 w - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; d# j$ r1 }! A7 z
- }0 y8 G4 ^* u/ P! g" N
; Y* o8 C( e" ]2 l- c; o5 u$ Y% S- private RenderType getLightTexture(ResourceLocation texture) {2 M% n% r% e4 h, }3 a
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, @1 I: f( h% z/ P4 j% d6 K - }
( b# H$ H2 C8 ?5 m; D9 p" ~ - : q4 y/ t6 C. l* d5 T/ P; t
- private RenderType getTexture(ResourceLocation texture) {
, l. Y6 F3 V2 N' `3 H5 t - return this.cache(texture, () -> entityCutout(texture), CACHE_B);, Z: ~/ ?$ a$ a
- }% u" R5 A) ~6 u; N1 P$ S6 t4 T
- * a- U. T, Z; p! j" n5 ]
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 o& k/ Y# d1 ?
- if (cache.containsKey(identifier)) {
3 f s0 k/ e; E! Q. @$ ] - return cache.get(identifier);* S# p1 P# n8 t8 F& h0 ~+ g3 g4 l& k
- } else {! ?, v4 W0 ?& B5 E
- final RenderType renderLayer = supplier.get();3 e- B4 U/ O- _4 W; M! C
- cache.put(identifier, renderLayer);
) q# g5 A$ r5 [4 I& W6 L& b' z - return renderLayer;6 X% { s# a4 N! E: Z7 ^, z
- }( @( T9 Y: j# m* g
- }
, v; Y" p: l& F/ \9 h) y# u) g - }
复制代码 |
|