|
|
' ]& @: I' s( V% I) A行,这个怎么样
8 I+ h! Q z/ I( \' _5 ^- package com.xhg78999.mtrfac.render;
5 ]# }# a( V, {9 w2 U5 a* s - , i4 A6 @" \) | H% ?
- import com.mojang.blaze3d.vertex.PoseStack;
3 T" E" i% D" L+ l& b - import com.mojang.blaze3d.vertex.VertexConsumer;
7 J( \) _1 S* S" E - import net.minecraft.client.renderer.RenderType;* F" B5 i1 H n& e8 p9 C
- import net.minecraft.resources.ResourceLocation; c4 j' V( }5 M* l! _
$ R1 H( f, g3 D* d- import java.util.*;, y1 x, q8 P, c- a1 A8 b1 A
- 0 U5 {2 i8 |$ \
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(1 O8 n2 m0 N: t
- 0 q/ O( _: [( q' c1 r
- public class LineRender{! y9 s1 L4 s# U* G) H
- private final PoseStack pose;/ w& q7 E, k1 T/ n! L
- private final MultiBufferSource source;
3 ^* u8 T# B) i9 s - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; c, o! q* O2 I/ R - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 z" N b8 T9 ]( ~2 M+ L! _) o
- # G! c& L7 d, [7 r+ s, I2 m
- ; }# M* a' Q- R1 g" k/ O& O
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){0 q* p1 i. S& w
- if(x1 == x2 && y1 == y2 && z1 == z2){* E) m" ?" ^# B9 }' _ n
- return;
2 W- ?7 U/ F3 A$ P' |5 N$ x - }
" h. a9 z3 z+ l5 [. l/ ?, |0 ? - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){3 w2 m/ J/ r& B! x7 N3 u( |; F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 l# q: g4 X% w - }
; |5 S. d7 u/ b4 G - pose.pushPose();! V* k$ K( i% c
- final int newLight = convertLight(6);" b( E# s% L* a. I3 U
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 Q2 c3 y1 Y! Z3 p T- ~
- final float lineHeightSmall = (y2 - y1);
9 h% S3 Q- O2 d9 M" `4 c9 x4 N - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
% i7 K, X( x# w - pose.popPose();% H. ?/ |" K7 f- w' C" T
- }& K* o* A& m, W& d2 `" R
- ) X" X6 l% d' C- P5 O; y4 {
- private RenderType getLayers(String texture, int light) {: R7 S! t- J9 a8 K% u: z% P
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 R5 Y Y8 }' J {+ {; {
- }
: B; Y* i6 X' @8 e/ f
% ?+ h- k* \ P- private RenderType getLightTexture(ResourceLocation texture) {
R" P. _$ c( w2 b8 ^ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 K! R6 d( e, N- y2 X# b
- }/ V' R& E4 Q! E! s# O
- ' A. L e3 {# _7 S4 }
- private RenderType getTexture(ResourceLocation texture) {
( i; G/ m% g* K# f - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
1 l, F' W3 e; G0 o3 g2 {. s - }+ ]0 _9 Y3 |$ }- q' m# o' D
- 9 I: }' z& T _) p% y
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; B9 R- A: d" Z0 S' z' R
- if (cache.containsKey(identifier)) {9 r- ^8 O$ ~4 I! k
- return cache.get(identifier);0 O' F& }$ B7 c: m# d
- } else {
$ P5 C! {: Y B, B% Q! L - final RenderType renderLayer = supplier.get();
/ S7 ~- D6 e) b, I9 J9 M1 ? - cache.put(identifier, renderLayer);
5 s8 k! n" M6 M+ T) J4 K - return renderLayer;7 V. b3 R. C* E h
- }
. F" F6 N& r0 q2 r# D- T( ` - }2 F+ F6 f7 @" V- c6 Q
- }
复制代码 |
|