|
|
( S0 M ~9 u! g行,这个怎么样
7 V( m: ]4 _) c! x3 i- package com.xhg78999.mtrfac.render;" q. j3 C: L) b' M
7 S: K' r+ t8 G; t6 I- import com.mojang.blaze3d.vertex.PoseStack;
" a* _3 F& Z9 A6 k! ]$ H& O - import com.mojang.blaze3d.vertex.VertexConsumer;
- I+ S5 k3 U% K7 u7 G - import net.minecraft.client.renderer.RenderType;& H6 z$ d0 _/ I& p$ ^! k: q* H
- import net.minecraft.resources.ResourceLocation;
2 b2 z9 L; [/ U* C+ K) I' } - 5 u% o8 A" W5 d+ a6 m1 R
- import java.util.*;
}' \: e# Q7 G# P' _7 x
2 x& W$ `( q7 o, R4 |) D' A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 W! M2 Z# {( r8 q
5 p* c: U$ U% n4 B# b- public class LineRender{, l0 V# N% T8 X @1 p/ {! a0 S% E
- private final PoseStack pose;( C; {9 _. C7 B9 C5 f+ v
- private final MultiBufferSource source;* T0 A9 T% @1 Y" r5 B% y+ i
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();: w- J# r2 i9 i' I& [ O
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 g9 w( ?2 q& N4 P6 n+ B& }- c9 P
- 6 O, B- q5 k- A3 ]3 G
- - D, c4 ]' m! ]1 G; n1 B, V
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ f3 x7 W! m+ |
- if(x1 == x2 && y1 == y2 && z1 == z2){
& v% }- D/ z8 Q8 \% B4 q - return;
4 D4 G) P B: J3 Y, Y, D: A; N. A$ D - }
8 G1 `0 v" G. R7 w" `+ c0 ]$ B - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){! a* y: F! x5 ~% r X, l
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 ^5 g0 [. _- I& D - }
1 v4 G% T4 D) G1 a# t! l - pose.pushPose();
( |. w$ P" q. o, x3 R7 k - final int newLight = convertLight(6);
$ @9 P k/ Q$ {# R% Y2 ` - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 p. S9 u& t* n; `8 k6 n# N& O
- final float lineHeightSmall = (y2 - y1);8 _, o) Z4 M n9 U: A# u+ u% c
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' x! M# s% {; _9 ~ - pose.popPose();
* U/ D2 Y( Z0 b, W! v& y* ~9 g' m - }
1 N4 O7 w P! Y$ p! k
4 u$ X$ h2 P! C3 [0 b$ b- private RenderType getLayers(String texture, int light) {+ r% m# V0 }9 @
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. F; a: r# [6 X4 V* b+ T3 ` - }
+ b: _3 c: d1 g8 f" u9 U5 u
/ O& H; H/ k A3 Y# j- private RenderType getLightTexture(ResourceLocation texture) {
! S9 P; j* t3 Q- n" m8 ?8 G5 x; q - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 l$ q$ \7 V$ X* `5 X* {6 Z, B1 y
- }
+ I; R# `) ^3 y3 v4 Z+ H+ B
/ G& ?4 \8 n% @; o6 Z+ ]* A- private RenderType getTexture(ResourceLocation texture) {
9 F0 [# l2 T" Z* v0 [/ | - return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 r8 M" ?# \+ g1 B% i# v: o+ g
- } D6 f; I* ~- _) E1 F) R7 t1 ^
% V, a4 W/ S- O. C- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 [ d$ h8 u. u$ [3 O4 b: d5 I
- if (cache.containsKey(identifier)) {, u; M; v1 a$ C1 I! d9 @
- return cache.get(identifier);) u0 P0 `. S; C. Z+ g
- } else {$ S- e6 j! m! j7 T
- final RenderType renderLayer = supplier.get();$ s4 d! {. ~& R8 R
- cache.put(identifier, renderLayer);
: C$ c* t0 N u6 |/ w - return renderLayer;
; G ?( l0 H' D/ l9 o0 ] - }
9 O& L0 I6 [$ y2 m0 t - }5 R$ J6 ]6 x7 ?
- }
复制代码 |
|