|
|
6 ?" ~ W; R1 l行,这个怎么样
& t- B" ~! l& u: n- package com.xhg78999.mtrfac.render;4 b6 q7 F4 v* M, f6 \$ I5 G
" v3 E$ a- T% b" t5 j- import com.mojang.blaze3d.vertex.PoseStack;5 U6 R: J7 e7 E# v
- import com.mojang.blaze3d.vertex.VertexConsumer;
& y5 n6 m) j; @& [4 a, ]2 E - import net.minecraft.client.renderer.RenderType;2 _3 M( V; R5 z- X, c# Y
- import net.minecraft.resources.ResourceLocation;. K& l# S6 Z+ v+ T$ n
' T6 p' E3 y8 H2 C" w- import java.util.*;% J+ F# N$ U5 V
- ( e/ ]1 m# k6 C) g- I
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. z7 r' W# v- [* R. U! g% A
& O q' Z: B5 x- public class LineRender{
$ O% @- r- O! M$ f. m - private final PoseStack pose;
+ N2 m! P9 a* g1 Y. U - private final MultiBufferSource source;4 ~0 y" e3 q1 z6 X/ o/ a* C
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 T: J' B+ z9 s# O. o; K3 T
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 F) _$ h- W6 [! T/ w8 U
8 U" b' a4 N& Z, l* W- Q/ _: T* m- " e& W0 y+ q- S$ I* Q# ], e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& d8 e- B- L$ d* e' g% @ - if(x1 == x2 && y1 == y2 && z1 == z2){
4 M0 b V. K6 O - return;
& b* d H& h$ @8 Y - }
, o, W* `0 B- t - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 ]5 d" G6 g1 C: j+ k5 y& `* G6 o4 P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ Z; c1 V* K1 U* U; X - }5 V/ c5 j0 L: D% M: b& \
- pose.pushPose();
. U- ^) N) h' F) \' S g - final int newLight = convertLight(6);
" k# \) ~: T m: W - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 F+ P/ @1 R& _
- final float lineHeightSmall = (y2 - y1);5 G) z( p8 I) h2 D9 c* G. Z1 V
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: m: L: R: ]* T1 g2 v - pose.popPose();
: ^! C1 f4 ]2 ? - }
; D$ r: S3 o7 \ - 4 v. L: e7 o8 M# W3 K4 W% x
- private RenderType getLayers(String texture, int light) {
$ `- }, X: W( y0 ` - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 q" h, h* K$ Z
- }
- O+ H _. }: M- |& E# { - ! [- \* y4 ]- U- U% E
- private RenderType getLightTexture(ResourceLocation texture) {
( n* P9 W: a8 T - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) L' `6 V" E" W5 W* o
- }
9 ] y7 i* n5 P - 3 L" _5 T# G b& \5 S6 m
- private RenderType getTexture(ResourceLocation texture) {' ?: K O( j6 j8 d/ j+ x, V
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 s- j9 c( ?! X: `, k - }
+ v2 M5 C/ r) ~0 k+ W% X
; g- I: b& B% g0 i- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: D' p1 o" k2 U7 C. }, r1 Q% Q. \7 W5 }7 g - if (cache.containsKey(identifier)) {/ ?6 @, K2 W0 y+ }- Q1 e7 x
- return cache.get(identifier);7 ~; c. P$ Z5 E' r
- } else {
$ w* |. S; f* C - final RenderType renderLayer = supplier.get();
: j% O. E3 t0 }+ {6 R E, x8 u - cache.put(identifier, renderLayer);
+ N9 V& D: l# \1 G" A - return renderLayer;
, M. ?; v+ K3 x. a - }" P+ ?) n" ^+ n8 Z+ _5 d
- }
" l0 n" m% E0 ^0 x' N# e. I7 d - }
复制代码 |
|