|
|
- U1 O1 C7 r1 n0 H2 y3 `
行,这个怎么样
8 k0 h/ J* |: w- package com.xhg78999.mtrfac.render;
( i, E# ^0 x) ~9 f2 F2 k
. g; C, f S! B- d0 F: ]- import com.mojang.blaze3d.vertex.PoseStack;
i {3 q* G$ Z9 m g - import com.mojang.blaze3d.vertex.VertexConsumer;# q1 h$ o8 `7 e+ X2 ?! `
- import net.minecraft.client.renderer.RenderType; R) j" w7 f4 N8 b3 ]5 Q) ?
- import net.minecraft.resources.ResourceLocation;
7 U. j! a+ z( O0 ?: g. }1 y) g
- |2 d1 o. _7 M' w7 u: ` D- import java.util.*;
. v" u2 U! W* x$ M; D - 3 ^8 O p5 `4 i% O w
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" ], [( x- P6 [: \8 U/ ^+ V
! U6 \7 }- e Q7 ^ A" Q; @) ]- public class LineRender{
g& m1 P7 H0 f; ?. p - private final PoseStack pose;- ]/ T, S2 x8 u- E7 H
- private final MultiBufferSource source;
) c' ^; Z H0 _; e - private static final Map<String, RenderType> CACHE_A = new HashMap<>();2 d) z0 p: O1 {( m8 f
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 D% }0 S* w' h8 [; r
; {$ ^( }! f$ u0 E- 9 E! v) K8 U4 I/ J& z) c; U# ^
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 I$ ]; P9 ]& g% ~( ?/ s! `' p9 p
- if(x1 == x2 && y1 == y2 && z1 == z2){
- ? g, y% n" ~4 ?0 P8 p$ F. N - return;1 ~8 b p1 |8 U; \ W9 I
- }+ {1 A$ H/ l9 m# o
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 [0 G4 m7 U7 }$ K4 A - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ o/ c3 |, C, g3 ^2 ]. G! ]) s - }
( ~. `# ~" S8 _) v7 w( P - pose.pushPose();' J- [ r- x- M6 Q" Y7 n
- final int newLight = convertLight(6);
, W8 p. l" j. k9 Q" |- ^$ N - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- J: F+ s! ?8 a2 {! O - final float lineHeightSmall = (y2 - y1);0 f" {1 ^' u3 \1 c; d( T1 {
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 L) G7 s2 a ^7 x
- pose.popPose();. p I7 | e; S( r4 H
- }) C4 S* z, j# a1 k; h4 F
N- d$ w/ Q i0 n$ O: t2 l- private RenderType getLayers(String texture, int light) {
/ Z: q0 A9 w. h) s. J2 j! x - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
u) j. o; W9 H, R7 P. I- p6 l - }
$ ?" P; y0 X+ [$ v* H3 { - 0 w* J1 `8 i0 x0 S2 J
- private RenderType getLightTexture(ResourceLocation texture) {( W( `& A$ H4 i, g
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. F" {* {: t( T0 x% } - }8 n% l+ v- \# O
- / T% x6 j. X; O) B
- private RenderType getTexture(ResourceLocation texture) {
0 ]! ^3 |& W6 l4 s8 R - return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ ~; W; @/ {7 S/ j! {. ~6 ?$ v
- }* M- W& J# y8 V9 ]
- ( N( W: Y5 @4 O! ^) a1 e9 o8 ~
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# ^( N6 I+ b% ~% n4 j# c* T
- if (cache.containsKey(identifier)) {3 W: r5 R A/ J; [ k7 w
- return cache.get(identifier);
# X( r* ?+ e/ o* w1 k* G! `' p; K& ? - } else {
, G% u- h; p# d6 K: f4 I& c1 C: h - final RenderType renderLayer = supplier.get();
9 N7 w4 `. o4 q - cache.put(identifier, renderLayer);
0 D# b8 t' k5 `/ b - return renderLayer; ?: E; w0 x9 c; B
- }* C2 d: h( D! a0 v1 }7 _8 }8 r
- }+ b% v3 D2 x, R% R* A
- }
复制代码 |
|