|
|
1 t! c9 M9 d* B- e
行,这个怎么样
j1 t/ S# `9 V- package com.xhg78999.mtrfac.render;
8 L- O& s! M# ~! H - : Z3 E8 w. F+ F) o; {. L# i
- import com.mojang.blaze3d.vertex.PoseStack;# Z5 X0 b7 M+ R0 m% L, j n3 v M
- import com.mojang.blaze3d.vertex.VertexConsumer;
0 J% v9 ^" Z6 r. r& c. B; U5 @ - import net.minecraft.client.renderer.RenderType;' N0 G" k2 |- C v: f& D( y ^! J
- import net.minecraft.resources.ResourceLocation;
& I l/ O* u |9 U/ [. p
7 U' M- B" q4 s. g7 ~2 n- import java.util.*;1 L% d: R$ `: O1 [. Y
# j8 k& m% ?5 `6 l" V x; J- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* `6 A, W3 ?0 ?0 y. ~" s
- 7 X' q1 e& ]( X
- public class LineRender{: S; o4 v* A0 Q8 c! D
- private final PoseStack pose;4 I' }# P v* B+ ?0 @6 T
- private final MultiBufferSource source;& C) A9 v" z) ^* m8 |* P. t8 b
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& _6 }, ?1 p9 _( B - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); I+ [; d% Q9 ~- e
( _) J1 }) P5 V6 T) y$ Z a- Y- 4 y! c8 M* ~- U4 G4 e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' Z! \# Y% |& v( W0 O" t
- if(x1 == x2 && y1 == y2 && z1 == z2){
2 v/ [/ A T7 O) N% w: D/ m0 O+ r9 M - return;
" I2 x$ A$ s+ S* C' O. n. S - }
' r# F T' S% R. C0 w - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 I: v! D+ C* W5 U' f J6 D
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) l" k% g/ P7 u% r" L y8 q' c1 y6 f5 ? - }+ Y6 t, A4 p% D, ~7 J4 [
- pose.pushPose();
* n+ X4 h; u* g Q% s9 o - final int newLight = convertLight(6);0 J7 _+ N: H3 Y q6 n8 a
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));$ G8 m/ T2 \9 d7 Z, B) B# Q) e1 g" U
- final float lineHeightSmall = (y2 - y1);
0 c3 x0 z, u6 q& L+ f2 ?! _/ D+ d; W - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);: @; y* T6 c9 U' g
- pose.popPose();
/ j9 {8 E; y$ L: _. }; K! k$ `: \ - }0 D0 B. l" l N+ Z2 w
- 2 N- I! C1 [% {8 {+ X/ V2 `
- private RenderType getLayers(String texture, int light) {- U0 k7 d+ n4 R6 ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));' Y/ ?2 {+ f/ M- i+ |1 G
- }
0 g1 Z. L2 O* r" R- c- h1 F
0 U" e# l& k/ w6 Z8 Z- private RenderType getLightTexture(ResourceLocation texture) {
& `$ I5 m" w6 a1 e1 ` - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 y3 m" }! H# W% b6 |! _ s: M - }
! s3 Y1 a2 G, s: l - " w$ C& ?' I. e: c; t, c
- private RenderType getTexture(ResourceLocation texture) {
3 R/ H8 C0 E! d - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. s$ S3 A* r5 h. M: z - }2 m* F' `7 n! s7 B# X- e
2 K, U7 B7 Q8 F( E, T& s1 ?/ E' E- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 [5 z0 }$ n! @. _5 U7 g1 [6 p - if (cache.containsKey(identifier)) {/ l ?% t6 u- `& X
- return cache.get(identifier);
5 ]9 o u. n4 W+ J. u0 e - } else {
3 G+ ]" Q1 f7 p8 |6 t - final RenderType renderLayer = supplier.get();) u Y! e1 ~; V& Q. e
- cache.put(identifier, renderLayer);) I# b/ a% E% A7 { L
- return renderLayer;! V, J! q6 G) L8 N! G$ E5 K
- }% F4 |7 H' L1 Y6 B9 @
- }
/ g/ ?* M2 _" b2 S3 U - }
复制代码 |
|