|
|
$ h- I+ A8 {2 V
行,这个怎么样
! ^* _+ @7 [% n& b3 n- package com.xhg78999.mtrfac.render;
# o9 R+ d3 [& d: a. O3 w
( U! N$ L8 p- H B) @0 Q% L- import com.mojang.blaze3d.vertex.PoseStack;
! Y1 U9 w9 f+ O2 e4 i) p - import com.mojang.blaze3d.vertex.VertexConsumer;% o6 h% o+ {" M" l* u% v U q
- import net.minecraft.client.renderer.RenderType;
6 H0 k" o& q1 @/ N# k - import net.minecraft.resources.ResourceLocation;$ x& C# R1 o2 B+ l4 m: M9 S
- + Z( t6 r. J: D' \7 a
- import java.util.*;
* W" _5 E3 F* Z: D
7 F+ M4 g: U% ~/ a6 q; a( z9 r- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
6 K2 Y3 ?0 |' O; b C# l - ' u( f: f, V. t4 Z
- public class LineRender{% m2 n3 I5 Z2 u& R6 K. h B! c
- private final PoseStack pose;' P' h/ r g4 l5 `
- private final MultiBufferSource source;% b" C6 V o5 m* U, W' y
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ g8 `2 j( `- I5 Y! t1 @ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( W. r- P# e @# j
8 B- Q: p- ^. i6 Q
- l5 R. Z- M9 i+ G! c! ?. K( F- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. r1 Y3 S$ M/ w+ |- t! r# m" y - if(x1 == x2 && y1 == y2 && z1 == z2){
) u$ {2 I7 H; Z# u7 L5 e/ g8 W9 ~ - return;# j; L7 {0 J. }2 z4 m! z$ Y6 U$ @
- }0 M; T4 W1 r3 F0 a1 W9 B
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& i5 t& w; C! a7 Z/ T7 s2 g0 Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
3 w1 g8 P; w1 p4 O4 p1 \& I - }
6 d! H8 j) i4 ^' N' G# ]( @ - pose.pushPose();
, `& H) z5 g. H9 d6 D - final int newLight = convertLight(6);
{6 ?$ u: H; \, l8 O - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
# Q: w2 H! a4 V5 c2 l; \9 V$ f - final float lineHeightSmall = (y2 - y1);
! p2 V. M4 H: N3 ?7 B - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
$ Q; W; ?1 I& k* S4 j: j1 q7 ~+ U - pose.popPose();7 K: m2 d! a* H# V& c
- }% e2 w& V2 Y9 y
3 y% \* S; f( ~ ]4 c! C- private RenderType getLayers(String texture, int light) {
/ u! S" z$ J. \! k3 j - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
9 y; ]. A4 a% o9 I, a1 ?9 l# s, b - }
; j. t1 \+ `6 N4 O$ H/ O: E4 Z% l - # e9 {/ h% _+ \7 U/ S# z
- private RenderType getLightTexture(ResourceLocation texture) {
C8 J$ Z( |8 @3 r: ~& k% H, b - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
Z) q5 u+ c) D/ B0 f; v J. y; ] - }# F6 H1 t+ x. V7 }
' t. H* w9 R* e1 h) J+ @% e+ \- private RenderType getTexture(ResourceLocation texture) {
/ w# X+ u; A$ W - return this.cache(texture, () -> entityCutout(texture), CACHE_B);3 U1 s/ L" \+ E$ r
- }
, r! u$ Z, ~/ ~* w; x
3 m# j3 x, q) x( u8 A- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 l: ]6 n, c3 u - if (cache.containsKey(identifier)) {
! Z8 d8 [& w8 G7 n4 L9 A; P - return cache.get(identifier);
: A3 ~" q- \* L% C2 } - } else {
8 |6 P8 m; t V3 }2 X9 A7 Y$ `! `" U - final RenderType renderLayer = supplier.get();5 J: }# k' G/ x1 X6 }
- cache.put(identifier, renderLayer);
! x; o' c1 o. ~- K0 g - return renderLayer;
, V+ N' k, R# x7 {4 i { c8 K - }
2 y( c( e! g# ~$ T1 G5 F - }! d$ d3 ^4 r: f Z9 a$ m
- }
复制代码 |
|