|
|
# I; D& w9 A6 ]/ ]
行,这个怎么样
: O4 E9 G6 z4 B& F: a; `1 Y- package com.xhg78999.mtrfac.render;# e. T. ~( _/ P2 U2 W
- . r- E6 ?7 E% Y3 V: x( `9 N3 I
- import com.mojang.blaze3d.vertex.PoseStack;
3 Q! G4 l9 }9 I4 r6 M: q - import com.mojang.blaze3d.vertex.VertexConsumer;
; j9 [% \- }, F3 o - import net.minecraft.client.renderer.RenderType;3 A% C- J% l" P7 g$ V1 q! r6 L
- import net.minecraft.resources.ResourceLocation;
: A1 n8 K/ b$ x) o5 q
, w* Q+ r" f. ]9 a$ h0 v, ^- import java.util.*;. u/ K. G2 _7 O7 y
2 @: x/ n8 l- i2 f7 v) Y- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 @' j5 m7 G+ g3 }8 N8 Z$ h) w. L - 3 x2 X2 u: V0 @" ]1 i F1 ^0 r
- public class LineRender{
* i& @* s+ {" Q' b8 ^$ O - private final PoseStack pose;' @/ `, w" r' M
- private final MultiBufferSource source;
, ]2 W+ ]1 A" t- S - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) ^: `2 L/ d' F( M - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# V+ {2 x2 o3 Q0 l
- ( g3 O8 }$ J I5 Y) B3 J$ Y
- 9 q- T. q7 H& l, X$ V
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 i/ j% q- Q5 a
- if(x1 == x2 && y1 == y2 && z1 == z2){+ B/ ~, p1 I, h1 H3 i8 Q
- return;+ d! l z) k0 h$ h" s/ j
- }
! k7 P+ f3 X8 p1 v& z S8 X! L - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
$ K+ I0 i! a" C - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");- S O: [* k4 j" B: ?
- }
3 o2 W1 U6 u Y+ Z8 d7 s - pose.pushPose();
& N3 |* a3 H- l; e0 b- ` - final int newLight = convertLight(6);9 r% G, Q% b. g2 C3 E, H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 N8 D; J4 ?6 i$ a `5 ]# O - final float lineHeightSmall = (y2 - y1);
+ s6 I* r2 X( }6 h! V$ \$ J - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 T3 |! D, R/ [5 F' r; U - pose.popPose();+ P5 |8 k# k, q* w- V% \4 p" D
- }
- A2 ^1 |; B* }# f - * R, e+ Q5 r* c' e- L- s" j& O
- private RenderType getLayers(String texture, int light) {
: Y- q+ t/ G% K. {$ k9 j - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* E4 J9 K6 X' g5 F2 z* b
- }, H# k. L \8 c2 p; D; ^
- / t: e7 R6 k" I# Y9 j/ e1 Q
- private RenderType getLightTexture(ResourceLocation texture) {5 S* X2 A9 g r8 S% Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);0 y' }$ R: `1 u7 H7 a+ b7 A" M
- }% e3 n9 b/ c1 W) b$ Q6 n e6 X
$ k: m. p7 t3 _3 |) \9 K- private RenderType getTexture(ResourceLocation texture) { \( d! B- B7 O
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);* P3 k- p; ~. i3 @
- }2 N6 K' K! f; L. c! n
- - |3 M4 D+ X! F8 c' q
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 v1 ^& D, L, M3 S$ K. D - if (cache.containsKey(identifier)) {% y4 O5 d1 Q) r% N$ U* A0 ^# S+ }
- return cache.get(identifier);6 w( N7 L( u- Q5 e- F* g
- } else {1 z) b* P8 w; z! W) H( d
- final RenderType renderLayer = supplier.get();
- d0 P5 m9 Z; z8 d - cache.put(identifier, renderLayer);5 |6 B6 `* z1 R+ h5 X2 m
- return renderLayer;
2 x. I E4 O8 v4 U - }
" m) y+ P+ j& H: x1 o - }
! ?1 k% z& }. K1 x - }
复制代码 |
|