|
|
! i- e8 L+ X) }行,这个怎么样
8 B: }6 W. `- m+ X/ X- package com.xhg78999.mtrfac.render;5 j" |. m7 I8 B! y5 ^
- # D* |( A q6 ~" p
- import com.mojang.blaze3d.vertex.PoseStack;
) V# _4 l% B7 F$ F/ L& K# B - import com.mojang.blaze3d.vertex.VertexConsumer;
+ G# y; k) Y( G) s6 M - import net.minecraft.client.renderer.RenderType;
# C; u) T! z+ y - import net.minecraft.resources.ResourceLocation;* j% z7 j* @- k$ `% P, f
( [1 {' Z9 O) s8 i4 H2 E9 K- import java.util.*;% x' u: O( \( m5 U y( B a) \/ G
- / G& F& n9 }* b
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) h, z; D3 h! u# d( A - ( ^ _3 P- _( f1 a3 \2 t: R
- public class LineRender{: G/ A4 Y' r/ n- |2 O, j. p
- private final PoseStack pose;3 J/ b% W# l# e. q
- private final MultiBufferSource source;
# z% _" u& ^ Z/ @7 h. E8 \8 @ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& f- n: K6 ^3 j3 q2 N# h8 r" ] - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% E9 b Q! p) @, ~0 Z* K: \5 N - ) `% Z3 `9 a% D$ z( g9 Z, p3 P
- + L0 a. V4 O" C+ n7 v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- J# O/ W3 k! b0 t - if(x1 == x2 && y1 == y2 && z1 == z2){! |4 [, E* @$ [- L3 j
- return;
- C* V& b' I/ A+ Y4 G - }' _$ j, [3 J$ Z3 \& S, f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& V7 S* g' [' h. N# |5 N% h+ | - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
# T3 K- |( \$ g. t" b+ A2 R - }
: g% e- ~. ?. M - pose.pushPose();
0 J9 v% ^3 j* v, k7 _ - final int newLight = convertLight(6);) _5 {' _% p9 w4 \$ U4 k8 N
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( T) O9 }* G* H
- final float lineHeightSmall = (y2 - y1);5 z* Q: V( \9 F! d; s* ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; _, K" e0 u2 P9 i# q - pose.popPose();0 L- t/ p2 c p
- }6 j. X& W1 H3 U7 y0 i- z
. u0 V! G( d1 J; ~3 O% n- private RenderType getLayers(String texture, int light) {/ Q" u5 a. N9 |
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
- \( F1 D3 {. J - }3 ]( w9 v! x/ f4 C, Y0 a
- ( o8 R! S6 a1 r4 |
- private RenderType getLightTexture(ResourceLocation texture) {, @. V8 S4 o9 h$ \' B
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) m3 Q0 Q' f, U; e2 l6 L% G2 `5 T - }
7 R' H& T2 B# F( A
* D+ [& u! w$ q9 a4 K/ s# q3 W6 o- private RenderType getTexture(ResourceLocation texture) {
. H& w V* w, r- a. ^) G" d - return this.cache(texture, () -> entityCutout(texture), CACHE_B);# M1 A: x2 b" b4 s2 t
- }
; w8 Y9 w$ Z( G. N* d- m, U
' P$ \5 v& |; }# [: L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
% S6 O$ n/ }! O - if (cache.containsKey(identifier)) {0 ]1 I0 h) i5 R! O
- return cache.get(identifier);! P( r" Y* d6 o$ _. F+ H
- } else {
+ [" B8 ^( f; B; x - final RenderType renderLayer = supplier.get();
) v4 T, g. O( d6 g v - cache.put(identifier, renderLayer);
8 [$ d9 i% P4 l" H* ^% ]3 R1 k - return renderLayer;" d+ I8 A! z* Y6 s% ~. Z
- }
! j+ h; R' q1 H# J8 V" ~ - }$ u4 B9 U8 ?! M( ]3 ~; {: t
- }
复制代码 |
|