|
|
$ o* P0 Y+ \* I! G8 k2 o, E; O
行,这个怎么样. _* T/ z1 Y0 B% _
- package com.xhg78999.mtrfac.render;
) C2 I" K& Z; D% O% m/ _) x9 Z: m - 5 D N* p& L* T; S( h" g; w
- import com.mojang.blaze3d.vertex.PoseStack;0 [3 }* @( L4 s
- import com.mojang.blaze3d.vertex.VertexConsumer;: t z7 g, `8 U! l
- import net.minecraft.client.renderer.RenderType;
7 u" p: W' a$ \9 T: B' H! [ - import net.minecraft.resources.ResourceLocation;* t9 Y; E1 B" e4 S3 d; H& k) p
5 t0 y) z' R6 k9 [9 q9 \- import java.util.*;2 U, z9 a) D$ `' K" D
- $ b6 M% |% R- U: @6 H% r4 k2 C' U
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 H3 E# S0 n2 e; P: Q
1 ]% n& G! i6 k( Y9 n, a5 d- public class LineRender{. B# S3 L' U2 J, i
- private final PoseStack pose;
: }1 ?( q) V& J - private final MultiBufferSource source;! a7 R1 L* U; a0 q; u5 k
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 c# Z& w: _8 m$ Q
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 {0 D4 `! m! \! y) v& S- P- v/ S
- % o+ T& ^( d. P- |: i- D X
- ! S( d: X; G! e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 J) m4 p a. j0 ] - if(x1 == x2 && y1 == y2 && z1 == z2){9 ~! g$ A& i |+ ^. ?3 i2 |
- return;4 L! J# C( m% m7 @# @" [& n0 S: ]
- }
: y" a" u( l3 d% M8 f5 F+ I - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 K, I. S9 I2 {# t1 H( ^! y$ F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 l3 @6 s# X+ A' T
- }, J9 |% z# w8 ^4 E, T Y7 {+ E
- pose.pushPose();) j+ }/ {7 V0 \+ u) {* _' \+ v
- final int newLight = convertLight(6);) T {/ N5 j- f* a/ j
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) i5 n& W/ G9 h3 Q6 {; a' f7 K - final float lineHeightSmall = (y2 - y1);4 ^6 }7 z. F/ V5 w8 \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ U7 W: R# X5 F& p
- pose.popPose();
9 O: P! G9 Q) q7 I, l - }
7 I9 O3 s& X0 ]
7 l& P$ U; q% `$ `. A/ h( c! f- private RenderType getLayers(String texture, int light) {0 ~! m& ], `8 E% z# u" v
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, S7 ?3 S) h/ T- O7 Z7 W! A3 y2 f( C - }
. _) r% y1 P7 i# r( [
* k5 q* |- x. J7 ?* C: n* Z- private RenderType getLightTexture(ResourceLocation texture) {% N9 l T2 K1 ~; w" V `" Y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);0 x- P8 [9 n' Y. s3 V
- }
1 F9 a* L: }9 C
6 ^* `, D( h( H; `7 y: K- private RenderType getTexture(ResourceLocation texture) {
( h, f: l2 `$ G t - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' K/ N& y+ v7 {0 d2 {0 |- { - }
4 d( M5 T k R2 Z6 N
1 b7 ]# u# \8 k+ U- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 S% D7 D. Y9 d; [ - if (cache.containsKey(identifier)) {/ I5 \4 O% c# ]$ j4 Y4 Q1 ?
- return cache.get(identifier);' ?9 A. ^( _( D+ U) |3 S3 F
- } else {
: O: o* d# S) W- `' {. |( W& Z5 M - final RenderType renderLayer = supplier.get();
# Q2 f* b- G! g) m - cache.put(identifier, renderLayer);8 y% {; C* h+ x* F6 k" b, g6 a
- return renderLayer;3 _- n5 `4 r6 }0 @
- }9 E! m9 f: u0 E" ]5 E
- }$ k& W f. X# i9 ?5 k
- }
复制代码 |
|