|
|
8 Z8 r# C4 E# j8 p! T2 `9 n行,这个怎么样
; l* ^! {$ T7 z1 e& t1 ~( S- package com.xhg78999.mtrfac.render;4 I- U( w; {% d7 N# N7 Y' v
7 v8 [! `0 N( k" |9 Z- import com.mojang.blaze3d.vertex.PoseStack;
0 B4 @6 y) w2 a/ ~ - import com.mojang.blaze3d.vertex.VertexConsumer;
7 { N1 ?8 w" t! ~( j% D+ q - import net.minecraft.client.renderer.RenderType;
% s7 b' j j% B/ R# H- Q {+ { - import net.minecraft.resources.ResourceLocation;0 z" h$ @' s( P2 `4 r; `+ {7 q# F
- & M) J( [, g7 ]# l# Y9 K) y3 ^0 }
- import java.util.*;& D3 C& Y' i- D9 h- b, k
- 8 R/ s3 `+ [: V/ \
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* N9 w8 z$ T; k% U& C/ n
- V7 D$ v1 I/ l- public class LineRender{
6 A7 I4 S& l1 h$ ` - private final PoseStack pose;
5 m" X1 k9 [, F3 H% |: I$ D- e0 N8 A - private final MultiBufferSource source;
% T7 @! G0 O( {* }- [: I. T) s$ _ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: B! z' Z0 o% T$ r8 Z0 G3 Q/ j; Q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ I) C& d' M1 K0 e1 C5 W
# |$ u* m7 m+ w/ r) f- + X# U1 w% s" t
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 Z- O1 ^& b5 X: s - if(x1 == x2 && y1 == y2 && z1 == z2){
6 ? w' Y+ Z5 n A! ]; F% [6 k - return;
- ?$ d+ q8 W/ p( c( | - }* ?5 ?* S3 r/ c4 \3 z# d) A2 h& q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, l! p ^' v( T. ^* W
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");/ f- y0 N! u) [3 X' |% S
- }
7 w. l+ y, K0 Z! [; w7 n - pose.pushPose();. j/ J" i+ ~/ \3 d6 N3 R t
- final int newLight = convertLight(6);0 v, |' x; W& Y9 |. f
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));: E& f9 p% w& s. _% U0 ^, x6 n) ^
- final float lineHeightSmall = (y2 - y1);: M# v5 A3 L5 G7 Z
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 c0 K8 W F- P: @
- pose.popPose();2 y0 d! J) B& b0 A ~
- }6 F1 R8 u D% x8 {
- 5 H1 B0 V$ E) @4 P) n' b* E
- private RenderType getLayers(String texture, int light) {
( H" ?/ \8 T- W1 D/ a6 c - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ X4 ] b" q! v5 \5 w( E0 { V - }
, X) a, G' b7 r5 X$ h$ R - / c$ F( v. I- |8 n
- private RenderType getLightTexture(ResourceLocation texture) {% X7 }" U! @) M, b! \2 m
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);0 C5 N! {3 u/ V1 b6 H4 G& V
- }/ O, k- b [3 m6 z
1 n3 X1 ^6 l* O0 x% F- private RenderType getTexture(ResourceLocation texture) {
$ g' b) \+ S4 I" l2 c" g% o - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% f$ i8 H: i. I2 n! U/ C4 G - }
2 d% w+ }2 i" ~, v1 ~ - . g. w g4 p# I6 c1 m- b1 }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% W3 O$ g* I' Y. [
- if (cache.containsKey(identifier)) {6 h" m/ E1 A9 y6 c5 j& z) U, W: d
- return cache.get(identifier);5 J; R& T2 e3 ?% z; c2 a. j
- } else {. v2 o$ d/ A' p6 W! h( P" _
- final RenderType renderLayer = supplier.get();
7 ~, D, C; \' _& G' ^" Q6 q. V - cache.put(identifier, renderLayer);! W& i3 t9 S9 _6 M
- return renderLayer;
4 z& j+ f0 q% @8 n+ V4 Q - }
7 J# H+ q [6 {. U$ P( A, \3 H - }
; e: i2 C3 @& s" D, `; B6 @$ b - }
复制代码 |
|