|
|
4 d8 D) `' ~5 O
行,这个怎么样' b* Z* Q$ r# V+ t
- package com.xhg78999.mtrfac.render;2 c1 z& z. a: Z! c+ U% w+ M! T
- ( R6 \& _, \& V9 z* z( {1 e! \
- import com.mojang.blaze3d.vertex.PoseStack;( T0 O0 t% [ R- [) X2 `# _% M
- import com.mojang.blaze3d.vertex.VertexConsumer;
5 D& T e6 g: J7 o8 n. d7 P - import net.minecraft.client.renderer.RenderType;, B F+ u" _0 T0 t- G* _
- import net.minecraft.resources.ResourceLocation;
% _; K' J4 y- z% N - : E9 |& [+ i, s! H6 b. j6 S# h
- import java.util.*;
0 N- O$ X, P: @ g% `9 f) }8 Z' f - : N. z6 A/ P: L. G, }* [
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( k0 n/ M; A6 f: b& W( s
9 ]* I* X# w: @" z& I& H: G# P- public class LineRender{% Q3 U! s- I3 z$ k
- private final PoseStack pose;2 [) {: O/ a | f( s# Y' f9 ~
- private final MultiBufferSource source;1 m3 M; K- ]" ?
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, `; i/ o- m" A- ?& I, f1 | - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" {" ~& a Z6 \0 ]* A
$ D5 ^9 l. w/ \9 K/ N* s7 ]1 b- 6 |+ s/ [0 y0 ^" l. a
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; U& U) m q& l! I7 T8 F8 J - if(x1 == x2 && y1 == y2 && z1 == z2){
& n. J4 x8 d: y. C% E& h - return;$ J e$ P0 P+ B
- }
3 m, T5 H0 A, u; D$ p) U; P- w - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* ]$ i* M! f: i& q
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
P/ r& Z' l8 I( ~$ u! _ - }
" x6 G- o7 Q3 [6 Z - pose.pushPose();* S* Z" D4 Y% K" E
- final int newLight = convertLight(6);. Q* c" F; i# z" P. i6 N2 \
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; p- m" ~8 Z0 o3 j
- final float lineHeightSmall = (y2 - y1);
7 g( U; U8 Q* r: C6 I7 T" v - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( G2 z% Q8 z- q: D3 n - pose.popPose();2 R" r; V) r" E, r6 ]
- }
) _/ B+ A# o5 P7 s' }% E
! K5 }5 B' R4 g- M9 I7 R P- private RenderType getLayers(String texture, int light) {7 S! H/ x; ?* F2 _9 o
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
7 b2 Y2 T0 L8 F# O3 Y - }7 `$ w# }4 c" v9 e
- ) `7 y- q' e7 d. n
- private RenderType getLightTexture(ResourceLocation texture) {) g$ D% ^0 X! `6 y; A9 p
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. n) d7 k6 f2 f+ W6 A - }
/ E. C" b& P# Y/ _7 W# r2 O( {
5 `9 C& |! ~8 e3 K u- private RenderType getTexture(ResourceLocation texture) {
& g' E5 L+ v- s l0 v - return this.cache(texture, () -> entityCutout(texture), CACHE_B);- z5 Z5 [2 P4 [
- }
4 }$ j% ], h$ }4 x - y5 b" A2 K0 q, m6 T, R
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 l/ ]; h8 {9 h0 H7 Q( ` - if (cache.containsKey(identifier)) {4 O Q8 \- K- k- t& S, }
- return cache.get(identifier);
% v) r/ J3 Q; m. f# P - } else {
! O1 Z% n2 [! c- n' }% @ - final RenderType renderLayer = supplier.get();
4 ]. r3 Y5 b$ u - cache.put(identifier, renderLayer);
& p/ [* k( H/ {" m: \8 ~ - return renderLayer;
4 |3 H$ }" h. f' K. k* O7 Y - }
) C; W6 Z* C5 V, s - }7 o! p! k2 M; Z* L) u3 `
- }
复制代码 |
|