|
|
8 b$ k7 J5 `! ^4 R4 b行,这个怎么样% m9 G- j0 I. _" }
- package com.xhg78999.mtrfac.render;
5 F' ^3 K; Z2 |" b. E - ' g1 V ]* ^. x& [
- import com.mojang.blaze3d.vertex.PoseStack;6 D0 ]* o7 t* O% i5 p
- import com.mojang.blaze3d.vertex.VertexConsumer;
7 |' Y$ l& P# z# ?% Z* Y - import net.minecraft.client.renderer.RenderType;
( d; \0 m6 j1 @" A1 | - import net.minecraft.resources.ResourceLocation;
+ j2 R4 K* h) U) [' g% `; N$ }
& E6 K& h2 G# a; O( [8 b- import java.util.*;
" X0 V, Q- \6 g: @" ?
4 ]5 ~! a# n# v( s8 D6 w- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :($ n N0 y( {1 R+ K- z# f% U
7 S- d2 d; H8 ~* Y; ^1 d0 N; Q; |- public class LineRender{
P! x. q/ \9 f0 ^/ t3 O - private final PoseStack pose;# N$ `! A9 Q, v- O" K9 T
- private final MultiBufferSource source;0 m2 m' x& O8 @) R3 g, E
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; B/ ?- d/ H; Y6 _5 U2 m - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" {+ u; c. A2 w, z' e+ N! a. A% a2 E
1 L* C" e+ T& L i/ e; r/ C: m) J* x
& L% Z _4 E6 w+ C- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. W$ |/ r, S1 D$ J) f
- if(x1 == x2 && y1 == y2 && z1 == z2){2 K1 _# J: q) w/ E# f( H
- return;
0 Z/ h) q+ O# S' H! P0 f1 e' { - }4 e" Y# t7 M7 f7 l! l
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( M7 E! S5 K, X# f
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
2 N) @* c* |6 \0 @# l - }
+ F/ z0 d- o$ d! L3 O4 }& _ - pose.pushPose();& X9 s* {$ Y* |0 c& e- j
- final int newLight = convertLight(6);4 @: u" x/ o/ P7 c3 b, g
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" L/ U5 K2 H. a9 d3 c5 X - final float lineHeightSmall = (y2 - y1); t" y1 @: T6 u) U
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
5 V9 Q. q2 g ^" Q- D- G - pose.popPose();( O8 W& J5 t) ?
- }
3 g2 O0 x4 I* b' i
1 \, A. |" D% H0 w k3 Y- private RenderType getLayers(String texture, int light) {1 S) W+ E: e2 k. y3 W9 O
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));$ p- y; b5 G, N0 V& `
- }! A9 d. o3 O h# q3 g: y3 {
" `- w, U b2 @) F1 [ l) A6 [# v- private RenderType getLightTexture(ResourceLocation texture) {
# x1 a7 @* y; ]8 w! b/ r( d# { - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
+ l* D- N# \, F4 G6 S - }/ h* K) h" V V* P: k
) Y/ D0 N a0 y+ h- private RenderType getTexture(ResourceLocation texture) {
# q6 w5 i) Z7 Z. ~! @ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, w. o3 P0 ~! k. {1 `8 g- L+ ] - }4 F; P# s6 i2 Q; l
- , T" _7 O( `7 D! |, R. Z
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 x/ X0 f$ f& z
- if (cache.containsKey(identifier)) {7 X( k$ i& v( O& C9 W' ?: `: {
- return cache.get(identifier);! @ e% A7 V/ ]4 Q% _. n+ h, K" q
- } else {
! C" S3 X A/ g* [' ? - final RenderType renderLayer = supplier.get();3 q) k# e3 D0 C- T! X5 r$ u' b
- cache.put(identifier, renderLayer);1 u7 t, U2 @1 X# M* F$ Q
- return renderLayer;, c t- y; X3 D/ P0 X* j
- }
6 ?1 T" T$ ^# ], Q - }' o1 u* `! t. j) Y* L2 n8 h
- }
复制代码 |
|