|
|
4 H0 S0 A E" g0 R2 d* Q行,这个怎么样) r! Z1 o9 Z: i$ E
- package com.xhg78999.mtrfac.render;
+ q) d1 J# W- x - 2 {+ f8 u6 w4 r$ T
- import com.mojang.blaze3d.vertex.PoseStack;
8 K) M, U& c4 V- _7 m - import com.mojang.blaze3d.vertex.VertexConsumer;/ C, i. ^; Y" l S1 L
- import net.minecraft.client.renderer.RenderType;
" U) d8 d" ]% { t8 @# A/ V - import net.minecraft.resources.ResourceLocation;/ o \- _# j, D0 }3 t8 U0 M
- 2 x/ _, e/ Y, b) [' x
- import java.util.*;& B. g0 M, r. g5 o% A2 V$ Z: G2 T" S3 w
- g4 z4 ^) @2 P, `! T
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. N; C' Y1 R+ }, [' H' y; m
: N z6 j' R9 ]/ G$ Q, F* I- public class LineRender{
( j: y( V9 K/ G: u! |. Q, l4 O - private final PoseStack pose;& o% a8 { b: H/ x6 h
- private final MultiBufferSource source;
& ]/ A. F7 O; V v! F8 }) R$ q. o - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 e# Q& l3 S7 u6 z+ N- ] - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();. X+ ~/ h! A' t3 D. ?
- 1 u, C% M9 F3 m, b# [
/ `- L, w% N; y0 ^- @9 h- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){! [! X& {! w7 H
- if(x1 == x2 && y1 == y2 && z1 == z2){
( A, V, n$ o0 @, R m - return;
+ X$ i( m8 N5 A - }$ y8 h; u" d) A" Q, T2 @" V( w" {# M! X
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 _3 q+ T: I- F; W6 }4 I% S5 n U
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 f1 t; Z! U. r2 {0 R
- }
# R- z& J5 W, F" d - pose.pushPose();
2 |2 ^# g O, b( w- h9 O - final int newLight = convertLight(6);- U" T/ B+ K" A# G) J* V# ~1 b0 y* I% R
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 a& a% H( n- M - final float lineHeightSmall = (y2 - y1);
3 W& `$ M4 A, ?4 N - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" B3 e+ f1 z* C7 S" O# p - pose.popPose();
& c+ Q, p k- ^( B+ P n - }
& X: x9 d8 T/ |. s9 j - 3 b* E M. [9 c, l5 E- f" D: Q
- private RenderType getLayers(String texture, int light) {
$ N' n+ S- D% p9 `3 @0 o) [( i- Q4 S8 B - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 }: R# p5 Q6 k2 u7 W
- }
' ], @+ Q5 b( W& U O3 W! Q
* p Y9 ^7 b0 Z* F s# l- private RenderType getLightTexture(ResourceLocation texture) {1 ?- ^+ Z1 s7 [1 u
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 o8 J3 y0 O- h - }, D# E" q7 [! M( ?- V" E
- / S- j' ]) W# o }' [+ `
- private RenderType getTexture(ResourceLocation texture) {
" y ~3 O% J7 H+ y - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; I3 U7 L ?$ Q8 W/ [5 S: Q: r - }
6 p K% y5 b: e" ^ - - a& k8 q: ~/ I: V
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
F! w l2 f0 P- z3 _' U - if (cache.containsKey(identifier)) {4 f- n4 ]; }' u6 j; g' k+ k
- return cache.get(identifier);
% } n& P# j1 v( o* N) H% Y - } else {
6 P/ [8 \5 I: _5 V - final RenderType renderLayer = supplier.get();1 ]$ ]/ \1 @, u9 d3 R" r
- cache.put(identifier, renderLayer);
5 F* r. T& R6 i- m+ I, I/ G - return renderLayer;) Z1 Q4 A( r5 P8 {* z' H
- }1 R, r3 Q2 `- I% b) r* @
- } l" f. ` w! K
- }
复制代码 |
|