|
|
) m. _+ p) e) T% x# f
行,这个怎么样. b2 i! |0 y: c! p& y6 I
- package com.xhg78999.mtrfac.render;2 c& n8 o/ W2 T6 O: [: F
6 _# n$ _/ a9 W1 m& r1 H* w% i, z- import com.mojang.blaze3d.vertex.PoseStack;
L; J* r, f. _/ u/ r - import com.mojang.blaze3d.vertex.VertexConsumer;' l: L. O9 D6 e& o# p$ |
- import net.minecraft.client.renderer.RenderType;
+ I# s5 P3 |6 q- x# q8 Z - import net.minecraft.resources.ResourceLocation;
: f8 I4 ]: E" y0 F - 2 x! f; L; ^3 l8 C7 n" e1 K
- import java.util.*;0 Q5 V4 ?( \8 o6 c
- : W8 I; P' z* t0 i
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 u* k9 Q7 X3 r3 J* U0 X - ' N+ z. w; [; Z
- public class LineRender{$ z/ ?& S# S" r2 a+ J. c3 I
- private final PoseStack pose;; E( X, v2 U, @& C8 ^/ I; \# J
- private final MultiBufferSource source;% n+ S0 A- C- ~; `' l; m: z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 S$ x( M& k& P9 D
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& t1 h4 F+ N; z4 k - ) `1 r4 ^# ?4 a$ t1 b
2 a1 b& L0 z; L# _6 f- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 e& I1 {; l ]' ~3 P4 O
- if(x1 == x2 && y1 == y2 && z1 == z2){" W/ O) v' V @& o r
- return;/ i3 g% V' @( Z2 m5 }: P: I
- }5 D& o9 ~ X; k
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ g. ]2 v+ [. A2 ]4 _
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
+ k# t; r, V5 O- X% | - }
1 L; O9 y, }5 g/ E9 U) l* t - pose.pushPose();
1 H; ?9 e6 o _6 r, c- x7 _. I - final int newLight = convertLight(6);
( x/ Z. z$ e' X" o } - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 |8 u; N; Q/ t3 z - final float lineHeightSmall = (y2 - y1);
2 l) R5 E" {! | - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);' }) @3 }, a. \1 k1 U
- pose.popPose();( r6 C7 L3 s8 D9 Q4 ^, I# X
- }
: e" }( O& ` n; ~' S* X - ) A- f! A/ m( x/ o6 n7 d, d- }( E4 H
- private RenderType getLayers(String texture, int light) {
* G- c5 }2 a, F8 x, B% j- L+ c - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# R2 r) T, {( e+ z0 v - }5 D0 c# E+ v& H1 ~1 Z# `/ ]
* C$ F% k" \! U- private RenderType getLightTexture(ResourceLocation texture) {
3 J$ o2 U0 Y, U. E/ O - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 w) [$ {0 E* i+ ]* |5 q
- }6 l H# V$ Z& a3 n3 J* R
- 5 ]7 a% }2 H* L+ V3 B8 }
- private RenderType getTexture(ResourceLocation texture) {1 o, J3 G9 s% o+ T% ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" I8 C3 c- I6 d9 d* ` - }
6 k' e! j7 k" Z* r
+ Z: z. p* I( z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {2 [0 r) ?& ]! M; K; `6 x
- if (cache.containsKey(identifier)) {4 I, ?+ I+ \1 p/ P
- return cache.get(identifier);" ] ^9 M% Q# a. [ Z/ K
- } else {/ |2 q+ J0 ^/ D' l! S! x, j
- final RenderType renderLayer = supplier.get();
7 L, @/ U c, ~: L N - cache.put(identifier, renderLayer);) Y- @- D k! \
- return renderLayer;
$ b/ ^% |5 D; w$ }- J - }4 x7 \8 r* [9 z7 ?( j8 ^0 S
- }' {7 d3 K% n2 m* O
- }
复制代码 |
|