|
|
a9 e+ m$ h! V
行,这个怎么样1 X% v- K. _& V% X5 B: u
- package com.xhg78999.mtrfac.render;
2 e* x1 E0 m+ V1 G - 3 _$ j8 o! k+ _
- import com.mojang.blaze3d.vertex.PoseStack;: Q! T0 J! \6 `7 Q' o7 k
- import com.mojang.blaze3d.vertex.VertexConsumer;
$ S( s$ D4 l; b' C - import net.minecraft.client.renderer.RenderType;
9 W5 p/ f2 m0 [9 }) T5 Z! A - import net.minecraft.resources.ResourceLocation;, K" J. g* l5 W. ^& C
- 8 ~3 ^! Y6 R4 C+ t& T9 R
- import java.util.*;
C1 t6 d" U3 T+ r& E - - v) Y# I' S) L8 B
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. Z; h0 y/ A d; p: e y- S* O: T - - ~, ^9 r9 v% _5 m7 E4 q) w
- public class LineRender{
3 X# p. m8 x( l" e1 b - private final PoseStack pose;, S1 x) e! z$ s U& G
- private final MultiBufferSource source;" L7 W L3 _9 S5 T
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 R- N# e6 s% Z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();- ~4 ?9 Z! r3 U
1 T4 L, V; Q* t) H9 k
/ i4 A' x3 i5 v; i- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){+ e: z$ Y% m* e
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 K6 U+ g. z6 ^ }( \ - return;$ S4 { n% s5 t' y
- }3 Q/ o2 A2 G" z3 t& `- J( a
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 b* G" P' ^* D: {& P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. W/ E0 G; Z7 Z4 q( F7 |; x; a
- }7 n4 r/ E6 f1 A6 ]9 e
- pose.pushPose();: j( O( N2 I, t* D$ Y' X
- final int newLight = convertLight(6);
; _3 ]. B5 i, x$ x$ e- O - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));2 {9 I3 {% i3 W! R; ~; w D
- final float lineHeightSmall = (y2 - y1);
% n- I; L* W- c5 t, _& d, o/ R - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 J& l( f9 p' Z9 F. |. U, K
- pose.popPose();
( U5 e+ _! ~4 A( Z6 Z' x - }
3 C) _* ^1 Q! G! r+ N0 I, p1 ~- L
$ S6 q0 s7 l+ y* z0 d- private RenderType getLayers(String texture, int light) {
0 `" G2 m$ w& L/ p - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! E& Y7 N& X' I7 v9 ^( @6 C
- }
: z) E/ B7 H2 L8 A. L - 5 A) {& l5 D' j+ o: q
- private RenderType getLightTexture(ResourceLocation texture) {% e8 r" f' C: O$ c; D
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, q6 V8 p' ]( ^6 k# r
- }/ ], s2 C3 v+ D& ^( W
9 d" u: ~3 g/ U3 ?* G. q0 E- private RenderType getTexture(ResourceLocation texture) {
+ h |; ^' a7 G6 f, {* I - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( Q; c/ x! M* N, g - }
4 t5 x1 N ~- _: M4 ~$ }+ [1 }
0 p2 h& A2 P6 z" D+ L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
( [4 m0 X' [) v: D! P7 o! J - if (cache.containsKey(identifier)) {
9 E- O t- F1 \3 b z - return cache.get(identifier);4 T$ Y* ^8 H2 T
- } else {
Q9 {# L" i0 V, k1 O - final RenderType renderLayer = supplier.get();. @( r/ O+ w7 \+ D- }2 W+ {
- cache.put(identifier, renderLayer);
' x6 X( o! {: o c! U+ a2 Q4 c# X e - return renderLayer;4 e5 z2 c" ?* \& c
- }8 J9 d: g/ F* q/ j+ _/ Q
- }
2 M+ ]: [5 I" B0 I1 u - }
复制代码 |
|