|
|
; W! J+ d) |' o# L$ J* A行,这个怎么样
8 Z) _/ [- ^# l7 j [" c- package com.xhg78999.mtrfac.render;
+ Y( t. [2 o3 v - % Y: V5 D* h1 M+ k1 T! @
- import com.mojang.blaze3d.vertex.PoseStack;# F) [: C5 p9 m1 u; U( w
- import com.mojang.blaze3d.vertex.VertexConsumer;4 v, f5 k4 R" [$ t
- import net.minecraft.client.renderer.RenderType;6 Z* J; _# C. w {
- import net.minecraft.resources.ResourceLocation;. Q$ N, W2 p$ ^- `2 g2 p
- # I/ ]* s4 W3 Q4 H4 _ g# R' q
- import java.util.*;4 n% d5 |& s" ^; s
* Z6 l, u0 g+ i# O6 i3 U4 [" v- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( J) Q3 T- i! V- Q% C6 o( {1 p
1 q n( ?" V$ B$ b) a- public class LineRender{
7 }3 T5 O5 E- F T8 ~1 s" u% _ - private final PoseStack pose;/ M. s% D- J5 A9 j
- private final MultiBufferSource source;1 t U2 ~* w( v2 k# f S: ?
- private static final Map<String, RenderType> CACHE_A = new HashMap<>(); S# V9 t5 ]8 D g8 D0 d( l0 {
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 ]3 a) C! A* ~$ m! }; A
& U* Y- ?3 G1 m: x- # h' G6 Z. j: d! N
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) v% o) D8 w/ `; ?9 @1 u1 ]* p; ? - if(x1 == x2 && y1 == y2 && z1 == z2){
& Q- `) h5 r# ]( W% ~6 e - return;
6 u$ L& Y& f. U/ R9 t; ~ - }
5 u$ V: M) ~% `, {/ c2 X - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ v, f/ d, K% m
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
( G6 X- Y$ N0 B% A7 l - }! f& Z! b6 ?3 f( L3 r& s$ q. d
- pose.pushPose();
& Z# e! U8 h( d' B" j - final int newLight = convertLight(6);1 p+ @: X2 e4 {, I' r
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
H7 J1 O4 i! k" j, s - final float lineHeightSmall = (y2 - y1);$ F1 B1 Q5 Z' X+ E! O1 r6 g/ @
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 ~/ B/ [0 o* H9 D4 @2 ^" [2 k; k4 `
- pose.popPose();% b6 v9 u& y' d X2 O# r
- }- |( m6 C( G3 r. ?2 _
! W9 B9 Q: L/ b$ K4 \9 I: Y- private RenderType getLayers(String texture, int light) {" |0 c1 T& w% A0 h/ r* S _
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));" L: U" Q7 o T: A3 R; O" N( l7 M
- }; j% ?- t' j$ n' W @, b* T
- ( ]/ L2 c. z6 V' b X* b
- private RenderType getLightTexture(ResourceLocation texture) {
* t# P, I! E0 i) O! T, T/ K - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: b! i, q( t9 R! @
- }
: V4 G5 M% O( d) ~; z% x( A - 2 V; M! [5 H9 P$ x. y* N2 D+ G
- private RenderType getTexture(ResourceLocation texture) {
- q" c$ b7 z8 h5 t# P. @ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
$ {: I* p+ i, r! i - }- r# W0 L! O$ J! ~
- + D0 V2 ]+ o% o) t7 \& [6 h) ^
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# l4 m! ?3 A2 K$ m
- if (cache.containsKey(identifier)) {6 z! f' ^+ D$ [) ]; k
- return cache.get(identifier);0 P4 a! N1 X& z0 y& J
- } else {) R7 P/ @+ x1 T" N9 E
- final RenderType renderLayer = supplier.get();
# N, h- P, N- i* i$ Z - cache.put(identifier, renderLayer);+ N' l6 W/ u$ A
- return renderLayer;
/ R8 P/ @2 _ u. d4 a! C3 _2 w; I7 P - }" [* t* @4 R+ ^2 ]5 A
- }
/ u: U8 @$ |7 t. U, V+ c6 z - }
复制代码 |
|