|
|
& w: U$ S5 u( A% Z, x
行,这个怎么样0 `! N, {9 g" y% d; Z
- package com.xhg78999.mtrfac.render;
^' w" R2 Z+ r) o3 {) v
9 N1 r( F, I J' r- import com.mojang.blaze3d.vertex.PoseStack;" `' R( u" t2 e X* r% h# D
- import com.mojang.blaze3d.vertex.VertexConsumer;
3 Q& |, [- R9 e7 e* L- a3 w - import net.minecraft.client.renderer.RenderType;" E* t; z0 Z# ^7 F& |; `# M
- import net.minecraft.resources.ResourceLocation; X0 j: ], a8 @ ^1 c, q
; c! C' C/ m3 b5 W+ |" A- import java.util.*;
' r( j P, K( B
$ g, H- w- z" ^. r. {- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: r; c4 h' l" A; p; V" p1 y
- : U* y( j9 z- W: O% a2 c
- public class LineRender{
& f: z# m0 B5 G! e* N) E3 u# f - private final PoseStack pose;
7 W, I7 Z" [5 c: n3 H9 M - private final MultiBufferSource source;) r: V F' C+ v. r; X
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ f$ F' z* z- s- ~
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
3 A8 d, I) A- r; W. W& o' s5 l - * z$ Z: i$ D# X
8 G p$ K% x+ o; O- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){* b- R. W* b* A( L% @! j( x
- if(x1 == x2 && y1 == y2 && z1 == z2){
. K; y+ K' Z: ]! t2 L( Q+ J6 I - return;* C2 g- a# Z h J0 X
- }
X) B, U" s; h - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% B' K. G( V. }. z, N/ a - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");* _' O; s9 H9 ^8 V; s% V$ w" c
- }6 n" ]% d3 P) B$ @$ q% P
- pose.pushPose();
- P2 T, L( T5 a' M1 R* T - final int newLight = convertLight(6);
+ K- | ?/ ]: j1 u1 _ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! F$ K9 S9 R# a! A& m - final float lineHeightSmall = (y2 - y1);, H6 m P4 G5 x ^4 H
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
+ y, X6 q4 \. i& W9 V ? c - pose.popPose();
- i5 Y2 v/ W2 G8 @/ p+ g# R: C; t0 e& X& j - }
1 u5 L5 e) i- A. h( h, d9 j - - e J8 o5 G2 ~/ L8 {% D6 ?
- private RenderType getLayers(String texture, int light) {
3 h# t0 V0 ~1 I6 a% T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 c3 W" S5 s* e/ w4 ~$ L
- }
/ G X4 O% w9 y6 `/ j
/ l9 J- @; r( E( S- private RenderType getLightTexture(ResourceLocation texture) {; t8 p+ M, C: O4 u, ?
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( h% T- g9 F$ v2 ^; }( {+ l - }& D# s5 c' x. _4 T0 W$ K7 I
- g% m! g% e2 A/ q0 ]# a7 {: C
- private RenderType getTexture(ResourceLocation texture) {
1 A' [ o' G4 j4 |. [ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);: {8 V: l" O6 M2 z9 g# N8 ?6 W! i" W
- }3 C& {2 E$ X9 g6 v& s3 P. O
- : r: [1 Z8 Y6 S8 ]2 C' ]* Z6 N
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; E( ~1 d, X' ?+ d
- if (cache.containsKey(identifier)) {3 o5 y+ _# I+ R% z
- return cache.get(identifier);
. {$ ^" |9 h4 A( ^( `+ i - } else {( d! U, x6 c+ ^' H: a6 M
- final RenderType renderLayer = supplier.get();. \/ _" L9 @) k
- cache.put(identifier, renderLayer);
/ _/ a' Z$ @+ s$ O - return renderLayer;
. J$ A. G0 V9 Z) V2 N - }
( b. i. ]! D9 m, S Z l b - }
) _6 H( }6 X1 j# a" ^' ~: a1 W2 x - }
复制代码 |
|