|
|
# N9 M5 n5 x7 J/ s5 F7 l
行,这个怎么样, n/ h7 M! n. K% r
- package com.xhg78999.mtrfac.render;1 w+ G- Z. _1 Y! h7 I
% q- I. i1 {: K) u- import com.mojang.blaze3d.vertex.PoseStack;
0 V- G7 K; j: C! d/ F - import com.mojang.blaze3d.vertex.VertexConsumer;; b2 v" t1 M$ A$ k0 Y4 ?
- import net.minecraft.client.renderer.RenderType;5 [9 `5 k7 F) j* J$ [5 w+ F" R2 `
- import net.minecraft.resources.ResourceLocation;
5 m* }( Q* M# F - ! c1 s- s: ]( W/ J4 e6 a$ [) j
- import java.util.*;
+ p4 @9 O& |. M8 |. X- x4 _) x
6 K/ [$ c8 y, N- t- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 A) m9 w k; u- g8 i- N* [ - ?6 G; F- f/ @
- public class LineRender{0 a1 Y* J* v6 c; W
- private final PoseStack pose;
! ]. Q1 D9 o0 i: d* ? - private final MultiBufferSource source; C5 v6 _! |6 |% n3 B: P
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ P9 l$ {7 Y) c+ E" d) N' Q) s - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, K# K% W; \8 h; H. y
( V! D; _- u# Z
% a3 f) d. t$ v4 L# K( a- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 T$ h) n5 R* q! u" \$ X - if(x1 == x2 && y1 == y2 && z1 == z2){) L0 p( Z" F0 r0 j# e4 j6 x
- return;
9 t% s2 N- ]' ^; ~) W. p$ r - }
* P8 O. G" E+ I; p4 _ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 f- w4 b, p! H
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
& Q" B, A0 r( z, F& x1 T - }& Y6 }# d0 e% ?3 `6 F( X2 b4 A7 }
- pose.pushPose();7 O p* q$ G* |5 S" k6 u
- final int newLight = convertLight(6);* v! ?$ B3 O6 L8 {! w& B8 A
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));8 b7 C( p1 [5 Y
- final float lineHeightSmall = (y2 - y1);
3 |( g* w6 g5 i. V- S6 e) q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& n2 {7 p) Z: O( @, c: \ - pose.popPose();
" ]" l. c7 W7 S B$ o - }
; T4 n- U( O* ^8 z: [* T" z. x( `& ~ - 5 W! P; w2 z* t6 A0 \3 _* \% X0 r6 b
- private RenderType getLayers(String texture, int light) {8 r* x) L: l r
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ v. J+ ~# @$ L* m7 C9 q! e7 H - }8 }6 Z8 z! ]% ?3 J/ w+ x+ [# r; {
- " p3 G0 a9 E6 a, l
- private RenderType getLightTexture(ResourceLocation texture) {
* J7 ?# D" C: @1 J$ O4 i6 G - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ J8 o9 r: \4 r, t - }, a- w0 B2 A4 \1 l9 e
- . @& x! H* O1 s) m# H
- private RenderType getTexture(ResourceLocation texture) {
, B/ C3 M7 z4 j9 O( s1 Z1 O% ` - return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 P, B3 I+ J% F$ C7 ^# M2 F3 N/ W
- } q; t. T+ y) D6 b( F# E
7 h% W& i1 [% T- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 h9 S, v5 l, c9 O& S, U: H3 x - if (cache.containsKey(identifier)) {2 F0 t5 A U2 J: h, c
- return cache.get(identifier);' W$ [$ Y9 y p: s3 a0 T
- } else {
' [1 ^; ^* N- i# u+ r1 Z - final RenderType renderLayer = supplier.get();
( V# i5 z0 t: e! H7 q - cache.put(identifier, renderLayer);
: ?# m" h' `% r( i& }, R - return renderLayer;0 D" x, k0 v7 ^' _- j1 U3 D4 R, a( e
- }
, @- u, o: }9 ` |7 T8 r6 \* W5 l" j$ ^ - }/ U& I9 h v6 ?2 \( T
- }
复制代码 |
|