|
|
* o9 e1 X8 `. Z- p2 }1 A# t( s5 X行,这个怎么样$ |4 E6 s- a& m1 k
- package com.xhg78999.mtrfac.render;* P9 O7 r+ K% A' f4 O- y
5 ~ ~6 f/ x6 j3 T* U0 [/ {- import com.mojang.blaze3d.vertex.PoseStack;, O: l, [8 ?8 q7 y8 e, u
- import com.mojang.blaze3d.vertex.VertexConsumer;" y" b9 E8 t: S3 Y& H2 @$ r _" n
- import net.minecraft.client.renderer.RenderType;
1 X* a) l. z( R* w - import net.minecraft.resources.ResourceLocation;
# u& u( I# l+ \ - " i8 f2 x( a. _/ w1 u1 G4 |
- import java.util.*;
0 v9 m& F/ }5 N; y - 7 r8 A0 H0 r2 j* a
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 ?9 v; x* ]4 q& `2 j' v. U
7 M1 h0 p0 c u3 T7 R- public class LineRender{
0 W$ `' z% p" `+ G - private final PoseStack pose;( r, y) Z& U- {% E- Y4 u
- private final MultiBufferSource source;5 `1 S. n7 c; g; n5 H; k; L A
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: M" R0 v+ j8 p) R C - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); e: {7 U+ `3 ?. L- g6 S1 a
- 9 b8 [! z9 y/ }% z a
- ; v. {1 X' L$ d2 i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- G0 W6 Q* l, `5 Q+ s; B3 [1 e' N - if(x1 == x2 && y1 == y2 && z1 == z2){/ d8 [" g% x2 f2 D! N
- return;
# O' S P3 V2 J4 g: [$ ~ - }9 S! y' N" T; ^" F5 O
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 ]% {6 O& Y$ O* `. Z; }$ {* v - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' \ n* @% H! Z0 g# T5 E
- }
/ }0 z7 L4 X9 V - pose.pushPose();
- E7 Y* [9 X7 D0 }9 {+ h: x1 ? - final int newLight = convertLight(6);
0 G+ d3 x" r) b% m H8 |" I! X% a. i/ d - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; @! J/ a% a( m, L7 I/ N0 E - final float lineHeightSmall = (y2 - y1);
- k: U# l: k$ h- \+ U' l" D - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 _' y1 _* R+ k* P. R% v
- pose.popPose();! m o2 ~' G) N+ l
- }# q, }! J$ ?0 r5 }2 {. j
- 2 z' M+ l/ [, y0 d2 f& E5 ?
- private RenderType getLayers(String texture, int light) {/ ?. w- k" A: q7 \! f0 a& ?0 Z" |' k( j
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ ]$ f: i/ z' w1 u6 [" h( U - }
4 R, A3 r6 F% S# G - . L2 q( Z" l. T" x! p
- private RenderType getLightTexture(ResourceLocation texture) {/ d4 ~, @& r9 U" ?5 i
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ P3 T! \9 W: w( q. K2 V0 N
- }
' }& b# [( A6 V7 l7 h+ N
! Y6 L; _. c" e/ X0 y- private RenderType getTexture(ResourceLocation texture) {# P" c+ ~- F$ |' { u$ A4 [; H
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( k( B4 M$ B+ a- z - }3 _6 j1 ?, M4 u4 K9 K5 J3 H H
- . y2 K7 F7 s0 s% p) F o% K) l: h) g
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; E# X+ X) i+ v9 d3 s( {1 i" A - if (cache.containsKey(identifier)) {
4 {" K4 q5 [, m, \ - return cache.get(identifier);
; E: K$ x" p) I9 o0 Y* [, H0 g - } else {* C. P0 a! x/ a0 W. j8 x
- final RenderType renderLayer = supplier.get();
# A7 a' X% l: q7 a0 |- s4 p% h) h - cache.put(identifier, renderLayer);, ]+ r7 I: F5 Z! e
- return renderLayer;
5 g% }6 ~1 i4 |' ~% a" _: d1 W - }4 q- r4 V) v/ @! A6 \, G+ Q
- }
* N& G2 M1 r8 x8 Q; Y0 i" T b - }
复制代码 |
|