|
|
; [2 ?" U: N+ O$ \8 i3 F# _
行,这个怎么样* L7 H/ S. d/ r% L Z
- package com.xhg78999.mtrfac.render;
$ S; z+ U# u8 A- t) \" j3 j4 s - # ^* x' G+ a! B6 e6 u
- import com.mojang.blaze3d.vertex.PoseStack;" e7 u* E" ]3 G! k* c
- import com.mojang.blaze3d.vertex.VertexConsumer;/ C( H, i: w0 S: c
- import net.minecraft.client.renderer.RenderType;; W% L/ ]& u. t
- import net.minecraft.resources.ResourceLocation;. e3 A3 M+ G! K( v; C- ?+ p3 Q
3 r3 y y4 |% q# z- m0 o; M+ W! Z- import java.util.*;
+ ]" {: l1 C! f7 h, J, ?0 z3 d - % S: ^* d4 J9 x* D# \! N
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 M1 z+ s% k% J6 S9 t1 {. S1 j
- I8 ]1 l$ [* }+ k2 _# @- public class LineRender{2 Q: x) c/ b1 h- e
- private final PoseStack pose;+ h7 b) O+ k; B! k$ Y* [6 ~
- private final MultiBufferSource source;
4 T4 d- o8 d/ w" e5 {( s! m - private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 a0 q) t: `# C% u1 J- T# C. Z
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 d$ q3 W& H- i1 o5 [
, \ E2 Z# x- a" X. C
' b$ A+ ], U! Z1 Y$ j4 r# E- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 `7 H$ q! o, _0 {: N - if(x1 == x2 && y1 == y2 && z1 == z2){
0 w, @5 I _0 x+ p/ q - return;
, Z) g$ H. t; {3 s - }
" h9 y) _8 k6 j5 a, e2 K$ P) b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 R' v& d6 D; S - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ W9 c' S3 U5 _* @/ i8 Z - }
: u* f+ V: `9 V3 m3 Y - pose.pushPose();8 q+ C" U6 d& L: e4 P
- final int newLight = convertLight(6);- p; U. ~+ _' C. u" b4 r/ f4 ]
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
8 n; a: v! p1 Q; F. M7 P, v* R - final float lineHeightSmall = (y2 - y1);
- Z4 ? i0 U0 r# `; C - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* e% ^+ `8 X7 K$ r ?
- pose.popPose();9 b9 n; `" [8 m& E
- }
& E* m7 D. w- I. J# y - 5 b& I% P8 b& ?3 Q! I; ?4 F6 m" _
- private RenderType getLayers(String texture, int light) {
. \8 q- r% B2 C* m' _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));& T. J6 E: r; ~& m, F% x
- }
+ U& a+ t. p# L
; g5 g$ \! Y8 F& d' Q3 \- private RenderType getLightTexture(ResourceLocation texture) {( F% I1 R T% ]. X1 g, Y% i6 ^
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' T( [6 j+ R/ n" ~
- }
9 F& L4 t n( |: H8 f/ }
0 r% w8 d; R9 u3 Y# H- }- private RenderType getTexture(ResourceLocation texture) {
1 O7 A8 w3 X0 `/ c/ i0 } V; ` - return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 M$ y! x0 v w9 U! c) P3 f4 Q8 T
- }( l% c7 v: J/ |0 o8 v1 s3 `
- ; k$ g; F# Y% \/ q8 j1 T
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, m2 I" A6 F2 b! I$ L5 p - if (cache.containsKey(identifier)) {
. F; l' L: [, i$ ^ x! N% @ - return cache.get(identifier);" h* f& ~' L4 N( y3 D& F/ C/ O3 _
- } else {( Q5 x/ B8 _) }2 z1 b
- final RenderType renderLayer = supplier.get();7 L$ }" x- h" v
- cache.put(identifier, renderLayer);# z F* W1 Q' W2 u6 P. J9 o
- return renderLayer;
6 ?& M4 b- B: T4 A9 U6 s1 e$ T' H - }) V3 V' q* X1 G( y- X, o2 v( @: Y
- }
# H! U# s' M0 ~5 s. {5 ^ - }
复制代码 |
|