|
|
& P1 T- H L9 A3 ~2 O行,这个怎么样; |; p/ k( D) T S: g
- package com.xhg78999.mtrfac.render; ]# A- D, p* m P1 t
, I3 c" a+ g& c- import com.mojang.blaze3d.vertex.PoseStack;
2 l1 t0 q" s" q7 s - import com.mojang.blaze3d.vertex.VertexConsumer;; _7 [. J% T6 m" w- T$ M
- import net.minecraft.client.renderer.RenderType;% J+ D! X7 `% d1 q5 }
- import net.minecraft.resources.ResourceLocation;! F; x% w- Z' U. p( L% m
- 7 \5 ~. z/ l% k( H7 _- _7 n
- import java.util.*;
4 l4 _% ]$ k3 P* `
! }' p/ _: M. J& c8 m% ]4 C- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 y3 y! e7 W' V# S
: k& o# y3 b; [7 Q' l- public class LineRender{2 }# Z9 C5 W8 \" o1 k
- private final PoseStack pose;
7 C W+ y) j I: } - private final MultiBufferSource source;
( k$ d4 r( O. u) I1 u) N! i4 {" y - private static final Map<String, RenderType> CACHE_A = new HashMap<>();; ~2 F9 N0 p0 t; d
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 t, L: }. w, g; F N w d+ ~
2 x2 \. f$ f( n/ }9 N! m$ U( H5 d
, v6 W; A- X: l R( S7 [7 ]- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 r4 N6 j% A* V - if(x1 == x2 && y1 == y2 && z1 == z2){
5 r6 A* A( y9 d- c3 c0 r9 ?1 R - return;1 O! B; [! {9 }: F, V% I& v9 ?
- }9 a! F7 S9 X: c! v I8 m
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. [. m) N- F8 S9 e. X' x O - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) h; N, z6 |4 |* q
- }
3 S5 X( }2 f- r, _( H - pose.pushPose();
4 ]% J( Y* D$ z# C5 W - final int newLight = convertLight(6);# Y% k1 r! A4 q" R) t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 C- c, V% s+ I4 A' } - final float lineHeightSmall = (y2 - y1);5 `; |; p6 _) n5 d( i
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& ]" u) R; j% f, a; A( ~, t - pose.popPose();& g& L; J; Z9 |; J& ]0 t. d( L' n
- }# o( G) D9 H6 v _- w. N
7 u% c6 |$ w% _0 c- private RenderType getLayers(String texture, int light) {
7 W9 K. y* P0 e5 d. G9 [8 d8 B) n - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));. C t! L4 Y( b
- }
* C9 [& r' V! V- ^2 U; Q8 o3 k1 _ - 8 c5 H8 v! d- o, _7 E/ g1 d; q
- private RenderType getLightTexture(ResourceLocation texture) {1 B$ r+ H1 R8 r
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);; L. n1 D! _" f a" x
- }
( Y# F6 n. d6 U) L( h, q. y' E. L
; C! T7 m$ C: Y$ G- private RenderType getTexture(ResourceLocation texture) {! b1 l. D' c! e) W
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 B! Z3 i6 p: f4 d+ Z1 q; | - }1 |) H) }6 s9 ^; {3 C
' V6 l4 `* _" L+ p- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { U% |# u* G5 ^+ ^; I+ N# w, V
- if (cache.containsKey(identifier)) {
' P# O) g6 h( y9 f1 z& y9 c - return cache.get(identifier);) @6 g6 u) {8 Y0 h( I
- } else {
& w' ]) K- r& B' ` - final RenderType renderLayer = supplier.get();7 h- ?3 Y- k% a2 S
- cache.put(identifier, renderLayer);
2 b0 U% G2 |! X% Q6 M. P - return renderLayer;' D0 E6 S; o4 \) r& n
- }
9 y: k* c* `0 V6 X1 z6 ~/ x - }, D: ?3 u4 |2 j; x
- }
复制代码 |
|