|
|
7 p0 W; r; z4 W' Z/ C+ ]8 _
行,这个怎么样
' s! Q! B1 Z; w( p( b# X8 Z' W- package com.xhg78999.mtrfac.render;
1 U, E% \; o: C4 q3 @. `
% J# [( c8 y5 R% G: a* g/ G- import com.mojang.blaze3d.vertex.PoseStack;; {% W f3 a- w2 b8 G" C
- import com.mojang.blaze3d.vertex.VertexConsumer;5 I- ?9 l' Y7 t% B- t. B. j
- import net.minecraft.client.renderer.RenderType;
% Q: _) n3 H' L4 t8 w - import net.minecraft.resources.ResourceLocation;
& \- d# g. K% j- O' G: {, O( x - 8 X/ g5 }% V1 f, X8 l$ a
- import java.util.*;; _# j! j& P3 O
- : x5 s8 F: G/ A4 r# @" @
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
b% c: r4 u3 k$ }" \/ H+ x/ u. g
7 C! A+ |# f* |* ]) U S- public class LineRender{! w8 [2 z: p7 J5 [% I! e5 o- f2 }
- private final PoseStack pose;4 w$ e& ?2 V) @0 t
- private final MultiBufferSource source;; Z9 E* ~* h5 ~
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();! Z4 z2 A, Z- G' ?. s( D V
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();8 j+ u; U. G h% b
. Y) I; { |# Q( n- : G$ z3 \* U, F
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){* k; f1 R: Y% A$ p# d0 `
- if(x1 == x2 && y1 == y2 && z1 == z2){
( ^. G* Q5 Y9 i# H - return;
! n0 x8 U& G# C9 Z& c: h4 m1 `. L - }0 H! y f7 Z; b' W4 ?' H
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 s: l$ r* z0 _9 p i
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' v$ |* o; D p' s3 J! x( z( N
- }
# \& S( A# c. _" g9 v2 l - pose.pushPose();4 c/ D& F0 M6 y6 X& B
- final int newLight = convertLight(6);
, g+ V- T% h- p+ b: R5 C4 `. J - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& M1 _1 M5 }, Z) F: f
- final float lineHeightSmall = (y2 - y1);
5 R- G! E9 q% Z4 u5 f# [ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight); T) d3 ^6 \' x0 F5 t; w! m( [
- pose.popPose();
# e: L1 D9 ]/ }& ~! A* h' }( v" e- F - }2 X, p% i* T% |2 R: Y) ?; S e
( s+ P5 u* M% y, Q* M- private RenderType getLayers(String texture, int light) {
! H/ e$ ?6 H0 l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
9 u: u: w6 O: d2 Q' I - }
! O# U q! Y' R, J) Z& O, O, @ - & l. n! b0 e# Y- M; A* Q6 L8 m' v
- private RenderType getLightTexture(ResourceLocation texture) {
5 U- Z8 P7 p" C: _/ w9 z4 u. N2 W0 N2 W - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);5 u7 | m0 j) ]- m
- }
; |" N; c! F4 ?+ H! n
" F7 j: G6 ~" {' L- private RenderType getTexture(ResourceLocation texture) {+ w) m9 }9 m" n- ~2 n6 r5 W/ A4 X
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 C6 w) W. o3 ]- R. d1 D+ [ - }6 R' ~9 S$ R, j1 K
# ^6 H, s- |% b- H# j1 ~! G- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {- I2 |. g% H9 u) b! |# p! ]
- if (cache.containsKey(identifier)) {
N, F+ n. Y* l6 p - return cache.get(identifier);
$ f% h3 U) Z( E+ V" `3 D+ G - } else {" z- }# Z' T+ }
- final RenderType renderLayer = supplier.get();
9 {' M. s" n4 R - cache.put(identifier, renderLayer);) z" W ]' H' V% p
- return renderLayer;
' N# u& K2 F k2 R - }
/ ?% Y, Z( w7 |# N4 y- y - }
e9 H# l- M' @) a5 I - }
复制代码 |
|