|
|
* `1 k) f& a/ ^ F, n: ~3 G4 C8 q: P" \行,这个怎么样9 E+ A( m0 t J( k! I
- package com.xhg78999.mtrfac.render;
9 u3 u5 ]' K" d' n - * @0 W0 v! w( m, e7 k- Z% l1 L( Y
- import com.mojang.blaze3d.vertex.PoseStack;5 V% u7 m3 \. B8 @
- import com.mojang.blaze3d.vertex.VertexConsumer;
. x( f: u8 D. _& V) z) | - import net.minecraft.client.renderer.RenderType;
! w+ u u t! _/ Z3 L% A - import net.minecraft.resources.ResourceLocation;
# J/ h( N6 t1 {! O - & D7 M5 b$ P2 t% ` o
- import java.util.*;
5 J$ G+ X! {4 ~
6 y0 Q2 K+ B5 ^4 w& a; Q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; K" n# {$ {$ z4 }6 L" T
- . u9 q: m! _. T( ]2 Q c. m
- public class LineRender{
& |3 X# u* u/ ?; C' m8 ]4 j8 a - private final PoseStack pose;
* S2 O& O3 ^+ F e+ R - private final MultiBufferSource source;/ n7 A7 r! r5 Y1 N, E
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( O4 R, R8 t8 \
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ j' I" r. L9 @/ C- ?+ \% p# x - 1 f. _4 W6 u( K, p* J7 ]; }& y O, X
- 6 w9 U; i' |" ]- P, M) J& c! E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 E- l$ o% e. J$ o2 A+ [% s5 l - if(x1 == x2 && y1 == y2 && z1 == z2){
8 @6 H! t) Q8 F - return;
/ l4 B h$ m5 d# Z( T/ x; } - }
* l( R' p/ ?! p$ O5 o, R4 w, Y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: @; ?) R( b" O1 W- A* c5 H - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' U9 u. C m" B p, E. Y7 F2 r
- }: F1 I; m S! D S1 |. T
- pose.pushPose();" U9 z9 e) u; z% w! W8 X1 C( p8 u
- final int newLight = convertLight(6);
# p! ~& H8 e5 F& {; K" c# V - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; c' M; |0 V( o0 y - final float lineHeightSmall = (y2 - y1);
& A( U2 p/ ]; J+ `- j& M - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
0 z; o0 y& w" ^5 Y - pose.popPose();
9 T8 x" u! Y" A; u, B6 m2 Z+ n - }. ]3 H4 E( }! {3 r& x
# F2 e- ?, b. d; ]4 l- private RenderType getLayers(String texture, int light) {: y v3 V+ | |2 j5 J7 G$ w
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 y. G e! g' T0 ]- K0 S. ? - }
2 _5 @2 y* o) K' t6 i - 0 f: d$ S8 t. z" u, C9 I
- private RenderType getLightTexture(ResourceLocation texture) {$ b. Y5 K7 p* Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);8 k3 u$ _) B6 z* X* t
- }
$ j. L0 M$ w3 i& I
' ]; R: E/ e" [% P8 h$ l, [& S7 f* g- private RenderType getTexture(ResourceLocation texture) { F/ a/ \8 B( t" A0 R8 i
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( D& Z- ^$ V/ _3 T - }
, C' R0 l3 O4 K% w/ e
7 b7 d% @0 k+ h- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 I/ X% Q) A% g8 D& q8 R" u. m
- if (cache.containsKey(identifier)) {, |" v4 ^4 r0 B' K9 v
- return cache.get(identifier);& C' l! |0 T9 |, W7 S
- } else {: _& J$ a5 v p. Z! x' f
- final RenderType renderLayer = supplier.get();
; S w) Z4 N2 ~& w! U9 N2 x - cache.put(identifier, renderLayer);; Q* n1 Y9 L3 w8 ^. \$ O
- return renderLayer;, y" m/ e$ G0 @. U$ |5 ~
- }% @+ ^4 ]( S, G3 g0 K
- }
0 O* K( U7 C' `- x - }
复制代码 |
|