|
|
# C! w0 D1 I: F, }
行,这个怎么样' N# B% S. E0 \6 \
- package com.xhg78999.mtrfac.render;
M6 D, }# H) e9 [' M - 1 p5 p8 B, }* U" ?- U; u
- import com.mojang.blaze3d.vertex.PoseStack;
2 j" g& z7 e4 H; k: `4 W; l - import com.mojang.blaze3d.vertex.VertexConsumer;
) I# o$ a0 @% _: u - import net.minecraft.client.renderer.RenderType;: Y ]! u7 S5 N5 B9 q6 y
- import net.minecraft.resources.ResourceLocation;: j# _; X+ ~/ n4 F% e2 P9 O8 V
% Q0 {! d# q# x2 V- import java.util.*;5 ]: S: k. h/ n( l- H4 ^! k8 t
& \6 f% g4 J8 M6 u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
p6 U! y. ?+ X$ x - # |: @5 t2 f) d+ F
- public class LineRender{+ E% M6 o2 g0 P/ o, F
- private final PoseStack pose;/ \8 i) M# V- F; T* Z9 X
- private final MultiBufferSource source;
; F' m2 p! o. w - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 b' R. S! W' g: |* h( ] - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();7 o A% h a* b1 L% N
; P/ W0 a* _- u6 h. K* N+ A
$ v' Y( g+ y" T- F- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& x! A7 Z3 K% n5 ^( h
- if(x1 == x2 && y1 == y2 && z1 == z2){
0 j0 w+ ]- X! D8 s; [: U2 G7 ]8 e - return;, Y3 A( F9 B: e
- }
1 p- t u5 r) C% x- O& } - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! L. h5 T5 _2 S4 l( T - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, ?' D# R/ L) G$ m) P# [* x3 L - }1 E f: N% M4 ?: L! c2 O6 W
- pose.pushPose();$ t j4 Q {2 j' a: c
- final int newLight = convertLight(6);) _/ b& a) t3 K1 _
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false)); Y: P4 e6 w( g# G: |9 ^
- final float lineHeightSmall = (y2 - y1);
; V9 ^$ K+ X) [1 Q4 C' Z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
% d* L z' r6 c; A6 z- o - pose.popPose();( U/ l" m. l' Y$ E f" M. V
- }7 r! _; C' K, }0 {" K s' x
- ( c7 Z# z) m w F9 g
- private RenderType getLayers(String texture, int light) {
0 \/ p- b! S/ Q1 T+ p - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, C; B1 w4 C( Z* I7 V
- }
* |/ Q5 b- r, r% n - $ v$ E+ w! o: x7 C, e
- private RenderType getLightTexture(ResourceLocation texture) {) H9 ]4 L; P: M7 }+ d
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ l) U/ u) [, u: C2 J - }
; ]+ V: z" r- \3 U - 7 X, m! \- p2 t! h( j: f! N
- private RenderType getTexture(ResourceLocation texture) {2 Q' \& b L0 P' C1 J6 [, [
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);! h2 q& p$ b, k" J7 N0 s
- }
) p7 \5 u8 O+ l' O% M- d
3 I. {. ~- G5 |3 o+ Z; L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; @; @& R! w( k
- if (cache.containsKey(identifier)) {
" ^' }9 e. ^: s+ L1 o - return cache.get(identifier);
2 ^9 W4 J* [% B$ |4 ^ - } else {
5 x* }8 [ y, u - final RenderType renderLayer = supplier.get();! Z* A+ e1 l0 z) V
- cache.put(identifier, renderLayer);
_+ Z: {; q. N( N! ` - return renderLayer;$ R: Q+ E3 B- V1 V2 C% D
- }7 n* t0 m9 r( {& S
- }1 ?9 U8 r' s$ {
- }
复制代码 |
|