|
|
( ~7 r/ A2 J5 P- O
行,这个怎么样
& H& V! C- |9 R9 b1 F7 r- package com.xhg78999.mtrfac.render;
u0 U" X2 m; k4 O% N9 l+ I% _( z; D- |$ X
1 }, h6 Q% h) m1 J% n, L$ S' ~$ l' n1 \- import com.mojang.blaze3d.vertex.PoseStack;$ j. N6 q1 I5 L" {- e* W+ K
- import com.mojang.blaze3d.vertex.VertexConsumer;
7 ?; h; f! R! e8 F3 E, U3 A2 @, Y - import net.minecraft.client.renderer.RenderType;
- @8 ^# m) C; i3 @1 f0 B* W - import net.minecraft.resources.ResourceLocation;
- E+ z. h; A8 V7 u: [
9 `) J' _; P5 [# o" M- import java.util.*;; c% B6 O' c0 r2 m
- ! t# I8 y% D! V: t/ s
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(3 d( ~6 q. I% C! K6 C+ D
- / p) Z- o+ X9 ]) _$ q$ \
- public class LineRender{
$ ~3 R# v- n' W: U* I - private final PoseStack pose;5 J4 M" E$ n# v1 S' m/ C: }: o5 T" e& ?
- private final MultiBufferSource source;. }6 i' O4 h/ C( n7 m$ d
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
" u* H! L3 p% b) Z/ L - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. ^9 w* Y" u' T! e: K& e$ @( q - 6 i4 M( ?& `6 y, V0 J# I' r0 [
- - R8 t: V: x0 R
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
3 P5 E% F5 i0 f( U - if(x1 == x2 && y1 == y2 && z1 == z2){
( D* r- \# Y8 G - return;
( Y8 b% O1 P0 V) o - }
7 [% t% x7 ^" H- q! S - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){! c; [) a- P0 X) g
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");! A% V: q/ i! T! p* k
- }# Y$ Y, ]8 ]' Y; C% B8 j: Z
- pose.pushPose();
) I0 Q4 R1 y- I1 n) @7 D4 D3 s' x3 y - final int newLight = convertLight(6);
: g1 C: o* m$ B - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 ?& N) ^4 ^4 I% a - final float lineHeightSmall = (y2 - y1);0 e# N/ b. U$ t8 Y9 {9 i
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
6 D5 f1 g9 E) u1 X$ p; b - pose.popPose(); T/ S5 ~. p* o0 J* z# ~
- }
' p/ U! Q2 z5 I7 J) S! j - 9 _+ ], t3 ]; y' e' D7 k2 ^
- private RenderType getLayers(String texture, int light) {
[/ }1 X6 F7 p6 U' i& T) @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
; @; r" z) I# M8 f8 _ - }
8 c3 _7 A/ H3 T* q: x - & f* n- D. e9 q- I% N. ?: B
- private RenderType getLightTexture(ResourceLocation texture) {* q# h; Y- E r) L* ?
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. L" c" f7 ?, F8 `/ R1 h
- }2 u4 w) l7 M5 ~# e
5 C8 Y( {6 `0 U$ w2 S- private RenderType getTexture(ResourceLocation texture) {
) f+ f" u# j; g$ G/ G! W - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
9 i7 A0 {$ e2 X1 S8 C8 b* D - }
7 E* t% s, I2 b$ Q - 8 Y- b) u; n' ~- x9 w% |
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* }+ N S0 G9 t* C9 W - if (cache.containsKey(identifier)) {# J/ O& M' O, m% k
- return cache.get(identifier);3 P3 |2 N2 @: e
- } else {
) S' x6 }$ l# D8 O - final RenderType renderLayer = supplier.get();
. h$ g$ y t2 c/ k - cache.put(identifier, renderLayer);0 V+ \& `4 H) [7 H. R
- return renderLayer;
: S8 S: R7 u1 V$ q' ~$ e& D - }* ? W" H P) l; X
- }
$ m. ^0 X2 N5 ?+ I# O - }
复制代码 |
|