|
|
; z, o8 h$ ]3 L
行,这个怎么样5 S+ P8 u9 `& c& w9 C
- package com.xhg78999.mtrfac.render;- Y# Z/ |: Z- K& V
- 6 |) g) c& W5 z8 m9 j( v* q
- import com.mojang.blaze3d.vertex.PoseStack;! Q6 e3 S8 F* x9 C3 M1 e5 X. e
- import com.mojang.blaze3d.vertex.VertexConsumer; l" b8 j u# M+ H
- import net.minecraft.client.renderer.RenderType;7 S% H% F& B/ j; q% ^
- import net.minecraft.resources.ResourceLocation;5 y) s; v/ y% v: x c3 k2 w
- $ f2 d$ V# l0 {1 Y) p7 G+ F
- import java.util.*;. L# o& X* v4 Z- f' m# P
- 8 {, Z. ~: s) X, H9 u1 i
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
9 ~( s* J6 O: j, U5 V1 e
* l; P8 g6 j) l* Y- public class LineRender{
3 [7 n, k6 e L9 ?; j2 J: e& ? - private final PoseStack pose;1 Q2 N/ o( B3 J0 d5 y+ Z% `% W
- private final MultiBufferSource source;; J1 C2 m& @" i. Z& C: A
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% ]% `8 A4 t9 i2 ^4 J) @ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% s8 G4 d$ H5 H N - ' e) e: a" `: h+ R4 f
- 1 ], b0 O7 F7 p! r1 N: u- _7 L* B5 n
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 M* q/ F# P7 J8 o+ s - if(x1 == x2 && y1 == y2 && z1 == z2){6 w3 }- P9 M+ q1 r2 c
- return;
3 @, N& S! w- }& i7 w: A) ]# C - }" a' p9 ]( p& p* t4 l
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* E% G. v4 {, b
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 x9 z0 Z) r1 h9 D- x, t7 C
- }
/ q" ^, W4 _1 L - pose.pushPose();) s3 J1 i0 s7 y& \& |
- final int newLight = convertLight(6);
) }7 H$ M& Z0 `; M% h* P - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 U6 u* @* ~+ V9 U3 ?; S
- final float lineHeightSmall = (y2 - y1);
( i) b) s3 v, U7 X& C - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# L: |. Y7 N' t* v0 | - pose.popPose();; m3 Y6 m& X @: O
- } {9 {; K b0 l8 e( S% k4 F1 w6 i
4 \4 @. j! I7 U9 M# }- private RenderType getLayers(String texture, int light) {" o& Y! Y3 a) {5 P; A7 A6 l/ F
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; P- k+ Y: b! A5 [# D' Z
- }
0 \5 {9 @ `3 K$ g+ B; i - 4 }$ J* l( `( f+ g" X
- private RenderType getLightTexture(ResourceLocation texture) {
. W! l& V1 ^8 J/ E1 L* c# \! V - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
- W: w; a" B% ^" i% }5 m: p- I - }) V2 E- a1 f: ^4 |# `: [; f' o" `' B
- ! u5 K& q6 B8 m! A
- private RenderType getTexture(ResourceLocation texture) {2 h9 v+ q- O5 `, T0 B
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
9 y' Q1 c) A2 E% v2 }6 P - }& P5 F$ k& I: [0 a# _
" P( D' ~! v: Y3 k, a% [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
?* y9 A: a7 {# {# T- U% e& l - if (cache.containsKey(identifier)) {- J1 `& @: I5 t3 E
- return cache.get(identifier);
- a- S) \; {2 A. L, { - } else {2 [5 E8 E; o/ S+ E8 {; L
- final RenderType renderLayer = supplier.get();
0 M' H) H N) B- @* i# L) l! J' Z, W - cache.put(identifier, renderLayer);
L; r8 `7 l& w7 K$ |/ | - return renderLayer;" v' A- B2 l% G9 v; L; G
- }: I5 N1 r* I! s0 ]/ }
- }7 f ~# `3 C: g: j" u- s; l5 H$ p5 _
- }
复制代码 |
|