|
|
2 I% Z a0 c" \9 W1 k' a8 f行,这个怎么样
3 s+ A+ p0 q. E! `5 C- package com.xhg78999.mtrfac.render;
: S& g3 _2 n- ~# \5 o7 s - ( J3 H- T" z" O' U
- import com.mojang.blaze3d.vertex.PoseStack;
3 o% X" s% H8 N P4 B- y5 } x! c3 o9 A - import com.mojang.blaze3d.vertex.VertexConsumer;: d5 i, ?# j5 r3 S3 s' o% s
- import net.minecraft.client.renderer.RenderType;* q! B1 U$ c3 ~5 D3 {2 T
- import net.minecraft.resources.ResourceLocation;! E( s2 U0 D$ \5 ]1 [- ^
- * i8 p7 w1 ~6 A5 w8 u9 K) T
- import java.util.*;
: I8 j' h2 H. w - 9 P" Z) O1 G/ \9 Z* z" w" d
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 O( p* W! [( x' l; U1 [) i
- + T7 }; M* ^ m; n, P5 M6 v& \
- public class LineRender{" C, _! P' X5 Y8 a
- private final PoseStack pose; L) M% V# p; `1 @
- private final MultiBufferSource source;: C0 y1 l) m. [ C9 Q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 p: f8 y/ Q. W, e9 r. y - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();. u- ?4 D( G; a- m: F5 ]4 {* F; U
- . b6 Y7 ?5 f! O& m7 S8 M* u, @
- ! E- g- R# ~' q" L
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
0 R+ U$ f; Y K% x0 `* N5 I - if(x1 == x2 && y1 == y2 && z1 == z2){
# r7 p- Z9 V3 N1 @* T& k' u8 Y7 u - return;% }; P' b" F" `& [2 h
- }0 R3 ~- R. Z* U/ C% t4 R& j
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){6 s. G" ~. H( {
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. x6 P+ d( P$ G# V4 J7 B - }
8 q7 c, o3 @' ?+ e) h7 v - pose.pushPose();
7 h7 T; z Q5 k/ q) `8 Q - final int newLight = convertLight(6);
, C( l8 \( ]% A! \+ x - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 M' O- O( T5 S; V. Z- J& x. V' X - final float lineHeightSmall = (y2 - y1);
; ?6 y7 E" Q! k# Q$ w2 j - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);: U4 L6 T, `2 N
- pose.popPose(); t0 D0 G7 d& G
- }
; e8 U5 o& d" }; q7 b6 h- d d7 R - ; x$ _8 k' V% Q
- private RenderType getLayers(String texture, int light) {+ g% L# l' t. [. M0 y+ w1 P: h: r1 M
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 u' A. f9 |. Q( U! `- d - }2 G* `, c2 y, C5 A+ S
- 6 o/ Y# S, b3 L/ n- p
- private RenderType getLightTexture(ResourceLocation texture) {
5 g# U+ e0 r! k" _' v& k0 k - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 k% w, K2 K! S: [! B9 `& L* u
- }% A/ B$ F+ N1 b" ^9 L
- ' Q* U; W6 }# o7 K6 x
- private RenderType getTexture(ResourceLocation texture) {
" o$ h4 i" r I# y) t6 w! v1 J1 H# U - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
# Z; B0 M& q' h- q0 s6 c - }
|% w% M" {" q- s. e
: E. d1 I7 |& B) S$ m- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( c6 Z# w* q1 g$ m. U
- if (cache.containsKey(identifier)) {" @0 {% R! Z7 a4 d
- return cache.get(identifier);
9 f3 }: ~# M& f, C1 z, [ - } else {
) }% P' G9 F/ l4 S& u& P - final RenderType renderLayer = supplier.get();
, m, C! O- s4 E# e7 h; C - cache.put(identifier, renderLayer);$ Z: E! f. a: ~2 ^& j
- return renderLayer;
" M7 ?" w" U& S7 t - }- y2 W4 Q5 s2 @- y
- }
; k8 H) E2 x* |$ ? - }
复制代码 |
|