|
|
2 K: ]% t: d& i行,这个怎么样2 |( g' P. u/ s H
- package com.xhg78999.mtrfac.render;
- Z: j: G9 d8 {5 N - 7 f( `& F: ~5 i4 ^# }) }# X7 E/ R6 t
- import com.mojang.blaze3d.vertex.PoseStack;
- T5 I+ V* w6 E& v7 k5 j7 K! N - import com.mojang.blaze3d.vertex.VertexConsumer;
6 `) Z' K! a0 }$ r$ { - import net.minecraft.client.renderer.RenderType;
" q9 W$ m. D$ Q) H3 R - import net.minecraft.resources.ResourceLocation;
h( c3 I& {' v. x- J# I - ) Z7 ^, U4 f$ L: z v7 c. U8 i
- import java.util.*;
# K6 D9 B4 w) ?. g0 F
) A0 M# ~, g/ w; U1 ?- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(5 P1 f5 B' G' u2 ~6 S) e
2 o# O' [2 X0 l+ u( B5 F- public class LineRender{& B0 ?+ D7 o8 m- h# ]
- private final PoseStack pose;* A- E L* R5 t) C
- private final MultiBufferSource source;( u3 ?( G( @3 D- E
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& L& z! E0 j* X9 q. R) `4 h0 q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) I+ q. f3 U0 Z6 G
% O' m, }' G/ `1 O) @! F6 T, k. U. H
9 M/ R3 n _4 K- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){, r$ t1 X7 J& ?9 |
- if(x1 == x2 && y1 == y2 && z1 == z2){
4 G2 {4 B4 z& H5 l6 D) H e - return;
7 m& `4 \9 m1 Q; T - }3 E3 ~. W& t+ `4 V/ o, O# T d; f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 O$ ]! R, c) ]7 P1 p0 T
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
3 X0 n; @* R }- K. s1 [9 Y2 r: H - }: t* c6 P0 x+ A, B; u2 x
- pose.pushPose();7 \; |7 e' Q I, {* z3 q6 D. m
- final int newLight = convertLight(6);& K! M9 }! g9 `- B$ ^. g* s
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 u4 J6 ~8 ]7 `. P& M, z - final float lineHeightSmall = (y2 - y1);$ e" b; R ]! Q$ r/ D4 K* Y4 _; y$ H
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
, }: C# f' Y: P# [2 t% e - pose.popPose();, {+ g2 @& f* h
- }" w p+ P q+ {
- w- O q9 R- T/ W- private RenderType getLayers(String texture, int light) {' x' C V8 v3 `
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));7 l3 s" e: ]. P" Q
- }& L. e5 |1 _. N8 P
- 2 h9 y) W* g3 _6 L Q
- private RenderType getLightTexture(ResourceLocation texture) {
. m; W: {4 F+ c Z/ l& D - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 N( Z$ H( I1 P8 R
- } ~# c: i7 Y8 o, Y ]) m. X, f0 J
- ' V: R% @& s5 Q$ L6 {6 D4 |9 m
- private RenderType getTexture(ResourceLocation texture) {; s; v$ y! f$ b0 T: w. B/ {
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);, o4 W* S1 I# l
- }9 C+ ^+ G; r9 @' t/ f
; u1 O3 Q. L2 ^$ r6 T# f- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ U+ ^) V9 S3 G# y! [# d
- if (cache.containsKey(identifier)) {0 F" P- p* x7 |% r6 {3 c+ N6 n
- return cache.get(identifier);
3 \( a! v! ^) S1 l3 @# k# e - } else {7 Q; B& Z- b! w& h
- final RenderType renderLayer = supplier.get();
3 y/ ~9 o6 G4 S) D5 G# P2 o - cache.put(identifier, renderLayer);
; _; T F7 R# r- u/ Q - return renderLayer;
4 i) a9 a' r. l: y ~ - }9 V: z) R3 }* W& z& I! a) L3 d
- }
1 E; |8 \* ~. T! X - }
复制代码 |
|