|
|
4 g5 k) M/ d! F, W$ O, b行,这个怎么样
/ I/ `. x! q0 L7 s" y/ ?( @- package com.xhg78999.mtrfac.render;; ]8 ~: y7 W$ \ ^9 q* D5 ]
- 8 D( L/ `; J A1 }$ J
- import com.mojang.blaze3d.vertex.PoseStack;
/ | ` w. g( F8 Z4 o' ` - import com.mojang.blaze3d.vertex.VertexConsumer;
' ^4 ^8 {. O% ]% Q! q - import net.minecraft.client.renderer.RenderType;, M$ l6 B, S9 g y" w" v
- import net.minecraft.resources.ResourceLocation;
! C8 y& G7 h, K& W% L2 T - 3 h/ {* O8 o* ^" C6 l" O! }! ?$ m
- import java.util.*;
/ O- W$ G8 s: O' Y) s+ f/ U
+ y7 z( k( } \4 G& b i- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(% s( r0 Q2 M& d1 H% Y* V
|2 e& {5 Y: o# ~6 `! a k! c- public class LineRender{
/ \; B9 T, u: L3 m - private final PoseStack pose; g+ c, M/ H: C" t0 R' a) U$ @
- private final MultiBufferSource source;
6 ?/ ~+ a3 o% s9 I - private static final Map<String, RenderType> CACHE_A = new HashMap<>();$ h; G+ Y: q+ s1 I r' ?3 X' a! w$ L
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();: e5 m! [4 X& I. {) n2 t% u
k( z6 x5 k+ @8 B& o! L- 1 Z% Q2 ^1 I7 q& g% c# q2 S) W
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 C% e/ ?- b9 h3 v+ D. L$ _5 u, E - if(x1 == x2 && y1 == y2 && z1 == z2){
5 g7 c( g$ N# w6 u - return;
1 t! }. E% [( L$ e3 E6 Z7 A# Y/ i - }
- r/ }! t( V$ I0 w- L9 T - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
, N, ?; i6 z0 O/ J/ u( Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" F; b X" z0 H" ?3 D$ u! { - }
% f5 y& X( Y' P9 f7 o% |8 b - pose.pushPose();: g1 v4 h' g9 I' `
- final int newLight = convertLight(6);
% J! D7 Y6 I+ A% K - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
/ f+ E5 L/ }2 f# m7 }( O3 e1 Y - final float lineHeightSmall = (y2 - y1);
' A1 E) D) D) \# }5 |3 l - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) S+ `8 ^% O& ] - pose.popPose();
9 I7 \- y7 q5 _' Q0 y - }& V B5 T5 I3 v% l! P- M
! c- K" H9 N# a6 X- private RenderType getLayers(String texture, int light) {. B$ K+ |$ b T5 p+ ]8 h
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
: C7 g6 A& C7 G. m: R - }
& y- g1 n4 x6 T) a" ]
% c4 x' ~8 n/ z" `, q1 {) M- private RenderType getLightTexture(ResourceLocation texture) {7 o" D7 Z. i; I1 x. g! F
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);# ], i) H |( f
- }
& h7 A3 E( H$ E+ O - % i y$ K5 y8 ^1 Q- R! b4 r
- private RenderType getTexture(ResourceLocation texture) {
, h- I9 _8 k( r - return this.cache(texture, () -> entityCutout(texture), CACHE_B);) y. s4 ]2 k. b2 J6 O
- }2 l# q: z C. K6 c# z: b3 q4 ^
0 L6 g9 f/ Q- U* H: V- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ s: `, h. ]' F. I3 u
- if (cache.containsKey(identifier)) {1 X. D* r* ^4 t5 Y$ _0 T3 p
- return cache.get(identifier);- V8 O3 s/ ]* X( ?" ^. H
- } else {
: x6 h5 N. ?7 k0 g - final RenderType renderLayer = supplier.get();! i! B i$ N) ~; M0 a
- cache.put(identifier, renderLayer);9 m& M8 Q1 ~* r# }6 W
- return renderLayer;
$ R$ G1 z- S% C9 k: p: C$ H8 ] - }8 Y& [6 D/ x( I# G |
- } c- | y; h: D& B# p/ B
- }
复制代码 |
|