|
|
4 x: H& d% d4 L8 K& |8 K- k
行,这个怎么样, S9 }3 a, z- u
- package com.xhg78999.mtrfac.render;
5 Q# \+ w& c7 H5 S - " ?6 t8 B+ e0 ]- j" Z& c* ]
- import com.mojang.blaze3d.vertex.PoseStack;0 n c* b! Y& T. B1 j3 G r
- import com.mojang.blaze3d.vertex.VertexConsumer;
0 K% ^. a* _. S& Q - import net.minecraft.client.renderer.RenderType;
G/ w4 P& j1 J+ l0 M/ ` - import net.minecraft.resources.ResourceLocation; ^6 l6 f; d B4 R- f! r
- |+ N/ Y0 T4 x, ~) d- import java.util.*;7 h' q T I Q6 W( v; z1 r4 p
- 9 Z) Q9 b) y% P5 j* M4 U
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. X# O3 t7 |2 p8 v( {; X
" Z& |8 s9 A6 `! o- public class LineRender{
7 y% V: Q1 v1 d1 P1 O3 a - private final PoseStack pose;
+ y( ], `) [+ M/ w& P3 B2 c# ?5 }. S - private final MultiBufferSource source;# s% K4 n0 j" [5 O, e
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();% E/ L$ V9 n1 q' [/ d9 \) J" B
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 U, s2 d- Y3 F/ n: s - ; t% c2 p! Q% G* G5 `
2 g* `5 x; [% |- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' B8 ^6 r4 M# { - if(x1 == x2 && y1 == y2 && z1 == z2){9 B% }: R) @. t8 G4 I/ [7 X
- return;
, o# u# `) t1 B0 k - }7 A8 j1 m( S0 |1 G$ z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
/ h; L+ P# l* b1 v+ D" S$ I* n0 w - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' o) ]+ l, D% ^" ]9 g' y
- }! R- x+ u, r, t* g/ W* b
- pose.pushPose();$ s) R/ M a7 V/ Z" Y+ I
- final int newLight = convertLight(6);$ Q# J$ P( q. z& [
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));) V/ j# p5 N& t: ?( p
- final float lineHeightSmall = (y2 - y1);! j0 e0 ^' E7 [' X( v: f
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 J( X" v l. X. |
- pose.popPose();
( @% ^% d$ X9 [6 g* S - }
/ H+ b; Q& L6 A; L3 u* U) j - ( V2 w- B% p' w' Z! {
- private RenderType getLayers(String texture, int light) {
+ J+ w, D0 O, o5 N9 ?! o+ K+ F - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 L1 C& v/ i$ N$ p H
- }9 K) m( B% y9 [
- / b3 M7 h9 {3 X: D
- private RenderType getLightTexture(ResourceLocation texture) {
! J: L: Y) l; A) D" L" S - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);0 r; r+ |0 z! H" \
- }
- Y0 w2 E. S/ z% g: o
' k3 q/ }$ S* [4 \/ r# m- private RenderType getTexture(ResourceLocation texture) {4 n2 ^! p* i) z/ p' V
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
* ]6 E/ j/ i8 y# E! n( {/ i$ d - }
, @* P& ]/ L2 ~5 M
. ^" b+ N" @' G( P7 A1 k% h: e- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 i6 m2 t( j1 y! \% z' d+ Z - if (cache.containsKey(identifier)) {1 ^/ F+ v, |( s% S
- return cache.get(identifier);- e9 K# s- o. C
- } else {
2 r, Y: g+ l: o" k# W - final RenderType renderLayer = supplier.get();
1 P; O' ?6 T& X - cache.put(identifier, renderLayer);6 J; u* {! Q& D1 W# f0 P
- return renderLayer;: Q% H# a0 v7 u. L: g8 b
- }! u8 c \! l2 X
- }
- R& A, K0 I9 @; A! ~ - }
复制代码 |
|