|
|
$ N Y2 d" F& D3 C( V行,这个怎么样
8 {+ [! @8 f: Z2 s: S* _- \% q- package com.xhg78999.mtrfac.render;
5 s4 t9 `, Z. y2 L1 P0 h - # W! {8 x# e0 |8 C4 S$ \+ Y
- import com.mojang.blaze3d.vertex.PoseStack;
* V. w( t1 j: u4 D - import com.mojang.blaze3d.vertex.VertexConsumer;7 M5 R9 g D: f+ L- J' M* V$ h
- import net.minecraft.client.renderer.RenderType;
0 r4 @. q- P f1 V- I. ? O - import net.minecraft.resources.ResourceLocation;
% H7 h# O) z+ p) r0 m
* K* ~; g5 y, E: o" b- c" F* s- import java.util.*;5 Z! j! K7 @( r) V0 |
! S" z1 t: E. f' `. j- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
: b5 G! u" `: K' X7 X9 D* ]
+ K* |4 n# y( `0 N+ |/ W- public class LineRender{+ `/ b" ?& ]% q( l7 U0 f
- private final PoseStack pose;6 C2 s$ t! u6 U3 ]% G- \, g
- private final MultiBufferSource source;+ } {- \3 c& c5 P+ m, T! u
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();: H4 y, p n0 H7 ]* g
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 Y9 G8 t J4 {; l# h y
( A* }" | Q# ^, J* _ h
4 M, Y/ [8 v8 L- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
V* A! q" M! }1 H8 @- i - if(x1 == x2 && y1 == y2 && z1 == z2){- m; m1 q: O j- i9 z
- return;
2 _9 G0 [1 I, e2 k0 c9 r: E - }; _1 `8 Z& Z% F& Q. z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 E0 i V1 c$ C
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 J7 ~) c7 m7 b, H' ~" ^' v' c
- }
( |8 J! I+ B4 C" f0 z5 V - pose.pushPose();
% e! Q: u0 \3 ]' l% S - final int newLight = convertLight(6);
" b R9 |+ p' [ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( ]0 I& z' D6 `; Q
- final float lineHeightSmall = (y2 - y1);# z% c" l# ]% v* ]& U, `. w
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
, k0 F8 _- T8 }) Y: ~+ Z" z - pose.popPose();
% w+ |# i! w6 @& t- A$ X6 Z {1 @. a - }
7 c/ {4 J6 e$ ]8 Y, M; y H9 O! U
- W5 p% N; x7 ?7 D. J- private RenderType getLayers(String texture, int light) {
: |5 X9 o, {, X7 S5 x* [ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% g& u1 {; v$ V" L: ^; {$ h
- }7 M1 K( o! M# n8 q& ^
" u: Q2 }+ S9 q2 ?- private RenderType getLightTexture(ResourceLocation texture) {9 |5 |' o3 H# _$ Z( R% D+ W# f; L
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, u2 J" V4 B: G* I6 z, j- V
- }
$ W1 \5 S! ^2 p( z' M/ q - & a! X& I( N. g D+ }* q' T) @
- private RenderType getTexture(ResourceLocation texture) {
0 {# o, Z) E1 w4 o i - return this.cache(texture, () -> entityCutout(texture), CACHE_B);( C/ K" M# J1 [9 ?6 v) M7 d. D9 ]
- }9 n/ c, c! \: i y
( W+ p/ _3 [5 n4 a. l5 d6 f- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ e; }% \6 y" a9 r# B
- if (cache.containsKey(identifier)) {/ d! w/ `' O: T$ o. E& h+ a4 ]
- return cache.get(identifier);/ k& r! }# k5 @; }3 d5 O$ A* W% r
- } else {4 U& @ s; B3 G& i" \
- final RenderType renderLayer = supplier.get();. K- s6 ^) K" B! i( N
- cache.put(identifier, renderLayer);: a. }6 E0 k( J# F: J, f) ~- [2 F
- return renderLayer;4 @! [8 \ z, I& V
- } Y$ E4 n- L& V- }) K0 S* e, v9 o
- }8 X8 A" J2 Y$ F5 s+ x
- }
复制代码 |
|