|
|
, m) k8 |9 O) e9 L
行,这个怎么样
& D- I+ t$ Z& L4 I0 p- package com.xhg78999.mtrfac.render;, \2 k! ?3 X$ y' O
5 r) k, ^% L6 t8 @- import com.mojang.blaze3d.vertex.PoseStack;7 j* j( u" N$ G, X7 c
- import com.mojang.blaze3d.vertex.VertexConsumer;
9 g4 S$ M) S0 f. L# Z) \1 ~ - import net.minecraft.client.renderer.RenderType;( |( U0 t$ \& P9 W
- import net.minecraft.resources.ResourceLocation;3 ~( D9 a/ @4 Z c8 h, h. `
: k( z8 b2 c9 s7 k& j7 _* L- import java.util.*;
f, N% [3 r; P0 D Z [+ y; Y( ?
) B Z$ y0 D$ C( T" P- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% }1 t& R* N0 i! u9 a! E! O
/ n* v1 E# M2 i* _8 m j0 x, z- public class LineRender{
# C' g* F* g0 S' D' ~ - private final PoseStack pose;
& G2 O r3 y8 ]+ X' E - private final MultiBufferSource source;8 s: k: w% s& _2 w. }
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ i, u- W6 X( V# N& r7 O( t - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); }# R* G0 o% R* A9 v. V
- 8 O/ j2 _. }9 f7 b6 p; j
- 6 m' |" e1 V! L0 W# a
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 C! m+ F4 }/ ?" p. r4 z/ B5 o
- if(x1 == x2 && y1 == y2 && z1 == z2){
! v4 v1 C+ G/ [4 [, J! J& h - return;) p! {7 V2 F" E+ M9 o
- }
: V- P5 y( g: K - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' {0 a k: M+ C( d1 O
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 K& X) ?% Z4 o3 A- X. V
- }; z" o' E' r# I- n) _6 K
- pose.pushPose();: J) M! `. U- I% t
- final int newLight = convertLight(6);
2 y0 e1 d6 _6 f' E$ S& v, k& B - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));3 T% p" F4 j- c$ Z, e h$ {
- final float lineHeightSmall = (y2 - y1);9 V4 I" A3 s+ X1 e! a6 ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# G' ^, G) p5 L2 w$ \/ z% K( Q' [( h - pose.popPose();
' Y; } x( g2 w$ L+ ~1 [ - }
; ^4 q4 ^* v" f - 8 g7 ]% n4 a" ?% M. _
- private RenderType getLayers(String texture, int light) {5 r* r% z4 w! s/ @; \- u3 }) @
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 R z, q# B" ^, L" M
- }# L( r% w# [+ M. }6 g& n6 p! L( j# ^
! l" v6 e0 z: M2 J2 U1 v. r/ J- private RenderType getLightTexture(ResourceLocation texture) {
. O4 q( j9 c1 F) h, E" x - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 O& ^& r, \ B+ A" K+ m - }
5 g, }) U; |+ t3 u7 w' c* b
|: O. \9 Y F! s7 H: U: p* A- private RenderType getTexture(ResourceLocation texture) {
+ q- Y. w! B p7 n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
) m. d/ ^9 {; N2 R7 \5 T' \% ^* i - }
5 p) E9 j8 l# `# f
( {% M# y% ~ t2 A* j- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {- y N$ D* x, [0 h7 A
- if (cache.containsKey(identifier)) {
/ M3 i% X9 X' ]0 k - return cache.get(identifier);/ S' i" k! P* A q( s: I0 x, {
- } else {) E$ d5 e' V" A. n# G
- final RenderType renderLayer = supplier.get();
% k, _6 K3 {1 q0 Q8 P9 _0 x - cache.put(identifier, renderLayer);* F9 ~4 z, E- I( S2 B: k
- return renderLayer;
, J ], U: g, ^* h1 f" @) R* m& \ - }0 z u3 p `2 E/ M
- }6 Z ]- \- n- y( t( T M, {
- }
复制代码 |
|