|
|
+ m- m) i. j2 t1 _: S
行,这个怎么样. r& s. D) v$ K$ x z" d( Y
- package com.xhg78999.mtrfac.render;2 Q: M L: ^% i
- * z- w5 N8 X7 V h$ s
- import com.mojang.blaze3d.vertex.PoseStack;3 i3 E" \ b0 T0 ]% s
- import com.mojang.blaze3d.vertex.VertexConsumer;
# V7 M5 i- X E0 ^% U8 y# C- _ - import net.minecraft.client.renderer.RenderType;
* \; q3 ?& S( k9 ?" p - import net.minecraft.resources.ResourceLocation;
+ l& o3 @& ~% ]5 X$ w - % }5 D% E0 ^9 D" M0 c
- import java.util.*;9 T, ~$ A* J- B8 K
2 Y( `! P" k3 M3 N8 ^8 H" u% `- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ |. P! V _9 @ - 3 V" ]+ a* S! s' ^3 u
- public class LineRender{2 o! B& L8 k) ~) q* E+ w
- private final PoseStack pose;* V0 L8 m" S& z/ U6 z4 `
- private final MultiBufferSource source;
( W! N' G/ N( u$ c - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
( J8 f5 c' E- a1 j - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. s9 o' c, D( w2 {+ y - 9 e0 v* S: g0 H, i
- 3 v( f) z) Y7 a& a8 ] P
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ D4 W- }4 f ?
- if(x1 == x2 && y1 == y2 && z1 == z2){
; {4 ^4 ^& C1 Q3 Q - return;
6 y+ b9 E( c: Q9 G; r1 k - }
) C- T9 e& s9 ], i - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! A( k* n% \- q, W0 L1 z1 L - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); h3 _1 w" f$ ^
- }$ N# b3 s. b# T3 J
- pose.pushPose();
- g" G% P6 f+ ] r - final int newLight = convertLight(6);
/ U9 t- T9 E e, | - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% @$ D# q: |& i' r# b
- final float lineHeightSmall = (y2 - y1);
4 t$ v5 C5 H3 v& @ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);4 V- {6 b/ G+ | `- c; r
- pose.popPose();# e2 G$ I, m+ _" y
- }
H$ `0 w: H7 ~3 h+ a* l - 0 P$ I0 ~1 A+ `2 w: w
- private RenderType getLayers(String texture, int light) {
: H. t( I4 r0 T5 U: d9 q - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
6 H# R/ W4 |8 `$ n: G - }$ _. O7 R C% f7 n
% ~/ X. h' V' x# h6 i1 X- private RenderType getLightTexture(ResourceLocation texture) {
5 x" `% p1 _, T - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
3 {' h, v8 d2 ]( N9 k - }
; l$ x1 g$ y" D& v - ! k2 v! x- B4 J; X! ]# S$ p8 u
- private RenderType getTexture(ResourceLocation texture) {5 n# U1 F9 t4 l& u( R5 ^
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);% F R C2 R1 Z/ Q! e
- }- n) v% V3 ~; ~4 a( d2 L
# _+ ~) k: q5 h5 j, f- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {! F9 E; z$ F# ]9 ^* T
- if (cache.containsKey(identifier)) {
6 e' \6 f- ]* \: | - return cache.get(identifier);
! k0 C0 g% o) ~% ~8 h - } else {
- n8 v: R& b5 k' { - final RenderType renderLayer = supplier.get();
, |- h& n" P! l- c! L9 d% x. ~ - cache.put(identifier, renderLayer);
: j% t: I& H- } x - return renderLayer;# ?; E1 k' |$ j) j2 Z0 O
- }( H# {! Z* L9 j. X! ?- y' C L$ r* V
- }
' `; I; M. R# M9 [6 S - }
复制代码 |
|