|
|
% y7 F0 ^8 K& N# K( g, Q7 D8 i行,这个怎么样$ J% ~2 q4 q/ y6 I2 Y
- package com.xhg78999.mtrfac.render;- a9 s/ b/ e. Q. O+ e
- 8 p4 V$ O6 R3 {
- import com.mojang.blaze3d.vertex.PoseStack;% n) u. Y5 b+ { j
- import com.mojang.blaze3d.vertex.VertexConsumer;
; H: N% H0 v3 m - import net.minecraft.client.renderer.RenderType;
- }6 P: Y8 ^6 V - import net.minecraft.resources.ResourceLocation;& {2 t- J7 e* b; t- h
9 {* s( e& k# Q8 q+ P- import java.util.*;
X v, D0 S5 ~$ G8 G t9 D3 ~, P; w8 s
6 z* J( N) x8 K) S( }' l- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* j4 x" Z; d) V# m0 W$ g+ H+ \
0 [* `4 D- G" g) K) d- public class LineRender{
9 S3 B: \9 j1 G5 u; ?9 `' M6 H; | - private final PoseStack pose;
& W5 I y# ]* ?5 L$ m+ R- ~; W - private final MultiBufferSource source;+ j" t1 x# {, l/ ]8 u$ u$ C* Y
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 e; C0 ?8 ~" Q; Y- H( |) a- Z
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
% y9 G1 B; D9 _' T( {
1 ]- L/ y5 ?9 @9 u9 _
' H9 h) N+ r- X' \' d- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 E, O5 K$ W3 X0 Q) O/ ?. c - if(x1 == x2 && y1 == y2 && z1 == z2){
1 @6 G7 o0 V2 t, }$ v2 w - return;
* d& D* ?! j9 B4 I - }
' W! k/ E2 }; b9 H b: d4 i @4 x - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 ?5 W8 u0 j3 q4 a. ]& K8 U - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); Z5 l5 H' \9 e* R% J) \# i, y; A
- }! ?2 f3 y# j, f2 t9 T2 v
- pose.pushPose();
) |% u. F4 C7 s7 X - final int newLight = convertLight(6);1 D3 O4 a/ _& e
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 c$ u, W7 ?. K. D7 x: f' { - final float lineHeightSmall = (y2 - y1);7 ~" r% r: K% F- v/ U( T
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* ^& m# A/ Y" k1 ^7 p# I - pose.popPose(); @8 @) c# n& p" r$ G
- }- q/ L# @: t1 e w8 l
, i. C+ S- p( H, ^4 v- private RenderType getLayers(String texture, int light) {
- J+ Q; Y1 q: M/ D$ K - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));& G! u8 I( T, Y* F' l
- }' K3 d+ W# w- y: ]3 G( ?
- - F. S/ a6 M3 h& J0 i V
- private RenderType getLightTexture(ResourceLocation texture) { U. b4 y! y: n1 O4 ?2 I
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 X9 h$ ~1 t B+ J7 n% h- t
- }
; A' y# k0 U; w+ | - & A1 j' `( N3 s
- private RenderType getTexture(ResourceLocation texture) {
! a$ x) V) |3 z$ n - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
D& K4 a, `" F0 j! S - }
z! E$ p( j# E! z" Z - 5 S B1 V9 C# U7 p% I' C
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ ?/ D! S- I: `" p) f! L6 J
- if (cache.containsKey(identifier)) {
3 N+ |- i4 g& u7 _4 @4 N - return cache.get(identifier);: u" x; T, R. p0 d8 N# k. z0 E
- } else {$ K- H$ K/ f6 J0 _5 ~$ A+ ~0 x }
- final RenderType renderLayer = supplier.get();
# |7 N8 U; x) ]! C& l4 T- f - cache.put(identifier, renderLayer);( A, d! {7 d. @1 ]; y1 Y
- return renderLayer;
0 Z Q F" S% M/ ^3 ^ - }6 y) R! S/ m5 ?6 X9 Z
- }1 u. s: N" j& f, W$ n
- }
复制代码 |
|