|
|
, {% f% Y' Q. G! o行,这个怎么样$ E( ?, r8 \, Q! Q" n/ {! Y5 R
- package com.xhg78999.mtrfac.render;
! z* N$ ^3 D6 j! m$ W
" J k7 @. O' G! R, C) n5 }3 I) j- import com.mojang.blaze3d.vertex.PoseStack;
$ y( x% i' s2 K7 y& c5 _3 w - import com.mojang.blaze3d.vertex.VertexConsumer;. N% P; I1 s6 _0 Z5 ^ b# P0 F5 h" S
- import net.minecraft.client.renderer.RenderType;
$ V$ `7 ^' {- G2 t - import net.minecraft.resources.ResourceLocation;
: ?! Q% ]) |1 u; F3 Z - % R: p, Y) D. S
- import java.util.*;
! d4 {; f s) n: b
) M3 t& }0 s& t7 k# {. g' Q# r, G; r- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& T- L! @9 v: x* W, [
- . I. W7 F0 w/ p g4 c$ \# |+ X
- public class LineRender{
: H% n2 [% Q: _8 i1 y, D" _ - private final PoseStack pose;# s6 s# K3 D1 ~: X! s+ `
- private final MultiBufferSource source;" K3 ^6 f) i+ `+ ?2 u
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ D9 M8 m4 H$ X) @/ z" s - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ F. |% z8 F7 t8 B+ ^0 H
3 p# @2 }7 ]: `, c0 k9 s- 2 p1 n! s- d0 x6 T9 ?, J
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){- D' B& L8 }' J9 q- \# S+ f
- if(x1 == x2 && y1 == y2 && z1 == z2){3 ^! b7 z: P' l2 f( r; r8 b
- return;
! P$ B- d6 |! C+ S/ z4 w - }. B0 f' }7 o1 `, `8 x
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 E" A* n& H' `2 E. I: F9 F( J
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, F6 W2 P7 y5 V
- }
: I1 S" ~% S8 K8 H! x - pose.pushPose();
' {4 V: h* p! v% X0 w - final int newLight = convertLight(6);' w9 x4 l; W: ?, y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 c$ ?/ G2 L' s6 Z) v* @3 q - final float lineHeightSmall = (y2 - y1);$ v: D" d4 w* |3 l% q2 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; g! L0 D" z5 u/ Y9 z8 ^5 v
- pose.popPose();& ^6 V! w }( N+ J
- }
: C) [' ^9 ~4 A5 d
! |8 T$ ?. l% Z1 @- private RenderType getLayers(String texture, int light) {
1 P( [' C" N' @" z( i - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));: }; F8 b0 Z. f C: n$ M5 S5 d& ?
- }' g! _0 t+ L' @8 v/ Z
- ; F8 C+ n u/ K
- private RenderType getLightTexture(ResourceLocation texture) {
: `' G& y5 z7 B6 G; g) J/ s* W - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);( c. l4 O3 Q$ g! B4 {0 y' ~
- }
w/ C4 g3 B. }. I4 G+ Y - ; ?/ a% S# O5 E8 `3 k
- private RenderType getTexture(ResourceLocation texture) {; P4 X4 p, u9 W: g' D
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 @: t1 _3 J g" q8 k2 c% ?8 n, A4 { - }
5 y* `) l7 t9 |0 p
( `2 B5 ~! P) s" z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
j$ {3 K! W. _) w. k - if (cache.containsKey(identifier)) {
2 [" `$ o! j, z) J! { - return cache.get(identifier);& L/ {/ O0 y3 a9 P4 Y1 u
- } else {
" U) J8 R, F6 r - final RenderType renderLayer = supplier.get();6 J( P+ Y; ~9 w2 R3 {
- cache.put(identifier, renderLayer);
" a' U' X$ ]5 _1 t( n" A7 V - return renderLayer;& @5 P6 `: O* o! x, M0 B* K. n
- }3 N& | p+ ?) e' ^
- }/ z# M' O% }$ P7 A4 D& w
- }
复制代码 |
|