|
|
! E* i) ]) `2 B; y3 `行,这个怎么样* K V, \" Y. ^+ f# K5 M+ m
- package com.xhg78999.mtrfac.render;- w3 y, p7 B8 P5 m( l
. s5 n/ P% s" p: |- import com.mojang.blaze3d.vertex.PoseStack;8 k: ?* g, H" q0 Q4 L, D5 v
- import com.mojang.blaze3d.vertex.VertexConsumer;
+ Z4 h' A& I; D - import net.minecraft.client.renderer.RenderType;& o3 L, a1 d1 Q9 N& M1 [
- import net.minecraft.resources.ResourceLocation;
$ ~* j8 \2 C2 v; U
. L9 B- i& B- I5 d- import java.util.*;' Y2 b$ T/ @2 \" \8 }$ T
- 3 f2 G- L& v3 M7 @# e" Z6 H$ G
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
6 h$ k0 Z+ M7 o3 Y; j
" p4 Q+ Q2 r0 K9 t# }7 o; c. p- public class LineRender{# e, U6 |, g5 j, d' h* e
- private final PoseStack pose;
" |+ |* K) U$ J; F. h6 t - private final MultiBufferSource source;
5 ~* B. x X7 I2 m( q5 [) G7 A9 o - private static final Map<String, RenderType> CACHE_A = new HashMap<>(); p3 W! e8 X7 K+ R7 o. |' u
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();$ F. L0 E; l. J; p" ]6 T; V _! ]
' ^% q9 _) w' n2 A# h/ w
/ V$ C- @. b2 F4 d1 r; E! o- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 Q6 q3 U0 h1 a
- if(x1 == x2 && y1 == y2 && z1 == z2){( X% Z) ]# Y+ t2 z1 Q
- return;- b0 v0 b' q' x% h
- }( Q, w8 R" n4 o3 J K" E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; [3 I7 Q* m- z. r
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");# I# |5 M% W/ a2 H8 L) N* p
- }0 U( g2 E. @' Q4 v& f. {, a1 j
- pose.pushPose();
+ G& K6 [) s) A Y - final int newLight = convertLight(6);( |& @, p& K( X3 z8 i$ k* J. j
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
8 @( P, _% j; J - final float lineHeightSmall = (y2 - y1);
+ w$ I8 j" u7 ^+ P( D - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
5 i% F3 u3 Z+ z+ E$ l5 F: I1 y - pose.popPose();6 \4 b: ?, j3 P+ e+ @: A
- }5 M( I6 C7 _( r- a/ o0 R
- : w& @8 h: a) E: n" b
- private RenderType getLayers(String texture, int light) {
" v! Q1 f- s2 Q6 @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, c: v' E% C- X- p; R7 {5 M
- }
8 p' Y! w$ T" i - $ o* q& w/ B* `+ ]7 z9 ]
- private RenderType getLightTexture(ResourceLocation texture) {
6 {- O2 ]9 y2 I - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; o: i3 z( q e; x: Z' }0 ^ - }) ~4 u: _5 v5 U; M) C, e
. [. y+ p1 W+ e$ ?- private RenderType getTexture(ResourceLocation texture) {
+ u+ |; i& m& q4 ^4 g - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
# C; H! @* U, ^' v/ v- J. ^ - }; ]- `3 H: N2 t" v
' a& k/ Q" {# h- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: N2 p+ Q0 {* d7 A - if (cache.containsKey(identifier)) { ]% j. T! A7 B: y6 N+ j
- return cache.get(identifier);- ], s0 @* P; x6 P: P, c% q( ]2 {% L8 k
- } else {3 x" f8 I0 p7 J
- final RenderType renderLayer = supplier.get();: |$ j: H1 C1 z: F; Q2 Q2 S
- cache.put(identifier, renderLayer);
o( }9 T1 m# [8 c' Y - return renderLayer;4 p" [: F& P3 {$ J
- }- X* w9 h; k( D0 P; h
- }7 l* U# {9 J" U) i4 F
- }
复制代码 |
|