|
|
5 {6 B: z7 z2 v2 w5 q7 u行,这个怎么样
, ^3 ^, Q- H j2 |8 N- package com.xhg78999.mtrfac.render;
2 O; y# M. `& [4 H7 L% J' N - ! R4 e0 R2 j# \! K9 c
- import com.mojang.blaze3d.vertex.PoseStack;
0 M" F! Z( @# ]- O: V) _ - import com.mojang.blaze3d.vertex.VertexConsumer;
" o' g. x6 p1 S0 N$ J: e - import net.minecraft.client.renderer.RenderType;
+ C. u- e/ B3 h/ ~ - import net.minecraft.resources.ResourceLocation;
( y7 T% z; |" W* V
# u5 `0 u6 i; C2 g* O" @* E, o- import java.util.*;
1 q6 K" T# F. B
( @1 D+ [! b2 A5 i4 n: S9 p* o- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(' N v, ], |1 e, i' `
3 G5 H: } S4 ?- \5 W/ R- public class LineRender{
+ ~# y% [% b: M' t. `/ e/ E* t5 ^ - private final PoseStack pose;' K# T5 ?$ b# r" b4 ~/ u5 `
- private final MultiBufferSource source;) _# m$ n4 \ |2 Q4 H
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();* M5 |) ?" ^/ t1 |1 r
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ m* u: Y. S- U# G1 L
- . P+ F% A3 L1 a- K
8 c& S7 k5 |+ ?& S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 P0 K& B" i7 | - if(x1 == x2 && y1 == y2 && z1 == z2){
- p! g# J0 d; Q - return;9 Q2 o/ F/ C& E }3 l
- } H/ S# ?( X% S1 ?% q8 b; s h8 ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 a7 Z3 B- T) D$ b - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 }) q* Q; `6 S' t6 a+ _
- }
1 d+ @# X" F; B | - pose.pushPose();2 d+ u D% m( Z
- final int newLight = convertLight(6);
# A1 Y; T7 X% X: P6 {2 p: \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
4 H1 m8 Z# M- x - final float lineHeightSmall = (y2 - y1);
' d& |) K1 [3 k1 ^ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 I) N8 B. z- V* T _
- pose.popPose();
/ ]( h+ b5 C$ q8 w& e - }4 R& H; I* N3 n5 C Q
- 9 m+ @- Q R0 e! _! s
- private RenderType getLayers(String texture, int light) {5 j/ J- H) j( o! Z3 s: U1 Z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 B8 O; O. ~; o6 A! B4 z# `- H
- }1 H9 r7 G* U3 }% k3 }
- . B2 u* p* q1 K% L# i5 f6 g8 C5 m: N
- private RenderType getLightTexture(ResourceLocation texture) {, `! {1 B9 N4 W5 `4 U/ q& V8 \
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* _# D, u. A( }' U- T- |* V' { - }
- A; m8 E" C4 I, L$ s- |7 g
0 b! w# `6 [+ S r! @- private RenderType getTexture(ResourceLocation texture) {
! p( D; n% n$ X! I. ]/ ?, M1 x - return this.cache(texture, () -> entityCutout(texture), CACHE_B);: n& G2 M6 D' N$ S, c1 O% ?
- }
+ t+ {2 ?% i( L8 i/ r' P
* e: R2 n: K* U2 Y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ k/ s9 M' ^+ _$ ?% \ _+ y0 j+ V, P
- if (cache.containsKey(identifier)) {
2 _9 Y- E" K7 V0 y( X - return cache.get(identifier);
0 B" J8 k6 }0 K% j2 u1 Z" S% {4 h0 z - } else {/ S, R* P! i: V/ l5 g) M0 }
- final RenderType renderLayer = supplier.get();
( V2 Z* E* q. L7 c* r - cache.put(identifier, renderLayer);& z- s0 O" I9 X) D0 i9 M) `6 N7 a/ r
- return renderLayer;
/ c7 u$ S/ f, w7 q1 q: ^3 A - }
; u/ g* D( _$ x8 J* A - }7 i1 e) K5 j- I2 {: p6 Q
- }
复制代码 |
|