|
|
# J! X4 n/ _! o# L3 K- b/ D行,这个怎么样
7 x% ? E0 ^* H/ x8 z- package com.xhg78999.mtrfac.render;4 F7 n/ S! ~: {2 |6 m
- . b/ U. e+ \, Q7 a3 ]( ?5 |
- import com.mojang.blaze3d.vertex.PoseStack;
# x: M8 Q% }, y) r* r! r; {7 C - import com.mojang.blaze3d.vertex.VertexConsumer;
9 q+ h) d. v$ `' Z" h1 t0 R - import net.minecraft.client.renderer.RenderType;, a* j, q6 o2 e+ |
- import net.minecraft.resources.ResourceLocation;
0 X0 j8 t/ p+ T; @- i - % z/ Q' ^( e' `4 n/ _
- import java.util.*;
! ?' v+ e v3 y; }9 k1 P' e - 7 _: ~. i, B X5 V- ?* u
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 V8 T" p+ G$ g! u( p p4 c: o - % _7 U6 F4 M& o5 {; ?
- public class LineRender{( ]! d( z- v% w+ b4 W* o
- private final PoseStack pose;
( _, G# U) Y+ T0 X - private final MultiBufferSource source;/ F3 I* k1 I# u6 r7 L7 p2 f9 y
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
& b# e# r w% A, b% s3 J. T9 H - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
7 I! d7 j& n$ T! `; R9 f7 o/ m3 L
0 f$ Q- z. C0 D% B& Q0 E4 h2 k" g
! r8 S! v3 Y5 P/ D- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ L# R2 Q5 }3 h% P) M/ Y/ k
- if(x1 == x2 && y1 == y2 && z1 == z2){
- y3 W1 ]9 @- N - return;, }5 D6 s7 N) s2 x: D4 u6 `
- }
) h# j; g. C7 Q7 O% k g& @% {$ Z# H9 u - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% p3 F2 S: W( e2 E" p& H& I - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! K2 B9 v6 s1 h# Y% _1 A; T7 K - }$ d7 |- c) ]- W. a) m: Z; ]# O9 O
- pose.pushPose();. o- i: H z1 r
- final int newLight = convertLight(6);- e! [) Q& U6 H. B; X+ ~% E. o% ?
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& E: F" T7 F4 K6 X, j! s
- final float lineHeightSmall = (y2 - y1);& y- B* D2 j1 d0 c/ d
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
! }6 \( a$ l/ H8 i8 ^# N, t% D - pose.popPose();: ^3 w- X& d! m, G# c/ v+ l6 _& P
- }
2 [ H/ T/ W8 w
Q4 E: p+ \, W- private RenderType getLayers(String texture, int light) {
; \& E* e: ^6 @4 ~, M, B - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( N! [) `, M1 u4 ]* m/ J# z% F - }) N# h/ T) d2 J J5 e! O+ g
- 7 p5 r( I) `! _/ v* h# U* ~5 b% |( U
- private RenderType getLightTexture(ResourceLocation texture) {" j9 T0 }: F9 x/ D
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 \6 w8 J& T" H
- }
. l0 D1 b$ u' L* r( l - 9 ?) ?# M+ T& l
- private RenderType getTexture(ResourceLocation texture) {+ u6 l& A6 l$ {5 r7 h8 z
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ j0 g" }( B, m. u; ^0 k - }
, }) T1 P# M7 f0 ~; N. Y! [ - % g- y$ `' {+ {( d% ^
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {- c1 U& t" e! j7 e1 z" u: g* Z
- if (cache.containsKey(identifier)) {) V9 z7 n; D, w
- return cache.get(identifier);
+ T* x' ~) R3 J - } else {
! E; D v* _8 A8 Q" u/ ~ - final RenderType renderLayer = supplier.get();# e+ N2 N3 u/ O6 q) b2 j
- cache.put(identifier, renderLayer);6 o8 o& q) u/ o; \9 @) r
- return renderLayer;
$ a- [8 [3 M0 A$ ]5 o7 ~# T" d - }
/ q% u* u- U/ n1 k' N9 z/ o - }
# M! ~+ y% M3 u - }
复制代码 |
|