|
|
! z1 \' k: K4 {2 W$ l! Z& m/ v行,这个怎么样
, R% e: v! k5 E- package com.xhg78999.mtrfac.render;% D2 G- `# j( ]; Q; P
- , i _ S, R) P% R. H
- import com.mojang.blaze3d.vertex.PoseStack;
- n2 D0 _) [! K Z, H - import com.mojang.blaze3d.vertex.VertexConsumer;
( [ C0 ]& I. h - import net.minecraft.client.renderer.RenderType;1 {3 r8 L, R, n' C3 _8 \" f% B6 I1 t
- import net.minecraft.resources.ResourceLocation;/ ~0 a3 K( I- K* `6 e+ r4 C
1 h2 x5 Q" r i. {- import java.util.*;+ m8 w& x- d3 {# V1 J9 H
- 1 @' c L9 N1 z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
: i" f) R3 R8 n! S - & P$ T5 O- e6 o1 {4 \
- public class LineRender{
; ~' z6 L/ n4 q2 E) q& J7 u - private final PoseStack pose;
9 z2 t6 N: ]1 k) S3 m& I$ A - private final MultiBufferSource source;
% q. K' [ k0 x1 E+ e$ `# j8 | - private static final Map<String, RenderType> CACHE_A = new HashMap<>();& Y2 u9 L* Q4 }: R/ x9 x
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();$ W/ N0 P6 O/ ^& |9 K7 S% o% c: d
, s5 J: S# u: u7 G1 s' L' k
4 @! Z1 h1 `( g9 y- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
/ E& \- ~# h' {% L8 O1 f9 ?; L' Z - if(x1 == x2 && y1 == y2 && z1 == z2){' E' E8 s) j: f/ O' U/ F7 y" y
- return;3 k! a1 V4 Y: l# {
- }) n: n2 z) B( p
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
7 k, E5 [1 R3 D% s( w% Z; p) ` - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 P9 i$ q" y3 K
- }
7 g, d$ t$ Q+ F& x2 d# h9 i; v% N - pose.pushPose();! S( {5 P7 N2 {! X. a S" C, F
- final int newLight = convertLight(6);
& q$ K/ t: u! A7 N - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false)); z* t# @# A1 n" Q: y
- final float lineHeightSmall = (y2 - y1);
5 n4 ~. N% B/ R9 w1 x7 S - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
- y# v( a: M0 @5 \4 u' @. [ - pose.popPose();
" t ]8 ^! n, s- m7 e - }
% O. R' [, u" C- |# x& e$ w( R! I) V3 ~
, n8 t( g" Z+ ]$ I- private RenderType getLayers(String texture, int light) {
4 z- C5 C8 b( Y; ?+ B. B1 w7 Y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
1 @0 U5 U1 ^8 M2 u/ z: Y - }5 r! n; Y. b0 \8 i3 ?
- j6 H. n4 N$ d' @6 \6 a
- private RenderType getLightTexture(ResourceLocation texture) {
3 n$ p( r$ C1 Z! ~9 @0 r' x( C& o - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
9 G& {( K) E D0 x7 c) p; k - }
0 A* g6 r: I H" h1 A2 N
7 j7 V) v$ `% Y+ C. N1 i* V- private RenderType getTexture(ResourceLocation texture) {8 \' t9 `! ?' [3 h H+ P F
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);3 B7 _ r; b- S `3 \
- }
8 ]( F3 R* R, ?" X; t! P - : p" B# u+ `. B$ T+ {3 P
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 i+ Z7 K, ^. P5 `( I
- if (cache.containsKey(identifier)) {
! @, E- h/ [$ Z9 O/ m# v. A( M. R - return cache.get(identifier);
3 u/ g g# c5 Q- Y; B8 n - } else {
R- p; U& Z2 T5 M9 Q - final RenderType renderLayer = supplier.get();6 W) x) _/ J8 d" q- z) e/ @
- cache.put(identifier, renderLayer);0 l7 i( D6 S& M( i% w5 r
- return renderLayer;! }: _* D& y$ _8 D; k; B
- }
4 G/ S$ q N8 g7 g0 r - }6 k( E) a8 ?* }- M
- }
复制代码 |
|