|
|
" w9 Z \3 Z* U3 J) G8 L行,这个怎么样( V7 r9 S/ S5 k3 N
- package com.xhg78999.mtrfac.render;
# l+ A$ m, X& W2 ~) ^7 l - ) Y( A: V( d- `* x
- import com.mojang.blaze3d.vertex.PoseStack;
2 R# t X, v" p2 M - import com.mojang.blaze3d.vertex.VertexConsumer;
9 F: Y( h: a0 U: U4 X- g9 i0 j1 ] - import net.minecraft.client.renderer.RenderType;5 ?4 F E' H2 t$ Y- `; n: s6 @
- import net.minecraft.resources.ResourceLocation;
" w* [- W! B7 C2 A5 R& Y - 2 T) m) N( m% w4 s# g+ M
- import java.util.*; M( T4 j& C, z7 B4 @4 E7 Q6 c
_2 q8 N3 e7 c6 }- |- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(9 S( I) j9 B* U3 G1 i7 I" \
0 ^# b4 S$ V) C3 Z' g% j- public class LineRender{- t& A5 k" Y. q K6 S' w
- private final PoseStack pose;3 c; B; x/ ~/ S
- private final MultiBufferSource source;+ ^% {) \) v. ] O8 R3 s: Y
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 a, U# u& n+ C$ X5 x - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
; ^/ p$ t; a Z+ W/ R$ D$ w; S5 }
e8 `% L( [ l! l w! J
) d( e' R# m1 Z2 X) W# Q- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# W9 f# C& h: C' c - if(x1 == x2 && y1 == y2 && z1 == z2){
) e$ Z3 S$ y! U8 c% B/ T - return;
! r" j m% z6 U: W - }
* M$ _5 T* T+ u) B; b( S5 b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ J3 E( [* g1 S8 Q9 j
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ Z; R* T" R% o* j e8 {+ A& T o - }3 S; {4 n" I+ c8 s
- pose.pushPose();1 O4 h z) W# N7 ~: }
- final int newLight = convertLight(6);' I, ?: H l0 m
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* i, i" M8 Z+ V g- W - final float lineHeightSmall = (y2 - y1);
0 l6 A$ J4 a9 ]( a3 ~+ G. Z. m$ B* _) Z - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
/ z% S% k2 H9 X - pose.popPose();
* a( j) X, R- y - }
6 k7 q$ [& s w9 u% E
6 e7 V# m4 h9 u, K- ?- private RenderType getLayers(String texture, int light) {. Q+ {6 R- @! I: y& \( S5 E7 A( u+ b! W" {
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 _) V, {8 s- P% C1 K
- }
5 L2 m L8 u( n/ o2 r& E - + w* P- D% G! c/ y
- private RenderType getLightTexture(ResourceLocation texture) {
' u. y9 ]. l2 o* e8 N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
" s d5 c$ Z( r, I7 l - }
6 y9 E# `& d: g g& ?3 c - ) w& M% y5 r; l+ X- E7 N% o
- private RenderType getTexture(ResourceLocation texture) {* w2 w8 B# k) y3 i* y `
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);; i8 j9 {5 ^: Z) x9 [: a! G" l
- }
9 t H% s7 Q. M8 T - 6 j1 }8 A& H' F! ~ `
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
~4 Z& z6 o* v& ~ - if (cache.containsKey(identifier)) {1 P; F2 E1 z) {5 ?0 G6 k; m1 J
- return cache.get(identifier);& v7 i+ u8 L6 r! m* q% i; _: f4 P
- } else {
0 @4 ?! S9 }9 i/ o2 j+ a- O - final RenderType renderLayer = supplier.get();
/ z3 `2 x2 x$ b' o: S - cache.put(identifier, renderLayer);
8 _! E+ `6 H' ]. s8 s - return renderLayer;
5 Z% Q0 G0 L! C, q6 _2 A+ w. N ` - }
/ u# n" n: i8 w7 W' z, l - }
: S( T4 f! v5 a" G - }
复制代码 |
|