|
|
! z: E0 u# t) C3 C% x行,这个怎么样
0 H$ J" q+ s/ k1 u6 q- package com.xhg78999.mtrfac.render;
0 B; m2 A- B3 E1 I1 B& e* L5 s. U& H2 K
) j5 h) d! Q2 g% N) F( g( U: R- import com.mojang.blaze3d.vertex.PoseStack;
+ ?! t- Y! D+ Y( P& g) @- ^* T - import com.mojang.blaze3d.vertex.VertexConsumer;
7 g: ]7 E$ q4 ^& o4 V - import net.minecraft.client.renderer.RenderType;& L9 N; k8 s2 ~
- import net.minecraft.resources.ResourceLocation;. [% `& L. I- d
- ' |, Y9 H5 g" e! \1 k! P$ `' u8 A
- import java.util.*;+ [# c' Q5 s0 t. ]2 j0 h
; F6 Q( i$ k7 l7 @( j3 |* W- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(# L$ z2 E# K& {$ W
- u, j" l+ d) `6 O! g8 k
- public class LineRender{, c& ]" H, D/ y# C$ A8 @5 k
- private final PoseStack pose;
" `* C' m3 g. _& x- D* s7 `4 G - private final MultiBufferSource source;
5 q+ D9 `! ?% ~: [4 q- U3 _ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ H. h2 Z0 D9 j- @# i; k - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% C2 ~+ R( K) U: W. L
3 c& h& P; A) {; _# l6 ^+ l0 G
6 ^7 m( ?1 Q! a, y, I9 {- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# ~# X& y2 a/ g( B" v - if(x1 == x2 && y1 == y2 && z1 == z2){
% x* Z! J0 c, Q8 L - return;) i! D' h3 q$ H$ P7 U& k
- }2 u; Y1 p# X& V0 c4 ]% b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
' }& ~, x6 ~( l H B$ z9 ?* r - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: |, _, k* a& a3 A. s - }
! ]9 v5 f; s, d7 _ - pose.pushPose();$ G; t. w/ ^* r" k
- final int newLight = convertLight(6);& y9 W& o$ R6 D" F/ o3 J; [
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));! ~5 @5 `, g4 e2 }7 F2 `
- final float lineHeightSmall = (y2 - y1);
9 f& M$ y: Y! M3 @* x! b9 I - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 X, A: I! x2 r( B K" F9 R }5 F
- pose.popPose();8 P4 f; p) B/ F7 x
- }' _* E% J! O0 O4 k, ^
- L! f6 j9 g$ A, v5 d
- private RenderType getLayers(String texture, int light) {/ {. m0 p; e5 o7 ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. a* C. y; J; y9 t" T& L9 a - }; K/ r% e. U5 i1 I+ e2 h, W
- ! ?2 `6 o" j* h
- private RenderType getLightTexture(ResourceLocation texture) {/ r. V" N5 k) m2 u& A
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);* h; M& n- F& k+ v
- }
: [6 @1 [# {* t. G+ r0 Y( F* h
) J: y9 [) c+ G5 R& O, P( r- private RenderType getTexture(ResourceLocation texture) {: G# E- @2 _+ Y. J
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 l! b1 s# O- I& Y
- }
9 T3 Q: h4 i4 O% Z
; S0 y2 y, `- M4 h8 R$ E- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {2 _2 l0 P5 }; @* p# `
- if (cache.containsKey(identifier)) {, I/ g; K8 S; r' H
- return cache.get(identifier);
% n& |0 u, S# t7 e' H. W7 W% N - } else {
2 c0 {5 S. b1 D) c/ c - final RenderType renderLayer = supplier.get();
8 @6 I! q! |; R+ o* w+ y$ w5 G5 L - cache.put(identifier, renderLayer);2 ^' V9 I D/ i( S# j% W
- return renderLayer;
/ I' Q/ d$ ]6 @) x - }* Q( I( n1 ?. M# ]+ f* `/ S3 I, Z; w
- }
. S; j, i' k. v0 a( W - }
复制代码 |
|