|
|
8 \% Q3 U' J0 L: A2 A" z
行,这个怎么样
& {$ w% o( U @: z$ `8 ^- package com.xhg78999.mtrfac.render;
* e$ g( c* }1 f, ?( ~% f - & Z9 X, d1 k( f- c* A
- import com.mojang.blaze3d.vertex.PoseStack;( P- Q8 [, G. h" J/ E- H1 o5 s
- import com.mojang.blaze3d.vertex.VertexConsumer;
& L! ?4 c' T4 Z) a; W/ D - import net.minecraft.client.renderer.RenderType;
1 { T3 U7 n( l l; E! Y w! r - import net.minecraft.resources.ResourceLocation;1 z B* w1 W5 R4 \' c7 ]
- ; G! Q4 m& z+ O
- import java.util.*;
/ T) g% t2 X- V1 S/ c- X
- H; ?3 K5 j1 U- c& j7 K2 C. N- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) u/ [+ L% ]1 q% c
R- p4 T5 `1 Z9 Q9 ]) Y3 T6 X4 W/ R- public class LineRender{4 a9 }* t0 q! @& N1 R
- private final PoseStack pose;6 q3 @+ {6 j7 H
- private final MultiBufferSource source;
4 i8 z" J( w. E8 W7 z" Z - private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 `3 f6 m7 q7 a: M
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 E4 x4 U3 J+ Z8 I; o h$ a. \ - / Q5 e* A. G* W% U+ K& w
( F' _1 ]) ?& e- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){: U3 f9 Y3 s* m8 d+ V
- if(x1 == x2 && y1 == y2 && z1 == z2){0 {/ a* U( I# \9 c
- return;; b t3 c2 T& T1 x
- }1 d$ {; x) T+ @/ H" i5 l) d& g
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ A Q3 [3 f0 v5 I - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 j0 K$ c- p5 o4 o8 y. ]
- }
+ ]: s4 z% q/ }. W7 t7 c - pose.pushPose();9 G, N6 G$ N+ M5 g; A+ o5 [
- final int newLight = convertLight(6);
" R0 L: _/ l* Z/ K! d9 s2 B - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: r/ ]1 T0 s/ p - final float lineHeightSmall = (y2 - y1);! t8 ~& i+ x0 c. P$ O
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* O8 P; \6 a) [ - pose.popPose();
& t2 k6 o6 I) C( G- W - }
[& {. e+ O$ B% {, x' @* N
* C; ?7 y+ ~3 c4 A% W- private RenderType getLayers(String texture, int light) {
4 N/ ?5 M5 j( S2 h9 O$ D G+ i* O4 j - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# I- r8 X. v4 X% o - }
$ c" e/ C* _; Y z# f, g) ?
+ o+ N2 J" \) `/ c: R) G- private RenderType getLightTexture(ResourceLocation texture) {6 h" G8 @4 n; ^! ~
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ D- H' ]: v! Y - }
; o# x9 T5 y c3 H - 2 O4 }- o1 p% v1 O( ~7 D
- private RenderType getTexture(ResourceLocation texture) {1 L& R4 v; H, z! d9 p0 T3 Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);- U2 q9 \4 z# j- y! ^! }
- }' B: M# }0 P8 {' ~" h' S
- 1 @, _7 t. K$ ~1 h3 ?3 {$ s
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
! ?2 X+ @% O1 o# C c3 j! g& x a - if (cache.containsKey(identifier)) {
# @" C5 Q% N. D% a+ g - return cache.get(identifier);5 C0 d# }8 ^& k. w& t
- } else {
- S! R, l" i7 v7 N1 g6 s' L4 @/ e - final RenderType renderLayer = supplier.get();
v- y+ f& h' _; |. i$ n3 u6 A - cache.put(identifier, renderLayer);- Y' ]1 S" x6 j- L
- return renderLayer;
5 t/ X9 D8 e0 Y! L1 b2 | - }- y3 \6 v+ d! @
- }
$ n# i. ]1 P+ w1 `( {0 o- U6 s - }
复制代码 |
|