|
|
! k: ~1 x7 @/ V- H
行,这个怎么样
8 L2 I. n Y" z- package com.xhg78999.mtrfac.render;
% [1 ]( ?! g" G! c( }6 h - 2 Q% r" b9 i* T7 X
- import com.mojang.blaze3d.vertex.PoseStack;
( I" V3 A& X, |5 c7 J - import com.mojang.blaze3d.vertex.VertexConsumer;
: e6 R+ U9 b' X. S9 G: b. C! B% W - import net.minecraft.client.renderer.RenderType;
+ s! ]1 I$ b+ V F( T9 | - import net.minecraft.resources.ResourceLocation;
" y7 B2 C8 I. }3 I - 7 T0 [5 f) J4 J! E x8 U
- import java.util.*;/ f- N* H( Z/ Q# Z; h2 S1 Z
- ; q8 t, V7 |9 o* @; `0 {
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 }* s; a/ W1 }
3 a! Y) m$ O- ?! I! Q3 x. d; S- public class LineRender{
0 K; E% z9 _ X/ m - private final PoseStack pose;' @8 h& e5 p0 Z5 n) X7 F6 i
- private final MultiBufferSource source;" @6 N. O4 b: A/ ?8 ?
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( U' [5 m5 \' J; N
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- @3 u& n# p" J4 [6 W' E' q V
3 D( _/ Q9 a3 p4 n- ; {! x' p, n& S. p/ [" r
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
8 O: l$ X9 }- K) _, }" ~0 N! Y - if(x1 == x2 && y1 == y2 && z1 == z2){
, f4 M/ A& J ]! H - return;6 r) F' _. T1 @, f9 @! W2 F6 |, A
- }
3 t& q* U0 L" q- Y! Q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" N0 H9 X6 n% i - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ E& c0 Q, c6 b7 M4 ]
- }9 g6 z D* H1 b$ k( u
- pose.pushPose();
) {# F; {; {# T2 O; h6 ~ - final int newLight = convertLight(6);! Y/ q1 Z0 g* l9 M$ n+ R/ i
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 Z# u7 }/ W3 @& ]3 {# t0 k. c: [
- final float lineHeightSmall = (y2 - y1);
$ v" Q* q7 z4 s8 d - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 R# r3 \5 }- ?- e# r1 }
- pose.popPose();7 M2 H: c* u# |* N0 c; l
- }) P1 P. e" r9 r S. q8 c
# L4 c2 d9 C( j$ O+ B1 m- private RenderType getLayers(String texture, int light) {
0 P, F2 ^, P4 x - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));7 h: `1 |+ | m& A8 `; {; {0 @1 B
- }# m7 I+ z5 k& {2 D& k2 B; z0 P( R9 A4 F
- ( z& M2 g$ o) f& s
- private RenderType getLightTexture(ResourceLocation texture) {
- o. K* x9 T) R: y- i - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
E8 }0 U4 e4 J - }! b& [7 C& E$ M: \$ }. i4 d
- / {- ?) u6 g& H1 }. f" ^) M
- private RenderType getTexture(ResourceLocation texture) {. r9 b/ l, G4 x5 k; c# c
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 I! I1 Y* ?4 S) s
- }9 C+ o9 t7 \' j
- 3 \" b" D# H. d- t
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {. l1 T5 d W; K$ l! J& o9 N
- if (cache.containsKey(identifier)) {
0 P: j% i) g1 t9 C" o: ^& @& X# t! m - return cache.get(identifier);- ?; F+ J6 b/ g/ {/ ]9 w/ o
- } else {0 M( \7 i6 \, l2 w: h P
- final RenderType renderLayer = supplier.get();* d2 f0 B) @# m1 d
- cache.put(identifier, renderLayer);
' e. t; e0 g# o - return renderLayer;
- e; o' t% u# ~ - }" _: i9 v9 Y+ z! W* @' i# `+ L0 k
- }7 B* T. u4 F, t0 T
- }
复制代码 |
|