|
|
3 b4 P& W) B3 n4 u$ Z: H/ k
行,这个怎么样8 _" k& K: k* o
- package com.xhg78999.mtrfac.render;3 n" W" q5 ^5 e9 k* { c
5 a% ]5 T. \0 H$ g- Y! n8 t' i- import com.mojang.blaze3d.vertex.PoseStack; o0 S; t9 k c, G
- import com.mojang.blaze3d.vertex.VertexConsumer;
; `) f- D! o- l- `0 L' J" U: q7 Y - import net.minecraft.client.renderer.RenderType;, d* \8 B4 Z1 t/ }# R' y
- import net.minecraft.resources.ResourceLocation;: R$ x4 K6 [2 _7 j- p
- $ z5 |6 }3 g3 I0 `/ `* w* K! U2 u
- import java.util.*;
+ Y& P& H+ y$ [4 A$ O1 L3 d - & z& Q- ~6 v& [ w0 o: C
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. [$ r8 G$ l; p9 J* t
" X; ^" M3 }( a- public class LineRender{
) R8 f2 @/ O+ }/ d8 u; T4 | - private final PoseStack pose;
4 J9 a& N% d' D' e! K - private final MultiBufferSource source;
, Z/ {4 I: O3 _0 |0 S* }8 \& B9 v - private static final Map<String, RenderType> CACHE_A = new HashMap<>();* _4 r0 a9 e5 A! I
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. e6 e1 }$ z3 D, e3 ?
8 F; Z- g0 S! h. n
5 n. y/ ^* Y- E" J1 l$ T- I- l( v- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
( O1 W4 P* x+ V7 x - if(x1 == x2 && y1 == y2 && z1 == z2){1 O/ e m" @6 B% M! S
- return;" s$ @) P4 s$ i- Z
- }# U7 b A* x+ ]: {4 m( [$ E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){4 r8 K1 [8 P1 v
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 s9 N3 R( h. Y5 G% K - }1 ^- O8 R+ J0 E) \) ~; R" u
- pose.pushPose();" Y9 i, O- C7 _* o* e r
- final int newLight = convertLight(6);& b2 x# P: E: R$ [# f
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));/ k: O% C- }$ r x
- final float lineHeightSmall = (y2 - y1);: O; }; L# `% [
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);$ v" r$ H1 b8 v- Q9 {3 t
- pose.popPose();
" e9 ] |1 Y" r5 n/ v - }
& ]. h9 U" v* ?" n8 _- ~3 _% ]
( H# m% t" m1 C% z8 ?0 t- private RenderType getLayers(String texture, int light) {
( F$ m% x9 A" y6 O% \! j$ r - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 g- D+ e2 G- m9 u8 D8 d% D# g - }
- K& K% l b+ K# L
/ F& O' E l/ m% [4 v- private RenderType getLightTexture(ResourceLocation texture) {
5 Y, \+ W: Z4 W7 e2 O - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);: [3 s! Y4 c* x! s3 S
- }. p+ W: z7 R, I" y! X, [! j
- . S7 \8 N9 [- a+ _
- private RenderType getTexture(ResourceLocation texture) {
7 [7 R, A0 `4 W6 | K/ I - return this.cache(texture, () -> entityCutout(texture), CACHE_B);, {* B! [3 ~! V' R+ f3 [
- }- w, m/ j2 d, e5 i. f' r5 M$ |
" u6 K5 t9 E5 \' K. P- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 w% ~( r _; x7 h5 L
- if (cache.containsKey(identifier)) {. y* W- g# i3 M/ G' `" S; I
- return cache.get(identifier);
5 d# _7 ~7 E; R8 [' H4 n - } else {
& l) ?* C6 U+ p' N3 W - final RenderType renderLayer = supplier.get();/ Z) _+ D C0 x/ Y, n- R. e" y
- cache.put(identifier, renderLayer);1 J: \1 x: b$ x" p# D
- return renderLayer;
- F f+ Y' D+ C - }: X# J3 t4 `% A
- }
* a% o _$ K) z8 x3 p! O - }
复制代码 |
|