|
|
* P- q7 }0 a$ _7 V/ s行,这个怎么样
' |/ |2 j3 K6 F) Q+ o: ~5 A; ]- package com.xhg78999.mtrfac.render;
' c8 t+ @. s! ]4 t7 W6 H3 P. n - " K- [5 s) b( @5 L1 Z3 H4 ~
- import com.mojang.blaze3d.vertex.PoseStack;
' W/ U! w6 O5 J8 L9 ]3 C - import com.mojang.blaze3d.vertex.VertexConsumer;
2 O9 `% O% s! D4 U2 d+ ] - import net.minecraft.client.renderer.RenderType;
4 [! S h L1 k* b" l2 b# x - import net.minecraft.resources.ResourceLocation;- _& O, z: S7 L
- + e% E. H: R& r9 I" K% z
- import java.util.*;
: P4 t: J0 p% @3 b% S - 2 m# |6 v; A$ O7 \) E1 F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
\3 X* i+ K2 F: f - - B4 u2 u2 D8 p3 x5 j+ z, y
- public class LineRender{) F4 V. i, v# F
- private final PoseStack pose;
! U. t# W7 u5 J - private final MultiBufferSource source;. x5 C8 o! r) g4 k9 p
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();% R2 @; U" c/ C. W
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();+ R. g: }/ x; u. @1 a- {
4 s' f$ H- B5 P2 |. a8 k' P- ) z5 v/ w W% m8 \. P6 r" L
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ M# D- m0 L! w3 V' g' d9 X- e& `
- if(x1 == x2 && y1 == y2 && z1 == z2){
3 L7 }' U3 I- {5 a1 l* z' N3 g - return;
' P2 g9 K# V: y- X" ~# q* b - }; `7 R6 Y$ h. ~0 w5 w! `
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: S; A# `* G( h* r7 V - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! c0 B. K+ J, T+ _# j - } x7 S5 \& d! T; I: u# Q0 C
- pose.pushPose();* M" z. P) H* Y
- final int newLight = convertLight(6);) ?* J* ^, u" C1 h# \0 s
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
) i8 c# L I4 Z - final float lineHeightSmall = (y2 - y1);$ X. g5 _' ]) x
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);" U6 ^$ D8 ?5 e7 T
- pose.popPose();% T3 W2 C* a6 U7 B* k+ D
- }8 J! n9 x1 t: d8 U$ p3 {- ]
6 Y0 O# B/ w/ p! g- private RenderType getLayers(String texture, int light) {
+ B4 z& g( k& T( s3 t - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));5 f9 n [) R; M* U, w3 J# l2 g- D
- }# Q8 Q( l$ }7 Y6 G3 @$ q$ O) w7 f
7 |3 X& Q X T4 |- private RenderType getLightTexture(ResourceLocation texture) {5 t6 Z: J, A: d' u& ]2 g
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
. `! z2 ] }# l+ ~8 m0 _ - }$ p$ E7 z. M* ]. p( M
, n6 k7 _: ^' Y( M# ^5 y3 A: S- private RenderType getTexture(ResourceLocation texture) {
# b1 d" A" h% E8 T* R* I - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 S5 w5 y' K3 g, @6 P - }
8 E- g' T# t/ ~" x6 L0 Q$ x7 G
6 P- h9 P# X* L6 j- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# v& W7 b5 i3 M Y& d! m2 o! p! n - if (cache.containsKey(identifier)) {
" C% o- j! ~- p# E4 z' e/ h% M0 t - return cache.get(identifier);9 k, [' @% M: B- F& o* ~
- } else {9 C$ X2 j3 D: h0 a$ a/ Q: h
- final RenderType renderLayer = supplier.get();- e5 @! x6 {6 ^$ Y+ |
- cache.put(identifier, renderLayer);- Y* A9 Z: {8 N9 S& V! D
- return renderLayer;# z2 p/ Y }# [; r% ]* G
- }9 s8 u8 U& w2 t/ j" v
- }
, M/ f5 l7 p+ P8 y1 s- x8 N - }
复制代码 |
|