|
|
$ X8 S z7 z/ c0 y6 o; C5 d行,这个怎么样
) G. r' ~2 ~) z6 F& S6 ?1 O1 R- package com.xhg78999.mtrfac.render;1 l2 J& V: d* ]7 A8 i
! o% g2 S$ ]2 t* G- import com.mojang.blaze3d.vertex.PoseStack;) R% L, X( o" A4 v% e
- import com.mojang.blaze3d.vertex.VertexConsumer;
7 r# [2 q0 b$ f( e0 T - import net.minecraft.client.renderer.RenderType;' Q' \4 P4 x$ S4 D8 Q
- import net.minecraft.resources.ResourceLocation;" T4 v _$ X8 s" w
- % l% ?, j/ @# v/ |9 l
- import java.util.*;- z6 Y; L z2 L0 l) r4 L& C
7 [# p* h F) {' B/ o0 U. }1 H/ ]- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(' K* L& Y' O$ x6 W: N6 U5 E8 [
- 2 } n6 S8 ^$ Y
- public class LineRender{/ _4 a' t4 B0 c# T0 Z7 ?
- private final PoseStack pose;, t1 `) o) w: V% g' j( l
- private final MultiBufferSource source;
- h1 A- ~3 f! w" P - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 i" o) D7 i) ?% U# X - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) k& \1 H: L" e# L8 x2 f& r
U' |; s2 f( l/ u3 D+ f7 E
% l$ |5 R6 ~" e* p0 h! N$ T D; W- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 s; \/ n* {: j: V; L - if(x1 == x2 && y1 == y2 && z1 == z2){7 x6 c* i: ~$ ^. q% d' i
- return;: c! q. j- j; v7 [% Y( z
- }5 s7 V; D; I+ _% T) p" [# I9 b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){8 ?3 i9 `, c/ s1 i6 {0 M, t/ P
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ s# s$ i- s7 `1 |1 C' ^ - }& C2 n+ T) _% w) q; j
- pose.pushPose();% k$ |" _; B" s' F
- final int newLight = convertLight(6);4 Z% F2 {8 ?/ x( j! W& |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));) G+ l0 P% n& v3 f/ u$ p5 \+ V
- final float lineHeightSmall = (y2 - y1);/ ^9 B/ J# Y T3 e
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# \* r" }' f7 b$ y' h; G+ G- Y - pose.popPose();+ z3 a* c( V* d; E" p% s
- }' A0 K: q& f, P9 _9 c) H
- - K& {# X3 U+ n5 K+ @) e) _
- private RenderType getLayers(String texture, int light) {
4 d+ X& M* i& I( {7 A& E - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));5 @/ O4 U$ z* S* T$ I! d
- }, P# A/ ]6 U1 X/ f8 O! U
- 1 P* P# l) r: q- M
- private RenderType getLightTexture(ResourceLocation texture) {& n! y$ w9 U- V4 x; [+ A! J
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. J' _5 y* A: G1 \! R) k
- }
) D5 N, b6 @, A7 M. O - ; d: O$ ^+ h7 R, k% b1 ^
- private RenderType getTexture(ResourceLocation texture) {7 W7 @% \1 ^9 S: g
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; W8 Z: j j$ O' D - }# C; f$ F$ Z1 ?$ j' w
+ A8 q# N0 V( W- O3 w* `% b- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 d; Q3 x6 c2 M- z
- if (cache.containsKey(identifier)) {+ S9 @& [7 P% ?1 q6 p( N' p
- return cache.get(identifier);
1 Z, M( ]& ]' j5 `2 ~ - } else {0 s y1 A- ^0 Q, v r! {2 ]9 v
- final RenderType renderLayer = supplier.get();
. r( F1 T# W( {1 j% D" Y6 E1 S* a - cache.put(identifier, renderLayer);9 L7 a0 T& Z5 A3 m1 T
- return renderLayer;
. ^5 ?0 g1 Q( A3 ^- b - }
5 X! \' G' D* m" ? - }. k& S7 G7 S7 t
- }
复制代码 |
|