|
|
& z5 h* ~- `, n' v/ U( @* |) g行,这个怎么样
& m6 F) B! v8 ^3 t( ]- package com.xhg78999.mtrfac.render;
8 Q- K* u5 ~& c8 C+ W2 ~ - 5 Q8 {. J8 v/ h0 r
- import com.mojang.blaze3d.vertex.PoseStack;
& ]0 X: p* X2 t0 ^7 B7 q) b9 c - import com.mojang.blaze3d.vertex.VertexConsumer;
% E B" w7 n0 ^& E* X. g& J - import net.minecraft.client.renderer.RenderType;
+ L$ H, q) F* b* z - import net.minecraft.resources.ResourceLocation;$ a+ M. Y7 d- v. [
3 H: [# U* ]1 Z8 T- import java.util.*;
% Q, n5 i0 i) P- Z$ T - 6 N+ a' j c- D' ~' @, \
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( B! P7 I( x' d* W: {
0 _# S9 z1 `% }7 n. P% ?) l4 G9 @- public class LineRender{
2 A5 ?, `) Y& E" N - private final PoseStack pose;2 U$ Y+ N2 `" Z; E- `
- private final MultiBufferSource source;7 a1 E5 X8 m; T! c
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# W+ G8 C6 H" R( a+ ]+ l - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 T" t( K& i( R" P6 ^% m9 `
! R: D9 r* h2 H2 z7 V5 N3 | {- ! _0 U) }/ ^) T, Q6 ?7 d% S2 l
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
`% [6 V% Z# F - if(x1 == x2 && y1 == y2 && z1 == z2){
& d# Q G, i& z3 E - return;
# V* X9 L! o, i4 C0 \ - }7 a& {) c. V E- l: O& E3 L! J
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( l$ o* E6 O9 X/ `* u( }
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 d- |7 | L1 f* R+ L: e, ?0 R% x& G! ` - }( ?, I$ Y4 f8 _$ S: ?
- pose.pushPose();
5 n: r* H0 F5 u! a - final int newLight = convertLight(6);
0 z; ^- A; p: u( R9 ^0 X - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
8 N* A E4 ]& ^, A5 A - final float lineHeightSmall = (y2 - y1);
/ i3 o3 C6 O% V4 G+ `- n A - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# @! z. d$ h1 m/ N" I" b
- pose.popPose();" `- } [9 |# ^# M) B$ K
- }
9 g1 P5 |2 {( E( l2 S' w
! z, H# P* A8 _* `- private RenderType getLayers(String texture, int light) {. U7 s G; S# n) D9 a
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));. U' i1 j, ^7 U, f5 D
- }
7 g" }; q, t6 @& M' Z) R0 B. I
" R5 U! M3 Z. q- private RenderType getLightTexture(ResourceLocation texture) {
1 P) H _+ B' a - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 v& R8 ~$ s5 | - }
5 W0 o: d. w: k: k - , n% L/ v2 @5 H+ p/ B2 m
- private RenderType getTexture(ResourceLocation texture) {/ R" o4 [' e. y Z8 g T/ k1 V; U) Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! q& h+ @7 N) P7 D - }* E% B: D% `6 n# p# j
- - P' @8 Y; w- z5 J! \' F
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {& T- E7 Z3 W% z4 b. A" P2 t+ l% f
- if (cache.containsKey(identifier)) {
( ?6 |1 ]- h1 i; a3 p1 z& f; r7 w - return cache.get(identifier);
9 V2 u9 S7 v. ]! k# D; v+ ` - } else {
1 I3 V; Z8 ?. \6 h - final RenderType renderLayer = supplier.get();
* L u4 U; Q$ P% |! p5 h% A: H - cache.put(identifier, renderLayer);
- y) ]# Q+ w- z; [- i - return renderLayer;; _% y7 k0 ]1 Q
- }# Z( K) s3 ?7 K2 s
- }* b5 ?$ g/ z2 ^+ I
- }
复制代码 |
|