|
|
0 x/ l i3 ]6 h" R* W# F- d
行,这个怎么样
8 Q [1 h: t3 A8 [2 w& l/ i- package com.xhg78999.mtrfac.render;* K8 I# F! w: _& F
- 4 l: F9 \) _$ J% U9 h/ S0 f
- import com.mojang.blaze3d.vertex.PoseStack;6 E) V$ v+ B [; |. k) h1 S$ A
- import com.mojang.blaze3d.vertex.VertexConsumer;
0 R b z* L* g+ y( Z/ K. k - import net.minecraft.client.renderer.RenderType;: m" u$ @+ s/ n4 B
- import net.minecraft.resources.ResourceLocation;
$ x/ E9 b3 }- n c, k- y8 w - - v, g. m! ?% X9 A
- import java.util.*;
, X7 R* K/ s9 [6 A - 0 v' ]- L; D2 x% u$ X
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
' W0 S: \. h+ g - 1 F9 Q$ e. p+ B0 g
- public class LineRender{
9 g/ e1 s8 N! C! I0 m, O9 v - private final PoseStack pose;
% h5 U6 o& X2 ^% b; H7 O* e - private final MultiBufferSource source;2 j4 `+ F ^% C' ~+ P* H
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
- D$ J5 _9 C3 `6 X) v: { - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
' [ R! e% W! v' y3 U3 p - 3 P+ [' h3 {3 \* x
- 5 e# }$ K/ ^2 f9 m) K) F4 h
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 @( Y% i( c5 V6 U6 {+ {5 G6 V - if(x1 == x2 && y1 == y2 && z1 == z2){
: k a% x* s, X0 a( n - return;8 `$ L0 s1 x7 O( u1 H8 q( I1 Y
- }
4 z/ |$ L0 c& T* o$ X - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
' U7 y# d7 I, W S. s9 f; V - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 s0 f. O, y; M! B! t4 Z) T# n1 j
- }
# e& c1 n, f9 `- t6 v2 b - pose.pushPose();
, r: I9 G- v# }* c& b# A7 ^ - final int newLight = convertLight(6);
" z. F6 s2 b0 Z! G9 y& A - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
* B- |6 o, N6 X9 t. z2 g! G - final float lineHeightSmall = (y2 - y1);3 o! z, C6 \- ~; G( w" m# R; o! S: E
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 q8 p1 \2 [; {0 L$ j
- pose.popPose();
) {" _! y' h. K2 z i - }% s6 p9 \, t2 W% A. L+ _0 H
- 1 J- J/ H% q7 U
- private RenderType getLayers(String texture, int light) {
, M$ |0 o* f1 [% y0 T# U" h6 k - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));$ A7 J) ~+ r. z1 y g( j
- }
9 T3 p) L; K$ M+ P1 u; K( | - ' [( [5 M6 G2 s; Z" ]4 Q
- private RenderType getLightTexture(ResourceLocation texture) {( D7 ? r! e& |* Y" l
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);% ~# G# A$ ~( c1 t
- }8 f1 v4 K$ C& }* K. h& x
, M! V+ D0 D P5 q- private RenderType getTexture(ResourceLocation texture) {
- G) R0 P' c, v! j$ W - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 k7 P; Z) @& N+ i8 r - } c4 {* } }) [- C- G, }& D- d! m7 P
$ c3 C: @, H n9 B& h" W9 ~4 ~- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ n( U8 h! ^8 {- \' n' L - if (cache.containsKey(identifier)) {
9 Z. n! V" `& `% ~, s, P" N - return cache.get(identifier);6 D1 y h- m. U8 N0 e) l, q
- } else {
; n8 ?# g5 Z% L p - final RenderType renderLayer = supplier.get();
u6 w- m- Y2 I8 K, H* ]) s - cache.put(identifier, renderLayer);8 }$ X7 L) J9 a; W2 [ j: E
- return renderLayer;
* F* `1 [3 N0 a3 |0 K! j) ] - }
+ R6 `2 a+ S5 G8 d5 w0 B6 ~ - }, P: M6 i2 I% ^! m
- }
复制代码 |
|