|
|
w. n- a. }; f8 i' x& R2 z
行,这个怎么样3 U" k A: L2 \+ q( p& O" u* u
- package com.xhg78999.mtrfac.render;
- b# o# x( \! [, S- F
: R% f9 n% x" [! I: w- import com.mojang.blaze3d.vertex.PoseStack;) a' ^/ a9 T8 k( l/ k* K$ d) O
- import com.mojang.blaze3d.vertex.VertexConsumer;
' N5 ]8 r9 m3 o3 _% V; @5 O - import net.minecraft.client.renderer.RenderType;# `: Y+ E4 W. l$ W
- import net.minecraft.resources.ResourceLocation;
- ^5 @2 S/ G% x8 e - 6 g5 K/ B5 J2 c) @! j) |0 e
- import java.util.*;( E3 h, T6 l9 H3 e) a# f. h1 A
" E& }" x' L, O q/ m; M8 g- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(" p; q8 Y4 q7 Q$ r
$ H3 F$ e3 g4 m( x- public class LineRender{
# T, }3 I- Y$ w% b - private final PoseStack pose;9 H6 S+ M& H2 |1 W! o+ z, ^0 s# C3 ?
- private final MultiBufferSource source;
5 j+ x' S; _7 j( d3 N- _% G1 h - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 P, c$ H3 F" ~; E* V - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 O+ w e( E& O4 K
6 J1 l- Z* ~3 w6 |/ f
5 V' V& u. Y2 i7 r& f- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, R+ @* C2 P% z7 a: D - if(x1 == x2 && y1 == y2 && z1 == z2){
6 W# c1 k$ I5 B3 }$ X - return;; |! K! Q5 ?% {; n/ M
- }
: C: a' n, d" S k! p: p - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ Y* ]! r! O2 Q4 t+ c7 f( H
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% R5 u* R. q9 {2 O+ Z* w$ m: B
- }7 D7 G( e" Z7 z# z) x: d; \
- pose.pushPose();/ N7 [% l+ ~, ] M% N% x
- final int newLight = convertLight(6);+ d6 c8 P6 \& y3 K1 h7 ^( v7 G! c
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, q3 Z! X2 b; V! B* k* L - final float lineHeightSmall = (y2 - y1);8 v" E; ?5 [! A* j2 T- ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
4 U; l4 g8 C* {! `$ j& } - pose.popPose();
1 v- i' _* `! _: w b - }" h/ h* M% E p/ D) \5 a
- 8 P5 B. z& E3 [! g; K) j: ]
- private RenderType getLayers(String texture, int light) {" P8 }1 c6 C$ n. K7 g
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, v( J# |. Z( A! c7 t8 p X: R; o; D - }
2 i9 c0 c& Y( D' i& w - 6 i9 T+ t* V. \7 J4 n: e
- private RenderType getLightTexture(ResourceLocation texture) {
" r3 i3 n4 a- _+ _ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);8 v/ g Q3 D' @. c6 d T
- }
% ~5 n2 V& {/ b) P - - g( r8 }. n$ L. K" W& d6 o
- private RenderType getTexture(ResourceLocation texture) {
K3 b0 K6 B: z4 c. T - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 D* w: v# }4 `' S! x' D6 W3 { - }" `- ?( ]' p3 e
4 p* s' T6 \2 s* t" h- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
" u) P. l+ g% G - if (cache.containsKey(identifier)) {
/ f- |: L" ?1 o1 ]( z: v5 ^ - return cache.get(identifier);5 B5 N( }1 Y, E5 L7 ]3 i0 v
- } else { ~' S# T6 |6 o4 t( Z E
- final RenderType renderLayer = supplier.get();
& _9 p) E1 g. i$ d. Q$ C5 f- O8 Y - cache.put(identifier, renderLayer);
4 X3 Z9 ^( m* ?8 W f - return renderLayer;
: j/ W. J9 g: ?3 S' L - }6 o! d- r# Q' s/ T$ J# X# i j& m1 N0 k
- }" J. B' h. N& {$ m( u+ j( ]4 f& g
- }
复制代码 |
|