|
|
2 o4 \3 ~( m% T7 t2 J1 P. ?行,这个怎么样/ C# _1 ]: d( L/ x
- package com.xhg78999.mtrfac.render;4 s* \) G0 A- U
7 M) }9 S1 m7 d7 O" }9 |- import com.mojang.blaze3d.vertex.PoseStack;& d0 ^! M' A8 |' [( w
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 Q, h4 k y5 a4 f+ {: w* D - import net.minecraft.client.renderer.RenderType;
& L6 F2 y2 ], D' B - import net.minecraft.resources.ResourceLocation;
) @9 J4 [1 A ]6 k4 ~1 c, j+ {7 W
( O5 ]1 u+ ]1 W+ p* A/ z- import java.util.*;
: o3 {4 ]& V. A2 O% [' Z, w
8 t9 j; y9 ?* l+ P4 W- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
% X+ X5 [7 T. ? w( { - " d9 b- B6 A; i. ^" M* }
- public class LineRender{
, L5 G* d% K% i3 {% \" g - private final PoseStack pose;
/ R6 f/ b, Y7 M - private final MultiBufferSource source;
7 o" v# A& F! T: ^ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 d, P/ A2 F' q2 F. {0 o: k% h4 }
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();. n3 N- R$ [7 `/ ^; C8 b
$ H/ L( V6 d h/ t! j- 5 a7 ]# w2 _% a I. L9 `7 i# P6 u
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% B3 J) d o- m" [
- if(x1 == x2 && y1 == y2 && z1 == z2){
8 U( _4 t7 [- G5 V - return;0 M1 c2 G4 R0 @( C8 E3 n0 H
- }2 H% M C; K' w
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% \) v3 n% z5 h/ ^ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
; z! {- I i: G - }/ _7 {) I7 B% H/ n9 _) X1 n2 F# R
- pose.pushPose();9 g! l1 Y! v. ?6 U$ V6 M, U, \
- final int newLight = convertLight(6);4 K. m/ L1 M8 }/ \ x+ H0 k
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 l* j8 l7 G8 y t8 l, V: i - final float lineHeightSmall = (y2 - y1);
! U6 O) M, u, } - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
, x& y& {6 J8 O4 w, a7 g+ {6 G5 o - pose.popPose();' R- f. Q u, p* a
- }
: ?2 `; o: x/ i/ T3 p0 |
! z3 F+ Z2 N4 L/ q! q/ X' ?/ r- private RenderType getLayers(String texture, int light) {
* z" Q" M7 d+ o' b0 x - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
9 z0 Y, u2 B5 f' k6 h( t: Z) ]' R - }
+ y) a8 V t ^% B- t7 i+ k - , B! b2 N! B0 n) c+ J
- private RenderType getLightTexture(ResourceLocation texture) {6 W1 j; }7 V4 T! Y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 B0 L' q/ W7 Z" ]; ^/ l, A- m
- }
" A, K) y$ w2 c7 o
* N3 k. a! e5 r7 N$ L- private RenderType getTexture(ResourceLocation texture) {
' r4 l5 i6 O- Y2 r1 g8 `8 V2 O7 z: P - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( X( a5 F X4 C - }; k4 _0 H$ a: z5 `
+ D3 j$ f& d: Q n: J: z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: [( {; e" ^- [6 \
- if (cache.containsKey(identifier)) {# @ Y* X, |" w5 e* S2 g _
- return cache.get(identifier);
x0 P$ T" W4 ^- Z5 Z( ` - } else {6 U/ h" K7 b: {6 ?) K; E# |1 E
- final RenderType renderLayer = supplier.get();
5 Z3 r1 f% G4 s; U- _ - cache.put(identifier, renderLayer);0 b& \2 m, ^- y6 d9 I
- return renderLayer;
! L+ G( R* K f* V - }7 r; B: W5 T9 ?, d& K
- }
4 B2 @( S9 H% v1 L% p - }
复制代码 |
|