|
|
1 F- x# `- Z* p行,这个怎么样
4 Y2 J- `: K7 k8 T! o( d# M- package com.xhg78999.mtrfac.render;. R) W. V9 d5 }9 Z
- 7 N7 e; |2 u2 {5 ?" ^' i- u
- import com.mojang.blaze3d.vertex.PoseStack;
5 D& D2 t- C. c" J. V v - import com.mojang.blaze3d.vertex.VertexConsumer;
U5 M; _3 {- L: N" i5 R6 u - import net.minecraft.client.renderer.RenderType;! s2 z! s# f4 F' [5 t& S- I
- import net.minecraft.resources.ResourceLocation;
" v9 d1 g) O m+ |6 E* ~ - & R+ i( C. Z$ K3 F
- import java.util.*;" `, Q. {# r0 V" \" a/ z! {
- - T; M. }7 I* [% o8 s
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# `( W2 d9 O: R+ t+ P$ I$ L: t e0 d - 7 h5 h6 J" m4 D; U- W2 o
- public class LineRender{# E5 `9 b/ k) o& c& O7 D; @& ]
- private final PoseStack pose;
, x, a$ t# W5 E - private final MultiBufferSource source;
& b6 b7 m& }% B - private static final Map<String, RenderType> CACHE_A = new HashMap<>();; I5 J8 _3 S3 q# x) \: X
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 J! n' {/ U. x
% Q. W4 h2 @7 }/ o1 v- ; y6 z8 A; n8 i
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' U9 r( f" G+ T: L - if(x1 == x2 && y1 == y2 && z1 == z2){
# y* t, Z0 M+ r, J - return;
9 O6 U3 o# }4 Z - }5 d$ N- |' P9 B* L# D* p
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( O6 a9 z- K, H: J
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 F" k3 Z9 X, c2 Z9 t* k/ N
- }8 P% W( D. ^. c9 J7 c/ M* n! x
- pose.pushPose();
- R( w G4 Y: d' M0 H" }) K& L! P - final int newLight = convertLight(6);4 c9 M- u7 \) |) b) h$ N! A( t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 T" t# h& B4 R s3 }
- final float lineHeightSmall = (y2 - y1);
& G0 ^: X( i# l. M' H - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 L5 ~, `7 @5 ? - pose.popPose();5 O1 c1 l6 \9 W7 R5 u/ `9 A' l
- }6 s+ C: t! w: b2 a. }8 f" D1 E
- 2 A! X* c. w, n! i: b$ s
- private RenderType getLayers(String texture, int light) {7 l: n* _* I7 g5 \
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 [ [8 l8 l! S7 J% s7 n
- }
2 F- K2 E# A# P+ O
( w: @9 _' S' h4 N- ?4 t! V$ L- private RenderType getLightTexture(ResourceLocation texture) {7 e: o6 D* f& [8 m0 O: d6 @
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);8 c; [- \' w. q5 V( x& o$ s/ y
- }+ ^* n H5 z4 h& l
- / D" J4 N# l8 }4 g1 A
- private RenderType getTexture(ResourceLocation texture) {) F2 x' L1 ?4 ]- e
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 R. a/ S) s1 [) Q1 q& `0 L9 A
- }8 U, @1 R" @0 | N# l/ b! M. H
- / m' j+ E5 F1 W( u% ~
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { i. a. J$ w3 D" S) T
- if (cache.containsKey(identifier)) {# @/ X1 g: @& l+ q4 x2 l: I0 ^+ Y
- return cache.get(identifier);
. ?3 X) z4 ^+ {( _ - } else {
3 C# [# p0 y* B+ \9 h+ y - final RenderType renderLayer = supplier.get();% p# [6 T" h- `. k6 [
- cache.put(identifier, renderLayer);
& @* |: }% a8 Y! Z2 n - return renderLayer;
0 n" _9 o! W) L7 B$ J" h - }) z; `& X: S9 {3 ]
- }7 }: `+ q! w; F
- }
复制代码 |
|