|
|
3 }' m* S/ Q: w/ K
行,这个怎么样
: {/ P* o# c' ^6 I3 U+ Q& H6 b) H- package com.xhg78999.mtrfac.render;
' k/ R, ]" j- E! z. z - ' z7 M+ T7 A4 U# F A: @2 a
- import com.mojang.blaze3d.vertex.PoseStack;3 @" ]1 g/ K( m/ G8 h
- import com.mojang.blaze3d.vertex.VertexConsumer;
. _/ F1 k0 |3 |7 y! r+ g+ ~0 Z - import net.minecraft.client.renderer.RenderType;
/ w7 W- Y: Y0 j m' r+ e- x - import net.minecraft.resources.ResourceLocation;* J' Q5 g" ]6 ^1 Y+ h6 P
9 d& P* J4 c3 Y5 c1 t3 }6 K0 ]- import java.util.*;
8 }8 o. w4 e* K; L, v- _8 i
. h. _* t5 A1 |; q. ~- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 H* x$ V6 |9 v2 _, B4 ^6 h. L8 p
- 0 A- Q+ H. [& u ~
- public class LineRender{; t5 N# ]& W% j6 d( u
- private final PoseStack pose;
4 b7 K: E3 w& Q" Z - private final MultiBufferSource source;+ z0 B$ j# h' W8 Q: G( V, z8 k
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 E+ L# X; I/ t9 ?7 I' L1 ]8 q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
Y5 e9 h& D& i" {" t3 | - % l) F# W+ {) u4 K" U J
3 E: i( }9 ~, \) w4 ^& P- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
P: d! l; A- m o( B - if(x1 == x2 && y1 == y2 && z1 == z2){
_3 l4 A' o& V- y( X# U - return;
/ S; v( O' {6 h, ~! ^9 C - }
4 ~; L% I4 `: i2 d- f( e9 N- V - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' Q3 \# Z0 u% A Y7 G; B( F; R
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* ~+ g/ t% g' ~ - }8 d9 g7 c: [* T+ I' _3 z* j8 r- @- ^
- pose.pushPose();- M, H ]) f$ a5 E: l
- final int newLight = convertLight(6);7 W9 B" ^& e7 W, g" _
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; R3 P7 [! j- K' k: m& Y- a - final float lineHeightSmall = (y2 - y1);
+ ]3 _" ^; m& e; {& Z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# }- |% K% N- N5 q5 L
- pose.popPose();; L0 Q e: g, o q
- }0 M$ o& J4 }$ _) [; ]0 {
/ Z: A5 I6 o: J+ p5 C- M7 ^# V% M- private RenderType getLayers(String texture, int light) {
% @0 v3 J6 Z( ]. Y# V, }! o) n7 G - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ X7 z! ~$ L# q) F! q3 u# t - }* I/ p+ i* r: k/ w! c8 k
/ P, c. k) @9 W, ~! @- private RenderType getLightTexture(ResourceLocation texture) {' E' A& B) c" l T
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 F" `2 {. A" ?0 m; a p, d7 D - }! T Q" @6 z9 d+ D8 O8 |; Q- Z# J2 K4 p
- & C# r2 J7 s E: P a
- private RenderType getTexture(ResourceLocation texture) {! Y! M; } k- K a8 y3 W% K
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);" a$ I8 ]7 B; G' K5 _6 A( X& f
- }
' p4 k3 o8 W3 D, c. C) D
, Z4 P |$ @ Z0 e( ~- c6 x' Y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 @& y2 V5 H2 i6 B
- if (cache.containsKey(identifier)) {
4 \* {" R0 Y) a- [) Y' U' ` - return cache.get(identifier);; a2 Y' b3 E M- j+ ?! i: P5 L. }
- } else {( b( S; }! G, a5 @2 N
- final RenderType renderLayer = supplier.get();
# R+ m4 B) P. a5 O - cache.put(identifier, renderLayer);7 }9 L4 x- I+ X7 n* ]& u6 K
- return renderLayer;1 ~! c# U. S+ ?5 z9 v& @; t
- }" m9 _2 d( B8 ?* ?4 _3 f
- }
8 s9 J* n% |& C0 e6 |3 C9 F. o4 u - }
复制代码 |
|