|
|
% x$ r- |! {: S$ y, Z* R G$ M8 @8 h. W行,这个怎么样
% f2 }" q9 D. z0 L, Q- package com.xhg78999.mtrfac.render; z( o+ \7 @+ l
- ! L% F& g/ A3 {: t0 `% k0 A ^
- import com.mojang.blaze3d.vertex.PoseStack;
6 F8 s/ p/ u0 ^7 S& A5 a$ Y - import com.mojang.blaze3d.vertex.VertexConsumer; x/ ? Q2 f" E% R9 V
- import net.minecraft.client.renderer.RenderType;. h3 B6 e1 {( _, |# N
- import net.minecraft.resources.ResourceLocation;
9 I8 `( K! a9 @' h# r
1 R: I$ N- ^$ @- import java.util.*;
7 @" q0 N) u+ K1 h; Z - & O7 y2 e) O+ g4 j1 }
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( i9 H1 _/ d8 h
- , A5 D Q. e" F+ r6 B. m
- public class LineRender{
! y4 i: _3 ^* {$ S$ W! S - private final PoseStack pose;7 t. N1 c& V2 q, z
- private final MultiBufferSource source;
# m4 K+ _/ R u1 K - private static final Map<String, RenderType> CACHE_A = new HashMap<>();/ B8 S- B, H) ]! p5 [5 y: q/ K
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! f8 n5 i# E. Y' j2 [- U
# s! ~3 j" i: H! k, w, b- 6 k7 T& p F% D# R ^2 f+ q) U
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 ~! g3 i, Z, |& y - if(x1 == x2 && y1 == y2 && z1 == z2){
7 H/ M" s% t5 _7 v6 s5 w - return;$ e4 P2 U" S1 Q$ L
- }, Q) p7 U+ K H5 Y3 m& F* s0 P' Q6 a7 N9 L
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( x/ K; `+ j3 Y
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- Q. W- h3 A: I3 i% }4 e, b2 R9 i2 k - }# q+ ~& r$ D4 d& O1 B6 ^( k6 c
- pose.pushPose();
( O; h* F9 W! G7 a - final int newLight = convertLight(6);3 o, V w$ i7 y) Q
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
. u9 O" Q4 X" ?6 o8 o - final float lineHeightSmall = (y2 - y1);, l( l% Z( M w! K
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 B5 D) @6 K- d! m& }( O
- pose.popPose();
* I0 A* ^8 B- J9 K$ { G - }
% U, `: h2 ]8 Q$ d; S1 V - 3 w( e+ A# e; d) u
- private RenderType getLayers(String texture, int light) {0 Q# l2 C3 [! s& `. g3 [
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));. e6 h1 F) `3 B' l! Y
- }) L5 L6 f! |/ T
# j& g/ m* X# o- private RenderType getLightTexture(ResourceLocation texture) {
: l4 p" J& G x+ I# H' _! v! N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& K9 b( c& U6 c- u1 r6 w" d+ U0 B" X
- }$ _8 b% `3 y3 q2 E3 s
" {8 \( E8 H! q1 p& t$ g& v- private RenderType getTexture(ResourceLocation texture) {9 _$ |+ V. b: t/ A7 |; P/ v
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; |5 Q. f6 |$ u- d# R
- }
8 }+ W: z7 S2 {9 c7 U# U" p - / v' D. D$ O) J7 s; Q5 Q4 s
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
+ y% @" O' O. r. j* R; K+ o - if (cache.containsKey(identifier)) {8 _. j! _0 s1 C. D( l
- return cache.get(identifier);+ K: A5 I; Q4 O
- } else {6 {2 l- u% G5 f( \
- final RenderType renderLayer = supplier.get();- N2 w8 J- q5 q- u+ s$ g
- cache.put(identifier, renderLayer);: l7 O: R$ C" ] y# K& A
- return renderLayer;
2 y4 u& |" J% V& @ - }
" k8 `4 r1 @8 ` - }
3 S' w$ W h# F! Z - }
复制代码 |
|