|
|
" d) g6 X& _- L4 b2 t9 ?$ s+ B行,这个怎么样" i( f7 F2 O/ t, a3 z0 [) d
- package com.xhg78999.mtrfac.render;
" k! h6 ?, W; ]5 V# R* K - 6 O/ O. I& `3 k: C6 {- w
- import com.mojang.blaze3d.vertex.PoseStack;
6 b$ {1 Q" `0 m - import com.mojang.blaze3d.vertex.VertexConsumer;
$ Q) V$ u, T" K% |. m; v" S. d# o - import net.minecraft.client.renderer.RenderType;
6 ], K' d5 s2 w b - import net.minecraft.resources.ResourceLocation;) ~1 N# s4 O/ K
, N; Q0 m& }% @- import java.util.*;* P8 Z3 ^0 A: `0 q( Y' _2 m1 ?
- % V$ P6 m% C$ V
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(5 v9 w; Y; i8 n. O* q$ x' ^, c# j# D
3 r- c5 B3 x! ?, D- public class LineRender{
2 {1 L2 `- Q0 y ^ d - private final PoseStack pose;
+ b# q; r7 p& M+ T - private final MultiBufferSource source;
2 D4 d G w5 z- F" Z- k0 q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();" s$ S* ]1 ^2 C; X
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 ]' \: h. j1 z; P7 ?
) C9 @6 ]: b: Q' g/ T; q/ h- & y2 J5 Y+ h3 T+ ?9 c$ G4 `2 \
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
0 B& `. q/ @" s$ G6 J - if(x1 == x2 && y1 == y2 && z1 == z2){& ^, z% ?. E, Q) U: m: D' N* Z9 r6 ]
- return;
% [7 f3 J% \' ~ - }
8 @: H' P/ }: E i - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% b0 p5 Y1 T/ x+ C8 }# ? - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
# m; J! @3 y9 `4 o- Z& y9 U- e5 E - }
7 d O% A2 H3 n: C - pose.pushPose();
" O C% R: ?' ~( H2 ? - final int newLight = convertLight(6);
- L/ d: N. _# q; T7 I# B - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( P+ b3 F( ~) U& P6 ?0 r - final float lineHeightSmall = (y2 - y1);
* L7 N, x9 d2 ~ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# V5 \, @; c7 J, f5 o9 x6 ` - pose.popPose();
. f8 U0 R ?$ a/ L1 y# S - }
9 `" q. o5 j; }7 e" L6 f6 n9 K% ] - # Y7 ^) n7 O! w5 K2 b2 C
- private RenderType getLayers(String texture, int light) {3 |2 T" L9 ^. G9 N) e
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 _: b9 w$ o6 P6 [+ v: ~ - }
0 D! t5 N9 g* i4 |7 o - 8 ~0 r# Z- ~6 J! o7 f
- private RenderType getLightTexture(ResourceLocation texture) {
; w% a6 m( E# V4 s' S - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 h1 T) q$ g' \- W) r; K& a
- }
, [8 m+ k6 v9 v3 r6 u - $ Q8 R& k8 l% w) {
- private RenderType getTexture(ResourceLocation texture) {) R. b5 Z! W7 \1 W1 ^
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);$ |* {6 c* {( j" n# v
- }
) Y, R: s' T9 m - 3 [; H6 Y4 ~7 ^8 O/ f
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# B# B, C+ h. J! u2 Y - if (cache.containsKey(identifier)) {9 s1 D7 G1 A# G. A; F7 {) ^
- return cache.get(identifier);
( o% O, i. v* B1 Y, n0 f - } else {- W5 P3 v0 x5 b1 e
- final RenderType renderLayer = supplier.get();
- a1 ]7 B4 T% D - cache.put(identifier, renderLayer);
0 D& r1 U% B. ]3 l: m' U% k* u/ j - return renderLayer;
5 A7 d3 j3 d# T6 ] - }( |5 u" G; ] W) L
- }5 S' f1 {3 ?& r6 L# F5 O
- }
复制代码 |
|