|
|
6 ] d5 u$ G/ e* n行,这个怎么样
: [. u6 j/ ?. F) [; v; C- package com.xhg78999.mtrfac.render; L' j1 P% e+ q' }0 n
- % z' H4 D. `5 O2 k3 A( x
- import com.mojang.blaze3d.vertex.PoseStack;
- C" |0 _$ u6 q2 l9 n. M% g - import com.mojang.blaze3d.vertex.VertexConsumer;
) O0 s( h7 t' [/ P& {- K7 c' K$ u! ` - import net.minecraft.client.renderer.RenderType;
" x6 V g! l4 w - import net.minecraft.resources.ResourceLocation;
" Y3 y, W1 C+ ` M$ |' U& M - % u) h: l8 ^! j1 i
- import java.util.*;0 Q5 C- C) C8 V
- h+ O; h% k/ j3 F; t6 \- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( X2 g9 z1 o9 @0 u: o) t - 9 [- Y7 [' E3 o
- public class LineRender{
V& e8 a' y) q" [) s' J" e. g - private final PoseStack pose;: \; l5 n$ T- I6 t0 f2 N
- private final MultiBufferSource source;
( S, x- F: U. ]9 l3 I7 v - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ Q7 `1 G, Z" v& G( q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); T a! N) L( O [
- ; s, A, P8 W% d t
* \; e7 u9 |2 u. m4 ^- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){: J% g+ r5 a0 \- J
- if(x1 == x2 && y1 == y2 && z1 == z2){9 {! O! D' V# p+ ^
- return;
. X2 h- m* P; E3 M. i - }
2 n. ~; M" C6 @( V9 v' d" b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 A$ h5 C. q( m. j
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
$ n4 m7 U: i8 l( F9 v - }9 |6 u# o* s, \! z
- pose.pushPose();) `6 I9 q! |. v3 i9 G& u( o" M% y2 I, ?
- final int newLight = convertLight(6);
7 _: K/ D. k9 R8 Z& K - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));8 Y5 C7 F9 |) T! F( F5 P" }0 |
- final float lineHeightSmall = (y2 - y1);
) q2 N- |) L& I - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);: | |9 G( q0 t! k1 x1 _' W/ v
- pose.popPose();, E1 D, ?; v- A' V* ], K
- }
, V( i$ @- O g1 M
- s- m& x3 X, H; `4 |- private RenderType getLayers(String texture, int light) {
3 _$ `$ j0 U% y& h/ Q9 f - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 G* B; @) `& b
- }
5 z% b, v& q% G3 W6 c) k9 W2 i
% n# V+ w+ M* f4 _" K& G) F7 s2 h- private RenderType getLightTexture(ResourceLocation texture) {
& V2 a- I/ ~1 P' P7 z: W; B7 k - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
, I* s7 u: e/ Z7 e& M - }
3 E2 C9 R6 ~, g# y: q
0 t' O" p, Y) F- private RenderType getTexture(ResourceLocation texture) {0 N5 N* R" a7 ?
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' Z$ n; l- F; `; o - }
. _/ m) r( t/ p1 e9 u
+ i5 t+ `; B; K' U$ ]( W* f! R- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 b1 B: t: l# @/ @+ T% U* ^1 ]$ H
- if (cache.containsKey(identifier)) {
" O$ l; Q: `: v9 K$ U1 S - return cache.get(identifier);" C: K8 a6 p* ~; \& |0 \
- } else {- C$ N X) j4 Q1 M$ \7 {
- final RenderType renderLayer = supplier.get();
6 n+ ]9 V" k" X: s - cache.put(identifier, renderLayer);
( [. O2 w6 \: s3 @ - return renderLayer;6 a3 J% Z* v( c. m6 J
- }. Z) p) f- x8 C
- }" j& P. F2 V' J0 ]8 ]. ^. J, n
- }
复制代码 |
|