|
|
! p- F E3 r8 `- {% q行,这个怎么样, r6 m% V# b- G. q
- package com.xhg78999.mtrfac.render;3 h& m: z' T' x, U
- u" [# x4 b, B
- import com.mojang.blaze3d.vertex.PoseStack;
5 X7 ` j* X1 u1 j - import com.mojang.blaze3d.vertex.VertexConsumer;/ \' o7 W! v9 E
- import net.minecraft.client.renderer.RenderType;
: W8 u3 ]8 C2 B: I. F7 U7 ` - import net.minecraft.resources.ResourceLocation;
* T1 H' O+ n3 J: i3 {0 I! F+ E* o" i7 s3 n
2 g3 _5 E% L7 B+ P+ w' m5 I- import java.util.*;
; \2 N4 c3 o* s2 y4 V# ] - % q0 d% b8 [+ ]" O1 q
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% A5 O1 \) C& k
. F6 [& A$ W0 y, I4 c- public class LineRender{6 |7 @+ o" M: C* P2 ~
- private final PoseStack pose;6 _; @. [6 A4 ~) y& k2 ]* e8 j
- private final MultiBufferSource source;. r8 c0 H- Z. T6 S8 |; X- J, _3 v
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! W) C* H4 ^/ \) P+ w5 R - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
, `: B* p! f6 a6 P& T- n) Q% \ - 3 b( U; `0 l4 G- \. V
/ @2 y4 u% U7 u- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ V# d8 L& C- ]1 E" T
- if(x1 == x2 && y1 == y2 && z1 == z2){
5 o- Y% x) l- |+ F k8 x9 U1 r' ` - return;2 o/ w' @8 S9 _! P
- }
6 T+ b+ b1 R2 H1 o9 M1 ^! w9 R2 y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
, z+ ?. Q! |2 m - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% J8 k# `1 J; B5 h0 a, x
- }" U$ o! f9 k+ U
- pose.pushPose();
$ y1 \7 o) G( ^; x0 n6 N" R8 j - final int newLight = convertLight(6);
7 ?5 T) s: N+ O% _/ | - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 }6 ^& b% @5 d+ k
- final float lineHeightSmall = (y2 - y1);% L* |. C6 g) l5 L
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% g! {) L/ ], ~' x/ S
- pose.popPose();
" ^6 @0 C; ?3 s0 M9 m5 l - }
& K8 K% f- h, A
( X( k/ r4 y8 o: E. [ U/ e- private RenderType getLayers(String texture, int light) {& G6 r7 \. i6 t1 U/ G
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
) N5 p; s$ P5 H+ Z0 p+ J. |4 _, k - }
" @0 F0 |7 |( c% o5 e
& Z( ^0 T4 A" k3 k) E6 b/ A- private RenderType getLightTexture(ResourceLocation texture) {
, ?! F/ g: |3 F - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& ~7 K7 k( d% T: ^( L! q& ? - }' o" C/ @7 `4 S/ P
- . B) U9 g8 Q4 E$ e
- private RenderType getTexture(ResourceLocation texture) {8 `: N" _# R- M( b6 T" p6 G/ {
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);5 e9 U f4 B6 f$ S
- }
6 H( l: \8 ~ c) \
( Q* l Z+ J% c h3 t, q1 }- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 O& N" ?' L' P& t; j( Q3 P0 Z
- if (cache.containsKey(identifier)) {
# \( M" G: p9 p! a8 q. } - return cache.get(identifier);7 ]7 g# j" H* i1 B
- } else {
1 ?! ?: q) T2 t. g8 ]$ t - final RenderType renderLayer = supplier.get();
; f- G ?0 }0 w - cache.put(identifier, renderLayer);5 y3 g' \) X; W1 n W3 {
- return renderLayer;( e& X' e3 b' S! H4 N8 q
- }
6 y+ u: U+ Y# b I8 a* i! l - }
1 S7 g5 ]) j: r* F! M" O$ G - }
复制代码 |
|