|
|
1 e- e3 L& i+ B4 E6 S& R行,这个怎么样! ]3 a* k/ `( [/ A* g
- package com.xhg78999.mtrfac.render;
' q1 v; y1 _5 p( `, H8 f, o/ [
4 ^; t! V; b. m) v# m0 X, k# R% L' s- import com.mojang.blaze3d.vertex.PoseStack;
, ]) }0 u3 B" Q6 n( z! j" [ - import com.mojang.blaze3d.vertex.VertexConsumer;9 F/ {0 B1 w. }9 X
- import net.minecraft.client.renderer.RenderType;
4 H! ]9 ]8 v: i) R - import net.minecraft.resources.ResourceLocation;+ L2 U) Q( W% h- F# D, V& [
- # s+ V: y9 k9 L% W
- import java.util.*;, I- Z m& }1 b4 L# V/ j: s0 m
. {4 j+ {* r7 K6 Z: O2 s$ v* y8 M1 ?- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
+ i( `% d# y; y2 X# g3 K' W4 f
! C6 d" e% b4 P% m1 G- public class LineRender{4 F( ~( k: o- Y# | U/ Z8 A0 {
- private final PoseStack pose;
5 ]; b5 a/ H2 S - private final MultiBufferSource source;: D! Z3 m7 F- ?* M
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 J0 }* \3 D5 F$ r4 M' l+ d( r - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( b$ }/ X+ Y G3 o& J
& m4 Y( J6 d; L+ L# e$ s) z
: _) }0 q; z$ F- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 Y/ M* E! z2 y$ Y! |& d$ B - if(x1 == x2 && y1 == y2 && z1 == z2){
* [. H5 H# q9 u4 w$ ` - return;
- y. I' B- S, a3 n8 Z - }
. e3 }) o7 z- O2 _1 C; f - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- a$ r) f4 u/ O) Y, y8 f - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 D5 E: q/ i7 M- o! k; R
- }
; J# J P. |' C; W# ~" d, O - pose.pushPose();+ b* `2 p$ j, I/ s
- final int newLight = convertLight(6);
" n$ v' y9 r1 z* a# k. A, m+ ~$ k - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" ]9 d$ q' e3 V" E - final float lineHeightSmall = (y2 - y1);; K( c( L) ^) q
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: d# W* T" E. X L - pose.popPose();; w2 O$ Z' x, s) i% p* Q3 @. w
- }; P+ L! E- d+ A5 W( v2 g
$ u* @3 M" y- f& M2 O- private RenderType getLayers(String texture, int light) {1 {& Z( L* H+ a, O
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ f1 ]* _) T$ E ^ - }, y6 i [, ?- S. }, Q. W% J
% g% h! ?4 K8 B( j8 f& ~- private RenderType getLightTexture(ResourceLocation texture) {. p& _! U! v( {
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);+ F. e8 J7 d& @5 J* O! H2 I
- }
3 y' `9 B6 T5 q* W. P
+ a' `" o- _1 q( h/ V4 ^% R% z- private RenderType getTexture(ResourceLocation texture) {
8 n7 H* S4 J' i - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
5 ` v1 n1 Y+ O - }0 @# t& `9 @: h, l; Z2 x! f
- & E& V4 q. p$ S& { [9 W+ I
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
6 l0 c0 Y' u9 [+ g8 z2 l - if (cache.containsKey(identifier)) {# S% D* M9 U6 ]0 n6 m
- return cache.get(identifier);
( J/ }; X8 g6 D9 X - } else { b9 G( B% L% {4 \# C) ]) p
- final RenderType renderLayer = supplier.get();
+ {/ a( n8 m4 V0 A - cache.put(identifier, renderLayer);& }9 a- s* _3 O0 ?! J) k+ X
- return renderLayer;& c! e7 e, j W
- }5 `( S( A% I( B% U' W# d3 e
- }
; \; @6 C; p5 S) `, i9 x - }
复制代码 |
|