|
|
( M, y; E# A. g' |( Q行,这个怎么样
# m1 l. y' u9 a! Z% F- W- package com.xhg78999.mtrfac.render;
8 K( p: u c+ l/ @ - 4 [1 W7 k5 r) |% I+ u E
- import com.mojang.blaze3d.vertex.PoseStack;4 r: P) M+ `0 _2 f
- import com.mojang.blaze3d.vertex.VertexConsumer;
; P+ t& y5 ^- @( M+ o# S8 Q8 f/ w - import net.minecraft.client.renderer.RenderType;
& f6 U* J$ Q+ d; ]$ m: X - import net.minecraft.resources.ResourceLocation;. r+ `- k( U/ M3 d- C, J0 l3 V: o
- 4 [* c* R$ \$ ~* t s; J, f( }
- import java.util.*;
% ^" a2 Y7 e9 G2 ]$ J
/ ]- P7 O5 i( `! }, I5 L- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(6 A% [% ? U: R# Z, ] C* z9 N
- ^! t: _( u3 Z$ M( S) ?- public class LineRender{
9 B3 }) a- r6 b# v& K - private final PoseStack pose;
5 Z- n. S3 w% \# q1 u - private final MultiBufferSource source;- n8 ^# w3 R. k( B/ I2 N+ r
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ k E; K, Q+ y% d' E3 \; o7 E& \ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();8 `: Y! A$ K8 G
- 6 X$ J6 i7 O l- ]
- " j( ? B; N8 ?# i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
* r* ~1 M8 i) K0 I3 U% F# D1 E9 u( ` - if(x1 == x2 && y1 == y2 && z1 == z2){8 J8 A4 y' ~6 g& v/ M0 R
- return;0 T1 x9 O3 s1 X
- }% t" D6 ~! F: Q, A4 k
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
, ?% H5 _) X7 @; ] - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 W) H- e2 d! N2 A+ {' j" a
- }6 `. O7 m$ i* X
- pose.pushPose();
) ?) l4 I+ s; @* d& X+ t - final int newLight = convertLight(6);
, o: G4 X. p4 f. f" h# B" I4 y - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 p' N6 L0 O7 w; r - final float lineHeightSmall = (y2 - y1);/ O; |( G$ M L. I6 D! e. {/ m
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: D+ f0 \! z+ @& g5 v0 _; ` - pose.popPose();7 g# s* B9 j$ y
- }7 G3 y+ x* p v7 t9 `
- $ @# E1 V/ R& w8 v4 G: h/ [) a4 y
- private RenderType getLayers(String texture, int light) {
7 @1 C* ^' P8 j# Z7 ]. s4 A6 e - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 w% x5 J# W! @0 z8 L
- }; F& u5 B$ u- H, ^' O! V, O
- 6 F' p1 g* S6 t' J [ K
- private RenderType getLightTexture(ResourceLocation texture) {0 Y0 K6 s+ O1 m6 i
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, I8 p# g3 J( T& R& E
- }
4 o: i8 O3 U6 X, ^9 E
3 u/ {' Y8 T D) n- L' V3 C4 |# \# Y& |- private RenderType getTexture(ResourceLocation texture) {+ T5 O/ p- k$ h- W4 m
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);( b, s6 F7 S; e, z2 u
- }! r( x! T# y/ n& j1 w' \: Z
9 G; O% N. {* j) y5 p. y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# u _: N9 q7 c
- if (cache.containsKey(identifier)) {! v8 p" d! r9 M" \$ P! G5 R
- return cache.get(identifier);
8 }4 j. B5 `# A6 A7 u9 S$ J - } else {) \6 H {& {5 \6 h" G0 v/ K9 n* B
- final RenderType renderLayer = supplier.get();
# ~# D# R( E- R X1 N, R - cache.put(identifier, renderLayer);/ L. \* t ]* e/ H, p" _
- return renderLayer;
2 ?1 I# U4 \) p( P2 t - }$ J3 C6 z9 k8 w5 M
- }% K5 b$ A2 J+ b
- }
复制代码 |
|