|
|
/ F" N) D) e1 Q* r3 B" l1 v% D8 P$ e
行,这个怎么样8 Y3 I5 C D4 ]
- package com.xhg78999.mtrfac.render;$ J2 g5 Q8 ?# _: [1 X
5 g; C0 |: R5 ~' v) }- import com.mojang.blaze3d.vertex.PoseStack;" Z5 G# G& N+ w# r4 a* t
- import com.mojang.blaze3d.vertex.VertexConsumer;9 J' K* r9 ^/ ~/ ^7 m
- import net.minecraft.client.renderer.RenderType;" }) d- r+ ?* i( L/ O( u
- import net.minecraft.resources.ResourceLocation;
% N1 f+ g" ]6 X5 w- K5 X
- h' j; j' l: f: e* a/ {- import java.util.*;& M) `, \* I" s4 j2 a7 ?
$ e: N. u+ \- i+ @/ V5 D0 w- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, y7 {" G4 {; T k
$ b5 Y7 d9 R& l" L- public class LineRender{4 b3 Q7 T8 v6 n U
- private final PoseStack pose;* z5 W: I: b! t+ p: f# r
- private final MultiBufferSource source;
W# b( u; b# Q7 J9 x* ]& X - private static final Map<String, RenderType> CACHE_A = new HashMap<>();: q1 @3 `5 i2 ~" n& r
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();$ j3 ~/ I) w1 s2 c, G' Z9 H
- 1 c8 A" P, X. t8 U+ e
- / J y* n, I3 O( |1 a$ O
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ {) [: u5 W0 N0 {" k6 D/ g* h
- if(x1 == x2 && y1 == y2 && z1 == z2){/ @& O' i' }' N2 R
- return;
% u- B# E; | Q' B! ]0 E) N - }
' g6 {$ `+ r& M6 Q) J5 S- J0 j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ j( W& h) R3 T8 D" H( v T
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");* B) n9 e2 n8 ?& S/ N
- }
) t% }6 ~; A% I+ I" |. D - pose.pushPose();
: @/ j9 d0 H- o# c% K - final int newLight = convertLight(6);/ e9 J Q$ G1 u' h5 k
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! d3 |( z% ~$ S2 h+ \7 k9 n - final float lineHeightSmall = (y2 - y1);
- `# x r# w$ Z- u6 ~( r - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& O4 @2 M. y8 Z4 a# @" z
- pose.popPose();2 [2 M3 ?1 ]$ q) q: m
- }" x2 C/ X* [1 ]
- " T% _+ ~- p/ Q; v1 y) q
- private RenderType getLayers(String texture, int light) {
- Q5 L, L8 d* ? - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));# m4 S/ I* y, o1 z0 a& d: k
- }/ J+ @ I8 z, T7 h& F
1 H N5 m) T4 Z( v- private RenderType getLightTexture(ResourceLocation texture) {
9 O, e: c/ g5 L) o+ p6 I+ \" F - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
9 b! n7 j( z9 h7 t; x) u" f! p2 o W - }
s6 f Q+ g- t/ c& T - 9 o# W1 f- a. G' Q4 [
- private RenderType getTexture(ResourceLocation texture) {- Z7 H' B! E$ I; M
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);' a" Y* C5 D1 _# w% U
- }4 b; u ? G% e% F8 I) U; v( K
1 q8 r$ V& q3 B4 I& F$ d- ^! g- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: U% e# L" Y: ~
- if (cache.containsKey(identifier)) {
, y' ^4 `) K4 L4 ?# u - return cache.get(identifier);, w8 V, g2 k5 {& R5 ^9 ^2 P
- } else {
0 \9 H* r1 h0 r3 }# l# g' A% C2 a - final RenderType renderLayer = supplier.get();
T8 l7 ~* w$ S+ H1 R* F3 t* U - cache.put(identifier, renderLayer);7 \2 s* H& ?( w( s8 \: B" K
- return renderLayer;/ w, y5 t2 H1 E- h
- }
6 x" o4 o- Q0 v - }5 j0 C: y4 D" H$ X$ v8 p
- }
复制代码 |
|