|
|
% ^# {2 k6 b2 t9 H4 V4 K9 T
行,这个怎么样
! S7 m& [; t' a% w8 Z# E0 M- package com.xhg78999.mtrfac.render;
3 v& I% X" J: `
9 f& W/ `6 r; _- import com.mojang.blaze3d.vertex.PoseStack;
8 y% E+ D0 G1 V. t+ @ - import com.mojang.blaze3d.vertex.VertexConsumer;, m Q) G- J9 y0 \% r' k
- import net.minecraft.client.renderer.RenderType;
9 Z5 r8 S Z) S$ U' ?$ U - import net.minecraft.resources.ResourceLocation;
" e$ d$ H# C; t/ M7 m - : Q& m' l# \8 |7 p
- import java.util.*;
2 n$ d: |$ d* n
% w" n$ ?0 S, j. w- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(- Y- a$ o7 W' ~; C
- + [) u- m9 x3 M* \7 ?
- public class LineRender{, H) W0 s% O5 |' s9 L
- private final PoseStack pose;
, I" v* z" g. `( n - private final MultiBufferSource source;$ D5 ]) g. t* {( k4 G2 m/ a/ F
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( z5 K0 p- c) H: A- F! Y" B) p% F
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( b: ^: D' y) g3 R" v
4 E& y- t, `- t' j; _, O" h. s8 }- 1 d% G" r9 ]. n# o' B
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ @' G6 v" x( f' d1 A0 W: b' K
- if(x1 == x2 && y1 == y2 && z1 == z2){! f, j( I: f/ K# f; N, j8 ~1 s
- return;
1 y% Y( g ^2 c' d- V" [ - }+ h* E& _7 `% p9 _2 e
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 Q( x; H& b! n$ t/ i& A& P
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: ]$ B3 {* n% o - }
9 J8 \4 ^) J+ j* n - pose.pushPose();! w* }3 J# p6 Y% L- U H
- final int newLight = convertLight(6);
. F6 L9 n$ l+ ?. b. f - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 l7 o5 j$ Z5 c$ ` - final float lineHeightSmall = (y2 - y1);
2 a `: y( q0 z* c - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);" L% {# _8 b+ t+ s @
- pose.popPose();
- U; y7 `# L2 d* ]/ o - }3 d3 I; }* }0 r" t6 O+ Z
- / t: ~$ z! h! F4 h& A$ b, S! ]
- private RenderType getLayers(String texture, int light) {& g0 {3 ?: m8 F9 N# h, M4 T
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));" [1 V! R5 ?$ `9 o) C2 d3 \6 i) c5 p
- }
" H8 N' I% l( w" |( n: ]
4 U7 r: P1 Z8 R' s. k" T- private RenderType getLightTexture(ResourceLocation texture) {
* c2 A; A, x& ?# t - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) f. J2 K% Z" x
- }) Z& E2 d! x) i; r! y: ^( w
- 1 N0 ?! ^7 F1 B3 ]' ^
- private RenderType getTexture(ResourceLocation texture) {# T' ?1 T. F3 T
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);. a8 m- Y6 H, B% k% A
- }
/ Z! n E9 f( g0 }2 z, | - ' K4 p4 w# J# i0 b4 r( T% M
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, L+ J$ f' [/ b) ~0 S% U1 o - if (cache.containsKey(identifier)) {
8 o3 Y; Y e, j& I& @, h* ~ - return cache.get(identifier);6 `% l* ?' O/ I. R& P3 z8 U2 w
- } else {
9 }* R$ ]0 G. G% v( c6 c - final RenderType renderLayer = supplier.get();& v5 {' o1 o x) a" D8 A: A5 ]: U
- cache.put(identifier, renderLayer);
$ b4 X; q* w" A: _ - return renderLayer;* J: J D! X5 C% u" J+ F* _! X
- }# ]+ j6 i3 n% x/ z! r, O% k
- }! W4 o0 `$ u7 g+ ?# N- F* _* ~; w
- }
复制代码 |
|