|
|
4 F( I- [ R. j行,这个怎么样2 h; ^( c$ X9 ~' X
- package com.xhg78999.mtrfac.render;
: J% _! `$ M. {5 i0 U; ]7 t( C$ \ - # W6 L1 i$ ^5 t- W% M& n* ]/ h
- import com.mojang.blaze3d.vertex.PoseStack;
/ A& e& E) Q9 @4 ~ ?) z7 ~; E - import com.mojang.blaze3d.vertex.VertexConsumer;6 u' P4 |% M/ J6 F
- import net.minecraft.client.renderer.RenderType;4 a1 ~9 v$ `2 P' U; ?- n: T2 D% g
- import net.minecraft.resources.ResourceLocation;8 [2 }$ L2 s: j
- - q! p7 E: p4 w' y
- import java.util.*;7 u c. m& g- i& R" H& f/ Y9 B7 v
- 2 w( N2 d& Y7 @2 J# V/ ?% Q
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* E% r l, O. ], ~! B) r& I; y# \ s; W
9 V6 w( e: D) ~# ~2 ^- y9 I2 ?- public class LineRender{6 P& r0 {; |' P
- private final PoseStack pose;
$ K0 a1 U/ `7 @+ B2 a( o5 T3 w - private final MultiBufferSource source;
0 r+ v, F0 O$ R - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' T$ B% ^, d! G0 @ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- a L4 S7 v5 |! Y! _+ L - 8 e4 Z/ M, A. l8 ^ @
, m6 Q1 B4 D T7 }8 a" I5 r$ x; [* O- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& U/ r+ |3 R7 ~+ M( Z7 P - if(x1 == x2 && y1 == y2 && z1 == z2){ H0 _ Y6 V# k: F+ n( L
- return;5 G- X9 k1 @/ f
- }. O: e' B2 P6 J5 a# n
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 t2 H; _0 C) n$ O7 i4 t
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");/ ], i/ o v R0 J0 h* b
- }' V6 g( N, s( P, ~- @
- pose.pushPose();
! Y. [# `1 X, ?5 x, x - final int newLight = convertLight(6);/ D: m( @* t/ f7 Z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( K+ Q6 g9 ?% r: r4 v3 I9 h - final float lineHeightSmall = (y2 - y1);- o! w H9 F3 U" x; q5 m# g
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- O- f2 X9 q/ w" P: L9 Q# G: w6 X
- pose.popPose();8 `+ K" q8 k W
- }& y, D6 O. u$ Q; [
7 v$ ?2 ~) E# C- private RenderType getLayers(String texture, int light) {
, B. h, ~# U l/ Q - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));7 ^+ P7 x/ O0 b8 Z& n. O
- }
( c1 @/ O/ l4 u1 B; t- L2 W5 J
$ s/ L; m4 p1 L! Q( Q& B- private RenderType getLightTexture(ResourceLocation texture) {
+ t: t; q) f& E* V* x d - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 h C5 j3 ~4 J/ h) G - }
5 s, q, l+ Z1 d$ E) Y. W; C
& G6 c! H! V& Z! j0 { _( p g& _- private RenderType getTexture(ResourceLocation texture) {
7 U3 O1 M' u. `6 P% c+ E6 C - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- ^- f' |# k" L8 T - }1 Y4 W* @" g" r
- J: Q, r9 J7 X6 k3 F5 Q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* v/ ^+ w9 v; x. q% R6 `8 Z) R
- if (cache.containsKey(identifier)) {
) q" {3 |- H+ k/ R0 o- n, }& E- ~ - return cache.get(identifier);( s7 R& x' T! L* C2 r
- } else {
6 r* B# |7 z& n/ v( e - final RenderType renderLayer = supplier.get();! Q3 ?5 w3 w" g! [
- cache.put(identifier, renderLayer);
/ H# }) x6 e a! ?* v( X5 w - return renderLayer;/ C! Q; o5 m! t
- } u9 C$ `8 \% W$ x$ N, F! { _
- }' Q$ j$ K1 u; X; o# w+ \2 c
- }
复制代码 |
|