|
|
, F$ o3 d4 i: E. U! w5 w. D
行,这个怎么样
0 K! A# O$ ], N; ~8 D. R- package com.xhg78999.mtrfac.render;% ~, h8 q# p4 I h. T
- & B# V. F* C% [8 _2 [- U- s, K6 x" ]
- import com.mojang.blaze3d.vertex.PoseStack;4 a& R: A& K0 ^2 O/ C+ Y$ u# I
- import com.mojang.blaze3d.vertex.VertexConsumer;* l4 d' v5 b8 w- l ]
- import net.minecraft.client.renderer.RenderType;
/ D; ^5 n4 V- Z( c - import net.minecraft.resources.ResourceLocation;
% V/ H9 h9 v9 L; J - ' Y* h8 K; Q! E$ S* T6 M: z8 F
- import java.util.*;! O* |% Y# n; P
- & Q2 N( G9 @" b8 a6 m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; ?) V% k- d0 C
7 i2 Y8 k2 @# E) K e' X1 f- public class LineRender{6 _" G1 @0 l! v' `8 D V
- private final PoseStack pose;
1 `& @5 h* A6 e - private final MultiBufferSource source;
( q2 e5 O3 o G! g. X4 h' D4 m - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
- F" C" P1 W$ x1 I9 j - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. Z- K8 _- t v) T7 F8 q$ J
4 k5 F! A9 J& ^% N B4 |: ]
) Q) W! S2 }2 }* Q- ^6 V- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 W4 @/ F4 ]9 M; y! |% v* s1 D" l
- if(x1 == x2 && y1 == y2 && z1 == z2){
- I3 _; x5 W( K* Z - return;
% `. M6 D R/ l3 ^! H- [' K/ g) _& {) M - }' l G" J, H0 L' U) j$ ^. u2 {) t1 |& b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 ]& N3 @9 I' I' s0 O; B - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
x( c$ L. g8 z - }8 a( P4 @# b: D; R$ S
- pose.pushPose();; ]/ S1 G0 k# u; ?6 G, c7 y
- final int newLight = convertLight(6);
' {) T' [ Z0 j- _, \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
8 ]9 D5 E% Y1 O& \" @; } - final float lineHeightSmall = (y2 - y1);+ ~8 ]5 V, T- R3 w& p7 N) c' ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# c; U; W; P9 [ q: h/ { - pose.popPose();$ O1 n( l4 I0 g1 Q+ c6 V: u% E
- }
6 x0 I; L9 |& g - , i$ R1 C2 H" f, v
- private RenderType getLayers(String texture, int light) {
2 H" o+ L, a: d z( L# n - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));$ n( O$ m) T7 t
- }& \* o+ s" P, \4 {+ p
: r3 S! u% `; V5 w3 T4 B( y- private RenderType getLightTexture(ResourceLocation texture) {
& y; j4 |# U6 K ~5 _- o# T - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& a, X2 }# k$ u7 Q: G - }1 Y$ ]7 v8 M& P, C2 q. r1 O5 s/ \2 {
- : O7 m* @ \ p+ s0 [, n
- private RenderType getTexture(ResourceLocation texture) {
) S* x/ ^4 H1 p5 Y9 l' E+ z# F - return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 E/ ~' r' H/ z4 @& C: V
- }( P8 _, v. O# L U* N) y' I
- ( q) [8 h4 U# c, L/ S: Q
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 j. p( F& V% _2 C
- if (cache.containsKey(identifier)) {
. } y) U7 \6 |, |; y& i - return cache.get(identifier);" b5 E* Y& `; f, g3 d
- } else {
; d$ j: [' n( Q5 \& U9 Z: v - final RenderType renderLayer = supplier.get();: y8 p9 o1 s) g
- cache.put(identifier, renderLayer);
8 ]) @- R. ~ \0 M/ B4 m - return renderLayer;, V9 ?; K+ r8 B2 e; P+ t4 C
- }
; v) G4 }( t j - }
: e3 j" L: w. o2 o: i - }
复制代码 |
|