|
|
( _/ [: S. {- _$ p行,这个怎么样
/ j) S, v! I# ]3 j: E/ j% d, L/ }- d- X8 h- package com.xhg78999.mtrfac.render;9 r: H3 N) v5 t: ^! N4 ~( T" r. [+ L
( \3 p7 j; g3 N+ w- import com.mojang.blaze3d.vertex.PoseStack;; f; d. |; e$ }0 m8 n+ W
- import com.mojang.blaze3d.vertex.VertexConsumer;
, o6 ]( x& D8 h - import net.minecraft.client.renderer.RenderType;
: ]# _7 d1 p- D* X3 r- Z - import net.minecraft.resources.ResourceLocation;
4 b# S7 \% A. e6 p1 J' O - 8 P( _( `0 J4 ~: E. v7 U. Z
- import java.util.*;7 E$ h9 m& K4 O: Y5 e
, _: L& K5 G% P- ]* m- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(+ k( e3 G& f/ s
/ a9 a8 C. P v- j* p/ i- public class LineRender{
) L- P9 K7 n3 s6 M; G" E8 O - private final PoseStack pose;( {) g" I% y$ T( M" o( m, x2 m& W2 _
- private final MultiBufferSource source;
! i6 \2 l4 F I: x$ [& U* Y$ j - private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 P( ~: |5 f$ L+ k; A
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& |3 T# i3 b0 u* k8 r t% _) l1 z - - S8 m; q8 ^* N. C
$ b3 l- W2 U6 `. K( d- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( \6 n4 ^( g; t
- if(x1 == x2 && y1 == y2 && z1 == z2){
: H# H) d# V& e9 G6 J* S - return;
" E$ p8 H9 z& n$ {; K - } R* ]6 B- q- {
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ V( j7 U* P: n! e u6 g$ g2 U
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 _( ~$ L, F: a' x& }& `/ |; R - }
n( R. \* B- z1 ?2 M - pose.pushPose();. x. r7 j! C% C8 V8 b
- final int newLight = convertLight(6);$ n2 P7 W9 p& m/ b2 d/ i
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 K. [3 Q2 n% s6 s3 u# G; e
- final float lineHeightSmall = (y2 - y1);2 |8 F/ R3 F/ k% i) r! u
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* O1 I( L6 r2 M( i J6 r
- pose.popPose();
* ~: q% l, F# l4 u3 v8 g - } P7 e7 I) i# V0 L0 G
3 i( d+ d) X7 ^& C$ w+ M- private RenderType getLayers(String texture, int light) {
% H. B3 |9 u- D9 Z- x8 q# U) J/ t& T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( L% f0 C: F' o* p - }: I- S) o& T, p g
+ E9 Y* ~5 u; ? f/ r& S3 X* u1 D- private RenderType getLightTexture(ResourceLocation texture) {, S' ~) E0 @) n! z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);2 r, I+ i# \" C/ O
- }
0 b7 `& Y( D; a, |( ^ - " e! `: Y' ]( y0 T ?) A
- private RenderType getTexture(ResourceLocation texture) {9 C2 v3 [4 V" e8 p
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 U* _5 Y) w; ]5 t
- }5 N4 s# r$ }: A- T8 b( o
% k; E* y( ?, d! N3 |' D- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 W' S& o4 P+ D4 r. L
- if (cache.containsKey(identifier)) {+ S7 j, `! P$ ^6 Z, d! G$ L
- return cache.get(identifier);+ H. z: N ?) ?- J# w6 ?9 B
- } else {
% T; H' u. z" M0 Q" y4 v - final RenderType renderLayer = supplier.get();
& F/ n# k2 P& M - cache.put(identifier, renderLayer);; I, G4 f% ]1 r. s) B
- return renderLayer;
+ G3 |) l8 q7 Q - }; f9 o' S5 N' N1 @- {6 o+ g
- }
3 }7 w5 @( f( ^ - }
复制代码 |
|