|
|
8 W& L& K2 s' _
行,这个怎么样
' H7 Y' U6 W1 t i) U1 l, @- package com.xhg78999.mtrfac.render;
4 Y! w5 w( m7 p' H2 e% m8 M
! w; r0 L1 T( A+ V4 U7 Q- import com.mojang.blaze3d.vertex.PoseStack;
5 j" d0 D- v7 A( S$ } - import com.mojang.blaze3d.vertex.VertexConsumer;
! F0 _8 X7 ?& I% x, z: _" {; s: \ - import net.minecraft.client.renderer.RenderType;& o( z0 D) u0 |
- import net.minecraft.resources.ResourceLocation;
3 z1 N( _5 R- {' m) @+ I - 3 s) n2 Z8 R: R+ E! j
- import java.util.*;
6 A' F" _2 Z- j - % V6 L0 o l7 O) u! h; p |
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(3 r" y0 y3 J4 d# [; w) f
5 L' V9 w% S/ ^4 \1 ]0 m- public class LineRender{ g8 @+ w6 G# y6 o+ I0 m* r& x% I
- private final PoseStack pose;2 C! q8 {) }2 E1 G9 {; R' b
- private final MultiBufferSource source;
$ c& g3 e- e h$ e) N/ a - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ K9 m" u, t+ A( Y' D# X - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 d" c Q R( v' Z
. ?8 j2 [0 x0 a1 G% {. r: p+ E
, o7 j8 Q# s9 b- i2 A- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% L# T7 R. } r) U/ a3 N7 z
- if(x1 == x2 && y1 == y2 && z1 == z2){# Z0 O% s: g, I' E
- return;9 i) F1 w. K, U' Y6 b" Z5 M+ Z b
- }% k7 @; J# s% b4 c/ b( G% F
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 Z8 o/ M1 G/ F8 H \# u - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");/ L. ?: |7 H$ D4 N3 h5 j
- }
( t E' K* l, O- k& z - pose.pushPose(); e$ ?, v2 w. ~; N- ^$ U
- final int newLight = convertLight(6);9 T5 A, x1 J: l4 ~8 E9 W2 _
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 }: I! ?: o8 l3 Z - final float lineHeightSmall = (y2 - y1);
0 C" E, p; b) L6 C1 w K - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 x: Q0 o& r4 y) F( N( q - pose.popPose();
& |% G, x, N6 K" `- q8 x - } R. K+ G7 b+ Q8 Z" W2 o8 C: K
- 2 r5 u4 _& @ f7 C
- private RenderType getLayers(String texture, int light) {+ f" [! n5 \3 _ e% V
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" c, K9 ?% D! ?- ~7 e - }
$ ~7 n* e0 E, [& K
; p- E% c$ I. r* v7 L1 Y- private RenderType getLightTexture(ResourceLocation texture) {* R/ }/ H A5 s1 `4 ]; p- G/ R/ k
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' b3 T5 z) f$ p% P" P - }
; ?0 o% f+ T$ J* E* W% q. I+ E9 u - 9 F6 r T8 B9 N& E0 b5 E. a1 x7 V
- private RenderType getTexture(ResourceLocation texture) {
/ ]% f5 a0 G* `9 e - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
v, } ?# j: n; _2 a- X& S - }
- d1 _1 W8 p. [$ y c" w: A - ) s3 _$ p/ Q& u4 ^/ z* u
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {2 J8 v& s, l4 k: z# k0 G/ k
- if (cache.containsKey(identifier)) {9 h7 T6 _4 |9 |& |: Y1 F l
- return cache.get(identifier);. y2 ]4 @) A# B+ B0 e' @$ g
- } else {0 C3 j7 z0 [0 z
- final RenderType renderLayer = supplier.get();" z# @4 F' a" j5 e( b' G/ R
- cache.put(identifier, renderLayer);
8 B0 k/ D( M" r% q- t - return renderLayer;
0 f; h. s A" ~3 L' J* G! @ - }
9 T' M0 `2 Y8 d6 m( m, h2 N - }
, {; D O! _. |* q - }
复制代码 |
|