|
|
# A8 y; J- h% r行,这个怎么样
* W" q8 l0 T3 p3 f4 J% i0 V" P- package com.xhg78999.mtrfac.render;$ S9 e0 h4 A$ `2 e
- 9 f. n! M% p3 b w, M1 D) t
- import com.mojang.blaze3d.vertex.PoseStack;
& `% Z2 a! X4 t - import com.mojang.blaze3d.vertex.VertexConsumer;
) Q P5 e5 r7 w! w1 R/ f - import net.minecraft.client.renderer.RenderType;! S s& e0 \2 l( t0 [" o4 @/ p
- import net.minecraft.resources.ResourceLocation;) q, ?2 ?& v9 p* x& n5 O9 ~: a
0 Y ?1 o& `- }* _* L# N/ R Y+ }- import java.util.*;
, I0 c2 W a+ v# K9 S6 Z% P6 d y - 1 f" Z( P& [' G# {
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(: p8 t4 F+ c7 ^ B' Q. U" n5 ^6 @
: f( g' C2 U, F& y- public class LineRender{ k8 A0 r. K* x: c9 W6 a3 E
- private final PoseStack pose;9 P; r7 j6 I' I- i6 B7 ]
- private final MultiBufferSource source; m3 f1 G2 J* A' A) f m4 \
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();! V) ~( I/ }% X$ ?/ R6 `* e ]( p, E
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 [, b$ s. ^, l6 y" e% Z
( b% Q3 ?. i2 P8 |" [( m* R& z% K5 p- ' b" H! H- k: Z% G" F
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
3 B" ?- o# p5 I1 E8 `* w1 b - if(x1 == x2 && y1 == y2 && z1 == z2){$ _) f' M# s/ Y( I/ h
- return;/ [! ?, d j" E6 `; I) D6 k N* m
- }! P% H7 E* S# z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# `7 z) |7 G. V \. F) C9 C - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" {, e- n! |9 N T6 X
- }
0 c5 r1 z) z$ |3 o3 m: F& G3 h3 [ - pose.pushPose();
& o3 C, F; r, G3 t6 Y! ]/ ^* v - final int newLight = convertLight(6);
. u: }, Y3 r) d0 Z - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. y7 H7 v! m5 O O% n% [2 c; ]
- final float lineHeightSmall = (y2 - y1);9 q4 L+ Q7 D6 T3 w
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* |' V' K0 g7 ~4 O) q' a* C( C
- pose.popPose();. b8 R. I3 M% q* {4 F. e
- }
- t/ P" e7 e2 o w% m) d) O8 s
! W7 m( V) k2 m5 B6 a- private RenderType getLayers(String texture, int light) {( z# z9 e0 |% `% i9 j
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
* A. T( h+ _, |: x n. f - }4 s0 c: j8 g1 V: ~+ h8 }
% ?8 s8 i {2 K9 N- private RenderType getLightTexture(ResourceLocation texture) {2 M) m P6 F; \
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 h4 K$ q, G5 _7 c/ t# h
- }
5 |& {" R0 M: {1 Y
. ^" J9 R+ }( y- private RenderType getTexture(ResourceLocation texture) {' H; b3 b; b2 ^
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);* S- s7 v9 C7 E$ y+ j2 w" Q
- }
5 z: ^5 [; E# S# K* O. L/ I - ! M/ n ?3 c. B# ?7 E" p: ]
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { V" Y& d6 B/ X9 f3 H
- if (cache.containsKey(identifier)) {
9 V% d" {, O+ `1 s8 Z3 X - return cache.get(identifier);7 U) E; b8 u# Q" S
- } else {
! P: t A; B( q9 ~: z F - final RenderType renderLayer = supplier.get();
4 h$ l R0 k2 b - cache.put(identifier, renderLayer);! M" O1 T( Z! g, \3 c3 w
- return renderLayer;
* T6 T# e" i% V/ u - }0 d" h7 l/ z. K8 F5 [2 [
- }. j, C. K$ O0 H# Y- z. q
- }
复制代码 |
|