|
|
: q0 G4 e8 o; b1 L行,这个怎么样 _" R/ H: D- G$ x" u
- package com.xhg78999.mtrfac.render;
) q. a5 _3 u2 {5 g4 [) ]4 L/ x
! j8 f; f; e- j9 S+ W6 T" _" l- import com.mojang.blaze3d.vertex.PoseStack;9 _8 J# ~( B+ D+ J9 Q
- import com.mojang.blaze3d.vertex.VertexConsumer;
( Z- ]& J- k8 \$ W - import net.minecraft.client.renderer.RenderType;
# o H) q2 P2 l- C H; j - import net.minecraft.resources.ResourceLocation;
3 p, G( A6 g( `8 ~4 @ - ( f$ d- p8 W+ I+ R
- import java.util.*;9 Z( z* c! q; X
- - M1 Y4 Q+ P" x( V5 ]
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
6 ]3 @$ }" e1 l! [ - , |4 l, f5 t% u4 T
- public class LineRender{
$ }+ c( Q& S9 ?2 Z - private final PoseStack pose;
. |6 f1 V4 `" k6 x6 d0 N5 X - private final MultiBufferSource source;
' T$ i4 y5 L+ ^% K: L& E8 s - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; [# G& b: M# F4 E. B. o' z- `- X - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
/ ?0 K/ A* w" Q+ x5 a% ?1 M" _; n - * S! w! P# I, S: j7 k+ _4 z
& t: y. L' \7 D6 Z! n& k B G- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 b6 G, k2 Y7 y. M/ N# t
- if(x1 == x2 && y1 == y2 && z1 == z2){
K! \! V. o3 w - return;( O1 G: i% z- m! ]# D% H/ b x( ]2 t: K$ y
- }
: G. P/ K% y% A/ a! J" E( S - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){% o1 r: K8 x1 e$ A. p4 M( H
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
9 ~, D0 f, U \, R' J4 `. b0 y - }! B, L& K. q5 W
- pose.pushPose();' q) o4 J n3 U* J! ~
- final int newLight = convertLight(6);
4 s2 | ^7 Y8 [+ E - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% ]1 v+ f; O& v V6 m T# t
- final float lineHeightSmall = (y2 - y1);
% J, X5 |" y6 X2 R1 v0 s - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% _* f. U3 _# n9 ~. a
- pose.popPose();' `8 V1 ~) H+ G8 `) G' Y8 x
- }& i d9 q3 W- K" L* P
) s* V, e: G1 X8 r4 X$ [9 O- private RenderType getLayers(String texture, int light) {) B5 C( b. [) T
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ G7 f! o! |+ o& i4 k: o6 [4 X3 L$ v - }
9 p" k& e9 r6 l* [: T8 B( @ - : Y; V6 O1 @2 n+ o) g' T! L
- private RenderType getLightTexture(ResourceLocation texture) {
+ r- L5 ? t1 H" B: _" a+ i% j - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" k, p+ d3 B* {
- }
$ r, P4 ~0 r% i# J7 q
5 t, h% d/ {, W' C, J+ |- private RenderType getTexture(ResourceLocation texture) {( ^$ `$ ~9 ]/ x' F
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ A; S2 K7 z& h9 l, X4 ` - }
2 S J7 q5 `0 H& N" y, [- z( i - % ^! @7 |9 y( u3 C: _0 {5 ]
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {/ M' a% ^4 F& p7 B4 t6 O
- if (cache.containsKey(identifier)) {
3 y5 i" g; r& C- t1 W" [ - return cache.get(identifier);4 [: \1 ]3 x! }! C1 ]3 ^3 h- t: `
- } else {
6 h. l3 m$ ]+ ]" t1 }0 H - final RenderType renderLayer = supplier.get();; F- J! x" e' [/ W
- cache.put(identifier, renderLayer);
0 }) ]6 f4 B% \# ]7 d2 Z( Q1 N - return renderLayer;
, y% |& b* n! ~4 g% S w$ v - }, V+ C' x6 D$ v
- }
$ u' S) `6 u0 A# B. Q; ~& p - }
复制代码 |
|