|
|
+ g3 K% [0 j3 g行,这个怎么样$ h/ h& l5 v. W
- package com.xhg78999.mtrfac.render;
5 C% `" C; [" [
. D, ^' u: e7 D0 s% ~$ ^% ]1 j- import com.mojang.blaze3d.vertex.PoseStack;
- V t4 R- S/ V1 b5 u' g' c4 q6 n - import com.mojang.blaze3d.vertex.VertexConsumer;
/ `& Q3 w5 K* [. g: x: \+ T - import net.minecraft.client.renderer.RenderType;
# c* l( d9 B4 [2 @' z9 H3 n6 ~ - import net.minecraft.resources.ResourceLocation;0 e8 ]# W) h/ K! l
- * i3 D7 v! `& \3 z" \8 J6 G
- import java.util.*;; N o* ]1 o4 Z5 D" J3 I* A6 Y
- - h/ W) V# W% l" B# n* l! x7 `" r
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(1 v1 t0 j" d7 Y/ v
- 5 O2 r1 h$ x2 k+ |2 j0 J3 n1 j
- public class LineRender{
' g& \3 x; V* O8 r/ A$ N k; h - private final PoseStack pose;
8 w6 N( X2 A( j( ?. C, X - private final MultiBufferSource source;: w4 O8 j, J- g, f+ L
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();# d; b" O; J; K0 X6 G- f4 C
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
3 X b- r: ?* ?7 M1 g: k0 z
/ Z/ A+ j \8 X: \4 b( \7 b1 D# r- 8 I/ Z* K1 u6 V3 G) p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( d7 Z& z- A# l, Q5 L6 ~- O1 m
- if(x1 == x2 && y1 == y2 && z1 == z2){
/ L. J! p/ t) P - return;
. u+ Z- `0 D+ m0 W3 p - }
( b7 M5 Z3 y- y4 a - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
7 b) O, _+ ~7 j1 N# b$ ~ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" b) i- X6 [8 b' S( K- u5 s2 u
- }
H. @, S [% p2 K1 b1 } - pose.pushPose();
1 Y4 O$ Q+ c" y - final int newLight = convertLight(6);2 q2 O$ \4 k" j6 T. W; q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 X1 M4 B8 l' B7 s5 a) c - final float lineHeightSmall = (y2 - y1);9 O- Y8 y: m3 X
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ Y" K9 Y& i0 x: g8 i& j' i9 i
- pose.popPose();
* X& |3 _' V/ T* I2 M9 t - }
! E6 T; ^7 S+ \; D, A& U. w0 S5 Y - " K* \; U* Q6 e$ G' X
- private RenderType getLayers(String texture, int light) {: |: B" D2 g U* N- f& i/ U1 ]
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
) r' d: n& E, E6 @ - }
6 i4 ^7 ?% p: a& E6 O/ j; E2 g, d9 R - 3 _" _1 O9 U; r$ |( q% W
- private RenderType getLightTexture(ResourceLocation texture) {* G4 l+ W! d- F( n+ l
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' E' d5 D' y% h7 D - }) k" G$ R: C; r/ |0 ~# W
4 c' |" w$ t0 d- c- L3 G8 H- private RenderType getTexture(ResourceLocation texture) {8 m& o) k3 U, C
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ ]( J9 t F" H2 R! X. S - }4 |/ v, \( F- W
" _: T. Q+ |6 |' u% @3 r H9 R! c- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 w3 N$ \* Q# a( S - if (cache.containsKey(identifier)) {/ S, w3 T4 p8 f ?: @
- return cache.get(identifier);
# M5 R% ~$ Y$ x! | - } else {( t- G3 y! d/ W7 E
- final RenderType renderLayer = supplier.get();! E5 F( q' M) w4 g
- cache.put(identifier, renderLayer);3 J* T) W+ @0 G
- return renderLayer;
: Y# I' p% G! U( D ] - }
% }1 o8 P. [: u7 m6 {3 |$ p - }
8 O. Z4 ^$ h/ I/ Z" S, H - }
复制代码 |
|