|
|
0 p) Q/ o; j$ v; h, M" v行,这个怎么样
; F7 {5 I; k2 a- S" U" W- package com.xhg78999.mtrfac.render;% U4 Z b- ^( M
- / Y1 s! ?4 |& [% Y3 Y7 Z
- import com.mojang.blaze3d.vertex.PoseStack;
$ b. ~5 _, G1 U1 Y: u- f - import com.mojang.blaze3d.vertex.VertexConsumer;
4 [# ^2 W) b4 } N. E7 S* O5 I - import net.minecraft.client.renderer.RenderType;! Y2 m" \. k& { }% e& i. P9 F/ H
- import net.minecraft.resources.ResourceLocation;0 X6 Y. B0 ^6 x" h) C& {% Y( q! |
- - g6 V9 _* ~$ d* r z( j8 P
- import java.util.*;
$ T0 u/ \2 j1 K) c8 ~6 c& h; H
- V2 W, i& s; w- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 j& B4 t! y! D - 1 c# k j" S/ ~. T, P
- public class LineRender{
, t+ }$ n: `# @: J, T - private final PoseStack pose;
3 c. z, T+ M' Y1 c - private final MultiBufferSource source;/ A! ]# q r$ w' u: @- K
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();/ V7 z+ R4 t f$ Y. f7 n
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, [; }% d" {( j+ M2 ^5 B; a
9 R2 ~- T% X8 X) ~. }1 z
3 R. l0 |# S5 g! q* ~- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) o3 G9 T, t- l$ q, m$ d! S - if(x1 == x2 && y1 == y2 && z1 == z2){
4 W) k6 _5 H2 p; T' F$ H - return;, y% L" [6 p( w
- }
+ s, x/ o0 @7 W/ E6 G6 _ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
6 ?4 i) q( L) D" \# X& w8 h" _! n - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");+ { n) E, J5 z
- } ^2 {* J7 V( n% z5 w/ ?, ?
- pose.pushPose();0 [; @& y; ?: h8 ^3 m& y" O
- final int newLight = convertLight(6);/ y* H$ t M# N# i! }! J' ]! Q9 g, G
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! ]7 V7 V% C! h) R' E# V0 A - final float lineHeightSmall = (y2 - y1);, m2 R0 z" Z/ H, J8 C
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* O. ]" M I' s& O$ I4 Q3 W. _+ Q - pose.popPose();
# }: d' [# K, R/ a - }
1 h5 _# V' \3 z# I0 O1 t" [! \
3 v1 ~! M! w* `+ ?5 ]8 W1 m# Y- private RenderType getLayers(String texture, int light) {! n l+ t f* z" V
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));) x* `) C6 ]/ I5 G1 {+ ~0 F9 }
- }
) A" C6 m: T# q& A
% `4 k0 Y- J: U! Z+ k, ]" q- private RenderType getLightTexture(ResourceLocation texture) {
( R6 y5 p) Q2 f* f3 u2 d - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, e5 d: S, J+ v% r - }$ @ i6 h4 S/ h# _3 s1 J3 O
- . }' A( `$ b, }" }+ i( d* Z
- private RenderType getTexture(ResourceLocation texture) {% N6 b. f4 t0 q! u0 {& |' Z! J& t
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);, k) w% b: ]' W+ I! \# X
- }% ]0 Q; p" b( d' L2 d. |
( L( x; u5 p2 s, _& k& q' w3 b6 `" w- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& E* C* u4 F N; q8 g) U2 s5 c - if (cache.containsKey(identifier)) {
5 E% R+ f0 q9 y( _6 G* }6 @ - return cache.get(identifier);# P1 ]$ p8 i9 `0 \0 ~
- } else {
\8 [7 J( I' b6 i. l- A - final RenderType renderLayer = supplier.get();
& j: ~/ a: o- m2 o" ]3 [ - cache.put(identifier, renderLayer);
, n( _2 @) ~ r v* ~ - return renderLayer;
( `: Q. `6 ]% d0 S - }
|0 ?3 s5 A. ^" } Z5 A - }" e- i3 g; s8 C- a& j% a, Y9 K
- }
复制代码 |
|