|
|
- k' ^ b# f4 x3 b. @9 F
行,这个怎么样( _: Y u( H& ^% L' U
- package com.xhg78999.mtrfac.render;
5 i5 a) E% n9 F) H: D! t1 x( t - ! D+ f. ^' _' _4 z
- import com.mojang.blaze3d.vertex.PoseStack;
: z3 o/ p e1 B; ]. P - import com.mojang.blaze3d.vertex.VertexConsumer;
5 A& C( w) W, }6 ?/ E - import net.minecraft.client.renderer.RenderType; S; {& z* I" {- S3 O
- import net.minecraft.resources.ResourceLocation;& O0 ~! h2 ^. x B
7 L; u3 o. B& Y! g- c0 O- import java.util.*;0 B6 P0 X2 v: D. m @9 i" _( [
3 |3 o7 H/ k! m9 s. I& `- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( A% i) D- ?' J/ V0 x& F
- $ V/ g/ F* x# `+ N
- public class LineRender{% M1 J' B8 J' t3 U' ]1 q! }
- private final PoseStack pose;
; S$ V) ~: Q6 y. Q - private final MultiBufferSource source;
9 j# w( U! W% E" n- l7 Y% e) a - private static final Map<String, RenderType> CACHE_A = new HashMap<>();( x- Y q( E5 k w. q+ P. d7 n: c
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();. \: z" N# ?. W/ L$ @" v
! c2 c6 k3 \+ s- . y8 [2 g1 ^$ `) h( b' d
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) U4 L7 h6 f8 L0 X: J9 m* d - if(x1 == x2 && y1 == y2 && z1 == z2){! J* H: G$ P% t3 B
- return;5 D: O$ c: b& P# A. s2 E
- }4 s- K( o2 B$ o: E+ @; K' p
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* L1 R# b- q; y" B( R- G1 z
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) s$ e. M% M a, F' ] - } W. f( a4 t. R, {) W t
- pose.pushPose();
8 L% S8 P& |+ Z4 S" W - final int newLight = convertLight(6);
4 B4 p2 E& ~# q/ {% C" q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# O: B0 U( p2 h7 z
- final float lineHeightSmall = (y2 - y1);
`6 D S/ s! @, F. W9 S+ y6 l( V - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( k, g( R$ I& A/ y; t" J - pose.popPose();
1 _9 v$ I( M2 t! c$ _( y - }
* i. r9 z8 l- _0 d" P - ( P& h5 J* g0 U/ {
- private RenderType getLayers(String texture, int light) {0 j7 H5 e, {) _" m
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 i4 X! x D- k( c# |
- }5 w3 j; ^% q: J
- 8 T& T i# \# _7 L( r) Q1 h
- private RenderType getLightTexture(ResourceLocation texture) {
$ u2 k9 t- W5 }- ?. H2 A9 K - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
3 A9 g9 f4 q+ H1 I" q3 Y& q0 q - }, ?/ q3 d! ?7 y2 s
- ( b! S3 L N+ T% f2 j/ H
- private RenderType getTexture(ResourceLocation texture) {
: y5 C, i4 S3 H& z3 p# \ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);* T2 f" P2 d7 w9 ~ Z
- }
% x- q3 F0 C" u- l
: `. U6 G0 D1 {( ]. b) A- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 `0 v$ G* b" q8 N; q" b8 l
- if (cache.containsKey(identifier)) {
f& F: l& q) h! `( j - return cache.get(identifier);
. r) U$ B% u( T, L, \+ G6 i6 l - } else {
7 y( E% ^7 \( u: u4 ~% d+ B - final RenderType renderLayer = supplier.get();
9 b* `3 x4 R8 u3 H7 {$ i - cache.put(identifier, renderLayer);
- y. A9 G) y3 H5 H: D' [ - return renderLayer;' T6 ?. P/ s1 A T/ m6 Z1 _+ v. m
- }
/ p( L/ @/ Z6 D - }8 V/ b; L2 t+ h3 w" S& l
- }
复制代码 |
|