|
|
: o1 Y9 o0 O( C2 q w6 J行,这个怎么样) {# u8 g; f. S( C1 Z- m: Y
- package com.xhg78999.mtrfac.render;0 b! k( E5 v9 v
- - u2 G% Q+ G& C' D b
- import com.mojang.blaze3d.vertex.PoseStack;4 x0 b. Q; ^ \( m& b" s) q
- import com.mojang.blaze3d.vertex.VertexConsumer;; _# W% P2 n6 @ {
- import net.minecraft.client.renderer.RenderType;
2 ~! a c- @- F9 m4 X9 H - import net.minecraft.resources.ResourceLocation;
; s$ W) ^4 b; u" |" \$ H b' F - ) G" x2 x1 a5 j
- import java.util.*;- A* U) u# W/ Y1 R/ @* c$ g) q$ y$ }
# e1 C6 E; O& w$ d! u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ q" ?2 ]* d9 L* I! v# W0 A( E
4 p; C' K. q9 d( e3 G6 N' N3 s- public class LineRender{
3 [/ o/ W4 b: E& [/ l2 W' `3 u5 P - private final PoseStack pose;
; R# |" S6 ~! ^. T) P - private final MultiBufferSource source;
. e3 R2 s# q0 W: G9 O$ x" O - private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 Z: j& g% c( ~% X) ~5 n
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
4 |' D+ }' h/ z7 l9 \1 }5 D$ g - 4 B y ]# b& J
* J5 y( U( i4 A/ D7 P" S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 [* h+ ?+ _+ Q" U! w - if(x1 == x2 && y1 == y2 && z1 == z2){6 ~+ I0 M6 y9 w% A/ K: ^+ x* _
- return;* {) W( E! y# Z H) i8 A, E
- }$ I- r4 X* ~, D, L: l
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 ?4 O- h5 A* ]$ m; R! s' R
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% I, j' D4 S( u, ^8 v; M - }
6 b2 _- J* x9 V - pose.pushPose();
4 b3 j( k2 {, N) a9 @9 b, b1 S7 B - final int newLight = convertLight(6);, w! _( W+ [* l4 {- y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% q# F6 [% ]$ C) V" Z6 F/ j
- final float lineHeightSmall = (y2 - y1);
. H+ u9 t k( G5 m [" b7 G - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);3 V+ H9 P& ~% P0 {8 i
- pose.popPose();
! O5 ]4 K$ C/ f0 X) |1 a - }- m) z1 C: x) Y: ~. e
- ) e+ S- T6 l. h$ ^. a- p. W
- private RenderType getLayers(String texture, int light) {. ^% l" m1 ~8 c5 k& |
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
E" M( d3 { S, q m - }: J# _$ f9 B6 d7 Y+ j# k
0 c: s. k" w5 r- Y9 U- private RenderType getLightTexture(ResourceLocation texture) {
5 L& }: g& D [3 S0 S - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 y" I9 q! X( a/ u - }
' V1 U: M) G/ {2 m
9 G9 Z6 r( N9 d% O) e2 O- private RenderType getTexture(ResourceLocation texture) {
& |+ c+ y$ G- q6 g- z7 m - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 A. Q# _' F7 f2 J3 R - }
3 K. V) Z+ t& o4 |1 o2 \, b. r m
. i5 |, ~1 ~$ `- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 M2 c& A0 p) K% O4 m3 s* O" `0 _
- if (cache.containsKey(identifier)) {9 H1 }* S/ [' J* k6 w3 L5 A
- return cache.get(identifier);/ B. j+ \( E. Y* R
- } else {
( ` [! y8 b5 m6 Y - final RenderType renderLayer = supplier.get();
) q' |: U2 a- M+ }- ] - cache.put(identifier, renderLayer);$ `5 s2 S$ e& X, ~5 U1 T
- return renderLayer;% ~* c* b- @2 T" ?" |3 t
- } l& B/ y9 c' d$ j7 q. \
- }8 |& L- a% R9 p! w+ [8 R
- }
复制代码 |
|