|
|
& G+ ^& a6 }$ ~! ^5 m2 }
行,这个怎么样
; ]. n6 N1 [- D9 Q- package com.xhg78999.mtrfac.render;0 w- e" e$ l( E: a2 v
- - ^) M; \0 A4 p
- import com.mojang.blaze3d.vertex.PoseStack;$ f) N2 d9 Z# Y0 ~1 g5 Z+ \
- import com.mojang.blaze3d.vertex.VertexConsumer;
/ X( R g- D3 \" f- d" _" T! J - import net.minecraft.client.renderer.RenderType;
7 o! M+ U( A) C - import net.minecraft.resources.ResourceLocation;# ?& z( n; j% b0 J
% W2 m( Y2 T7 E7 {- import java.util.*;
0 z7 R- k6 M! A4 k, ? \6 r
( V& N2 d! N2 J, u0 ^9 g y- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(6 V. i+ ]7 t1 D, N
3 j/ z h2 w- r% Z8 M- public class LineRender{
& {! x8 V5 c7 v1 T5 S" a8 E - private final PoseStack pose;* m- Q1 \: y: U6 J! C$ Z3 \* y
- private final MultiBufferSource source;
6 `$ p) y9 V( ~! g; v9 j6 u - private static final Map<String, RenderType> CACHE_A = new HashMap<>();, T2 F* Z, U; E/ _9 o/ q0 I( K
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 e6 l. m0 {# O$ }/ c
! k6 `% |& V" j+ j9 _, Q( p" I- 6 B1 z3 e( `* q0 t& p5 x
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; F& M- b3 Z1 ^. k/ l( n/ x
- if(x1 == x2 && y1 == y2 && z1 == z2){( {5 J* s0 {5 ` [
- return;
+ X) }( I7 ~1 L- B - }
& ^7 j% g+ l( Z* h2 | [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
* x: A, l$ \% ~! e - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( M0 s" }; L2 T6 X' B
- }; D% }# d7 v8 e6 s6 s
- pose.pushPose();
9 t3 f0 ^# F" Z' L - final int newLight = convertLight(6);
$ r1 x: {" d% V1 [8 H - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 t6 w9 x% ~7 G, C2 o
- final float lineHeightSmall = (y2 - y1);- P. s8 J9 U, d! k1 n
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- f, d! w* f, w# V1 p; t3 Z
- pose.popPose();
, j2 p( b3 `4 t; u k- T - }* j- R, C q) j& o0 g
- & Z$ r6 T+ u/ x8 R" H& X
- private RenderType getLayers(String texture, int light) {; w+ D- K* b9 i$ L
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ U9 |8 ^& H2 ^
- }
2 \- `4 e3 c9 k% T9 } - 3 V* f. {& H9 ~2 p; S" q9 r! @1 t
- private RenderType getLightTexture(ResourceLocation texture) {
0 q5 S) T$ ~0 S$ u' k0 R - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ \' V4 s7 h3 n+ M" ]& Z
- }3 _4 Z D# K' ~8 M7 P
- E# X& ~' E. s, s- private RenderType getTexture(ResourceLocation texture) {
% `) W( z. r) A2 V8 y& x7 q - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" T4 E4 r. |' B ?9 v( Y7 h. }/ T8 _ - } R$ @" U' B& W4 `8 f, b
- : z2 f. \ i! t7 y8 `6 J, \ ?2 c. G
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* G* b+ w! O" e; a( d \! n" J1 q# z - if (cache.containsKey(identifier)) {
" Z$ u" S8 E3 z8 ^9 H - return cache.get(identifier); m+ [# p% |& v
- } else {
& k+ y2 Y: [# X: d' _4 c - final RenderType renderLayer = supplier.get();
+ I9 S$ G7 j3 o9 t( f& n - cache.put(identifier, renderLayer);! d# c, j6 L% j& `
- return renderLayer;
_ g2 B9 M! ~! C8 h) [ - }
. q7 {, X. _7 l - }3 O% M B& |4 o6 E4 `2 a( C
- }
复制代码 |
|