|
|
# w! V' u% `4 O行,这个怎么样0 J6 M& q" N8 J
- package com.xhg78999.mtrfac.render;* f$ V) T7 c- s
- : x6 m, t$ F7 |, s5 s
- import com.mojang.blaze3d.vertex.PoseStack;+ L, J+ K9 _& X( N }
- import com.mojang.blaze3d.vertex.VertexConsumer;3 B- H2 l* E7 b2 F7 n; p7 V, W3 [
- import net.minecraft.client.renderer.RenderType;( _( D: `0 c6 _3 h; D
- import net.minecraft.resources.ResourceLocation;6 a" w7 a c- U& C
% h6 T+ i: S- p3 A- import java.util.*;
! g; z# M! ]6 w% F7 r - " w2 L8 {% I$ v, s! m1 E8 u2 o3 t9 U
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% ?, s( d, V% H
- 4 ^! a. M) H9 i4 Q8 Z
- public class LineRender{
6 \$ f' A( L, E. @- i7 ~- R" P# n5 U - private final PoseStack pose;
4 K* r F, ^. q+ K; Y' R - private final MultiBufferSource source; q8 w5 r' C& j& G; L
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();! o9 z: `3 F2 Z- F% Q2 l
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();3 N B) ~+ ~6 D: l
- & b& T4 o9 F9 t9 s7 ]8 w1 _ A9 b
2 \4 `. n3 d) x4 }% v$ ]$ C1 G( a- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 i) r4 m' @# L, n2 H: `; W. X - if(x1 == x2 && y1 == y2 && z1 == z2){3 u9 X6 D+ ~% k I
- return;5 `. m. A/ X" q5 i
- }
, j) X' o! r' J6 {) ?2 M1 B0 [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 S Y0 n. r8 j3 Q5 N x
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& s! ^8 k" @2 Z& ?1 K3 n; U
- }+ e6 v1 A$ b, p3 R0 i
- pose.pushPose();
7 N# v' U8 D1 [4 }- I. m2 f - final int newLight = convertLight(6);
1 Z, d2 N O& D7 {5 C - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 ?0 w. o8 A6 S0 j0 G+ W; i
- final float lineHeightSmall = (y2 - y1);
4 y- @8 m* L2 k4 A8 M# v' C5 ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ V! b& [5 `2 z& O5 B; {
- pose.popPose();
( Q/ k, s% D! s* m/ i - }( a& `3 a7 t4 B% m3 f: X+ S5 n) o: R
4 _% [; R% F+ G) q4 L- private RenderType getLayers(String texture, int light) {0 i- T9 o1 c, X: }7 P
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
; s0 |: ], \, E, I; S - }
4 E4 l5 h3 f) K) Z4 g: c" s - 1 u$ }* [# C: O3 r1 ^% M' @1 Q ~
- private RenderType getLightTexture(ResourceLocation texture) {
4 }, U+ i) l0 ?! ?+ W. ~ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 V9 E6 i2 w+ ?! }; ]8 v n2 b0 }
- }
% ^# t' q; N2 f- T, P T) h! g
1 U( J. X7 G1 c( h& x- private RenderType getTexture(ResourceLocation texture) {
- I( G1 T, _. i - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! ]( a$ U) z" A# B" R) U - }
4 b# ?3 K( k. o( E: b - " }4 ~. z' R0 _ D7 O" `
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 K8 m; m$ J. R8 E0 |* T l - if (cache.containsKey(identifier)) {- J8 K$ A8 D( T3 \/ r7 N7 B7 F: U H% W
- return cache.get(identifier);
- R4 s1 I ^. _& P3 H9 l4 h/ K! N - } else {
( J6 }* ~5 h) P% w' B - final RenderType renderLayer = supplier.get();' o6 i; k% O) I
- cache.put(identifier, renderLayer);
: `. ~* i$ b" H6 `+ F- F: T - return renderLayer;: F3 [, K# V7 F/ ?& l9 c% \- D8 r, Q
- }
3 p1 r2 K0 x- P5 M/ Y( `1 { - } @% A2 P% c9 U! p. Q
- }
复制代码 |
|