|
|
' c) p5 q7 V! z* K
行,这个怎么样
1 v5 T! ^3 w, [( i8 C- U5 P$ V5 c& d- package com.xhg78999.mtrfac.render;% v, E/ ?* \) L& M" i7 p! }
% I }0 r% q3 N$ Z w- import com.mojang.blaze3d.vertex.PoseStack;7 t' V4 M4 S- x. J1 z
- import com.mojang.blaze3d.vertex.VertexConsumer;1 L. K; G _) a
- import net.minecraft.client.renderer.RenderType;( M2 B, p3 Z" h
- import net.minecraft.resources.ResourceLocation;
+ T# y- r, g7 k7 R - : S! @ h1 @+ d
- import java.util.*;# j+ |* r P* I
- ( s/ A9 O |: x3 y/ K. }4 I' f
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
1 R; ^& r. Z6 |; O! ^% I* ~
* J2 i3 f" L q2 i, b- public class LineRender{* } {# w( V# A5 S+ T P
- private final PoseStack pose;
8 C/ D! u4 {$ B1 ?' h - private final MultiBufferSource source;
* l1 N* C+ R! E: D - private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 h U+ E0 k, f4 O& B' _* K H
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();, S9 [7 k+ ?; f! f& q0 M; d
4 e( V! B0 t3 |9 m- ~$ H2 a! [: e- 8 G/ r% {% M7 \$ }/ c) E4 H
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){* n$ T% U1 U9 t7 d
- if(x1 == x2 && y1 == y2 && z1 == z2){
/ U2 x$ N# A8 Y; s - return;0 K# ^! v. _1 K& j+ C' n. s/ s5 o0 M
- }$ I2 o) j& w: z* i
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
P# L7 F( z% z1 i( S, B" O - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
1 C( c" w3 B- i' } - }
. |" z _* d9 g/ p$ c - pose.pushPose();5 c. _ s) |2 R; k0 v1 D
- final int newLight = convertLight(6);. k1 a+ j* j5 q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' N8 i/ Z# z, ^+ z; N" V1 E - final float lineHeightSmall = (y2 - y1);
0 w) [+ R1 } w2 h - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 t4 }# d" A4 e# m; R3 |: q - pose.popPose();
5 n: `$ _% s# h8 l - }
, z; E: F. n( ` - ) L5 G4 U# t# A) ]6 y, n
- private RenderType getLayers(String texture, int light) {
& C+ G; J1 s$ a7 s - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 K# {# d- u9 P1 {& d9 g: [ - }
& l A* L& D% U9 h2 t& ]0 {# c1 G) L
7 [5 C3 i: p, u( b. j- private RenderType getLightTexture(ResourceLocation texture) {
' K% R' |' h1 G - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);! I* v8 ` Q! i
- }
% @& G8 K! C- v2 l! v8 g
; C1 b& i3 U `- private RenderType getTexture(ResourceLocation texture) {
3 k' Q) ?$ C% T4 } - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
1 }2 n' B3 O' D# E1 w) E l+ x - }
* P" w$ J) I4 \, @/ w/ h! ]9 E& {
# A7 }7 j. g0 `( F6 P2 T- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* b5 L) g' G3 i V* U - if (cache.containsKey(identifier)) {
; b7 ?! s% n: Y! [6 o - return cache.get(identifier);$ T( T& p0 |" r6 b+ ?8 p% i
- } else {( N6 K+ h, w }: z# T# {
- final RenderType renderLayer = supplier.get();5 ^9 [4 C5 k* }$ E7 L7 j: Q9 x
- cache.put(identifier, renderLayer);
( ~- ^5 e! C+ |/ O# g - return renderLayer;
& _* g3 g! k# ~- @! R6 E - }8 @( G6 r$ y8 G5 ]: O) H
- } R, Q2 w6 ^0 j2 k3 e7 n
- }
复制代码 |
|