|
|
) u+ y$ T% @ D1 o y
行,这个怎么样. H5 H8 D" N* ]% H# X% I/ a0 C
- package com.xhg78999.mtrfac.render;
5 c4 p: e$ r1 h
+ V" L/ A8 y' O" }. B; j, E- import com.mojang.blaze3d.vertex.PoseStack;, N: J4 [' V' v, N
- import com.mojang.blaze3d.vertex.VertexConsumer;
$ K- |4 G7 Y9 V3 j9 f - import net.minecraft.client.renderer.RenderType;
9 G6 }! @$ E2 C - import net.minecraft.resources.ResourceLocation;
# c; q9 L$ Y7 Y/ k7 ]1 {' H - 5 G2 B2 @3 ^! w
- import java.util.*;
) @/ L/ r; u8 ] - 3 T3 Q8 a' d, t" f1 {3 y+ L u
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, t% U' U5 t1 C
Q4 C* T- Z- o4 e- public class LineRender{
9 e$ w3 m5 C3 @ - private final PoseStack pose;
- {$ y" N2 W# Q2 o - private final MultiBufferSource source;6 k N! Z0 G" P0 v7 s k
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
$ F& K; e/ n8 I+ t* w6 @, M! c# }. V3 g - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 S: s& G1 |5 c
2 w% a' _9 A3 r6 [3 [: p1 l
5 |, y7 J9 `- n7 o( H- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
" A3 @. u5 F) C3 D! z. n: Q - if(x1 == x2 && y1 == y2 && z1 == z2){! u3 B8 Y( y% U2 g
- return;
2 Q; R. {# m" k - }
5 A G) h' T+ w# O' I' t2 Z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; y% T3 ?4 |7 ^ M: g
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
* |. S2 D( j2 b+ f9 p0 P - }' G+ _0 O+ Q7 q* y
- pose.pushPose();+ z T! Y) s( S* V2 [) M3 V. v
- final int newLight = convertLight(6);% C! Q+ l! {8 \3 ~7 }
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& e x+ y( Q& |
- final float lineHeightSmall = (y2 - y1);
$ I7 l# Y6 s6 Z2 C1 T0 j$ T - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);0 V, v' C+ ?. I: x2 @- [
- pose.popPose();
1 D* D% L+ d3 Y6 P9 | - }* |1 }+ T2 L' N7 J( j0 @$ A8 a
+ [% E$ F- X4 E$ E; `2 S- private RenderType getLayers(String texture, int light) {$ \2 [- i8 d# r, b. T: L
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, Z( {8 z' R% ~5 c# ~5 |9 L; y' O
- }
: [! @% ^- R' Y7 d" W$ V - ! c, N/ `7 Q4 W2 Y6 n: N* j1 X( O' b
- private RenderType getLightTexture(ResourceLocation texture) {2 k9 V& [+ `; g
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A); w1 L; a+ D6 _
- }
% [, a+ L1 u" d% Y
- g5 C) o8 W8 a# p$ D- private RenderType getTexture(ResourceLocation texture) {
5 `! t9 s) C( \4 m1 \4 _4 S - return this.cache(texture, () -> entityCutout(texture), CACHE_B); W- D; x l# K- f t% |2 h& |
- }0 z' u, Z" n- k. d
- 7 N4 b% [# F5 u; j% R2 L
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
r& M# m7 A0 R' T: w* w2 b k - if (cache.containsKey(identifier)) {
4 g* f9 o2 r) p9 X - return cache.get(identifier);
1 o3 a5 z; h d' H- b l3 z1 b - } else { ^& r2 Q3 P# J+ X" h' X1 I
- final RenderType renderLayer = supplier.get();* z6 V- [* K0 |. I4 ?
- cache.put(identifier, renderLayer);
9 c- q1 U3 `; i/ G - return renderLayer;. v9 y5 o, O$ ^ [* k$ a% r/ `
- }
5 _+ e, h- r' J - }
5 ]. s5 A; M. h5 v - }
复制代码 |
|