|
|
. b9 I+ m, o/ }8 l
行,这个怎么样" E/ i" W: A& P
- package com.xhg78999.mtrfac.render;
4 C# G( e3 p( a! f {9 |$ M
) _% h( @) s5 Y( N/ Y. t$ q5 `- import com.mojang.blaze3d.vertex.PoseStack;- d/ a) h/ F% I
- import com.mojang.blaze3d.vertex.VertexConsumer;
4 q4 i6 O& u+ v R+ L - import net.minecraft.client.renderer.RenderType;: y% q5 o( o! H$ Z
- import net.minecraft.resources.ResourceLocation;3 T6 t" a/ {4 _- t
- & k6 g. i& e. s9 \
- import java.util.*;6 R' d& l4 Y6 ?: p( s
$ E7 m7 R8 W, }0 b7 M. S# q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* N0 Y9 u$ ^' M$ X
0 ?+ I) y4 w0 V5 r! @- public class LineRender{
, o7 B; z9 @1 T, f: e - private final PoseStack pose;" ~9 ^7 U8 Q7 c f
- private final MultiBufferSource source;4 ?5 r, x( m6 I5 F" v
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 \7 \0 L+ g% x6 n% U) R- \% x
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();* W* t0 Y5 R$ \! N2 Y3 V
- ( N e: O! @# L- l& \( T1 I' }
- 4 b0 t8 Q; ?! a a
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){7 w# _$ C2 x+ d( h1 A
- if(x1 == x2 && y1 == y2 && z1 == z2){* f0 c6 i0 J5 x! {6 V% a5 r) I
- return;$ Y+ a, t l6 l* ?/ f4 Y
- }7 X7 U7 z% z- H0 R7 E9 N0 v/ m6 m9 Z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; ] l+ z- l% S f6 ? - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! I' b4 K7 L* w' h4 i( Q7 j - }
: c& W# u! x8 \ - pose.pushPose();
9 @5 k) F! \8 j' f; ^; V$ c - final int newLight = convertLight(6);3 Y+ }( y$ k3 x) V
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 g+ g0 W, ]" s) b* t5 V
- final float lineHeightSmall = (y2 - y1);
( s _8 E/ E0 D5 x' z4 V4 s - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 O; q* j0 ~/ o: S b K
- pose.popPose();& ?7 `& Z: V) O# V' [. q4 U
- }
0 F0 o$ O- n7 ^ - ( e4 e8 k x5 P4 V" x) ^: |# V; ?
- private RenderType getLayers(String texture, int light) {
2 x2 M3 |2 O$ _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
J- k4 l6 g9 J0 l S; H - }# c u/ P9 B$ Y5 o: [6 ~
- & b+ Q4 I& g& I7 c& z
- private RenderType getLightTexture(ResourceLocation texture) {
9 j4 P. l) C/ e0 H2 i5 F9 n - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ ?5 H3 }) _! c9 ` - }
" \8 e7 E% G& H# f' g - / { r+ d* K+ U
- private RenderType getTexture(ResourceLocation texture) {
: [4 Q' r7 T+ C5 z/ `6 e: G/ ] - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. c$ o- |2 |) G+ j- Z - }9 x8 v$ E; ^6 @' n7 g
8 `2 q/ ~- w6 O, n# h5 ]1 D4 Z$ v' L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {/ R7 I% G1 H/ N1 q( R
- if (cache.containsKey(identifier)) { T% s; K! s- y
- return cache.get(identifier);% I7 |1 s9 u+ i
- } else {1 ^4 N* q2 k$ d% v1 S F. v! {0 R
- final RenderType renderLayer = supplier.get();
. @8 l0 V' q9 v3 k - cache.put(identifier, renderLayer);
4 S- {0 z+ C. g0 k8 w/ O - return renderLayer;% f4 C+ R0 s' r2 F! i" ]
- }
: i' D @- x0 o$ m - }) \. z0 u- k5 _: `; x
- }
复制代码 |
|