|
|
H2 L9 q( S4 W6 `1 O# v行,这个怎么样
9 B+ m9 u6 }, B# ]/ q- package com.xhg78999.mtrfac.render;7 t2 R* A# T, @& k$ U
' q" [/ `* Y, b3 h; E. F- import com.mojang.blaze3d.vertex.PoseStack;
8 F- c$ J, f9 \7 ? - import com.mojang.blaze3d.vertex.VertexConsumer;
( g5 q! I; x5 K - import net.minecraft.client.renderer.RenderType;
h; V5 y# G+ ^; J6 d - import net.minecraft.resources.ResourceLocation;" z; A) ~: [, \$ |& U4 F. B
" U8 [! T3 f$ P. t. }# [- import java.util.*;7 x4 E. k7 b7 w& M- A" J
( e" h1 m7 U3 }3 `3 K( t$ u1 c5 k- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
% w9 J3 }7 Q( ^ - * ]8 f9 w/ J# C" {2 Q: }& y d! M
- public class LineRender{
! s3 u+ r) E( w' v3 z4 N - private final PoseStack pose;9 m9 v. T- M h2 Q; u2 v9 z& R
- private final MultiBufferSource source;
c1 W; C! [' v3 C0 \+ B) W( S - private static final Map<String, RenderType> CACHE_A = new HashMap<>();) R1 D6 U" a" v p: r
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
5 m0 Z" |. n/ J& @
# B' l! i1 N$ [- u9 i) p7 v- ! V( k' [3 h" K7 L8 p1 O" Z5 P$ Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
/ F, T( K9 P5 [) L' n- q$ E T+ P - if(x1 == x2 && y1 == y2 && z1 == z2){9 ~+ d- U2 f/ ]
- return;, i: P I' b+ H
- }
5 \; `7 y9 j( ~9 U% u - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ K3 {. t2 ~) y4 t5 s$ Q! d - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
( A/ T0 P/ p5 b5 p - }' z6 l) X6 O, y8 n1 W! K
- pose.pushPose();5 G1 y- t0 }: P# u/ Q5 {
- final int newLight = convertLight(6);
2 Q1 p0 b6 |+ [ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ q2 o# C, R- T& u+ L0 Q! v - final float lineHeightSmall = (y2 - y1);/ y7 Q" s' Q* B2 h3 n
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( J7 a% ?' H- t. ]! Z0 k6 D
- pose.popPose();
7 Y y! r) j7 k! g! ] - }& @7 C6 B! U" g4 t9 X. w* h9 j; L0 W
' a9 L; R B, q3 D% F+ g1 ~4 H- private RenderType getLayers(String texture, int light) {5 L7 H, c3 r4 e6 T' _ V
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));5 y1 G* R X0 w: B/ f
- }
8 B0 S0 \! F- P
- s3 M1 w* o$ N) x/ X3 p) b- private RenderType getLightTexture(ResourceLocation texture) {
; b E+ a" ^8 X# O) y1 h9 ` - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: ~. \6 B9 l! u: |$ d- ~; p% @ - }
$ w! B5 K( D" e* ? m - 7 v. b( M3 o5 {: i/ T
- private RenderType getTexture(ResourceLocation texture) {
: p' a% G! K1 z0 j$ Z% R, C - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, \, o9 h7 X7 e9 O$ j - }
, R v, F# Y# [6 M% C0 U
; k+ l3 C/ P. y4 ~7 p5 M2 p6 j6 @- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 b( \/ L% J2 L" `( u$ y9 k
- if (cache.containsKey(identifier)) {5 K- E% ]1 v) Z+ c$ U8 u
- return cache.get(identifier);9 M7 K0 l& g) p) |
- } else {+ P' ?8 P* a% T, k; s2 O* ^" J" N% X
- final RenderType renderLayer = supplier.get();1 m3 @) ^- F' ~: H2 [7 o
- cache.put(identifier, renderLayer);( [5 v! P: l3 H: l
- return renderLayer;& F. n. w3 H6 g+ ?
- }% g0 j! V+ T. u- I2 q/ T
- }$ Z$ g3 e+ A. J0 V* r- |& Q* A4 W1 F! V
- }
复制代码 |
|