|
|
' \" L1 s+ O3 W) N; S行,这个怎么样: U$ K3 L! X! [7 ]0 i1 T5 Z
- package com.xhg78999.mtrfac.render;" y; S9 d' z, R* |' w
* v5 C( Y) v) g5 B- import com.mojang.blaze3d.vertex.PoseStack;* x& ]/ u$ ^7 b5 [9 \
- import com.mojang.blaze3d.vertex.VertexConsumer;! E5 V6 h0 j" t
- import net.minecraft.client.renderer.RenderType;1 Y. o; g8 i; {$ D4 F
- import net.minecraft.resources.ResourceLocation;
' r, P0 E9 M1 T- u; e0 x - 3 q0 {& _& z( V0 L
- import java.util.*;
6 o* }! l4 z5 F% \) n+ T! V
( f, {+ A9 q# @6 c' e- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( i: V# H7 P0 `4 D; e
$ j6 L Y1 z6 ^" A# z) F Y0 L- public class LineRender{4 V! p6 Y. `- t: G3 t7 A8 B
- private final PoseStack pose;6 ]* r" e: H( A( N
- private final MultiBufferSource source;
8 q) i7 m9 F; t1 Z* O0 t. s- y - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! d3 i$ N! H6 D6 `! ~9 B3 J, h - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
4 j& X4 ]* v/ F; f0 c+ _6 ]+ i# d
0 v. U* | L5 L2 u5 P4 R, ?- 8 z% E h0 @3 P% F5 }' A
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; d5 P% `2 [* Z; R9 |% S/ D
- if(x1 == x2 && y1 == y2 && z1 == z2){
3 _* U, Z- L' y$ Y% |9 D/ S - return;! M4 A) ^6 Q" L5 J( G" \3 [
- }
. b8 G9 E& U5 w - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# a1 |6 h& S; X& n; ^& @4 G) l - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
$ V2 i. ~" H% e" Q; I) K1 F. J - }
8 p& J$ r7 q8 v* P w$ R, f - pose.pushPose();
1 N3 V( [4 D; T, N3 f) g - final int newLight = convertLight(6);
4 K' H F4 Z1 z [! g1 G6 B+ { - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& ?! H: z v5 b, @! ]. [
- final float lineHeightSmall = (y2 - y1);% q" S$ c0 M M. {2 C- R
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 k- b$ f* a: ]3 q0 S
- pose.popPose();' G- m+ V+ c9 A
- }) \0 T8 J1 |$ Y
2 X, u4 B/ F" m r i6 |% S8 Q& X- private RenderType getLayers(String texture, int light) {( S* |8 B5 V7 V
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 ]7 |8 d$ P6 f: V0 A/ J, H
- } N* b' T$ r- a0 H) t
- - o4 F r( E; s- ]) N# Q* G
- private RenderType getLightTexture(ResourceLocation texture) {8 X8 l! N: I$ ~7 M+ y, k7 e
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# U! @* A- N& Y) I! i" ? - }
, _7 Q' z5 y- x - . q9 L3 Q* }5 H% Q
- private RenderType getTexture(ResourceLocation texture) {
! S5 n" D6 t; S3 D - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 q) t; v* k( y( y) F5 L
- }
" ^4 V% C$ s6 {" O1 i. D$ L- _7 Z
1 y( T9 ~ N6 d. T: b" o) V" V" V# g- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 q1 U" K2 `3 F7 c7 P7 T! ? - if (cache.containsKey(identifier)) {- t( B) d4 B/ E6 @. A9 X* j: i
- return cache.get(identifier);6 t* e' N- H& R. c$ P5 J
- } else {
7 b) K6 ]2 L# O - final RenderType renderLayer = supplier.get();
f3 p; I5 y+ p+ @ |7 z/ H - cache.put(identifier, renderLayer);
, L7 A: a% ^3 ^1 a8 {) X( v. E - return renderLayer;
7 P& E. |: Y3 P5 Z - }) B& V; N0 y6 H% Z. n z* |9 B# G
- }
4 k# m; ^) n1 W- K/ X- e - }
复制代码 |
|