|
|
2 p6 G, o$ g8 {6 F ^
行,这个怎么样+ U! V/ W, Z6 h* |6 q* h" o+ z% I
- package com.xhg78999.mtrfac.render;' I' f# j# k0 b6 E c6 S
2 c$ G' O& l4 s+ E; y3 V' J- import com.mojang.blaze3d.vertex.PoseStack;/ R. K2 n5 T6 J7 [ F$ O. `
- import com.mojang.blaze3d.vertex.VertexConsumer;2 X, `+ d# [! `+ v7 d1 @+ o
- import net.minecraft.client.renderer.RenderType;* m$ X& g, O9 y, P# w
- import net.minecraft.resources.ResourceLocation;
: C4 P) K8 z+ p8 Q# n& @4 a' I# q' j
0 w: Q* v/ a8 i% k- import java.util.*;8 r* T% g" ^8 g6 Y
/ [) D9 X& N; S& t: i+ Z2 V- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 P' P9 j2 @$ p9 u" g. E y% v
+ w; K* c! a' B7 _- public class LineRender{
: {1 H+ ^+ s! T - private final PoseStack pose;
5 w. D2 z! v: _" ` - private final MultiBufferSource source;! F& Y. F% T8 s. _+ M6 D4 {
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 V+ g: K! I) f2 w6 |0 B - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 }+ i: a& Y) [; |7 g. A0 I
- ) n7 s1 B& ]. X
- 6 |9 ]& U9 S3 J# l' K/ z" }
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 @3 s4 X' Z9 l' c - if(x1 == x2 && y1 == y2 && z1 == z2){6 q: J$ k$ \) I" a' U8 C
- return;! y* K1 v' F" z
- }7 P7 R5 x2 ?9 e; l, {& E6 J9 K8 E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* m6 K) f* X1 x' I. x
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
' V1 g: O* |; N' D* w$ L - }0 U- L% F* B& Y7 c
- pose.pushPose();
9 k: X4 b7 [" b+ p' K. V - final int newLight = convertLight(6);- T _1 c; ^" E" d2 I8 R
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- _: a( o. L8 P1 K - final float lineHeightSmall = (y2 - y1);' `3 V) n% T/ J6 \! Y6 s
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( C+ h5 u" r) K - pose.popPose();4 v; Z" w9 u _4 D9 S2 I
- }
* x& ?) r8 a4 m9 ~- K* G9 u @
6 W) ~- f- |; ~: M- private RenderType getLayers(String texture, int light) {
. S, Z. f7 a8 L* D. V. w9 W - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ z* V r2 U) l
- }/ T! b; w: K# w+ W
- q; E; `% s2 x ]6 z% E" w ^- private RenderType getLightTexture(ResourceLocation texture) {# i! q+ Y. W# k# r0 x
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! q; _, r! l4 Y# g- P; ]) ?
- }
: r$ j% s0 f6 }9 L; D
0 I5 |* I7 U4 b1 i% T- M3 Q1 R0 ?- private RenderType getTexture(ResourceLocation texture) {6 P4 S# s( T- o! k' e& c, I
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 @3 P5 w$ c+ }* W3 R1 Z
- }
2 ~0 Z/ m( C" Q; f; f5 Z4 Y - ; i& U$ k0 y f0 A# I: g" J) h1 x
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ m8 s! h6 o: {+ N6 A
- if (cache.containsKey(identifier)) {9 z7 k& m% O: d" D
- return cache.get(identifier);
" O( _8 O. N4 W* W4 I: i - } else {
1 U; {* {. K& B1 X. P0 l - final RenderType renderLayer = supplier.get();; L! R' l) r1 w0 [ S" ~
- cache.put(identifier, renderLayer);+ @; M2 P- C' k5 b3 j
- return renderLayer;! r9 W4 ~2 i8 |2 m
- }
; w: P1 _1 }5 f; y3 V - }
9 j; E; z+ {4 }- H - }
复制代码 |
|