|
|
1 B" Z, z5 Y. x5 s( J$ W+ R' R9 ^行,这个怎么样
' P' o6 h% w4 @- package com.xhg78999.mtrfac.render;
]" C. d1 n' d: e. ~4 T& h0 C' |0 j - + z, H. n+ g) j
- import com.mojang.blaze3d.vertex.PoseStack;
7 {( f2 s8 i% ]/ E - import com.mojang.blaze3d.vertex.VertexConsumer;
% R4 j; h5 f5 ]$ z - import net.minecraft.client.renderer.RenderType;# n8 i4 `( r% H& z5 d. |
- import net.minecraft.resources.ResourceLocation; p) Z3 O$ a9 e3 H* I" a9 h& W5 M
- h) C2 Z5 e1 ^- import java.util.*;# ]2 L* r+ d, p0 s
- 8 A: n6 d, R" D1 l6 D# M. Y
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: v( c* S8 C6 E
- - Z. J( Z3 Q/ C; z$ Q
- public class LineRender{
" f6 n- e: c+ r( k - private final PoseStack pose;1 Y% {% z6 g; S1 `" H
- private final MultiBufferSource source;
( A+ K; \) \3 ]* P: x0 o& S2 y/ I - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! o( j n5 h7 ?0 u4 F - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 ~$ M! s3 | A1 p - , u$ u: o" q' g8 k! D& f
- ( V. c( W, @6 l2 h3 v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. v: S0 Q @! L- z3 y
- if(x1 == x2 && y1 == y2 && z1 == z2){5 @9 y* Q# e: @' X
- return;( L/ N {( j4 J) {: \
- }* n' x+ l7 A1 J2 @2 k# R. h$ Z6 Q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){+ u% X; H3 z1 i; _& i, Y. m' X* o" r
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");; K% L9 s- q( b% x
- }
& [. _; G9 M9 K# A - pose.pushPose();' P9 T9 ?+ C/ | I% F3 w
- final int newLight = convertLight(6);/ t: y8 G7 X7 @% C4 g( A
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));" @( I- G% ]& ~' [: I6 j
- final float lineHeightSmall = (y2 - y1);
- A1 D3 ~2 N" v; C3 a - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ ?8 L! Q i: \& B" w - pose.popPose();
& ^( \5 s1 j$ y. T9 ?) n: g; v0 C - }
% Q7 l- Q/ x4 Z) A - ; A- }+ j' G K- o8 _" f' `- }
- private RenderType getLayers(String texture, int light) {
; s; X# b; c3 V6 b& f/ _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 x# ?" O6 @" s7 H2 ]6 t - }" T$ d6 w; P8 H% a5 @
- ) b( R: W# O/ i% ^0 b( X" b
- private RenderType getLightTexture(ResourceLocation texture) {
# v4 b, Y0 A2 d5 d# j& @' r9 E) q7 i - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& M+ C% r4 ~+ h8 I! M
- }2 l, e- o1 S0 K( i
- 5 r7 H" E6 r9 x: ~( Y7 _* H
- private RenderType getTexture(ResourceLocation texture) {
3 V! G' I* M/ ~& F2 ? - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& P9 h; Z, \* ~7 x7 B - }
6 E1 @4 X! L! n: Q1 | - 7 M0 A! \0 ]8 w P" i" c* B+ r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( n* r! @, F p% ^, a
- if (cache.containsKey(identifier)) {
* x8 j8 K5 @5 S - return cache.get(identifier);
5 U f) x8 i j- O& e- ~5 o - } else {/ h/ S4 r5 Q( L4 _* z6 T
- final RenderType renderLayer = supplier.get(); {/ N5 j/ [# D b7 _
- cache.put(identifier, renderLayer);0 ]1 ]. l9 ]& F6 W* e& D! @( Z( ]- I
- return renderLayer;- f2 X, }: j' h) j
- }
) `4 F+ m* ~0 _- w! e - }: C; l1 y, F s3 y" x1 ^& Y
- }
复制代码 |
|