|
|
2 E3 D( P# o! t, N7 @% o5 g9 N行,这个怎么样/ k& [( m2 Y2 J; h$ @8 v' A, g
- package com.xhg78999.mtrfac.render;
3 y3 p( p6 E0 D9 T - ! ]$ @5 l8 m. ^4 @4 k0 W
- import com.mojang.blaze3d.vertex.PoseStack;
0 s2 E9 B0 y) y" @6 `9 J' ~4 q - import com.mojang.blaze3d.vertex.VertexConsumer;
% N' I1 z+ A: M0 w2 `4 k; A - import net.minecraft.client.renderer.RenderType; t% Z7 o$ F K1 K$ N* t
- import net.minecraft.resources.ResourceLocation;
r# { K# H, U* t( X* I: d
2 A; g/ g' z. [, C K8 X+ x5 J- import java.util.*;
6 H& M" y) [; t; T
6 v, v: f" r5 W& D" Q! N ?- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(5 w' {& M1 y- C1 b) r, m
- 9 b1 y# c, o6 Y$ s
- public class LineRender{
5 S. V3 {+ ?# _ - private final PoseStack pose;+ S c: C3 w8 i/ o2 K( w( o5 j+ Z( z
- private final MultiBufferSource source;- p4 A# i$ {8 l
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();% O4 t) s7 W" t7 K
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
# b, v' e6 r$ n# } - , }; T) s% n+ z6 o6 V7 Z1 {. N
0 h1 _4 S% a5 S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
( q0 E7 B0 M$ v `5 D+ q/ J. u - if(x1 == x2 && y1 == y2 && z1 == z2){
2 T& `4 ~5 A4 b - return;1 s/ D* l" g( X2 V# E1 t) ?: v% w$ A
- }
! n6 t: `1 L/ M. A8 G; u! { b" f - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: k# `; V1 I- n) X
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* [! R' o6 P4 {% I* V* [7 J - }" l$ I: u! J- H4 M1 z/ X. L4 Z
- pose.pushPose();: @; X L( u( e, z) K3 Y. h" y
- final int newLight = convertLight(6);
" Q, t6 X2 X) N9 L, V8 }: y - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 U4 E; h- X2 b3 U5 u - final float lineHeightSmall = (y2 - y1);
& j" W8 v' o1 r, ?! h$ ^$ ` y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
9 m7 w$ H) u+ P: h - pose.popPose();
: k3 L0 b% ?8 }. Y' \6 r8 z - }
% J8 F' s" |% t. ^% h' n
5 t4 L, y. z; c0 h. h# F0 e* T# Z- private RenderType getLayers(String texture, int light) {
3 {9 t( ^) ?' J. D7 h! ? - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
* x' ` D3 m% z" K) t7 s - }' Y, u' O# k" m# T+ P
- # O: T: o, a: A% j7 S
- private RenderType getLightTexture(ResourceLocation texture) { G0 f) @5 z7 ~2 H3 G* ]5 \0 y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);( U7 Q [% l! u& b; k, ?5 G
- }
9 X# I) L3 y$ j3 [8 @
1 [4 x3 W4 O# p; ]& d- private RenderType getTexture(ResourceLocation texture) {" a! D$ g5 {; ?
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
9 i: G% ]' b3 m4 p- d; O0 U. j - }3 R9 O/ n3 h+ f2 H6 u: Q
- ' t8 n/ W O$ {5 ~+ C3 S x. s- S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { a/ h' F0 Q' x: b( T, X- y! o9 X
- if (cache.containsKey(identifier)) {
% F. G n7 W, o! D - return cache.get(identifier);
5 n0 _9 g* o+ I9 r4 k& P - } else {
; e( r* c2 Y; A H1 ]3 b - final RenderType renderLayer = supplier.get();
# I. _3 d4 e; Z. d* F - cache.put(identifier, renderLayer);. M; d5 \5 l( O" g
- return renderLayer;4 H. s/ O3 z5 b }% c. c$ _- D; J
- }
8 R9 [1 v! ?; t+ L! v - }
( y0 M7 \: v4 L, z3 D$ m" Q* d8 z - }
复制代码 |
|