|
|
2 ~3 S, Q; ]5 w" p( L
行,这个怎么样
" ?- z( c6 Y% X2 L8 x, C7 s- package com.xhg78999.mtrfac.render;
" F8 F$ M4 h6 B7 U - ! o' A6 @- e0 m: M/ S ?' Q) Q
- import com.mojang.blaze3d.vertex.PoseStack;( L) V7 j, |4 p6 V5 Z
- import com.mojang.blaze3d.vertex.VertexConsumer;
! f( ]) W4 L$ M5 ~& ~ - import net.minecraft.client.renderer.RenderType;
8 w5 k9 w0 q' O5 O4 w0 x0 \' ] - import net.minecraft.resources.ResourceLocation;: G" W/ I" W- N7 L
; K, x4 O) _9 |5 \8 G) e- import java.util.*;
2 R0 r( ^7 b" H- p/ {9 T. J. W - " {: [( Z/ m" t: m) n# ?( u
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(# f+ c5 e2 t2 _3 A1 |
- 7 O6 E+ a8 [) o' E
- public class LineRender{' C i, y. O8 L7 t0 y
- private final PoseStack pose;
% T0 s9 X+ P$ ] - private final MultiBufferSource source;0 P2 z0 ^ K) w, a( k3 z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 K# I' V4 k# y4 E+ a
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# ~9 n. u/ A( B7 L( `" u, F7 ]
- 0 B6 y f7 f- N8 p" J. g+ T0 A/ z: R
( e3 p, q6 z- O- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ I! i0 v7 ~% E, `/ s7 K- P5 W - if(x1 == x2 && y1 == y2 && z1 == z2){8 Y% w0 ], M8 g! q$ \
- return;
5 |% N2 V# i9 l - }
* z+ |) A- {, b" ~- k( y/ R6 j8 q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){3 x* p" T- D. m$ G
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 n& G9 A0 H. w. C4 m' n2 T, R
- }4 T3 R# S Y6 k8 h7 z; ~ I
- pose.pushPose();
" h# u# _/ F. G, f4 u - final int newLight = convertLight(6);
6 h( t2 z* V K* v/ Z [/ Z+ ^: W2 R# a1 q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false)); M) U! n& z/ P( U& f% e7 m
- final float lineHeightSmall = (y2 - y1);# Q" `% c( P. Z* A6 `' o' X" T
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' ?: Y2 C5 S) S - pose.popPose();5 v& q% A% q. y/ \0 H6 z
- }0 M$ [9 e: B! p+ t
: B" `* c- ] C3 q6 F' Z; r- private RenderType getLayers(String texture, int light) {
' ?. e0 n% y8 A5 D* s X - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
) D. \+ K, { w6 z! X0 @ - }7 c3 D5 s! \3 A0 b8 Y
- # B) V6 g% W0 y2 n' X$ Q4 M
- private RenderType getLightTexture(ResourceLocation texture) {: y1 `6 P8 n" U" A/ @1 a
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# y: l, { E5 | - }8 ~/ U$ }# @# n4 g0 B7 b4 P. E
# ?8 D0 w, z- L$ r2 @5 P0 y- private RenderType getTexture(ResourceLocation texture) {
# w2 u, C1 |' m& b, h% I8 ?5 ?) V - return this.cache(texture, () -> entityCutout(texture), CACHE_B);( F5 \9 X w- F8 b
- }# f5 ~+ y( z1 H: i* A
- ) u, {! _, L9 Q: L# I1 J2 o
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
/ w5 j5 k/ T: d$ q" m7 R - if (cache.containsKey(identifier)) {
" i; \) N5 b9 V( {5 H) ] - return cache.get(identifier);. e% E/ j3 ]* q; G H+ r) U4 J2 s
- } else {1 G/ w7 {8 z( k% p) M+ h2 |
- final RenderType renderLayer = supplier.get();6 h; @3 Y* n* H6 P; p( v
- cache.put(identifier, renderLayer);& x3 O) p9 ?4 }; h6 D. E2 }: {. t7 f8 Y
- return renderLayer;
: D$ v3 q) Z2 k9 I7 G - }
0 E6 F" Z4 J8 a# c3 ` }/ M& x - }- _" Y; P) E. i) Z. i& D
- }
复制代码 |
|