|
|
5 U/ h1 m; @# A2 [0 K( s行,这个怎么样
( Q+ q9 t* H7 D. N5 o- package com.xhg78999.mtrfac.render;
/ a8 b* x/ V5 B' ^ - : F; Z- S1 N# L7 ] B( q0 ~
- import com.mojang.blaze3d.vertex.PoseStack;
7 e' k( I% H* L# k - import com.mojang.blaze3d.vertex.VertexConsumer;( O, B! h! n# }0 L0 X1 B
- import net.minecraft.client.renderer.RenderType;
" Y, _9 y1 \$ r2 N - import net.minecraft.resources.ResourceLocation;
; H- _( a8 R3 n* n B
' t* |/ g/ m# h6 T u- import java.util.*;- h( F$ O/ ]' W! D' Y% W3 @, q
! q; \/ s5 \0 v) T2 G5 z% ?3 [0 O- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(8 d! A8 L( X2 Y7 p8 K8 `" a( [
- 1 ?$ @1 V7 }5 E& `- ?6 [" h
- public class LineRender{" k' j% D! I9 {- F+ q
- private final PoseStack pose;1 P3 I" L- y V3 a2 L% R
- private final MultiBufferSource source;
+ L6 u: V! o5 P' g9 A9 J - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: n2 m% }, I# \5 e5 s! _ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) ]& ^7 Y4 j1 F( v - ' S. H7 |2 T; K8 n- r$ u
% R) U/ S8 {2 N8 E9 A. c, e4 S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
f4 c% g+ J: G. } - if(x1 == x2 && y1 == y2 && z1 == z2){
8 P. H- C- C- V3 _, A# P - return;
5 Z4 P. S: {3 F9 V6 m - }
; Y3 k5 I0 O$ h! t h4 k - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){$ [6 d! ?: L8 Z0 O. y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. V( ^: N3 O# b! @
- }/ f7 N5 _! z- u( T9 v I" b; O/ q
- pose.pushPose();! X( i: ]* r6 E, R2 ]5 d
- final int newLight = convertLight(6);% a9 o5 {4 {8 @! e+ n6 D! N
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 @& B7 ?; m$ A1 s0 |+ G - final float lineHeightSmall = (y2 - y1);0 { h5 K+ t8 s0 @* P5 n+ n( Y
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);$ F, c' |1 G! ~1 i* t" j
- pose.popPose();2 s: d: n: H( e& ~ M
- }% {' ^0 d& m1 E r' p8 i4 e" ^# l
- 3 w, p. C6 D/ c& Q0 e/ {' J- A
- private RenderType getLayers(String texture, int light) {
$ R0 s/ M# w: i U5 i7 I - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 C/ A& ^3 q i% j
- }. Z( i- A/ ]. @ Q
- 7 c7 D) C3 R/ [' D1 J+ @& u
- private RenderType getLightTexture(ResourceLocation texture) {8 I6 W: G- B0 [4 K; E
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! H" X; ?% W+ x% V
- }9 _8 @6 g$ i) z3 R+ |7 S
- $ }/ p2 g! e& y, {
- private RenderType getTexture(ResourceLocation texture) {
6 L( _% w& b! R9 p4 w6 \% n; G! w - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. u1 u5 e& I9 ^2 {# \* z - }& S# j% ~% Z3 H9 Y8 Z
- & D2 o% C3 P+ e2 Q. B* E9 d0 P
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
+ {: r' g! Z# y6 F - if (cache.containsKey(identifier)) {) k8 \# d4 T: a0 v! j
- return cache.get(identifier);; U% ~' D' b" m/ R+ v3 y9 W. H
- } else {1 R' n8 Z" j/ a% ~ w+ {+ `8 A0 A
- final RenderType renderLayer = supplier.get();
3 L- G4 q6 ?0 g6 i/ A - cache.put(identifier, renderLayer);
' q' A4 S) Z! X5 A9 X8 p - return renderLayer;2 S/ N+ C/ `8 Z! A9 y) {( E( N
- }$ ?& @* g' k/ e4 s# L% o
- }
: E7 {8 t# i9 P, P/ [( L5 l - }
复制代码 |
|