|
|
) J3 b3 R ]3 q9 f; D) \行,这个怎么样" ]1 L: E! H- G; L1 z" B3 C, S
- package com.xhg78999.mtrfac.render;
+ W& K/ @8 t+ G, Z - 8 u2 n/ `$ D. h5 P
- import com.mojang.blaze3d.vertex.PoseStack;
* T* V/ Y1 l9 n p# q2 I4 {2 d9 O - import com.mojang.blaze3d.vertex.VertexConsumer;& s$ y; l8 N/ B1 M
- import net.minecraft.client.renderer.RenderType;! D+ L9 I' q4 |2 u) }. S
- import net.minecraft.resources.ResourceLocation;
9 L4 _2 {3 _$ V+ n
) l: v$ U( x. c1 ]; o4 W+ A M- import java.util.*;! g1 z; T! ~) F+ h! G& n1 h
7 C5 x$ V9 j* ]2 q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) g/ V) Q" _" @9 W4 e9 n
+ i( `0 U9 G8 p- public class LineRender{2 f; z/ x5 ~9 D" ?
- private final PoseStack pose;
O) B) N6 g( U0 D$ u - private final MultiBufferSource source;
u V( Y {4 r6 I+ _ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();: c5 k" r y# z/ k0 C
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
/ i" u N* o' B, R8 Y/ \. ^ - % h+ ^5 p' g( L& i8 ]+ O
! m: q" A& V3 C2 f4 C. k- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. R/ H7 E1 t/ D, M! H% f
- if(x1 == x2 && y1 == y2 && z1 == z2){
5 k4 N/ C( G# g6 B - return;
3 k) o; L( i5 T$ b O* e: v0 B4 h6 m - }2 Z$ S! {& V5 o" H/ ^# Z6 J
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 \0 B& h0 o3 Z9 B) H2 Y. w - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( T$ Q; A: x6 d4 p
- }
' Y% ] @ W4 }# J. H5 v) w - pose.pushPose();
2 p. D6 n7 X S+ O - final int newLight = convertLight(6);
' A: V* [0 r7 v' B - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! P; I5 t3 x$ z; l# J- Y8 C7 z - final float lineHeightSmall = (y2 - y1);" |* V# [0 t# \; e8 ~- M
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) N0 a" ~; B4 t/ ^0 N8 k2 \/ p* L
- pose.popPose();; r& v: ?$ `9 c0 B% o
- }
; r6 H& M" O+ Y: T9 Z! Q, z
4 t! c! z6 }3 S0 p+ l- private RenderType getLayers(String texture, int light) {
# ?3 M' `" q6 l+ ^ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
[ \$ J1 m. U% c; h# A0 Q) P - }
9 f: Y# y2 Z; n
% \8 @( h2 q) O" I3 Z- private RenderType getLightTexture(ResourceLocation texture) {, ?% d; V I* c1 [7 [( s
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);+ [% b" I) p, V' t+ v
- }% e6 B% H( n6 h# L- \( d3 s7 i" e
- & V& g, h$ c2 N9 _- d6 e" @
- private RenderType getTexture(ResourceLocation texture) {/ M* m. J) c4 p& T3 ]
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ W7 T: z( l( n0 G - }, H7 v, L/ K* P. q
- # t7 U3 P3 P" m; Z8 U9 F( x. S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# W. i. r8 T0 o" Y2 Y5 Q5 P - if (cache.containsKey(identifier)) {
* Q% A, ]( k& g. Q( q - return cache.get(identifier);. P9 P2 O7 h5 r/ `
- } else {% Q6 x/ M# r* g2 _
- final RenderType renderLayer = supplier.get();
& }1 m( U* w$ H4 j+ N* M% y+ K - cache.put(identifier, renderLayer);) `$ ?. Q4 z- w; o e4 E( S
- return renderLayer;
" D) I; N' J* L" O - }
: V' S: k# y# f5 X - }! T! {! p. b/ S: [ I+ u# A
- }
复制代码 |
|