|
|
/ t. ~5 t# o* C行,这个怎么样9 a% e( r' ~ G% n+ b+ k/ Z
- package com.xhg78999.mtrfac.render;2 B; U/ a3 ?' A* I
- . |) o4 r1 k+ Y9 n8 B
- import com.mojang.blaze3d.vertex.PoseStack;2 u+ [; _% M# q L- l' C/ A6 O6 I
- import com.mojang.blaze3d.vertex.VertexConsumer;' Q( N6 o! X% |. O
- import net.minecraft.client.renderer.RenderType;
- D' B: G1 y: Z$ j! d7 z - import net.minecraft.resources.ResourceLocation;* ]* u" [+ X5 d1 A) Q1 O; e( @7 D
1 r' V# E9 o' \4 c; w: f$ f/ o- import java.util.*;8 _9 M% w+ A( g: B* w: u
5 B9 H$ z3 A$ Q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* l1 q* K$ ?0 R* d# U t
- $ ?! k y9 [# ?: A/ i
- public class LineRender{( ^ E& M. H* @2 d
- private final PoseStack pose;' F$ Z2 X4 A- o# m# g7 B; X" w
- private final MultiBufferSource source;
! q# p8 d/ ^; C - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' J( T( ]# e* B8 D. q2 q0 c - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 H# |6 O+ Y) i( s+ i5 y% Z4 b - + I3 Z0 q- p& F4 E- ~
, y- ^% L3 w; y- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){5 O0 g7 h1 Q) t( k+ _- h
- if(x1 == x2 && y1 == y2 && z1 == z2){
, p* k! \% ~ w2 q! y/ ?. B2 V - return;6 L: e9 P2 K7 q# `9 G7 i- q+ T3 w
- }
( {$ [( \ ~% |1 S - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 m. p% `- z1 T6 e6 M
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( G& T$ m, R: @; t" I, G- v
- }, _2 r8 q$ c* B
- pose.pushPose();
/ m& g/ X8 G: {+ |2 ?: |0 `) r - final int newLight = convertLight(6);
: O4 B' `4 q1 u5 `' o - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 J! s! O, p/ L) U% [9 i( b - final float lineHeightSmall = (y2 - y1);
- }1 r! B- w0 v4 ?5 X2 |% X - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
2 j, @ Q8 J- }) ?4 g - pose.popPose();) }/ l. U! B5 P- C- q
- }+ }* ~3 S% c& V( B1 f
- _1 l% u: \5 p* ]$ S& T8 h- private RenderType getLayers(String texture, int light) {# |8 N4 Q3 x" j! X9 M2 f [! |9 l- c
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ u) O1 r4 J7 d
- }# N8 a7 j3 e1 s: D
) r; x% h* D |, t# x {- private RenderType getLightTexture(ResourceLocation texture) {
/ |7 s: C/ S2 J& m5 m - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
^/ b2 G' Z: X" C- w' H. r - }
1 `+ P$ ^' W) z* j; Y8 z
/ E' u) e5 `- L8 r d- private RenderType getTexture(ResourceLocation texture) {, X0 g% |1 j6 ~. Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ o8 ], Q$ @2 Z- A. S9 B - }
* v& _0 d0 d6 B5 z! w* m. v n) d - : f6 E. d: n( s9 q; d
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 o& [) E! B% _2 W$ Q0 p% r - if (cache.containsKey(identifier)) {
7 {$ u* j' ]3 v2 w6 H& F1 [ - return cache.get(identifier);$ V2 m0 i; {& c# m% n# ~
- } else {7 k( }! k3 }) r1 W
- final RenderType renderLayer = supplier.get();" g4 g3 ^+ d4 q6 G/ @$ @
- cache.put(identifier, renderLayer);
9 m9 B3 R4 v( K$ O- j: ^8 t+ e - return renderLayer;
1 ?; S: ^9 R4 O% X, u8 U" X" m - }$ y- A- v4 I/ x1 h3 E: O S. U* r
- }0 S8 q+ e8 P! i; E& |. |5 V/ S: C
- }
复制代码 |
|