|
|
/ b% k0 I4 d: o( ^, J
行,这个怎么样. {8 W6 q" l b8 q" h* f0 t: E
- package com.xhg78999.mtrfac.render;
( K( W i2 @' c+ E9 P$ }
4 W1 K$ j# n1 O9 c3 }- import com.mojang.blaze3d.vertex.PoseStack;4 c0 M8 B4 ~7 g
- import com.mojang.blaze3d.vertex.VertexConsumer;
7 ]2 R; E7 _: c |8 Z5 o7 ]* k0 {. Y - import net.minecraft.client.renderer.RenderType;
+ v3 f1 e$ h( m - import net.minecraft.resources.ResourceLocation;0 L/ X( C3 w! n9 Y
- * c6 K. M) V: C5 S" q% {5 j
- import java.util.*;: f7 m" J' V% x+ F; `6 ^! F
0 {+ h u' t) a* L- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(2 h4 F' \$ f5 `( f X% ?* y" f
- }9 W9 ~' @# V6 L% p6 T2 m- public class LineRender{! a- o9 D) T$ |0 K' ?
- private final PoseStack pose;
( p5 d$ q! e3 O1 t F0 l" E9 B - private final MultiBufferSource source;
: W |6 Z- A% ^( |0 J6 c - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: w# `1 V. J1 }' X% c0 R9 c% Q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 \. r$ _8 T ^ - $ [& O. v L7 Y, r/ v
2 W7 }$ P# A- J% M& K- w. v8 P8 n- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ d% n7 t) h2 x& p$ o# ~+ p - if(x1 == x2 && y1 == y2 && z1 == z2){
# s$ _5 E' ^3 Q) ~ - return;
! U# |0 w% O- m5 w- n C6 m' l: l - }
" o* ]: a& F8 s' M - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# R$ _6 F- L& N \
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 O7 X" ?' p0 ?4 A3 G
- } i# u. L. P1 g) R( I3 K# z0 q4 h
- pose.pushPose();
/ I/ u/ w9 M6 I- T8 n' p- Z. x' ? - final int newLight = convertLight(6);
: Q" x' |, T- X4 e( w b/ d - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, z. j$ b9 O* a! v0 s2 z - final float lineHeightSmall = (y2 - y1);9 [6 e7 r, x) n5 Q4 R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 b6 j9 y' ]3 x. z7 z z# J - pose.popPose();
. ]$ N! @7 o7 Y& f, F( ~ - }' {& f- E6 V7 S
% G& Z2 g% n6 g! Z6 t3 B0 m- private RenderType getLayers(String texture, int light) {/ b& F: S, }$ H
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' V. x1 V [* x$ Z, k9 w/ W - }8 s+ g' b, T f9 L. m) N# v
- Z) X+ L! i! z E: C7 N* r- private RenderType getLightTexture(ResourceLocation texture) {
: D$ x& N* b# e2 d5 [ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ G) H) o( f8 l6 s0 k
- }4 D1 f' r) c, n- e" i) u5 t
- i4 g! `+ `: y
- private RenderType getTexture(ResourceLocation texture) {
5 w: S* g0 h; A' q7 |+ p/ J+ [% H - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
' l- O$ W& B% _- r0 K - }' P5 N9 G) p* m& N; A2 [3 ^2 O: i0 o
7 t, E$ k* w5 {" C- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 D4 G6 }2 u: }7 J1 ^- q - if (cache.containsKey(identifier)) {
# b) `4 p. r( Q) D1 ` - return cache.get(identifier);% K6 E, z7 A/ t2 j7 ^& x. e' }( e5 i
- } else {2 f) P r7 |8 I. L3 H+ D
- final RenderType renderLayer = supplier.get();7 Z8 P3 @2 {7 w j' G
- cache.put(identifier, renderLayer);
0 m" t# |, t& Q& M+ N! H# D- I1 `' C - return renderLayer;
" F8 V5 ]: b) o, B8 A - }
& I6 }9 N5 i' m j. \7 p0 d# H1 D - }
# w6 O* | Y" i/ Z# L - }
复制代码 |
|