|
|
# s8 Z# x8 \# G! E( A行,这个怎么样8 a [) |! @" ^8 ~% z# \
- package com.xhg78999.mtrfac.render;
7 K1 m5 A2 E3 J1 Z$ n9 r
$ r$ |' c: Y' h7 B5 k" ] V6 _' N- import com.mojang.blaze3d.vertex.PoseStack;; @( k4 U% d1 N1 j+ q9 S8 Q- h
- import com.mojang.blaze3d.vertex.VertexConsumer;& G- `* Q: h, ?4 `2 L
- import net.minecraft.client.renderer.RenderType;
( D- C9 P! }# Y1 M - import net.minecraft.resources.ResourceLocation;
' m/ ^3 i) \, k: Q" }. `- P
- u# w& w% H- A) b) j' {- import java.util.*;4 R& u* o( i' r1 x
- 8 [: m' ]; b; J8 i1 ]& `9 W
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(+ K% S/ \1 _( M4 D- K2 V2 e* o' z
- ( P, @, U+ n# G) ?& A0 R4 o( i: |( |( W
- public class LineRender{
0 R8 e+ l; P; @: W5 w - private final PoseStack pose;- Q5 B: U; r1 V- |1 w4 c# Y. O( n) d
- private final MultiBufferSource source;
% P4 J. W5 A4 S- {% ^; ~" e - private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 l5 [6 M0 z8 d
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( b7 S+ F h: f9 H$ F9 x6 U* p - 5 F b! o. W9 F6 k' ~
1 N) x$ w z+ B9 \4 m- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
/ N" s; w& I, Q1 c - if(x1 == x2 && y1 == y2 && z1 == z2){5 r) ^. w2 }( C( m6 u. n7 S
- return;
9 Z: G3 b# [2 q! M$ X - }9 Z% l, v* K1 o# i$ K
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
6 E5 A/ E. N2 ]# j- d4 y* B! Q& X - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
, r; B" o: I- q- [ - }
, R9 f2 w) n: k - pose.pushPose();
# s) T9 s; r' Y; G5 a* [ - final int newLight = convertLight(6);" y: i( z* s4 f+ a4 p; j; b1 D% m
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));' @6 O& o- ]/ R6 r
- final float lineHeightSmall = (y2 - y1);
# x: | `2 w, h - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" k$ |8 C- [1 ^# j - pose.popPose();$ `) j0 _/ `$ d# W
- }
/ @" N% H1 N, _; m- E: I$ O# U; \/ S
# \4 ]. U1 F* ?, L# l. ~4 d6 L- private RenderType getLayers(String texture, int light) {/ ~3 r* ?3 ?* @7 T6 d' j, }
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 E. w, t* D% |' q" K$ r
- }/ N: r* M/ g9 N$ O ^ J
- : M! d1 V6 V$ A1 @% B9 m. T: M: D
- private RenderType getLightTexture(ResourceLocation texture) {
' }) P' Z3 r! ~% r9 H* M - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; U2 q g! g: u, }9 w. g - }
6 w3 I) a- o' U& E4 O) V - 7 y' c; y+ i0 \8 ?
- private RenderType getTexture(ResourceLocation texture) {
: Z% S5 f! N% X; r/ X" d6 a: c - return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ P( M, c3 V: x( R8 H
- }
* r% r7 [# N* E; X: O
, {" T( I- O C# c8 E/ [ T3 Z3 l7 b# X- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
+ ^2 S4 \9 v9 q$ @: T1 H - if (cache.containsKey(identifier)) {' K0 j! t" Q: q1 G2 [
- return cache.get(identifier);" a) Z7 j1 S& S4 W4 x+ S
- } else {
& g1 O$ } H3 l4 `5 r - final RenderType renderLayer = supplier.get();9 F" u3 J& H0 H1 F* p
- cache.put(identifier, renderLayer);. g: g' u3 H/ E/ y. X0 t' \
- return renderLayer;* N" s4 H- g( J6 w2 N6 w5 K0 @
- }
z8 \9 M" M5 e" P. H - }
8 b9 N6 \ X& U- r( U. b7 P: X - }
复制代码 |
|