|
|
% d" o: u _& A7 o) l, H, y
行,这个怎么样+ e( D6 r; B1 V; g+ |4 L
- package com.xhg78999.mtrfac.render;
8 x+ M; f3 U1 q. O" U! Z( Q* @
& @' S* t$ N; s3 x# } q- import com.mojang.blaze3d.vertex.PoseStack;
1 Z- D# \, X( t - import com.mojang.blaze3d.vertex.VertexConsumer;
& m1 o8 D5 V# ^/ H/ Z( g' ?# B8 V - import net.minecraft.client.renderer.RenderType;
3 G+ ]* x7 V7 l7 T7 K - import net.minecraft.resources.ResourceLocation;( W G0 i0 R+ H6 T: e% E
: P) R& `2 v5 {" f! m- import java.util.*;
2 J/ Q4 `, G/ ?) I. {
) D3 T! z9 w- p! r! w" {- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :() `5 H/ L/ p! X# K' b& F5 M6 E
3 q, s9 [3 S! L' D) T& f- public class LineRender{
# N1 C( R, M I4 S1 u4 x+ | - private final PoseStack pose;
3 u! N! J( X( @* c" U1 m# I - private final MultiBufferSource source;$ B) C5 f8 P9 U/ t' u$ z. \$ x
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();' ^. y; h5 V; @( J' {
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); ^! a$ k0 D4 r% w
- t3 ?' m/ g# p7 }7 E2 h8 K
( ^. s" A$ j6 K. c- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 O0 {& v( m0 |) o/ \ - if(x1 == x2 && y1 == y2 && z1 == z2){) O# t6 E7 Z) B" u# w" |5 e
- return;
% H# G; |9 d* u6 t. x - }9 K/ X+ j) |' a$ z- ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 L# X0 h, J& Z2 q4 Z% D! S - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 l W% n2 T1 x1 V
- }
, ]8 Z& r/ z, z3 S% { - pose.pushPose();
0 f5 M7 d) ]( E! L7 m+ n - final int newLight = convertLight(6);
/ j" ]: H& t3 m9 \9 K3 E9 Q - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
7 E, L2 t+ Q1 M, I+ M3 B - final float lineHeightSmall = (y2 - y1);! ~ }0 U* j" }. V
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 @4 _4 N* p" @ b2 x
- pose.popPose();7 W4 x3 R- C! G$ ?2 U
- }
% l* Y% _, j/ a+ O - n, Z1 D1 @8 k
- private RenderType getLayers(String texture, int light) {
' h4 l: q/ m8 ` - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
: x& ?1 N/ o$ }* g7 M - }* j/ l% z4 u6 ]% ?. H6 q2 O% V
, J% B# z- L R9 r1 k- private RenderType getLightTexture(ResourceLocation texture) {
; c. V& {% A9 Y- W8 l+ o - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
9 F) O3 o s4 u; m ~- ^+ `& z - }
' n, A, ~0 R/ n1 w q4 k - - \$ K' d2 f, n: `- E% U. K
- private RenderType getTexture(ResourceLocation texture) {
( W% t. ~5 ^" h# n; g# Q5 N3 d - return this.cache(texture, () -> entityCutout(texture), CACHE_B);/ y3 A3 A7 m* Z% o& Y n& G, n- i
- }8 o4 L$ k9 k `% U$ ~% n4 O
- ' u. S8 H+ G& y4 {" b+ |8 Z
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* Y @, G+ W5 j4 A1 Z. i& y3 J0 g - if (cache.containsKey(identifier)) {/ i* c! Z& P+ a, `3 C2 m- j
- return cache.get(identifier);$ B- O! O0 ?9 w$ i7 v: B9 [
- } else {
' L5 j6 T; r7 v7 y% b - final RenderType renderLayer = supplier.get();! {# t3 N! o4 K: @
- cache.put(identifier, renderLayer);
$ L- W& y1 B7 i* [" {2 I4 f/ j" v$ k - return renderLayer;4 J' Z" k; C @ Y3 O0 d
- }
) j) L s7 ?* `/ `/ p- f. @ - }
6 M% w w$ o! e( I1 L- E - }
复制代码 |
|