|
|
4 b0 X; k# R% |8 C
行,这个怎么样$ `: i$ m& [" V1 b% G
- package com.xhg78999.mtrfac.render;
/ [! s' e; g% ^. O( D8 M) u* c! ] - ) d% F. Y: \/ R# `
- import com.mojang.blaze3d.vertex.PoseStack;
6 b4 t. G. P [! @ - import com.mojang.blaze3d.vertex.VertexConsumer;% i& Z7 V* E. s- P3 s
- import net.minecraft.client.renderer.RenderType;
3 {% V* V+ q. a5 q1 w9 a1 o - import net.minecraft.resources.ResourceLocation;( Q3 r( p6 o3 ^, b& T# I
- 8 V# f0 }) y. i) Q! ^6 m9 v
- import java.util.*;7 s: \5 @, d' G. `
0 S! p9 O) b- _- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
% f+ t- D$ ?* E/ ?4 I - ) ] e, R- U( @& h6 Y8 _, g
- public class LineRender{) c* C, l7 r& B
- private final PoseStack pose;- g6 f# i. d" y. t6 u5 N6 q
- private final MultiBufferSource source;% [2 G: L: {8 L- L2 _: l
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();' F0 @4 Z- j$ Z1 H S
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); x! ~% E, N6 b& |6 m& e" B
6 n& M0 @3 S% W% k; p- ( G+ T6 L4 G! C# e" u0 I' f I
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){# Y1 i. I7 \+ v% {( y( y
- if(x1 == x2 && y1 == y2 && z1 == z2){* q4 D. G; H; n8 ]
- return;
, E. r1 ^* t$ W+ G1 @+ n - }
2 T d4 w' N" k7 w4 Q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){. J! z( `( c8 p+ |4 c# W) N( Z
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. b. T0 K4 l- m. j- m% c$ V
- }
, n" g' x8 m, U- W* r! o- P - pose.pushPose();
8 |0 j" ~4 n4 v5 ^2 `- i5 ]0 e - final int newLight = convertLight(6);5 @- }$ g# ]; Y, j0 Y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) q/ S/ }% c+ i - final float lineHeightSmall = (y2 - y1);4 ]% q+ m( y, S+ C C+ l
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 e: D, o0 d6 K% I4 B - pose.popPose();
& H0 @; q7 W- ], u - }( c6 h% N! i: e: w
- / G9 X: I# k% O0 R% Y! O
- private RenderType getLayers(String texture, int light) {
5 Y% ^( S; T/ j! [( n: r - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, b, _2 ?* ? k8 d- m$ b
- }
0 y: x3 q* _3 e- k2 |! ~) \ - 6 J7 l$ n% I; c: o# K$ w9 ]+ V
- private RenderType getLightTexture(ResourceLocation texture) {
% ]) a# K* _! h* T0 k- | - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ B X. v5 p7 i% V4 S8 Z
- }% x8 V1 U1 o* h, \! a& y. j& }
8 _1 w2 l% d1 z6 x7 [% o8 Q- private RenderType getTexture(ResourceLocation texture) {
5 D, A$ m% q! F* M5 `% W$ T7 Z - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! B6 U6 J1 B: j) L( E- @; S - }* o4 u9 |' y0 g$ L% }$ }7 Z3 E
# I& P+ S& m. d, Z/ H8 y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 y5 K* k) u4 H7 Q( T8 g6 F - if (cache.containsKey(identifier)) {
5 W, H3 b) @) L! O1 M - return cache.get(identifier);/ k( l% z/ D2 m. r" ]0 V u* {; @" i% X5 o
- } else {% B- Z4 M7 m$ C9 r
- final RenderType renderLayer = supplier.get();
' }- h# M" N% S# y/ v4 i% S - cache.put(identifier, renderLayer);5 c# K7 y4 {0 A' u
- return renderLayer;
( l9 L, l& I k1 |' T$ s - }* r! A1 a4 k" }! o' z! R
- }- q+ Y d$ C6 E! `0 p: z" h8 L0 f
- }
复制代码 |
|