|
|
# M3 [+ M/ V2 A0 J2 r% w, A1 f
行,这个怎么样
$ d& G# v; @) H H- ^- package com.xhg78999.mtrfac.render;
* f' `' S: j' o% J J& Q" u1 R - : |' k/ L* F9 s# X
- import com.mojang.blaze3d.vertex.PoseStack;2 v, v1 Z/ X/ X5 g" g
- import com.mojang.blaze3d.vertex.VertexConsumer;
$ Y2 R' l- w) O( O - import net.minecraft.client.renderer.RenderType;$ ~6 B+ ^) P1 y2 x
- import net.minecraft.resources.ResourceLocation;# W- X8 a# ]; y. n% k# G
, \, z/ r* u0 E3 ^% \7 Z- import java.util.*;+ f0 @4 {& w- o
- ( K# Y* X6 T2 C0 ?+ k! K# c% S; z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( H2 a) m1 V, k( }: s ]
9 u; M0 Z% W$ ~9 r; l( a; M- public class LineRender{7 K/ x' D* t+ X: y$ o
- private final PoseStack pose;
5 U+ M9 d* ^0 p% Y' G - private final MultiBufferSource source;, w# S% q* g# i3 D1 B8 x% M6 Z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& n$ m$ |. Y7 C& x - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( I$ g; Z* G( b& x) P$ p# a) e
+ k7 o+ t0 j# S
1 ?' j% }4 I5 S, B- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){# E; I' A" ^- O) h1 E
- if(x1 == x2 && y1 == y2 && z1 == z2){$ I7 N: V) F* `' _; T
- return;
+ ^! p, ?# j' |0 s6 r - }) }1 u' t7 z0 U$ q3 B- x, K4 v
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. X8 x- D# H4 M5 M0 ? - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");5 p0 l+ u' K$ s
- }
* s0 h& F" ?/ }/ h - pose.pushPose();
1 l0 P# h+ W ]) M - final int newLight = convertLight(6);% e- o, C+ U( }# Q T5 v
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));) f' t) c! J( t4 o$ ~$ E4 E/ T
- final float lineHeightSmall = (y2 - y1);8 O9 k8 c6 j! }
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ j+ d" K/ e: e - pose.popPose();/ }' e: P# L2 }* |3 ^! A: S
- }) X2 [- |& a$ k g: T; X0 a7 ~, u
& M# P' J( `. R4 {! Z! V8 d- private RenderType getLayers(String texture, int light) {* `8 a2 l" o8 @ f
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# @2 E7 Y3 D3 `: X - }# P% _5 d3 \9 ^: S9 t! R( w. t
5 _2 X% L9 R; R3 w) o- private RenderType getLightTexture(ResourceLocation texture) {0 d0 ~, O& t; P2 @3 V4 B
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 \& C& F0 p- J; Q& L, I( w - }! l1 E( f3 i3 z* Y% }
; X& ~2 C+ c! ^& L- D7 ~! Z- private RenderType getTexture(ResourceLocation texture) {& F6 O7 d! s" ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 n/ t$ `9 o: _# [4 k# r% P - }
* C8 c% k7 K0 P7 b9 W, r: c+ O) ]8 T3 c
$ l# i- e5 a+ ?$ C3 e- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { W7 m( H" S+ R1 o2 P+ {* m
- if (cache.containsKey(identifier)) {9 o' @" }# @0 `! A5 }: w
- return cache.get(identifier);
- w# [! K, S# F( [( ? - } else { g0 n; `. p+ T8 F' w+ s
- final RenderType renderLayer = supplier.get();+ |" O) Z( E4 f* c! }% F# h
- cache.put(identifier, renderLayer);' V9 R* i4 n& i) N8 ]
- return renderLayer;
; o, b G, a* z, c - }
/ m( m3 w& `) n# a; Z% E& F - }) h" ]0 y- O- S! Q
- }
复制代码 |
|