|
|
. f' t$ F' d% T. l$ d# c$ b# N: J {
行,这个怎么样$ n" P6 q* |9 N5 l3 j$ Q' B
- package com.xhg78999.mtrfac.render;
& k4 d* j! e( i* O1 o! C+ _ - ( b, e9 J9 s( b4 |3 c" W' J
- import com.mojang.blaze3d.vertex.PoseStack;
' I- j+ p1 G& @9 i; R I. W - import com.mojang.blaze3d.vertex.VertexConsumer;
; ^( F3 J# Z- k8 b. b - import net.minecraft.client.renderer.RenderType;+ A k" M$ I4 }3 O* r1 U
- import net.minecraft.resources.ResourceLocation;/ P0 D/ F- z: X9 \2 O) L
2 M+ J# s9 ~( Z# K& [! T0 o6 l" ^- import java.util.*;
& m% H6 k, N& L* ~
" w! r- S( Q* r o4 r- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 [- L# q' Y$ k; [; R
- - p) e) i# s. x
- public class LineRender{4 [2 z$ T. u4 w. M0 h
- private final PoseStack pose;
7 f# q7 \2 a6 G9 d% B) q! Z - private final MultiBufferSource source;
" o1 N2 F% d, d1 C" J1 J) V/ g - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
0 Q$ O! C8 n0 l* c* x% ? - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) L5 q/ v. w0 X* u$ ^, C
- 0 Z5 q7 V a$ S& k1 E
& j! P9 d& u3 ]$ M( d- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
8 u5 q; \/ m3 P1 P) l6 R* F# T - if(x1 == x2 && y1 == y2 && z1 == z2){
& i- S; j+ ]5 d - return;+ w: `" @1 [5 N8 l: H
- }
2 u% K. p* {* n/ V2 p - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& h- `: c# A/ E) c# Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. _! N" ^- r3 X/ W
- }
/ |, C3 j4 O2 E - pose.pushPose();; e0 K" ~' g' I8 o6 Z* M
- final int newLight = convertLight(6);2 Z2 R5 H, w' Y* R4 f3 v) W
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));" {. r$ ^( Y9 g0 d6 C0 p) Z! s' W
- final float lineHeightSmall = (y2 - y1);4 q: G7 R0 y L* ?6 T, b3 d" G* O. K
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);+ X( z& F4 D" [6 v
- pose.popPose();: c4 d# S" d6 G d1 j
- }& u c3 U$ g7 O5 l! g- }5 E
9 W, a) N* o$ h; a: E2 l# H6 I- private RenderType getLayers(String texture, int light) {
; x& W# K! T4 a3 U( g( j% } - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));2 a/ M6 |# s, ~2 W) u/ U1 G
- }# s9 h+ z K1 I; l6 B5 O8 g
; t0 B8 b3 C$ l+ @- private RenderType getLightTexture(ResourceLocation texture) {
% U$ q1 N5 j6 j, \* ^+ {6 m - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 q2 y* |: ?+ m2 `3 w
- }: w( r# _& `6 l& P v* l) R9 G
9 ?1 z1 z+ v8 a% |) p. m: W. E- private RenderType getTexture(ResourceLocation texture) {
/ h& E$ k \# u/ C* X! r* w - return this.cache(texture, () -> entityCutout(texture), CACHE_B);, b, \9 I. t& W- o* y3 Y! ]: Q
- }
8 }/ d% U/ ?2 l* i6 b4 F
- m5 o$ Z% ?; S8 Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: a* u) i0 e9 X+ ]0 J5 S
- if (cache.containsKey(identifier)) {7 t$ J- |$ `( t. m+ Q* x
- return cache.get(identifier);
& b# \% n& T- o I% O - } else {
9 y8 N$ N& i/ e! u/ I% n; @ - final RenderType renderLayer = supplier.get();
- S# |0 b- s; p0 U) i - cache.put(identifier, renderLayer); v. H7 V) g) w% ?* q/ w0 D+ {& r b
- return renderLayer;
, P* X3 A1 t0 q1 \; q9 A/ p0 l: X - }5 z% ]9 m3 O9 l* D3 h3 ^/ Z7 i
- }
. {2 d6 I% @: `7 y; ] - }
复制代码 |
|