|
|
' D/ g- y0 _" ^# z: [% n
行,这个怎么样
! @3 q5 c/ p0 i/ W- package com.xhg78999.mtrfac.render;( K3 Q3 p+ I1 Z2 I' [$ M
- % |6 W. R& i4 Z. J7 G( _* r
- import com.mojang.blaze3d.vertex.PoseStack;
3 Z9 Z# }! B' r; C8 h - import com.mojang.blaze3d.vertex.VertexConsumer;2 S' ^6 \- ^7 N
- import net.minecraft.client.renderer.RenderType;
$ R7 R$ w. d( t2 r3 n9 x4 w - import net.minecraft.resources.ResourceLocation;
/ k3 L' M% ?- q$ c$ j R
" E' T0 T# f; I' C5 _- import java.util.*;
8 o M$ | d8 \$ D
' X9 Z4 w, z3 w4 i' F0 d- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& y$ s" M& O |( X
9 x/ Y) ?+ \( x4 n& g- public class LineRender{# R: f8 o0 E: ]" t; @/ F
- private final PoseStack pose;
. X1 o2 |; n5 j% Q - private final MultiBufferSource source;
. c, `4 _; w( [# G3 H - private static final Map<String, RenderType> CACHE_A = new HashMap<>();% i$ R) g$ Q: B9 T1 x' U, h
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ Z) ^9 K) J2 ~4 I9 l
# q' [; R2 u5 n! d, W* @- * y9 L7 R& _5 K. f) R
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
3 i0 a/ K4 q0 M( H - if(x1 == x2 && y1 == y2 && z1 == z2){( P6 m1 u5 Y; q b% o$ N! Z8 Z& t4 p2 m
- return;) E. t- L# a) i& J
- }
8 i4 o% W$ Q1 l$ o( U( W4 b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# d- s+ _# F8 h2 ^" c0 U - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* @' f; |; i+ j/ M" d5 O9 Y; b+ M" B - }
: z2 p5 `& {" |1 D - pose.pushPose();9 `! I( }+ A. s% e' C, z
- final int newLight = convertLight(6);
4 K, M6 c: K. _/ X - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 Y0 q. p( A+ b9 m
- final float lineHeightSmall = (y2 - y1);
) ~$ _) M1 i! O$ h; {0 t& d - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' ~$ X$ o3 [- D2 G5 y - pose.popPose();
8 R* B* e! {0 c! J1 l: u" ? - }
/ Z; t7 C' {" l
3 ~0 T' k" O8 ^4 S( w- private RenderType getLayers(String texture, int light) {
8 t9 g5 E8 Q! F; {( Y/ f* u' S - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( {( B$ Z; t1 G" H* W" h - }9 v0 W/ L3 K5 i. N$ p
4 E4 Z* Q4 A% T3 |& V" _5 x9 r/ K- private RenderType getLightTexture(ResourceLocation texture) {1 b* n7 U; q* v4 F: K6 B9 j
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
3 ~7 }6 s& C# i( K# O8 `0 ~- g E - }
5 \8 \" s6 b4 M
, Y$ J) `1 y N% t- private RenderType getTexture(ResourceLocation texture) {
/ M3 q# w6 c( L - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 ~1 J: s$ t9 D8 [$ |" t - }
2 l, q& U6 y7 h7 m& _! L - 1 _5 X6 H) X: l& e
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
- D1 |- r% m) I( m - if (cache.containsKey(identifier)) {
. l& V9 g" P- v; z- Q( u - return cache.get(identifier);4 d- g, C! [- y; x5 {
- } else {
+ E, v/ E$ D5 J - final RenderType renderLayer = supplier.get();
; d" d0 j8 w/ g* a( a/ ` - cache.put(identifier, renderLayer);8 s/ f8 y" \ r1 M+ K$ {" e% T
- return renderLayer;* H( a! n p5 r
- }( \/ ]" G! t( J0 o$ @6 ?
- }
' Y/ F+ }% @1 [* H* W" E. v - }
复制代码 |
|