|
|
( J0 j6 ?* K2 A7 B行,这个怎么样1 i3 ~: W9 i2 Z/ A$ f4 Q
- package com.xhg78999.mtrfac.render;
. u/ {4 U0 X4 e: M- t
8 v$ J5 Q9 L1 B% W7 B9 L- v; m- import com.mojang.blaze3d.vertex.PoseStack;
6 [5 D1 b( M q: g$ ], r7 `8 h - import com.mojang.blaze3d.vertex.VertexConsumer;
+ x3 M1 l5 Z( x& R( ^- s7 T8 x; d - import net.minecraft.client.renderer.RenderType;$ D, J" k8 g5 r+ ]& j
- import net.minecraft.resources.ResourceLocation;( g: n& q' N2 \& t8 c5 R0 @0 A
/ S6 E. `- z. Z# e3 x9 x# O; h- import java.util.*;
( W! B Q- V$ |/ g8 V - : H9 u' g* |. g& K& A$ c
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# \# e/ e. Z; ~2 X
6 ]! P- X5 s; S0 z/ i, a9 |" l- public class LineRender{5 k! i" q+ v9 g
- private final PoseStack pose;, R$ i1 |9 q7 h9 i* A
- private final MultiBufferSource source;+ P8 M5 u) X; e
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% O& M5 J8 o8 `5 `* Z3 p, k X - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- Z: \8 E% u5 b6 r; g
2 w! u, I- r; ]* j
" s: A( ^- Q+ f+ \5 ]- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: T M- J* M5 Y; \4 N8 G - if(x1 == x2 && y1 == y2 && z1 == z2){3 D ]7 E7 d; J5 ?; G- L
- return; s" X$ S8 ^) E% Z
- }6 Y* _+ _, a {. p5 g" }
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 j1 P! c+ V, R# D
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- P( y5 u; J6 `5 S - }
5 B( J( c1 v. p% r& e9 O - pose.pushPose();! @+ V4 N3 c- T/ t+ X
- final int newLight = convertLight(6);) D* u) l0 F6 m" _; y( Q6 F. ]
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 [' k! F) @$ G6 Y$ I0 z - final float lineHeightSmall = (y2 - y1);
$ j( k6 t& T- R0 v3 t* S0 t - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& L% J8 p# g0 P& Q - pose.popPose();& @4 I& o. ^: F' E) e( O. V
- }
; @& U3 x2 e$ |( l" S0 O
6 s+ K) @$ A( ~/ h! l3 f- private RenderType getLayers(String texture, int light) {( P, `9 b% J! H6 p( I( D1 `
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
) U* x6 M4 q; B, f T6 _" z - }1 x+ [- ^- w6 Z6 m6 ^
- }0 F. H' U# i) [8 w- private RenderType getLightTexture(ResourceLocation texture) {+ ~$ _* l% N8 V* n
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& ^' c" k& H( W$ {9 X
- }
2 ^, o% r6 i, _' R! z0 O - 7 J3 @6 t' R ]! F5 G
- private RenderType getTexture(ResourceLocation texture) {
" r5 R m: e: B1 U5 Z7 s0 b7 n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);& m) z: i3 C' w! {# h0 v9 v
- }& p2 A# W X' I2 X& r
8 u: Z! C* I. x( a Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. z) C1 Q5 X# q6 T2 |5 ? - if (cache.containsKey(identifier)) {$ O* l5 F+ y! c, V4 r1 q
- return cache.get(identifier);
/ S: S3 P! k+ E - } else {- K% x, b2 q0 L! O7 x" a
- final RenderType renderLayer = supplier.get();! K1 o( ?5 H+ ^+ ?# w
- cache.put(identifier, renderLayer);- ?4 A6 F# ^# Z' G
- return renderLayer;
4 C4 E# [- Q- U, \& d - }
1 B- @2 Z0 F* D; E* ` - }* I1 m% B* h4 T% b3 q
- }
复制代码 |
|