|
|
) |0 N( D3 E9 W/ {. x$ E5 Q9 I6 q/ o行,这个怎么样
0 d% |: b9 A6 [' }9 e0 |0 f, [0 m- package com.xhg78999.mtrfac.render;
! l3 o5 I+ Y8 D C. P, c
$ B& J& n. R3 J( k. d, j( w; M- import com.mojang.blaze3d.vertex.PoseStack; Q' V% i6 K% ?8 m2 I c5 ~
- import com.mojang.blaze3d.vertex.VertexConsumer;
: s7 `* A/ r. ]. L - import net.minecraft.client.renderer.RenderType;& {3 `- h, o" L8 w1 T
- import net.minecraft.resources.ResourceLocation;) R+ o+ g0 J6 G4 d9 R
- : F6 e/ `9 V R" t) _
- import java.util.*;
! W' K5 L* s- ` - 6 r- {! f( b' K b' a6 j
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) G& g% @% W6 [2 \" C - 8 H' v$ J. c/ j: I T5 A& w: \; u
- public class LineRender{
3 e+ t. s+ z( y9 ` - private final PoseStack pose;
( j% t; v* x: i7 N( s% \ - private final MultiBufferSource source;- b/ `& C- c2 N/ p4 d& z/ ~
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
" n2 l2 c( o: k( V5 @ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 y8 P# ]4 p! C! p, F
) ^. |; q1 P9 S8 K- + t! T' W& R/ B+ s* p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){+ X/ c* o1 w5 t
- if(x1 == x2 && y1 == y2 && z1 == z2){. j& R& T7 }0 n2 F# w3 h. l
- return;
- d& V h: v% d- D8 {. h/ I" a- F9 k - }- m s7 [9 |2 Q& Q) f
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, P/ q& E- G C2 I) n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" V" |2 D8 L- p& |! _ - } a/ [& A& Q' U6 H
- pose.pushPose();+ u9 c! _! M" e9 D9 `
- final int newLight = convertLight(6);& _7 H" G6 O" t% ^+ {
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; E8 G5 V2 S) b5 W6 K - final float lineHeightSmall = (y2 - y1); j4 B+ V/ w; ]& u) \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 v! W' ~3 Z* W1 `2 y5 x6 ~% s6 {2 @* u - pose.popPose();. M. g+ D! e" \# ~' L9 {
- }: t" \* Z, K9 n
- 4 y7 _2 T% s/ @/ V. L! ^0 R8 Z
- private RenderType getLayers(String texture, int light) {0 D" T& d0 B6 {3 O" W+ k
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
: L8 }: z2 V( X9 v3 G; r: E1 j - }
! r: l% T) w8 r) e" P- r0 { - 7 L# k* l9 `7 ~ `. U4 Z7 r$ p
- private RenderType getLightTexture(ResourceLocation texture) {% h3 s6 D) t' ?3 A. C+ [& G
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 @! W5 h7 \# F4 \/ ?/ ] - }* ?( h& `3 D# j
- $ U, R0 @- j, f$ U1 E* B
- private RenderType getTexture(ResourceLocation texture) {7 e. U) C5 W1 {0 Z1 u
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 W V# ] S: q K
- }; U* r3 U" |. p" I
+ U- g/ e5 p3 E: m# @1 b" e' D* T- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. d1 m I5 ]2 q* o# \1 C - if (cache.containsKey(identifier)) {0 _6 z* P* s& n0 Z/ u X* s2 x6 J, h0 X
- return cache.get(identifier);7 i5 Y9 Z* t! B" T9 x, \% D
- } else {+ g7 E( p2 `! `) u8 R& z
- final RenderType renderLayer = supplier.get();& V. f5 a/ J9 G! `9 d6 J/ \7 S, E
- cache.put(identifier, renderLayer);; ]4 g( z9 f) ~
- return renderLayer;
9 N6 O# V8 G! m" Y7 j! r# I - }2 f6 Z. D# J/ U/ U* i
- }, h! [, ^% o5 g8 T( M% Q
- }
复制代码 |
|