|
|
, y) a5 @. d' I
行,这个怎么样
) Y& e, E( m w% t" u/ D7 ^5 J; f* _- package com.xhg78999.mtrfac.render;
7 h3 O, `4 f9 s6 u - 7 s( c( ?7 D6 H8 W9 j, P
- import com.mojang.blaze3d.vertex.PoseStack;
5 q3 U% D# W2 Y2 V$ ]6 z - import com.mojang.blaze3d.vertex.VertexConsumer;
& D. q# I* k* j4 [ - import net.minecraft.client.renderer.RenderType;; X5 ^% @' A+ _5 L+ i
- import net.minecraft.resources.ResourceLocation;
* B" ~( W4 H6 z - # S0 {# ~; @0 S- u2 z" }4 C
- import java.util.*;" O3 H* ?: X6 ?5 A
* Y% v7 w v1 q V+ P$ i- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(- A6 }2 E( F- ^) A# |
- 4 a6 S8 b. |9 x; a( u
- public class LineRender{# q/ Z- N- s- i8 A
- private final PoseStack pose;* L6 P/ k- b% T8 F. T
- private final MultiBufferSource source;" _/ |5 W, j/ X
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ K$ X I4 d& o: ? - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();$ c% C: V# m7 _" E3 w! M
, X. k7 j% G' B3 f- B' e
. q3 V3 S, e9 M: ^- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){+ G- Q' r1 i3 A! u- h
- if(x1 == x2 && y1 == y2 && z1 == z2){
% }2 C) D- l& d Z7 V0 w) Y; c - return;; H7 }6 y( U* _% s S
- }- Z- h: i! N$ Y
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 ] X2 B# E6 D
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");0 w2 ~9 D% x0 K$ ^% e% z4 K
- }: s. r5 i* i: N8 e) b# S* r
- pose.pushPose();
0 i+ ^# d# D# Z - final int newLight = convertLight(6);! L( Z7 P/ P( t
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; H6 c* @5 X7 c( ~6 m/ w - final float lineHeightSmall = (y2 - y1);- b8 Y6 O! H( q* B$ V& B) [
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; e( a9 H3 m# E) j
- pose.popPose();6 J' W2 N2 q# Z% m! N
- }
- k7 w X# M: Y% a- ?
; X$ z& x) J: \6 Q8 l- private RenderType getLayers(String texture, int light) {4 b" B0 F2 e( }( i) C2 z7 p
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. o3 h3 V0 [2 L8 o' X - }
% S5 |9 q- ~4 z5 `) s; ?
4 b/ X6 d- ~8 X1 T' y) n- private RenderType getLightTexture(ResourceLocation texture) {
6 V/ r2 Z* e) w ?7 {0 s/ d - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 C' k; ^& _$ o% h' W% n
- }
; L# x3 ]0 ?% v: V" F u - * `% r A- B+ i9 _1 v8 F4 H
- private RenderType getTexture(ResourceLocation texture) {, l" \6 y0 `! e5 ]
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);' C9 r; @+ Y* W" @+ a% N
- }6 g2 l2 {: }* Q" K3 z G
3 S/ {+ K: @2 k4 o. a3 e% s- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 u7 N: U* k7 V5 u% U6 b# t - if (cache.containsKey(identifier)) {' R0 D% T# T1 b1 Q. z. m* |
- return cache.get(identifier);
4 k2 J2 Y ^- m2 \% r - } else {* k" Y0 f0 |3 d* O3 w% T
- final RenderType renderLayer = supplier.get();' z) `2 l! V$ j9 S+ o
- cache.put(identifier, renderLayer);& U: K4 G& ^" p; ]
- return renderLayer;
q# }" ~; m W& T4 _6 | s$ H - }; B( M p8 f# ~& ~6 l6 r. ^; {
- }4 l- E' \! [" z- s% D! l) e% {# S
- }
复制代码 |
|