|
|
) O* M$ T( y6 a8 e+ q* w0 V$ S. L* K1 Z行,这个怎么样
$ O' i+ j" X- [- package com.xhg78999.mtrfac.render;
; u s1 z. n9 Q. A
+ Q- J' N3 X* B) ` R- import com.mojang.blaze3d.vertex.PoseStack;
; S1 y( n- r0 I - import com.mojang.blaze3d.vertex.VertexConsumer;, g0 Y3 x+ H* Z8 `
- import net.minecraft.client.renderer.RenderType;; f' q5 _9 D- E/ q! R' y, \
- import net.minecraft.resources.ResourceLocation;3 a+ d% w' D! \# i0 v
% ^3 U# b Q3 Q) n: X4 X- import java.util.*;& ]' ?" t# t- D0 C3 a+ g
- 1 e6 L; E f6 t6 R0 j
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
% j3 Y( B' j4 x- k - * J+ N& n* b h# R
- public class LineRender{3 A3 \0 x# T2 x* n1 x
- private final PoseStack pose;* Z# K5 F) G6 J3 O9 z0 Y
- private final MultiBufferSource source;. }5 \$ U0 v2 N& q) t0 {
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
7 F( y1 Y0 d% h) K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 w5 m+ C3 [2 k& w3 T
9 [$ @* |( F1 R$ |$ M
6 u7 [% q2 b5 ?: s& G- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. c/ b6 E: O- Z) P! j2 D8 g1 E/ k
- if(x1 == x2 && y1 == y2 && z1 == z2){
3 Z+ y' E) i5 m% } - return;# P: `+ E! x" }
- }6 P4 L$ X* P7 j0 t
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
& Z) [; y; j( X* @9 ?% g - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
1 h0 z n/ B+ }) @/ | - }
. s6 Z2 ^. ~+ E. `8 r - pose.pushPose();
7 U$ O" Q( k8 Y, T* k - final int newLight = convertLight(6);7 G/ ^: ?* k$ t6 {0 j2 e) ~
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# T/ u5 ]4 J$ O! R
- final float lineHeightSmall = (y2 - y1);7 w1 E1 o! `& G: C7 G+ M9 E
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) n3 E' ^/ c( p# ?- X/ g- |
- pose.popPose();
; Y" W2 i" ^, x* d - }& |6 U: k6 e6 a& Z9 M6 o
6 h& C+ `+ M; f3 Z- private RenderType getLayers(String texture, int light) {
' R, H c4 w. O$ k" U0 w - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
; B' N' D7 I! G, f2 \- \$ K: [ - }+ Y, A+ ` I! u1 h
f" e( G# ~2 Q- private RenderType getLightTexture(ResourceLocation texture) {* q5 y- ?" J6 H3 R: {5 e1 U
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);( g, Z: N6 L2 D8 g, i, Z! s5 `
- }+ N5 N3 T" A* d4 Q
" t$ ]' `3 L4 q; y- private RenderType getTexture(ResourceLocation texture) {
- ~( }. P- @! M0 L8 N( @1 M - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% f7 _3 E, R! o, B! \ - }- ]: n' n/ h) o$ e# O
. v' J* e: X3 q+ |" z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( h q+ Q. O# L! ?- V( h
- if (cache.containsKey(identifier)) {
/ E) v/ h+ X# y& s2 ?& u4 y - return cache.get(identifier);
. m* b6 W6 A0 S3 R, F- G2 J" L4 }( B - } else {* B/ }. ~+ h, ~
- final RenderType renderLayer = supplier.get();9 f4 _7 U3 k: b' W9 ]+ ~
- cache.put(identifier, renderLayer);
9 l5 N0 L) r) i. `5 c: ~ - return renderLayer;6 K1 \) n4 g% J( A
- }
0 P: |. {! p! |2 x f( `5 f - }/ e% w% F& F8 ^5 v! k3 [0 H' ?
- }
复制代码 |
|