|
|
4 O$ N% w5 R2 m4 Q: q" I' Q0 u* @行,这个怎么样
+ f% B4 M- j; O, X' N- package com.xhg78999.mtrfac.render;
9 M# c" v4 b/ F - ( Y1 i0 J# D3 n* h/ Q$ c
- import com.mojang.blaze3d.vertex.PoseStack;; N1 o8 |0 l! r- j% T9 P
- import com.mojang.blaze3d.vertex.VertexConsumer;8 |* R( T$ M9 I' f; Y
- import net.minecraft.client.renderer.RenderType;
/ q+ u3 n7 N' Q4 b7 ` - import net.minecraft.resources.ResourceLocation;
4 D; Y9 K$ a) e
" O* w- H" V A. |: _- import java.util.*;
: ~0 |% D3 W: h; h e' z
/ {, v1 S, p" D s! Y- y5 c7 v- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
@* ]$ w+ W. [# B6 V/ } u
" j, v6 p7 I& }9 N2 n- public class LineRender{
$ @) b$ V, O, ^; ` P7 D5 L" w- k - private final PoseStack pose;
6 t* j5 q% g3 ^+ ]% K/ ?4 J3 b& N - private final MultiBufferSource source;0 N G1 x- G! b2 H
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
( {! M9 Y: ]7 |$ g4 V - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# H- f- G5 A$ V; S6 s+ A
, h1 ^4 I# R) r! G( u
2 A/ H0 L- {; d2 A9 p. }- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 n* D0 n ]/ d2 u - if(x1 == x2 && y1 == y2 && z1 == z2){
3 H- }# p& f. A3 n - return;* K" t! f- Z: H% H/ O- C* B2 T
- }
7 J/ o) [. C. X( [. z- t5 C. H - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
7 n+ {+ o7 m; ~ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 K- q3 @6 F# P( h
- }
0 ]/ \ e5 D- E$ A* X+ p: M - pose.pushPose();
1 s" R) d# s _- O l - final int newLight = convertLight(6);
" c+ N, d# K2 g: `. c0 | - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));2 U8 y+ E, z# J7 H0 }" o3 x
- final float lineHeightSmall = (y2 - y1);- p9 c3 k) m8 P6 a/ z l
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
{8 Z' x, \8 B5 u( @2 m2 V O2 K7 E+ y - pose.popPose();
9 ]# Q3 U* P2 j1 j ]5 \$ V+ _ - }0 D7 \) S5 P# c9 j9 T' t
4 P* r) g/ p/ w8 U# _$ Y2 z/ `- private RenderType getLayers(String texture, int light) {
: B: p" v* `/ u( y0 I - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; `* T6 ]0 U- Y/ @5 ~5 _
- }
1 X( ]& [5 p/ t# C4 \. C - 7 X' p' f5 }- Y, E [# p( U
- private RenderType getLightTexture(ResourceLocation texture) {
* G0 U" F" _# R& @8 q - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);2 |, o1 A( S$ i. \, v9 t
- }
' ]: e5 H0 U1 F4 u& j% y
( F1 E( @- p a9 Q. e) A# j+ [+ U- private RenderType getTexture(ResourceLocation texture) {
; Y* c% ~8 E4 V - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 y4 L2 |0 {$ j8 I( Y - }, {* \& U( ~; }6 ]2 ^# X5 p
( \6 X% x! S% I. J3 L% r7 Y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
) \7 ]# J Z. ?% P& K - if (cache.containsKey(identifier)) {
, p6 \* c7 P& y x* J- m9 V - return cache.get(identifier);
; b/ |9 X* w9 b4 Y. y) p - } else {
0 K* M2 n" |0 Y - final RenderType renderLayer = supplier.get();" z. f; B* y8 d- Q' _
- cache.put(identifier, renderLayer);7 _) G ~4 p2 [8 x: {
- return renderLayer;" K, U0 |3 p/ j/ G9 F* s4 W
- }0 A; K% g0 a9 T! A+ D; ^
- }
6 X& E! }7 V" _. e - }
复制代码 |
|