|
|
$ K7 f: U- k( A- G行,这个怎么样. W* H/ K+ w2 c9 l" d) a4 [
- package com.xhg78999.mtrfac.render;1 l- q% o9 Z# |3 A( m% n- ^% r) i
: @! `( B! C: g* a- import com.mojang.blaze3d.vertex.PoseStack;
5 ~4 q, J; f" Q) `" q; ? - import com.mojang.blaze3d.vertex.VertexConsumer;
! }. P, ^ D% z - import net.minecraft.client.renderer.RenderType;" O1 O6 F/ [* M
- import net.minecraft.resources.ResourceLocation;
% D" @$ r5 @6 L: w - ; Y* l" _6 k, n: W
- import java.util.*;& z% s0 G6 l6 Y* r0 W& p! `9 g
; i) r) w9 a. v! h- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ X7 S1 F% r; C; ~8 j. L4 X/ B2 `
" f! G* x# p+ M8 ~' g& W- public class LineRender{4 m" b! H# A2 g7 R% v- v
- private final PoseStack pose;
9 n- f; o* D+ Z* V - private final MultiBufferSource source;
; g; z' L- r1 z1 D- F - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, O/ ?+ O) @2 |( r4 z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 P6 U+ q; [0 i; R# N# c
- # ] S5 w/ P2 t) Q0 X6 ^
- - O) C8 d- f1 a
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: h) `$ i0 C: M1 P; z' ] - if(x1 == x2 && y1 == y2 && z1 == z2){7 y, z0 I4 D1 F+ l3 e! S3 P
- return;: u& n0 V4 e+ H6 R* |0 c% k
- }# h! `( }* l" o( R+ T' _
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" W5 Y) \. C& m& P - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, H) k' I' I+ C: ^
- }4 T1 ]7 J5 |: T8 A1 ]4 E' O. v; |
- pose.pushPose();7 n- ~8 _% L r" u
- final int newLight = convertLight(6);' \4 C% `4 r" k% q6 @- Z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));2 o( S7 ?( }$ f
- final float lineHeightSmall = (y2 - y1);& g2 |$ K- {( A# X) n
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* h" H( G2 Q1 J0 r/ ^+ y
- pose.popPose();
# T8 l- G- J c. @% C - }
+ W. E6 K- }2 r$ A& h: s% l! f( N! {
1 s5 m2 q: K9 q/ x: `6 w+ p- private RenderType getLayers(String texture, int light) {" t- n1 j) e8 n, y: N1 ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( W# P0 N9 x8 J; G - }% w1 q! Q' Z3 m( {) d
1 E" [: J7 w7 }* ]& U O! V- private RenderType getLightTexture(ResourceLocation texture) {
. @7 [1 H- m% H/ X" r! V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 G+ b: ?* {- {& J - }5 }; Y3 E) G0 P7 z/ ^
- 5 H( G2 t6 P5 X. P3 O& ?) P' J
- private RenderType getTexture(ResourceLocation texture) {
) ?0 T, h7 R, ^ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 V6 g: n3 I6 C% P2 Q - }9 P5 d. d) T2 e- |4 |
j) f8 |; j9 a F- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
! L- Z# g, f1 q( u, H& F - if (cache.containsKey(identifier)) {
M# Y( G7 W6 @# d6 p - return cache.get(identifier);% X2 o# y6 B B! w+ X9 }: I
- } else { z5 D$ N' j# Z4 [6 a4 _$ G! T
- final RenderType renderLayer = supplier.get();
0 M* ^6 P2 {. q5 o; p# f* t0 U m - cache.put(identifier, renderLayer); _+ c4 P0 K* e
- return renderLayer;
# {: z; `, @/ K9 m - }
3 _4 ~- J; ~4 ~ C4 _ - }9 M+ [0 L9 B( g% P9 Z/ ~
- }
复制代码 |
|