|
|
) L' \9 Z# N. z7 Q+ _) c行,这个怎么样( S9 x7 D* b7 D! N
- package com.xhg78999.mtrfac.render;
" B8 h4 S; a* D* O$ N4 x. k4 L
: f, l0 i) n. l3 o7 j9 A N- import com.mojang.blaze3d.vertex.PoseStack;
u$ {2 N$ N7 K7 \. }& k5 E/ h - import com.mojang.blaze3d.vertex.VertexConsumer; H2 R5 [$ B# s7 I* z" L6 b" @
- import net.minecraft.client.renderer.RenderType;/ f* I e% R/ u5 z' b
- import net.minecraft.resources.ResourceLocation;6 _; A% }3 R: f) @
- + l* \/ z+ J* G* L1 v/ H
- import java.util.*;; s) t/ q# p% C) {
- 0 e, G2 T& n- ~! ?& w) w" U; v
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ y. w0 k( F. u2 p - ( c, @' F }2 T' [& n1 {0 j: p; Y
- public class LineRender{$ [! s6 P9 W' S. a
- private final PoseStack pose;
5 ?" @1 n4 V3 Z6 k% G; y5 a' V2 J0 f - private final MultiBufferSource source;. ^9 ]9 y1 Y) q' V$ }4 A
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! n4 m$ r8 P! f' \/ y; ^ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, @& p: v# C8 f8 e. T2 B
5 J; }1 L5 y" T, R+ r. B
! U8 k& E1 u7 o( o& }- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 k g8 q# F! N0 K ] - if(x1 == x2 && y1 == y2 && z1 == z2){: c2 C3 q H4 T
- return;3 e3 k- `# q' [( P6 W: A: B: F0 f
- }
w& S- `) n2 L0 P E - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 R* w1 Y) U( h9 q
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 m7 }* e) X* k* M" B& _
- }0 ^8 L: [1 _+ c/ r- x
- pose.pushPose();/ K: K' Z$ ]1 r. ?& m. N
- final int newLight = convertLight(6);
. U. l4 P Z2 t0 C. X* G - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( g* ?/ U' Y: X7 s+ L - final float lineHeightSmall = (y2 - y1);3 l9 Y/ a. M3 t+ `6 g7 o J! u1 D
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) _4 B- c' I. x - pose.popPose();
5 F% R% U) ?8 W) h - }5 q5 ^, F5 m5 B4 Y" O. d9 Q
4 S7 c Y- G7 i- private RenderType getLayers(String texture, int light) {
) b4 ]3 B6 m, F9 C# m - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));) E+ p# p( F! Z2 H! ]$ s
- }+ g. J e1 y$ n/ ~7 Z
- 9 Q0 ~$ P9 j- h( N
- private RenderType getLightTexture(ResourceLocation texture) {
; t& m' N6 K. R E" P - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 ~ P0 |9 y% o
- }
: e+ f. S$ Z6 V5 r8 J( v - _" w: q# P' d5 E4 x0 M
- private RenderType getTexture(ResourceLocation texture) {
- K. i3 Q. x# n& w$ B - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' }8 H- X# k, X# h - }. {7 x9 d2 W2 E; g
- ' g6 c9 A+ b# N }& K
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* R# @. n6 _+ o/ U9 n
- if (cache.containsKey(identifier)) {
0 O" K* i3 l1 _; \) m" B- Z - return cache.get(identifier);/ s, u1 J( q5 j3 {
- } else {
' F- P0 C: D! |( a/ h - final RenderType renderLayer = supplier.get();
# l. U( a9 f& R | - cache.put(identifier, renderLayer);* |5 f) j( I/ S' y% P1 C1 c; ]
- return renderLayer;
* j1 W" Z# [/ |( _ - }6 o. @7 }0 d5 t: U: x0 h0 a
- }% M; K. p5 r: ~0 U2 ~2 \
- }
复制代码 |
|