|
|
) v0 a0 S" O G' X* |1 u9 X, I! @行,这个怎么样) c4 ~8 A1 z! C# @
- package com.xhg78999.mtrfac.render;
$ N& z# t( V: ?5 F
6 {- T8 g% d9 q8 k' U5 D' b1 \- import com.mojang.blaze3d.vertex.PoseStack;
% o1 T4 _8 R6 F2 i7 N; P' L+ P2 m - import com.mojang.blaze3d.vertex.VertexConsumer;
4 x! y0 O# a1 G! y0 Q0 G - import net.minecraft.client.renderer.RenderType;
. n7 Z( V+ c* c; H - import net.minecraft.resources.ResourceLocation;2 F) u- S3 H& N0 Z
- , E% v4 G; A2 Y7 _
- import java.util.*; w* K) i+ _" ~
/ J; [. M$ U w5 E# E$ X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
6 a- f. j0 X4 W, D
. @* e8 }/ s7 C; ~" Q- public class LineRender{
9 {6 j" O7 k9 s - private final PoseStack pose;
, N9 J/ S6 Z+ Y - private final MultiBufferSource source;1 H+ m0 c# \ J0 r# u, a" [5 A
- private static final Map<String, RenderType> CACHE_A = new HashMap<>(); C: d! C/ ?; v% B
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
; b! Z+ g% z% A z0 Y: R - + v/ d, P" G2 z5 T4 Q
- 7 |3 C8 G* d( d3 U; E7 \
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 \6 x, ?1 d; M9 R - if(x1 == x2 && y1 == y2 && z1 == z2){ `+ m/ G1 N7 f- D; Y
- return;; i6 p4 A0 u/ m* v
- }4 t; y/ F6 T8 ^( i- O! s4 ^
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 r! {9 `1 s* x
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
3 y6 Y" x* \. y b! {4 ~" \ - }; [, K8 R7 _' J [2 n
- pose.pushPose();4 W. Z& b& K( }2 T) i1 s) w4 S
- final int newLight = convertLight(6);
$ D' F/ V2 s: T$ |# ] - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
% ~" w: N: Q' }2 o& x - final float lineHeightSmall = (y2 - y1);5 E8 h* G0 W$ s, I0 T' O. ]3 W
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% q. t2 m3 K3 r
- pose.popPose();
3 @4 c }" j- }$ T, Y C0 X) x5 d! v - }# \1 y5 g" y# c: J( o. H
- Q: m2 D S4 v
- private RenderType getLayers(String texture, int light) {( K5 u. \3 p! j
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 F! E1 G& j" q - }
1 d8 ~# j; E0 I& O6 Y1 q - # r2 o4 g- k8 P2 ^. T
- private RenderType getLightTexture(ResourceLocation texture) {
7 c8 x. m" F, S* S5 Y/ b - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);* L! [6 A) [. K$ F# {7 f% z, d
- }
' X+ O, f8 |4 Y: V
% I: e* t% @5 q; J5 b* M1 c1 N% l- private RenderType getTexture(ResourceLocation texture) {/ `6 O* L X6 A' N Z; n
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);: N; a: E: ^* k5 z
- }7 {: F6 Z1 r# Y! `) k5 N
- 6 u/ A M/ [$ M5 b* ]" m/ S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 L0 \/ f( K8 c W
- if (cache.containsKey(identifier)) {
3 s. a* u7 f/ p* ~ y7 M/ I - return cache.get(identifier);
; I2 i% _+ s ~0 C - } else {# f2 N+ a# a- b; T9 O9 ]' E+ ?# l
- final RenderType renderLayer = supplier.get();& t; F3 s. h( E7 c. u2 m+ J
- cache.put(identifier, renderLayer);9 E' _; r% g3 v( {) m9 _3 M
- return renderLayer;- Z- Y( I1 k5 B
- }0 k% A4 |6 X/ \
- }9 d) K5 s. G! O6 |' k% {7 w
- }
复制代码 |
|