|
|
# {3 y; O- v* Y B4 t( P/ Z; r
行,这个怎么样
* Q, B% L# h/ C K$ l: \9 ^0 m- package com.xhg78999.mtrfac.render;
Y( |* u0 c* c$ i3 B) Y+ ?
6 v4 ^& Z, n2 `7 e7 k) w- import com.mojang.blaze3d.vertex.PoseStack;2 K. P8 E- i* l' S- V' B/ `% ?
- import com.mojang.blaze3d.vertex.VertexConsumer;
% Q7 n% z0 C1 s - import net.minecraft.client.renderer.RenderType;
7 P _ G. Q8 ~ - import net.minecraft.resources.ResourceLocation;
& S. O0 w3 c+ ~$ G/ B; `" Y
% B8 F- O* [# `; G; \9 Q. p) H5 j- import java.util.*;; J0 a: i6 q- P. v' v `, V
- ' g- m' l$ q6 `
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& l+ `. T" i5 {8 n; a2 Q! X
% n3 I5 o2 w" T4 Z2 S2 N# D- public class LineRender{) k. H0 i; w# P ~$ D% V9 H
- private final PoseStack pose;
8 @( ?0 ]9 g- ]! N - private final MultiBufferSource source;* p/ v5 `# [2 ^" q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" T' H2 q) [, j) Q1 \+ O1 c3 Q
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! T1 C- g$ G2 H1 s
- 4 U: w- [8 f2 ^% R' D
- - E6 X) E$ M- R2 o9 K0 s
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' Z& i! w' x+ V! `7 {
- if(x1 == x2 && y1 == y2 && z1 == z2){; x& `( K5 I% N' X
- return;' q9 U; h$ e. }( g0 J
- }
% l" D | S4 _8 u. F7 j7 k8 J$ e - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
0 ?9 @8 W8 y# P) ?( }. n8 | - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" A* h! M$ j0 m3 G - } c# {0 r' v) T- N( q2 I( q
- pose.pushPose();
3 z4 z. a1 s( M - final int newLight = convertLight(6);
7 k0 H P/ p' l: x4 D, p0 S2 x/ \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" r! Q( | ?6 U+ X( L4 m5 s - final float lineHeightSmall = (y2 - y1);
2 F0 P7 Z' t# B S4 l$ O3 Z* n - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 _$ R/ H/ ~ |0 V/ Z% i h
- pose.popPose();# a6 c1 `' p/ ~6 s, h
- }9 @, t! A4 j) ~! e" L
- $ A, i# z F3 X5 s( Y D6 o0 l
- private RenderType getLayers(String texture, int light) {
& s2 u. G) [& T1 G' J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, v! b' |1 ]1 g
- }( ]2 {5 N# X/ m9 n8 V; Y
, J! ~7 Z1 X+ T2 b- private RenderType getLightTexture(ResourceLocation texture) {* j8 P% [: ~1 A: }0 v
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 L% \5 _6 G1 i, N7 ~. O9 r- g& G
- }! p- d! J( h4 I) Z7 L1 R
8 g' h* l: q- N3 T# y# k: S5 y) |7 {& U5 c- private RenderType getTexture(ResourceLocation texture) {
5 Y9 }, K* J1 P9 Q - return this.cache(texture, () -> entityCutout(texture), CACHE_B);: s9 x0 W* ?- q+ O
- }
' K4 g( D) R5 W: i: ^: l - - Y0 o2 v6 o; g6 |4 _8 B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 {' g! F7 ?: f& ^8 w4 }% \, G
- if (cache.containsKey(identifier)) {) B, [ h( o- N( M! v, ^- z
- return cache.get(identifier);1 N* w2 `& G9 Q( y
- } else {; Y; Z! F4 u$ w1 u7 |# u$ {
- final RenderType renderLayer = supplier.get();
. g" D9 k& l; [# [- I$ K% `0 i - cache.put(identifier, renderLayer);+ O, c* w/ J8 [) C
- return renderLayer;4 X/ H9 j0 F3 c1 e+ r6 a
- }
" B/ V: h+ b5 F# l# u - }
# \- @* @# A7 H# i - }
复制代码 |
|