|
|
! |( r/ Z; P4 p. \
行,这个怎么样* i( z7 y" h+ X8 _
- package com.xhg78999.mtrfac.render;
! Z j2 n: e9 b( |, ^% s# L: C
. g" j" l# M7 ]' w- import com.mojang.blaze3d.vertex.PoseStack;4 X9 |9 E& ] O8 H, @
- import com.mojang.blaze3d.vertex.VertexConsumer;
. N+ F- R$ ]$ G; s - import net.minecraft.client.renderer.RenderType;6 k, s5 t% |" t- F1 U+ {) C9 p
- import net.minecraft.resources.ResourceLocation;) t" Z. H1 ]7 Q3 x- d
1 c2 I3 L# S2 c P7 K$ s- import java.util.*;
5 T9 P2 P4 N- Z: Q/ J
: p- h! u0 g. V3 B6 _& @2 a& W- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! I" ~1 P- h- Z; Y9 N' w
- % u7 f9 i) `3 T2 [( S/ A1 o
- public class LineRender{
! {$ H1 X7 M q- z - private final PoseStack pose;/ X2 _* ?7 ?& D# n+ O$ B) v
- private final MultiBufferSource source;
/ j9 ~3 U. o! g4 r+ |' o - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: ^0 H: e3 E3 w0 B' b( ] - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) V: H0 V8 y k' G2 o: I, E- x - , b/ o5 ]8 y# e( \5 ^" e! {8 c7 Q( Z4 X
- 0 W9 S$ P, }9 F
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, S. ^$ N u, E6 j* P& G - if(x1 == x2 && y1 == y2 && z1 == z2){
# A J1 f- [, b7 J - return;5 R3 {1 J" j5 }9 L$ @. _* k. _
- }
0 d6 G4 {, ^9 Z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 ], r* L U% }5 H& X' L - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 o. m4 r8 F' Q$ ^
- }
+ z8 u3 R( H- i9 Y6 [ - pose.pushPose();6 w4 o0 a$ k6 ~9 b
- final int newLight = convertLight(6);, ^ p+ u* E" `. B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
& f, z9 Q4 G7 a3 u G6 j$ G - final float lineHeightSmall = (y2 - y1);2 g0 O! s6 p, z z* a0 U
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
. x* B. U2 [2 v G - pose.popPose();# M+ y7 _# I& N6 W: f( W
- }
3 r2 e {7 W0 Y }% X& `
1 i! Y0 X6 a% C& G' Z8 x$ p( |- private RenderType getLayers(String texture, int light) {
. f p* o/ C$ F$ s - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, f8 P; {9 E4 m% U( ~+ Z+ \2 F
- }
, M$ E2 y4 m$ }' r6 [ - - S2 U/ q+ E3 N7 y0 }7 e9 M
- private RenderType getLightTexture(ResourceLocation texture) {
2 o8 W* {' `0 X: g! {" e - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);( R& j" x, t" b1 V8 N& u3 F
- }4 h1 d( d J+ ^3 [# }
- $ z" r; A8 {) d f
- private RenderType getTexture(ResourceLocation texture) {
' }; T" ^& x% R" \" [ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);; c) T7 x9 O# ^
- }6 U2 J% S( `% l9 S+ z+ h
. W7 S: {& [* e# z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 Q. o8 R$ Z: I; V. }% I
- if (cache.containsKey(identifier)) {
5 H3 U7 m. ^3 @3 k$ R - return cache.get(identifier);
, E4 k! O8 Y) j l; d& s - } else {
: T' n. H6 j! z& A - final RenderType renderLayer = supplier.get();
" Q. H9 e2 a( K- j3 J# F, q6 j3 W9 | - cache.put(identifier, renderLayer);- r; L3 O$ z: ?+ v4 l ?' W
- return renderLayer;
) e% F8 W( k' e - }* P) U5 x$ a0 G2 \, J& h& _3 \, F+ j' S" K
- }6 J) g# {! T, r j, ^: [5 V% L
- }
复制代码 |
|