|
|
" h$ R6 M8 g4 ]' F( ? V行,这个怎么样/ c, `# F4 |5 }+ }
- package com.xhg78999.mtrfac.render;
0 A5 L8 N' `% S
6 R1 N* i l. ]4 Q$ V7 i+ Y- import com.mojang.blaze3d.vertex.PoseStack;' n% t& C2 W0 o8 \6 t% R, N
- import com.mojang.blaze3d.vertex.VertexConsumer;2 z F6 X7 G7 x( B% `" B8 b
- import net.minecraft.client.renderer.RenderType;4 R6 [ j' q' Z' ^
- import net.minecraft.resources.ResourceLocation;6 H. C- F6 N9 B
- 9 S/ u: A1 M8 v* [$ K
- import java.util.*;
% ]8 K+ S1 ^. _) S- S - / j3 Q! H0 G$ d$ ]) A5 H
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# q3 K' U6 w0 C9 p2 I6 y z& a
A N) E& F5 T6 G2 B- public class LineRender{
" {0 D5 |& i4 ]& E: U2 c% Z - private final PoseStack pose;0 M" p8 I& L" o0 s
- private final MultiBufferSource source;- S8 |$ o" C# e5 P
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ m# m. | }! N" m
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); J8 J8 G/ z8 P. n/ t" g" P$ W
- 8 U4 g6 T4 R9 P- `
8 c) V) ^& d6 T; i5 ?% p* u- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. u+ Y4 _" l* ?. w - if(x1 == x2 && y1 == y2 && z1 == z2){: b) ]. P! H( \
- return;. h" _6 c7 E$ J2 t& }6 h6 c% d* \
- }
" y$ i2 p) Y# Q* X7 u. f% f - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 a/ ^7 {5 r6 X' V" S" s/ ^
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 n" P# R( s% z% S! y1 [0 f
- }
& J0 I$ l% }0 ] M9 Y, b/ y1 ` - pose.pushPose();
: s: F" k% ]' G4 r9 H- { - final int newLight = convertLight(6);% X- g& M: c% ^0 H. P1 t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. q/ [& P, a2 T) l. d, G
- final float lineHeightSmall = (y2 - y1);
/ i9 @( f( q7 d( h E% h/ t0 i - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);4 p, n3 h7 ]$ A8 H
- pose.popPose();2 J! d# N4 _" S. P# Y
- }
* v0 }6 C* |& \/ [. h# M" Y! T
" Q. d4 F8 I5 H! z- private RenderType getLayers(String texture, int light) {7 y7 G* k- \- M; |8 A ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ n) N6 @; o. o, h9 l! L - }
* n/ |/ D6 l. @7 | - % J8 @) \1 Z( |) d" ?- T; G
- private RenderType getLightTexture(ResourceLocation texture) {( V* b( }8 `, @8 @
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
9 Z/ B' _1 I1 B! k; B - }
; ?+ \1 Q: O' m - / V- N! p$ v# z) L; ^7 |3 P
- private RenderType getTexture(ResourceLocation texture) {& W9 I \- W7 X% J" R" {
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);# ^2 ?6 A) g! [- d# c
- }
+ J, G$ Q- e/ U7 @! K X2 i - 3 c0 U; |. ?# _ A M6 B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {, A/ F, i( W! {
- if (cache.containsKey(identifier)) {* Q: u( ~' r' ?+ y9 [" }6 ~
- return cache.get(identifier);
8 D, U' N7 R6 U4 M7 P1 { - } else {
% u& G3 J% ?' G: m9 Y1 ^ - final RenderType renderLayer = supplier.get();" R& g9 S7 W: E$ Z3 U! P9 Q
- cache.put(identifier, renderLayer);
) L% O4 `( d3 |1 K8 p - return renderLayer;
7 {# p4 g4 e$ Z) Z+ R1 y - }
( b) ?& o i P( ]4 c - }
. ~0 U) ?1 X% v% l+ n4 A - }
复制代码 |
|