|
|
- w! n* q' y- J+ k& G% _行,这个怎么样- H8 A, ]# q7 p: V
- package com.xhg78999.mtrfac.render;- a9 _4 G z, A, Y/ ]
' z# ~8 r; l3 y+ Y1 @- import com.mojang.blaze3d.vertex.PoseStack;
+ Y$ O9 L" \& a; `7 ? - import com.mojang.blaze3d.vertex.VertexConsumer;* u# {( H7 y G! u2 X3 }+ n, P
- import net.minecraft.client.renderer.RenderType;1 y9 T! G6 q, O4 f5 W F) r
- import net.minecraft.resources.ResourceLocation;9 K* b* ^& U& z! E
- 6 \8 |, Z( E0 M; @
- import java.util.*;1 A2 E$ D$ s/ J
: ^' w: m9 U9 P- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(9 f+ @2 r9 U1 J/ f2 Q
1 @5 |9 D- `' j% i- public class LineRender{( [* R" s5 @3 E9 s- l" f5 J' U6 [
- private final PoseStack pose;
0 @: r8 W4 Q- S# f7 O* A - private final MultiBufferSource source;
9 k! S2 U( p6 ^8 _ v; ?% r - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: B& y1 O0 ]* ~4 W9 | - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();8 X1 |3 \9 i0 I1 }5 d+ z
- 3 g% `8 q9 g/ s; g3 C+ X+ n
6 O5 n! K1 H: c8 q4 ~3 Y0 z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 l3 T1 Q0 P$ Q: n& A6 E8 x
- if(x1 == x2 && y1 == y2 && z1 == z2){7 J- s. N2 l7 F! E$ J$ t; R3 e
- return;, j0 a* f. l+ ~, r
- }: b( q1 q* i( n
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. I. E2 p" ~. J6 E/ s4 [2 Q$ B - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: x S" g4 |' ~' M( |0 f - }) k" h: |% @. I% ]* Y% o0 r
- pose.pushPose();
% [6 j5 K' S; s0 c3 z - final int newLight = convertLight(6);5 C N) b7 Y% A* t8 j
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 @% x' i+ U W" d) k3 y$ Y
- final float lineHeightSmall = (y2 - y1);) S: \* C# ?% [ X1 ~0 ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- n9 @- m% ?6 P! _" v" U) _ - pose.popPose();
' }- n1 V2 w/ D - }
( g2 ~7 m" I" J* q+ f - ; o6 j2 V4 @1 R0 L: X0 G& q' m
- private RenderType getLayers(String texture, int light) {
# |: m* b: f% j9 d) O - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( v4 H7 n: D# z( w4 M) x/ u - }
; @ t: c8 ~ ]: T2 Z0 O
+ R6 ?6 k# l5 ]3 M% Z! e- private RenderType getLightTexture(ResourceLocation texture) {# t# h( m ?$ Y5 C' V5 Z4 B7 r9 \
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) a6 `& @7 w6 K/ l8 Q - }2 b+ U1 n& ~- h+ R: K1 i
" T, l; u C' A0 B- private RenderType getTexture(ResourceLocation texture) {7 P- K0 M5 r" z X7 {: R
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);- c6 Y- I: M6 N4 \
- }5 D9 Y5 v5 J2 B, n R! D
- ! ]! g0 v& E Y2 B5 v3 i. h
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
9 b4 M! j2 @" j - if (cache.containsKey(identifier)) {
- I* q* I5 a7 T8 n4 r' D/ q) Q8 \ - return cache.get(identifier);, o8 o7 C6 L6 E: h! x/ d$ I% @
- } else {
5 X _" y, \& D- n+ T) _ - final RenderType renderLayer = supplier.get();$ B( {" F, t% A. n8 [- i
- cache.put(identifier, renderLayer);
( g! r4 h9 a; ?9 v8 ~3 o1 M - return renderLayer;5 x5 b$ a0 N6 U+ s
- }, R6 G' [+ N' G% ~
- }( m `! t- K3 O. q
- }
复制代码 |
|