|
|
: `2 T# }+ _5 F行,这个怎么样
6 V7 \3 G* T# ]1 |) |" T& S2 }- package com.xhg78999.mtrfac.render;! ]& a! F7 P, P( f: K. ~ q
- 2 N4 B$ I" x* F. q
- import com.mojang.blaze3d.vertex.PoseStack;. f0 u, |" Y+ W T4 n
- import com.mojang.blaze3d.vertex.VertexConsumer;6 C8 z! ~2 X+ W$ h$ j
- import net.minecraft.client.renderer.RenderType;; d$ f; G2 H5 ~! q# }, B( V
- import net.minecraft.resources.ResourceLocation;
9 h1 B* q0 ^! ?/ c
+ M1 l' e' r( J" o2 k- import java.util.*;6 d& {1 M" m' J% k9 O( h- v9 q+ i
- ( x1 Q U% F7 M$ F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
( r& F* l4 F% R( B4 H
9 g5 y# j& E/ A0 Y: G- public class LineRender{
; W; U1 j$ N& \0 o - private final PoseStack pose;1 r/ A4 y: H8 _) {% x4 T
- private final MultiBufferSource source;
3 I' W) x5 ^ T6 ] - private static final Map<String, RenderType> CACHE_A = new HashMap<>();" G' w d& E4 J8 J
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
; u% p3 z- r$ }2 S* p - E: E- D' E! y: z
- + I# _1 W( K* Q
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
8 r) m) ]+ X+ C e1 D! b5 [, C - if(x1 == x2 && y1 == y2 && z1 == z2){
- e! {. L% ^7 K! B( X$ h- U8 O - return;
5 U8 P; I$ I% @4 H& \9 ^ - }" z& R. N0 h. R9 w* p- S! ^' C2 \
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){- k8 G# \2 o% U8 v( n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 g/ m+ Q* ?2 z9 @7 B( E0 X2 d3 b
- }& Q# ^4 K. f! M. W
- pose.pushPose();" B. @. a1 P: p; X$ @
- final int newLight = convertLight(6);
- d; K* v4 l7 f; { - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; {1 z# K N" _
- final float lineHeightSmall = (y2 - y1);
1 Q, |2 v' R$ A7 \ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) R8 P/ `3 h1 G# X3 E
- pose.popPose();
( h( {: f: L3 q2 F8 c - } M& g6 v) I6 b
- & j* @6 [2 J/ ?+ \
- private RenderType getLayers(String texture, int light) {
; u" u$ ^0 q) Z$ R5 p - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. Z! x! c, o0 R$ s8 a - }
! z0 X' z+ G8 Z% ]4 L, B
- f5 g2 D5 [6 T/ S* S, h9 _; l- private RenderType getLightTexture(ResourceLocation texture) {2 E4 r9 I( R% f4 Q& [
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);( d0 }9 x" D6 u, ~
- }
! W9 G6 Z, k: A0 N: J4 t" h7 _. ? - + q* Z# E3 u( C, X# [9 X' E4 S
- private RenderType getTexture(ResourceLocation texture) {! E0 S3 E: m+ @5 v: j' G
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);) X; D% o1 T. T" U
- }# Z$ V+ u( k& \1 g$ b5 x+ E% L
2 _5 t5 E* a# V* C: r- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( d0 } _+ B. i
- if (cache.containsKey(identifier)) {4 c9 d: s2 I+ X7 k2 p" T4 E! ` q# Y
- return cache.get(identifier);
/ D5 i; r- _$ G - } else {
9 i2 T& z' b& u# b3 _, e - final RenderType renderLayer = supplier.get();
+ _2 g) m2 W9 h6 ?* N7 L - cache.put(identifier, renderLayer);. k( l$ T6 N# U
- return renderLayer;1 L7 a7 a4 I' y( [0 h
- }
* |: e2 j, z4 F1 I - }9 H& X l7 I5 B' R7 a* @
- }
复制代码 |
|