|
|
' v0 I! A$ M8 i0 h- K9 i9 [( j2 N
行,这个怎么样
3 @4 h% Y; h' Q- package com.xhg78999.mtrfac.render;
0 g/ ~7 N/ V h6 r3 s, D - ) @0 [7 Z) n! c3 I
- import com.mojang.blaze3d.vertex.PoseStack;
4 ^3 b/ E$ |) P - import com.mojang.blaze3d.vertex.VertexConsumer;
4 f8 i* ]& q% H4 [5 ^! V! o - import net.minecraft.client.renderer.RenderType;, U! b' D; h; x z) `! c
- import net.minecraft.resources.ResourceLocation;
/ t. Z, w( y( Q% r$ Z1 T - * f' K% a8 b: F9 H7 e8 J. S1 _
- import java.util.*;
$ f2 U2 ~( m9 |- f
' p( ]8 z, w& Z+ U8 A5 P- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 q$ t: q( `$ Q" y9 w
0 @- B7 O7 k* u+ h/ F- public class LineRender{
% A. [, h [- T1 [ - private final PoseStack pose;) x8 l* ~6 ?" o0 L# u
- private final MultiBufferSource source;: _& M( H1 [( N6 I
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ f0 F0 E$ w' a7 C. j1 I - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 ^, P# @" E9 o+ |+ _' c
^( [. i7 U0 }* ~
3 \4 r: d/ E6 N0 ~- m: n- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ O7 F1 s; C' u6 r1 @ - if(x1 == x2 && y1 == y2 && z1 == z2){
& x* \/ X, f8 e7 R8 R - return;
% {) V, G* J$ m- i - }$ G H& [1 o) j; A
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' r8 z/ i; G1 ^) R H
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
' R3 L7 a. k T - }
, n% z) Q3 x! `8 ~/ H1 L$ b - pose.pushPose();
6 |7 x9 N0 Q( k; F* U4 E9 J: A - final int newLight = convertLight(6); B% a- u" |1 ?5 f( u
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));* v$ @, t0 Z+ `& k. q2 z: h) m
- final float lineHeightSmall = (y2 - y1);
8 W' Y& z4 t2 @" ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);" O. [, E: T1 [ t
- pose.popPose();
# o4 U- }" V( e( H; y3 K - }+ B8 P0 T$ ^! x7 Q
- - i: I% j) a" z, R& E
- private RenderType getLayers(String texture, int light) {
8 r. N; I6 Z: N - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));+ }: a# K8 E/ _2 y3 M) @( x0 s
- }& I5 ~: ]; Y* z2 b
- 0 y6 _* f/ l9 m3 w7 K4 j# @, J
- private RenderType getLightTexture(ResourceLocation texture) {4 z! n+ E' v% c' V
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);- x1 Y# J( N+ x# |0 N
- }* p- X6 Y+ s4 f
- - b- f1 h: n: j3 l; Z
- private RenderType getTexture(ResourceLocation texture) {
% @& J: L9 S6 p8 L9 Y- G$ _ - return this.cache(texture, () -> entityCutout(texture), CACHE_B); i+ B C) ~4 u9 s, n
- }, P6 d; I; C$ E. S; k H& W
4 r+ i4 k8 j3 A$ Y7 r! Z& q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 n* k, r0 @( k$ ~/ Z4 |: k - if (cache.containsKey(identifier)) {
, h4 l4 X/ ?- z. \/ w& u5 q - return cache.get(identifier);% d( s1 w% D; k* ?3 H+ J: f
- } else {
6 v% g% A/ y+ H' q - final RenderType renderLayer = supplier.get();
- v9 w+ p1 Q% { - cache.put(identifier, renderLayer);
* N# y9 A. Q# U) w8 ~# D8 ` - return renderLayer;) _+ ^) r0 m# l4 m# [
- }
* @& h/ D1 d- b - }
( R3 i) W0 @/ o4 z - }
复制代码 |
|