|
|
+ R0 A3 a2 J1 _: R! m2 [
行,这个怎么样/ m; U/ S# U$ c0 E. h
- package com.xhg78999.mtrfac.render;9 Z: \% R' u1 J; }, i. C
; f6 a, O8 q, K: j5 p7 c0 H- import com.mojang.blaze3d.vertex.PoseStack;" c: r8 h) V2 w
- import com.mojang.blaze3d.vertex.VertexConsumer;& P! V' V6 M2 [+ w: ]( U; c& d) o) Z
- import net.minecraft.client.renderer.RenderType;
8 _' b9 x" [ y1 @ - import net.minecraft.resources.ResourceLocation;
* z; @8 y. K4 |1 ?* w( ^9 J* U' { - 3 u( c3 R/ M" R" B- ~% b8 T/ ?+ P
- import java.util.*;
* t5 Q+ b' a/ W" e6 {/ ~
8 E' G' G3 K& p, D( {& B- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( R7 @% ~1 g: o& k# P. f5 T
- 8 U* O. l j4 g* A# R
- public class LineRender{2 w2 i% r1 J# l6 R2 Z: p3 ?/ H
- private final PoseStack pose;
. C5 T: C0 |& p* g( r- w7 {6 j - private final MultiBufferSource source;
2 o/ \2 Y3 u0 u3 b! p6 p - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 i$ o3 B. [3 L0 M - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 e8 o4 v/ k& z# T" f. u! {) l
( Q4 M- Y- ]+ z
/ T7 y4 G/ L# I" e4 Q' G- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){: m) q" s6 V j
- if(x1 == x2 && y1 == y2 && z1 == z2){
! l, { C& T2 X6 Y - return;3 `1 E' y4 Z5 ]3 C4 ~3 V
- }" z) k: Z( G+ E; Z" e8 K9 [3 ^
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 _8 v+ ]* V' b8 Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");3 e- X9 s3 u% B3 h
- }
/ [5 Q! `/ K- I U; c [ - pose.pushPose();; u4 x7 ^5 M# P2 S
- final int newLight = convertLight(6);
( B# O* k2 C! V5 j" |1 h" G - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' v/ v3 m1 B$ `& G8 p" W0 v - final float lineHeightSmall = (y2 - y1);) u' ]0 H- ]3 A6 p
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# C4 n+ N8 h% J- I. F( o
- pose.popPose();
5 |" E9 [" M9 X) @* ?5 X - }# j- f9 l4 C( a& K G2 t1 E$ Q; f3 u
- u: w- J3 k9 H. T6 `1 [2 F
- private RenderType getLayers(String texture, int light) {5 G7 t/ W4 \! i9 i; G% f
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
8 z! s$ Z. w- ^4 i* n* Z - }* ?) x9 a4 O! E1 }! m' r
- ) \- v: L8 N* {/ P* r& V
- private RenderType getLightTexture(ResourceLocation texture) {
7 ]7 f; ^% w: {( X* F) P2 m - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 c# W# _% T2 q8 s& Y, Y
- }) m7 t% \3 B! C$ M. \0 U2 O
5 J( j! a F% k. B* n6 C6 s" V- private RenderType getTexture(ResourceLocation texture) {0 r* p M* u o; A4 h* @( f
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
$ C5 r: F# f, Y; a! ? - }
- D# h+ N0 n: D$ I( I- S' P; F
1 A- J! V+ F. y. u5 _! W; p- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 b0 O4 e. v* a' f - if (cache.containsKey(identifier)) {& v* \* A) b: v! B
- return cache.get(identifier);
0 _5 v, Z% E( \1 \2 H8 s: N2 K9 B- c - } else {" A% ^6 y6 u- p* A
- final RenderType renderLayer = supplier.get();
& l% r/ G! U2 P* x1 f2 ^7 ` - cache.put(identifier, renderLayer);# I& m: P" N. Q
- return renderLayer;3 t* V% N% ?" j2 H: ~0 ]' k
- }
2 g2 ]$ q# E3 y1 R - }
- m" }- c1 U- f. Z - }
复制代码 |
|