|
|
# ~& D4 V" C4 b0 i' h% H& x7 I
行,这个怎么样" S- B# _7 k3 W! h5 |7 N; [
- package com.xhg78999.mtrfac.render;7 k* n. F+ T# w2 e- `
- ' }1 g% ^6 t* w! z0 h; c
- import com.mojang.blaze3d.vertex.PoseStack;1 k" I5 k4 ?5 h4 H
- import com.mojang.blaze3d.vertex.VertexConsumer;
B4 A9 T0 K" |9 v - import net.minecraft.client.renderer.RenderType;
& H( M$ C6 C4 Q4 r7 a* \% h" C - import net.minecraft.resources.ResourceLocation; s& t1 y) M; ^& `) Z+ H
0 V& v H9 X/ I4 H) _: K6 {3 q- import java.util.*;
7 e6 Y! \# d) R+ ]1 ^) Q+ a8 Z
$ n P p* C# o4 ]( C- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% K. C6 G0 m8 A, I1 ~8 G7 w( V
1 T7 z7 ]- n1 T3 X- public class LineRender{
* b; n2 t# x: t# F+ |+ O/ d/ R - private final PoseStack pose;
( K% j* R6 u! k _ - private final MultiBufferSource source;2 W( L6 a; K6 v$ q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ A# K9 o7 q7 U7 h) B - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
# T" l V- F& ] - ; x' c- F: c& _$ g
" W$ `. F9 F5 F- P9 s' ~2 m: K% i- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){# y. s' Y, ?7 O6 b1 o1 y& t7 o
- if(x1 == x2 && y1 == y2 && z1 == z2){+ y) ]& y( x) u: e2 U# w# N
- return;
0 T. t5 E; |5 S6 w - }
4 H% h; u( d3 v4 ^# M7 ` - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' b- v! L R* ?+ P9 ~/ w8 J
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) @+ |4 J5 ^6 @ g/ ~6 M9 o6 w
- }
" ^" \3 X2 h6 `9 M" A7 D - pose.pushPose();
% }3 I r: H* @, I9 A - final int newLight = convertLight(6);
6 j8 j. X, X8 e3 O - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- A5 g9 s0 W9 C" L; Y/ ? - final float lineHeightSmall = (y2 - y1);
, E* Z! V3 F8 g1 [4 w* Q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
% R v, {* }% z K; N0 z - pose.popPose();
( o# P4 [3 R3 t' E0 n5 n - }
6 e0 X3 n, \! s& l1 ?3 s - " k' i# Q# s7 B6 X0 @
- private RenderType getLayers(String texture, int light) {
" [9 c7 R! J. l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
) `% o" ?8 u: e: M7 Z - }
5 G0 p9 r) `! c4 g# A - - j, w5 z# b2 l
- private RenderType getLightTexture(ResourceLocation texture) {! a% c: p& ]% [
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 u/ q6 j- `* l5 r
- }
* b! @; z8 u- T. Q; A - ; S _/ C4 E" A. u' G
- private RenderType getTexture(ResourceLocation texture) {
' l1 _0 d" u) @- @1 @ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' e5 I) E/ C/ B2 d# w- r - }
6 f, K8 p* `7 R/ g* k
' Z7 @1 K# J4 ^& l P. Z g- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 [% P" Q, j! N4 V* i
- if (cache.containsKey(identifier)) {$ @9 ~: V# V/ F+ L) Q. {
- return cache.get(identifier);# o" n: A) S+ z4 n: Q
- } else {
' C0 V* h! P7 L1 y; G0 f/ t/ w0 ], m - final RenderType renderLayer = supplier.get();/ N6 m" i- y' T. h G' f( s7 R
- cache.put(identifier, renderLayer);, i9 A& F( M+ a1 h# C+ F' [( I
- return renderLayer;
" G9 Z# A& v9 I - }' j/ [) @" g0 l' I1 F; h
- }: y4 o! M* S& d
- }
复制代码 |
|