|
|
4 v+ a+ ^1 T' Q% g
行,这个怎么样
" T% s! u/ x; f6 Y/ P7 l- package com.xhg78999.mtrfac.render;( B. E) D5 Z4 o9 Q! R) c
- * k$ O* S6 {3 Y4 @
- import com.mojang.blaze3d.vertex.PoseStack;4 S( ^5 H6 ~* x1 |) I
- import com.mojang.blaze3d.vertex.VertexConsumer;8 X$ M+ _" E- ?5 i; f8 r9 _
- import net.minecraft.client.renderer.RenderType;! F- y9 K8 W% c! G& N
- import net.minecraft.resources.ResourceLocation;
- ~7 H# U: j, X - " N) U# G$ }- F% _
- import java.util.*;: ^$ f3 h( B8 U! K
6 W" u0 U& q5 G. w& e z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
' m# H3 J/ m+ N P+ b: e - + C. \, k$ W* v
- public class LineRender{
$ E$ C8 | [4 \8 K6 A+ T - private final PoseStack pose; P* _/ `' g' W4 M4 _, d
- private final MultiBufferSource source;
# T7 ?2 n+ ^( [, y - private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 N, h" f5 Y: D) `
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 v* R; a& c/ V7 R; H
- ' ?0 }5 C- V. F& w2 U n4 p4 v1 S% M
- ) d" C; [9 P, T" @6 }# b- N3 Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; L5 k. V) k M! C- A6 D6 j - if(x1 == x2 && y1 == y2 && z1 == z2){
# e* n: Y4 a2 K+ L0 j% | - return;
" j$ E& u0 `8 t - } h& N; `# a8 w
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
' ]7 y( X/ M$ B: t - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
- W; A# ]$ | b$ z - }
0 U: \- x0 Q( q f7 U - pose.pushPose();, M4 M) g1 ~) Y |8 t, z8 D( [& P
- final int newLight = convertLight(6);2 Q- M. a8 H4 l9 h/ d" B% f
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));8 L' h$ s, a1 K. K
- final float lineHeightSmall = (y2 - y1);( P$ t- _9 Y/ I4 R+ l) \ ] g2 D
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* C8 w) a: I. g6 i6 b
- pose.popPose();& z" D% x7 M8 f0 h' G1 C
- }/ B& J, y7 z2 A0 L
- . {, Y8 I& Y7 N* u
- private RenderType getLayers(String texture, int light) {% a4 s, i Z5 q& t. Z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# c; f& d ?3 L* G - }6 R0 z3 N0 t. V S
* s- K- Z( Y% L+ Q1 z0 O+ q2 y5 X- private RenderType getLightTexture(ResourceLocation texture) {
6 _$ m$ y% P+ Q2 p - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ ]7 [% I8 }, v, n$ ?
- }+ a- ~& c |; a5 C5 b2 n, J, L
. w4 d5 }; d: w. g2 R% }$ ?- private RenderType getTexture(ResourceLocation texture) {
! S9 L( _9 W1 o1 N& O - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
}! w" c6 t. e9 d# S - }8 D; A7 F- n" H: O
- {8 @9 W# V$ `; p$ S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 I" \! r$ [! Z - if (cache.containsKey(identifier)) {, M+ I! n: x& z* u
- return cache.get(identifier);2 S6 K& `1 f1 f9 o; y1 |
- } else {+ Z( R! w( B$ g2 {2 ], m
- final RenderType renderLayer = supplier.get();
* H( V9 @& F( X - cache.put(identifier, renderLayer);
% M( \% L+ K! P8 X g1 U - return renderLayer;
9 k1 C0 o- w' Z# y8 c( X - }
$ u4 W6 w! j0 ~1 s - }
^; r4 R8 o: A& _- f! L: E - }
复制代码 |
|