|
|
1 r5 Z: H% v0 }$ e9 X! ~
行,这个怎么样( `/ j: N/ Y" N7 U! o
- package com.xhg78999.mtrfac.render;
) _6 Z. M2 B' i9 @+ t: } - 0 I5 q% q; n* I. T+ [
- import com.mojang.blaze3d.vertex.PoseStack;
+ {: F8 b% Q& Z$ S: E- X - import com.mojang.blaze3d.vertex.VertexConsumer;
% x8 n: |2 ^1 d9 |' p2 t6 r. s - import net.minecraft.client.renderer.RenderType;% t7 v& W0 M& V+ N/ m: X
- import net.minecraft.resources.ResourceLocation;
$ Q+ M* u6 a. J6 n E0 z
4 }3 v4 C; P" q) c' M8 k0 k- import java.util.*;
) B0 e4 T1 C! J& S, ]/ g - / [3 b8 R8 h" E
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% N/ u B2 q* J
; L( Q! l0 i' j. F/ {9 P- public class LineRender{) _% Q( U1 o, B; G' r, {
- private final PoseStack pose;& {" ]# s( | M
- private final MultiBufferSource source;# H! ]* S: `4 f6 I3 [
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();2 l, H, n4 E' k4 `, U; E& Y% b
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();+ T0 P0 N5 W$ [6 U/ z7 H+ b8 C; B+ _8 Z' I
8 J. Y1 ~6 i& h5 Q" m
+ Z- g( D1 g. a( N L- K' A- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! Y9 k" a! J9 V! s6 ?
- if(x1 == x2 && y1 == y2 && z1 == z2){. L7 d6 n, F1 R
- return;
4 F% S. V1 Z$ O7 x4 H; l! u - }
7 m$ J6 T4 I6 x" `. L8 H - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 z( e; m E& e3 K$ B, `) z( j
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* z/ i6 v, H/ d1 k# F - }8 g5 `% U7 |: g w+ S, b0 y- H
- pose.pushPose();
& ~' T' L3 k; g$ e; |9 x - final int newLight = convertLight(6);
, h" s/ X8 c, O0 ~/ @" j4 X5 f - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, l, Y7 H$ O1 o( j3 } - final float lineHeightSmall = (y2 - y1);* i: L: d! B: T5 Q; i
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
0 M9 F5 h5 B( Z" z - pose.popPose();! C: m* Z4 q' U6 F! s
- }
' u' ^: n" T: n7 \; s, o% l - 6 a6 n# A9 C% D, r
- private RenderType getLayers(String texture, int light) {3 H2 s! g' U0 R3 B; W9 W
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 ]2 E8 e) U; }, U% m5 Y, G7 F
- }
) i" l- I. q- G) {1 n1 b
( s0 X4 Q/ N3 L! K- V- private RenderType getLightTexture(ResourceLocation texture) {9 |- B+ F+ @6 n% I
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 g5 r" j! Y9 v v$ `- c6 A - }
* C$ W7 @7 @* \! `- @7 C" e% a - / W$ ?# T+ r e. i. `! {+ K- P
- private RenderType getTexture(ResourceLocation texture) {9 o7 D6 |& R$ m
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
) \9 Z$ `9 C- x. z9 j- [* S - }
5 _* e! F1 A' c: J* c5 ]! q4 j D - ! Q0 j8 K! a# p6 e1 `9 k8 r) x' }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( X9 q5 h2 |% {) G4 v
- if (cache.containsKey(identifier)) {
- @& A( |4 ^- b - return cache.get(identifier);
( x/ G# S! K5 u7 ]5 _. z - } else {* A) n5 o( k' X6 B4 ?$ r3 H
- final RenderType renderLayer = supplier.get();/ ?0 ?' Y; m! F) D$ E! T4 Z1 T
- cache.put(identifier, renderLayer);
+ P9 e1 {0 Z3 T3 W4 l/ `- } - return renderLayer;4 ~4 o2 D: ~; V5 @7 @+ P
- }# o. t! j& }( b$ d% N& M3 q- \; U
- }
( J6 F1 q/ Z. F& o - }
复制代码 |
|