|
|
, d. h3 k2 g) s& e3 ]* g
行,这个怎么样
! }7 \( o F8 l/ O* F$ P- package com.xhg78999.mtrfac.render;1 H" n8 d. g7 [& t3 m2 ?: b% a8 f
- x+ X y5 |5 _3 y' u- Y
- import com.mojang.blaze3d.vertex.PoseStack;
5 l3 i, Z; l3 L0 B7 S+ s) p# { - import com.mojang.blaze3d.vertex.VertexConsumer;
* [* @ |* Y: b' a - import net.minecraft.client.renderer.RenderType;
- x: j- B& {! _8 N - import net.minecraft.resources.ResourceLocation;
" R, G- `0 H5 e3 \4 l4 k* q
2 J! U; v P% m5 q, n. W- import java.util.*;
7 ~3 T9 A& C0 t% M
. S- y" Z: l: a ]7 `- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* E" r2 L; U% e
. O" x/ Z1 @: C. @1 k0 K% J- {- public class LineRender{
8 M, u& H {& G, A' i+ ` - private final PoseStack pose;3 {9 Z" K( T; T! |) A% ^ r9 e
- private final MultiBufferSource source;+ V, H$ b! m( {( h9 m' C- L! n/ q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();1 v! i, I, @6 d1 o3 |4 ?; U5 a/ w( Q
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();; Z& y6 B" [7 }8 V5 e0 F3 ^! r
; Q( Q! }0 o' {
- \4 u- _) q( f0 k$ }% p- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ T. T" p. q; Y
- if(x1 == x2 && y1 == y2 && z1 == z2){1 P7 i! f4 ? M* ^8 |
- return;( G" a9 L `, R; J
- }7 U. R+ B' Z" g8 }6 i
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 R- H) b( u! ~) K% Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. M& G+ w$ @/ }1 C- d5 N
- }
' f, c/ r' f& ^ - pose.pushPose();$ E. R+ n& N+ ?
- final int newLight = convertLight(6);' ^$ X' c/ ]$ F
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' r k" ]! h+ c$ a# U4 y. t - final float lineHeightSmall = (y2 - y1);; t* {+ j# Q) A: i9 g8 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 l$ I' n- t* j: R$ U1 b
- pose.popPose();6 d7 ^. }! G5 R6 y- a0 h
- }7 l- T2 v. i+ n r# A
- ' M8 [' R n' [7 T9 j3 w8 ]6 \1 V# I
- private RenderType getLayers(String texture, int light) {
7 x0 O' Z3 {1 \2 k+ v4 n - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 h4 B0 f% r! Q1 Q) Q - }
8 C& I% V! [! Z) h- {, W - $ W* H2 y, d. N( ]3 X! p
- private RenderType getLightTexture(ResourceLocation texture) {% i7 M9 M) R& q
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# m- _0 t5 R9 ]) R# K% v J - }
& l& T8 R) o! _ - " E4 `* \; a* Q# ?! r" W
- private RenderType getTexture(ResourceLocation texture) {' w2 i" o: T+ s! n
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 | G$ q Y1 g( r! m! d$ H4 s% C
- }
3 k& p r8 D5 w6 v+ z: I
3 F7 ?4 ^( {- W) Z/ e- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {! H/ O" I. V* U
- if (cache.containsKey(identifier)) {
: G% W& M8 \3 N3 w+ s - return cache.get(identifier);. a0 d8 O; g. {9 M: m+ R7 K9 `
- } else {0 e" a" Y& s7 l/ Z6 N" e% I( G
- final RenderType renderLayer = supplier.get();# C; o3 M8 P' ]3 o+ K5 u; k
- cache.put(identifier, renderLayer);8 n4 E9 b, @) {5 [0 x, b- ]' T/ q2 E
- return renderLayer;
) N' Z9 O2 b: I' R. J+ r6 x0 e. d - }+ ]) m: U7 r# P5 J4 g
- }
: X( s* [: ~# K5 m/ u - }
复制代码 |
|