|
|
5 C9 I, X" K& P) T行,这个怎么样
- \. D, t7 F- n" t- package com.xhg78999.mtrfac.render;8 M% o7 g& @: ^
- & v: J6 f* s1 O/ f% O
- import com.mojang.blaze3d.vertex.PoseStack;4 {* d; i/ x) j, s5 j8 r
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 i Z* [1 ^5 {* f- w, B* `8 N - import net.minecraft.client.renderer.RenderType;, o' w1 b+ A5 C% X& r$ W+ B
- import net.minecraft.resources.ResourceLocation;
+ C D3 m; Z$ f! i7 Y4 s; p - + \1 D5 x; U0 R- a
- import java.util.*;
; u7 i( `8 Z+ e! S; O. u3 t: ]; I - $ T! g) p/ K8 J. p
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(# {# i7 o" H$ n$ o) |. J' E3 g
+ @; ?1 L* r' l0 H; o- public class LineRender{
% V6 ?! o* C7 } - private final PoseStack pose;& x7 R; ~5 u' C4 U
- private final MultiBufferSource source;
! `/ m" V E6 `# x: ?2 T; H3 H: s( h - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 A# C4 n5 q& M- d - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. f" ^3 z- r, Z$ y; S l* C - 9 s6 p: B: |: n9 w) `
- 6 ]7 W R+ q% R- S
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' O* a0 t3 l" v6 F7 x) j' Q( U1 L
- if(x1 == x2 && y1 == y2 && z1 == z2){
" r( Y$ W8 w3 z; F! Z) {4 r7 _ - return;* _$ P9 u+ ~( _4 r$ d; V
- }
7 |" a- d, n' J. z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 j" I# S0 p2 e6 V3 G2 T$ r, X
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 r: @; ^& F( N' m: n* t/ T% c7 S
- }7 e: ]5 V3 k' d3 ?
- pose.pushPose();" X! O( j2 y0 Y | D$ p) i2 D
- final int newLight = convertLight(6);5 Z% ?5 J4 a# R& _% ?4 a: k. M
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ _( E+ b: O& g* S1 h - final float lineHeightSmall = (y2 - y1);; M7 q1 _% A% J; y: z# o' q1 H2 z* ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# k {4 B/ K( i2 T
- pose.popPose();2 b; g) v# A' d- N5 ?& _( c
- }
1 V& Y8 K5 \4 l0 l& v( r2 r- F
" n9 n6 k6 v p; i- private RenderType getLayers(String texture, int light) {; g [( G! V, d1 f6 z# @/ K! F" J
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ \+ _! k8 @1 E/ M4 q
- }
: M! @. c& S" C9 h; E - : F) \# N9 U' K0 Z3 d
- private RenderType getLightTexture(ResourceLocation texture) {- h, l( a- H$ ~" y$ U+ T
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. y. e' d# E7 {# ?7 n% K - } d3 w. ~! q4 b9 q
- 3 r& x4 X$ y3 B+ T, @
- private RenderType getTexture(ResourceLocation texture) {* d& n) O1 [ e- S, t! |
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 }8 c, Z" C; H# h8 ` - }
& t( ]2 m% |/ @0 X8 K/ E
+ d0 S+ z3 Q! V7 n8 D- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {& A6 i, g; W$ }# Z/ j( ^; }
- if (cache.containsKey(identifier)) {: d; Z; x ~( O4 @( ^9 z. i
- return cache.get(identifier);
- B+ C6 O2 I7 U2 g+ o0 w3 M - } else {1 A+ A* e! p( K( `
- final RenderType renderLayer = supplier.get();
+ Y' \ ~ N- R& Q0 ] - cache.put(identifier, renderLayer);+ c$ a9 C" |8 j- B* e6 {
- return renderLayer;/ U4 J+ ?% F3 ^/ d- Q( \
- }
4 O; @$ N5 B+ J5 S6 r - }
( Y9 K2 E7 `7 i. e' Z - }
复制代码 |
|