|
|
( J2 a" a# [3 Z% k# @6 z
行,这个怎么样
" e' ?( t, J; }4 I6 ]5 X- package com.xhg78999.mtrfac.render;4 l# s. c- L7 n% h$ K: p# A4 ~
1 n- R& g. E0 q6 @3 Q' d- import com.mojang.blaze3d.vertex.PoseStack; k- S! l" _1 V: ]9 q/ q
- import com.mojang.blaze3d.vertex.VertexConsumer;
: L+ `/ Y. l r5 t1 I* I# M, E - import net.minecraft.client.renderer.RenderType;
- _2 s8 m/ f8 u7 f# {8 G6 r+ _ - import net.minecraft.resources.ResourceLocation;) [5 S: I3 W( ?3 Q; a3 b
- # [0 u* X0 E4 c e
- import java.util.*;
8 M$ E# w- Q J4 A- Y# _" Q: ?% V - $ p. _9 \' \* E+ v) B) B
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% I6 N. a/ o' s5 f2 s+ Z! m5 c5 J
- ; P% C) t2 _5 T* v4 n/ p
- public class LineRender{
4 B$ y. }$ m! S" Y% J8 d7 M - private final PoseStack pose;
9 L0 C8 U; Q7 n( ~- n8 t* u - private final MultiBufferSource source;
4 P( H4 ^0 Z ^3 O+ | - private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 ?9 L7 X- R o% l
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 T3 [* f/ L) b& g" T/ ?
8 L3 J8 B2 ^% @, ?# a- # V! p" Q0 V+ M. d( N# G
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 `0 k" u4 B0 U, e7 Q3 \
- if(x1 == x2 && y1 == y2 && z1 == z2){
' ^- @5 @7 F3 o& N - return;4 }6 D9 B" k+ _1 ]
- }! W: @2 s% \- s+ t; n6 q" w7 r3 B
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" P. P+ s7 \: B4 ?5 C7 ` - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
9 c. {- E" l$ X. [# N - }3 M9 ]3 X; d- S4 b# _* K& K+ J! D
- pose.pushPose();
, d5 R! \" @& { - final int newLight = convertLight(6);! l3 @" l! y/ n5 v* H
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 w$ ?; b, m) u! C) W
- final float lineHeightSmall = (y2 - y1);9 x* e9 F$ L' D U- ~: M3 w
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: [. n% N% L/ j4 e' D: g. Y. S' h - pose.popPose();
! U8 l) z+ \7 H - }9 w. j i1 e" q K! ]2 J/ a1 U
& Q/ s, Z$ L0 k- private RenderType getLayers(String texture, int light) {
. F0 D1 {/ s+ Q7 W7 Y3 J - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
& O. w% _+ f5 y* Z+ s1 u - }
; y6 I& O z( {, T( W% F" {8 @ - 9 C' z9 L* \7 s! j7 _/ {
- private RenderType getLightTexture(ResourceLocation texture) {
# e! S6 S$ ~3 w, {7 k' g$ \' `5 k - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ R$ R6 g! @3 t( ?# C# V
- }/ H+ U/ S0 t5 Y8 A, G! L
- 0 W9 V+ l& N) _& r& C2 U/ o; _
- private RenderType getTexture(ResourceLocation texture) {, n9 S9 l0 e" B/ u
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);, k* J# S. T' L; a/ t
- }' p2 s. l( x5 p5 F% U% p& i' Q: ~
$ D( K6 o# X1 a7 z1 ]% ~2 J" Q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 t k8 p; g! _0 K' R- P6 u/ a
- if (cache.containsKey(identifier)) {
& E) P+ u/ h$ g, C S9 N7 ~, m - return cache.get(identifier);
" K: z" ~2 A& y5 T - } else {7 U8 t' t2 `! j* J& K
- final RenderType renderLayer = supplier.get();
8 n; G# |. G' T0 g# {' D" m1 T - cache.put(identifier, renderLayer);
: _8 j/ S7 ~5 A# Q - return renderLayer;
2 _. ~7 x! r- c4 d4 z - }; w+ N* l; o, } p( Y
- }
& J- |& w* D6 Z6 b2 q) q - }
复制代码 |
|