|
|
! S. o# C$ K# R1 V" u1 t4 ]
行,这个怎么样" L O4 X$ a8 k2 }; V# r
- package com.xhg78999.mtrfac.render;
. o: y! g' E3 Y2 I: [ - 7 U+ K6 C0 |% ~" |2 P* w: ^6 ^
- import com.mojang.blaze3d.vertex.PoseStack;+ _( D5 f6 W" r; ~: z; D
- import com.mojang.blaze3d.vertex.VertexConsumer;
1 i, I; a+ U( n% Z; p - import net.minecraft.client.renderer.RenderType; R5 ~% H" n" H- l$ B
- import net.minecraft.resources.ResourceLocation;! s7 f0 S* u' b- H
9 I0 ^2 Y9 X$ O6 [1 E! Q0 a6 X8 T- import java.util.*; W0 W( E7 ^& ]3 ]+ T% j
, A7 U. i0 ]3 o* F4 X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(7 |# G1 ^! I8 A7 x, q) `
- # \, F% s8 X7 k1 q/ h3 q
- public class LineRender{
4 } W0 v$ N- q' Z2 M - private final PoseStack pose;; N4 P; ]2 v/ W
- private final MultiBufferSource source;
@& l/ F$ x; u! }" f+ A2 u) b - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ k) Q4 K5 K# N. j! | - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();' m. J$ g- C/ [$ D
8 p5 n+ E2 }+ @5 o" z
) }" e+ y. c, ]% @' t$ J- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) K/ \0 i# i3 ]3 F1 { - if(x1 == x2 && y1 == y2 && z1 == z2){
6 P) w: R# g/ \) Y& Y - return;
+ l, f& m3 u+ [5 ?/ s# @$ R# w% t. \ - }, d, R4 o+ `9 a9 T" c7 |
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 Z- b( F/ n3 E9 k' x
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 r5 @- B: {+ a6 Y( T) p9 I% z7 V
- }8 z9 ?3 g- T2 f9 W0 q
- pose.pushPose();& ?9 a, a0 y/ N% e# d
- final int newLight = convertLight(6);0 q8 K% q: |2 H8 J6 a8 o- R7 j
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& t- S( O. Y% k! Y8 f5 j; g
- final float lineHeightSmall = (y2 - y1);
: S/ @" [. f9 I) S - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 A$ L7 ]( ~1 j& W( \6 y
- pose.popPose();% E( d2 @* y2 h; X
- }1 s7 Y* |1 b- d* j
- 1 [; p' h8 s: C" }: }. i
- private RenderType getLayers(String texture, int light) {
% h4 o; a% X* J. Z4 i( V - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
2 E$ x+ v6 P, k2 T/ \7 N+ A1 T( V( F - }
) d w, n+ c, R) b: [' ?
6 u6 x- M. B2 k; j6 N2 A) f: ]+ R- private RenderType getLightTexture(ResourceLocation texture) {8 W3 m1 X6 m% o/ n0 H4 N5 _
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 L3 b! _3 s' L, y0 t$ m
- }8 a# L6 s3 G: V6 N
8 s4 i$ s) @& l: a' q! c- private RenderType getTexture(ResourceLocation texture) {! j* p/ U0 f6 z% v* Q( B
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 F% H* G/ E2 a& O& S) @
- }6 q6 @) k" z# y: _3 x
+ o3 U2 c: J9 [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 B9 H; k# l7 w& q) R, m
- if (cache.containsKey(identifier)) {1 e; {, p9 n6 A, \, Y
- return cache.get(identifier);3 N) f2 v3 ?* ]. _9 Y0 r' C+ ?' w) g
- } else {
: h! e! a0 A, X# r5 R - final RenderType renderLayer = supplier.get();
3 f" P4 u( t& R _- i - cache.put(identifier, renderLayer);" r7 Y7 h- L! A3 F
- return renderLayer;8 a, Y9 D/ d4 `+ u3 p
- }
# e5 i9 h- c: ^ u% i - }
1 O5 [9 m# s3 L: ^) m - }
复制代码 |
|