|
|
# b2 v, E/ R# D, E! I行,这个怎么样
( |6 A, C6 Y; {# F/ ?( Y# b- package com.xhg78999.mtrfac.render;2 v- \' }: j" M; @0 `1 }
- ' v! |( b) j8 }' R' E/ M+ _
- import com.mojang.blaze3d.vertex.PoseStack;
' o4 W4 R( L$ A) h% g( g - import com.mojang.blaze3d.vertex.VertexConsumer;$ w/ |: j$ x: c1 @+ j" o# \. V
- import net.minecraft.client.renderer.RenderType;
0 H- z+ H/ J( V7 |3 ~7 K - import net.minecraft.resources.ResourceLocation;- o- n" t: U$ B, d% M8 A
* \* G) F* {: }8 @: R! c2 _, G- import java.util.*;7 e @5 F3 m% Z$ k( I3 h
- ! I9 W7 ]. ^& ]& K
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; j8 V/ Q9 Y1 l( A+ K$ d2 v
- ( ?1 Z' E+ I$ V
- public class LineRender{
4 Q; P1 }4 Q, A: X* U; t - private final PoseStack pose;% ], b) k0 n/ d
- private final MultiBufferSource source;
; x2 ]* B/ J" ]- q; d T+ G - private static final Map<String, RenderType> CACHE_A = new HashMap<>();4 V6 o Z3 D& g, f
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& s z# A% s# p- J0 z+ z
- n* ?7 A* E( u
- ' r/ J3 a! E, a j: i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& O0 k4 [3 }* u, o, |
- if(x1 == x2 && y1 == y2 && z1 == z2){& F) Y' R6 W4 U9 K% o8 u/ J ?2 v
- return;% N) }, O. P! Q' @3 Z. A
- }
% ]7 m- S/ ?7 e J4 U; y# V" b4 A - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 Q4 J, f2 ?3 }& g
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& D9 I- T P' \4 l6 V
- }/ a. c% b4 R! H* n
- pose.pushPose();
" ^- L/ J. e* I; G& z( `% G - final int newLight = convertLight(6); [1 [/ V* ^) l* t" o0 E9 ^5 y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 P4 D/ g. ]1 J" P# \ - final float lineHeightSmall = (y2 - y1);
' G* z/ ]% r! P: Y! @- A - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 }! d" p. E8 W" l" d7 D
- pose.popPose();/ m2 V# m4 e5 e8 j9 e
- }
7 t5 M% }8 o$ y0 f
6 F. c4 d/ A Y6 A# E5 O' T- private RenderType getLayers(String texture, int light) {
9 g r3 j" t1 ~0 X8 a7 C - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 j4 S, G) J5 c: a3 q - }
5 W$ ^5 o$ O& n H/ R8 C) E) `
0 O& Z! |( O' b2 F- n, \: z- private RenderType getLightTexture(ResourceLocation texture) {, w" C& z$ W) }; F* d
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 e# f" x1 k/ J5 r4 \
- }+ |/ {) y4 s: A7 X% h" `
7 B) P0 B5 F: Z) n/ |; `/ f) J- private RenderType getTexture(ResourceLocation texture) {
: M/ l c# @' a% V! ~" X1 b - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% W) \! T& }+ X" w: Y - }2 j7 d( h: x" g' k6 a4 m
I, R% u8 T* p/ ?/ B- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ X0 f+ X) O2 z5 G
- if (cache.containsKey(identifier)) {
6 U3 ` g; O: `# F' O: J3 I - return cache.get(identifier);
6 u8 I& g/ B+ K; n$ v - } else {# B5 C% X0 |4 G& M
- final RenderType renderLayer = supplier.get();
; ?" g/ g$ W3 k& r1 e7 a$ F$ J1 ^ - cache.put(identifier, renderLayer);
1 i5 [ J9 z0 H* `) S6 z/ r - return renderLayer;3 }+ y% ^* R0 Y( t8 u6 v6 d
- }' x' F- A" B$ f" ]0 v
- }7 B6 D& h% Q2 b {& b( R
- }
复制代码 |
|