|
|
9 x# J! a+ @: L# ^" W2 U {行,这个怎么样- _3 Q3 k3 P) V2 F2 @* {
- package com.xhg78999.mtrfac.render;# }2 H+ |7 j+ S8 W; A- `
- ( v6 m! u- A! n: `9 z2 T
- import com.mojang.blaze3d.vertex.PoseStack;5 V# G4 n9 y, R2 _' H2 [: ?
- import com.mojang.blaze3d.vertex.VertexConsumer;7 b, Y% z S/ `0 J7 j
- import net.minecraft.client.renderer.RenderType;9 j! i( ]# P) O9 `7 O8 {$ _
- import net.minecraft.resources.ResourceLocation;: R9 b( S. J# @: h) w ^# v4 z
( v3 U8 f" C9 k$ l. _' M0 p$ G0 x c- import java.util.*; [+ p0 x6 b. K
0 P/ m( h* Y8 C7 c0 f- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! `# |* g Y+ E! j8 D
* b+ V" W6 p0 a7 I- public class LineRender{2 J/ K- h6 q9 x* R3 O6 v; d
- private final PoseStack pose;: x, h1 O& ~6 j( C8 a) q! A9 H
- private final MultiBufferSource source;
4 r/ l% B- m8 A/ |- | - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 s5 d6 H' i' S - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( S' o2 o) ]1 e h2 l
# \4 j$ ?/ q7 J9 b8 R: X) o
# d2 i [( p/ J- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 |& f% r" a( T* \2 d0 ` - if(x1 == x2 && y1 == y2 && z1 == z2){
* J: ~4 M' R: X3 g& o5 K' L# v - return;; ~: @9 v) X" \3 o9 T" w5 b* B
- }
9 y5 T, y, p4 x# J c - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
T8 ?" b9 a/ [1 ]0 G$ G - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
P+ \) S S3 O2 T3 e" a - }
6 C( V0 {; X; C, Q, C - pose.pushPose();6 G' B- l1 D5 T6 @/ ?8 {+ O
- final int newLight = convertLight(6);6 m: Z. h4 m- i* O
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 F2 N/ j$ c) O - final float lineHeightSmall = (y2 - y1);
: z& W( S2 K; P' ?2 _/ s - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
9 B+ ?8 q. }" ?2 @% } u. e - pose.popPose();( Y% l6 o6 y) j# _. W N
- }
/ f- i# ], v+ c) K( B- N" A4 `
. E9 p# C* ?) c. [) C. i* Z8 ^- private RenderType getLayers(String texture, int light) {' {3 I/ W' Y* ? @
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));6 M2 Y7 x& [, N; ^* y2 `6 h- f
- }
@/ S. V1 Q& i9 Y) A - " C1 q* J9 }! @! m; p' h) F
- private RenderType getLightTexture(ResourceLocation texture) {
2 l' q0 h. M' N" u3 G8 } - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 x+ m) t. h& X/ n% c
- }
|# q% F: i2 j+ C
1 I+ K$ c4 u; F9 n+ x0 M* j8 {) m3 f- private RenderType getTexture(ResourceLocation texture) {$ B; r8 |( w/ q& c
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( m/ ~0 L0 p# }+ C - }
7 M- ]! Y& e: M/ g) L* n
- H; l2 L x5 d( h- L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 i# S' v8 o# {7 R; g8 @& g6 }
- if (cache.containsKey(identifier)) {
% M+ ], H" z4 b/ e - return cache.get(identifier);. s I2 L; C* y/ Y ?5 h* a$ D& t
- } else {
) N: C5 G) q3 u( N: J' A5 T6 ` - final RenderType renderLayer = supplier.get();
4 ^( q3 y& C- n6 A$ j6 h - cache.put(identifier, renderLayer);7 G j/ b5 x. L) m; x5 D
- return renderLayer;
$ h/ v" A0 d) W, K$ E/ U - }
* C* V. B5 S! f2 J% i/ m - }- j1 l( c4 ~! l$ A M3 s& s4 z
- }
复制代码 |
|