|
|
- b' o) @# t4 j, ]2 ] L& o行,这个怎么样
: V; @. b; G. ?& c, b s9 j* D' g( `- package com.xhg78999.mtrfac.render;8 ]/ z w \3 Y, A" y* K- y9 l8 W
- ! y, n! N' S0 A$ Q
- import com.mojang.blaze3d.vertex.PoseStack;
0 i1 @8 U1 I( D3 c& n3 R - import com.mojang.blaze3d.vertex.VertexConsumer;0 V: m; e% |' c9 Y1 R
- import net.minecraft.client.renderer.RenderType;5 B' ~* s: m/ [; h: b: z/ ^
- import net.minecraft.resources.ResourceLocation;7 m$ A! v% r$ }- i
. p, D, C" R6 w' R- import java.util.*;- B' t: F9 ^, y4 u- g* T
; v2 b( Q4 X+ T* t: {/ @% @; X; j- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% H/ H+ r' U+ [- p8 U7 X: g2 E: X
5 W# j8 {9 E: H( l3 x- public class LineRender{) N; N2 }/ a/ @5 e! h5 M: W% D8 M
- private final PoseStack pose;
2 I9 e' X. t3 q u: S" Y7 y' v - private final MultiBufferSource source;5 X) E4 C$ a8 V0 ]5 _% \$ S4 o2 r
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 T6 y2 B5 Z5 R5 K9 h# S - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! ?" ^. d$ i% ]3 B
# o; r. |' G5 M b( _) h
% a& O/ R/ x: Z$ G& `; P- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 H4 a4 W/ q0 F1 ]* P$ A$ C) b
- if(x1 == x2 && y1 == y2 && z1 == z2){
V0 M# |& n8 O4 r2 `$ ? - return;
}- y0 c+ \: u2 o7 j; L6 h - }& X7 `9 n5 n' a. }
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 L5 B) y4 r% ~% i# l/ }! W" y* M6 @
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& V0 ]# X$ ^2 Z1 Z
- }
2 t/ U7 y. z/ Z# o - pose.pushPose();# b, D6 ~( t9 }$ G% A' u
- final int newLight = convertLight(6);. X M X+ s( L0 T/ I
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));9 r7 y4 [$ _1 l7 X2 c$ b3 K( U4 @& |
- final float lineHeightSmall = (y2 - y1);
; e( @& M3 X) n8 @. g - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 ^0 \" k' F9 A3 R
- pose.popPose();
2 }% x6 o7 ]$ d8 p' l4 x4 P1 ~ - }/ @* t# ?7 f( J/ B; m4 J5 r
- & Z$ j: N( v- E8 s
- private RenderType getLayers(String texture, int light) {
( F1 Z0 z. d: W; t - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));2 m6 v( g/ y% P+ y: Y
- }
+ F# H# L. i7 E3 t4 w8 e& ?
7 n# L1 q2 w' s& j! H7 I& M- private RenderType getLightTexture(ResourceLocation texture) {
# @8 V/ x0 Z8 L8 v) W: H- G/ U - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ `: q6 Z, ^$ d' K - }
6 Q0 d0 w9 K$ d. k' }/ Z( G/ L
6 V! x5 B# W6 L. L* j- private RenderType getTexture(ResourceLocation texture) {
( A' R+ o. w; Q3 S2 e- R - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, E( y2 v- d# Y- n& Z - } E% q& S8 O/ H$ Y. Q
- % {: b8 X b0 m( V# P, ~, |
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 K% i0 [5 T# `! u* M - if (cache.containsKey(identifier)) {
( b. R5 \7 I' _1 e2 }9 d - return cache.get(identifier);
7 @; s# p+ E( Q: Y1 x' b - } else {: w! Z* O/ X# V- }* n" Z a
- final RenderType renderLayer = supplier.get();5 l) _# W' w/ T0 V% h; X
- cache.put(identifier, renderLayer);
" D5 w; ^& {, W1 m, \/ V$ A0 m! D - return renderLayer;
* I4 u: X: X" Z6 y0 \" a* i' r - }
' |: p- G% }% E' g - }* G$ n% L* D x$ j! i, W+ G
- }
复制代码 |
|