|
|
; N, R8 |" p K# b" P, A行,这个怎么样 Q: h0 A- \5 v; n. J7 ?
- package com.xhg78999.mtrfac.render;& G7 Y- K- P! ?" D3 u
- 3 ~6 b9 X# t! {1 g$ b; A! J( ?
- import com.mojang.blaze3d.vertex.PoseStack;
# J, d, N9 g) d' b: _, E( k - import com.mojang.blaze3d.vertex.VertexConsumer;
" j+ j3 {0 B' ^9 s) |* o - import net.minecraft.client.renderer.RenderType;
1 K' C/ ~, d7 d$ F( I+ ]( O- l - import net.minecraft.resources.ResourceLocation;" h* F& a H5 @ |" U
/ z" }$ r" P, I& _- import java.util.*;
0 M* M8 s' Z2 v2 E
, ~# M. o, d9 f, x- P8 J0 C- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; J X: h9 p5 ~/ q - 5 A$ n! i. @( n/ K' Q& ?
- public class LineRender{5 G) q4 ]( [9 _- U
- private final PoseStack pose;! j! O9 {( S. A0 S
- private final MultiBufferSource source;2 }9 t' N" u5 Q: z# q7 u2 J, i
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
6 W3 Q3 c$ j1 l# A - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
: R% ?& c0 q- n( F' s9 { - 7 f# @% k S0 s+ y1 y3 l
- 2 q0 b* i* j* {+ m$ ^/ E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ [' \" _: Z J/ `0 S - if(x1 == x2 && y1 == y2 && z1 == z2){: ^; ]9 c( `/ a% U+ a
- return;7 d, o1 ]2 j6 D9 ~: o. G7 H- z
- }
! c# \ K( W; a# z - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: u! h" F5 G8 s - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
2 i4 W* i9 O1 M& c& S8 W0 |5 B: R - }
8 ~. o. C. ?# A8 K4 h6 z3 f, [) ~6 V - pose.pushPose();6 M# V4 `" w" V9 F+ Y
- final int newLight = convertLight(6);
' I9 C6 U! B8 ?" [) r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( @0 y, c7 d2 G
- final float lineHeightSmall = (y2 - y1);
u8 F3 {: |6 t# }" T* K3 H/ U8 K2 _ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' m4 \$ a" Q' T! A1 r) N4 X - pose.popPose();
( y5 d3 D4 [6 L$ c& {+ g; T - }
( ^" o. h) ?0 ` - ! V' f; L0 a6 j
- private RenderType getLayers(String texture, int light) {
( z, _# w q( H, S3 R - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; Y7 A$ o; E: H7 d' P
- }( Z$ r& m. X3 E& ~, z
- 5 R: s7 a( C$ A1 M9 a! O- M) W# K
- private RenderType getLightTexture(ResourceLocation texture) {
; b% n( P1 }9 |9 ]2 }" C - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 n. y" u$ A; g! G; H5 n# E - }+ V9 Y" T: E9 M) D. s
, C" ^! [& A M6 J0 e5 ~- private RenderType getTexture(ResourceLocation texture) {
* w7 U# V( |2 b/ f$ _, h - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 F0 R% p/ l, @9 C" V - }. s4 L/ j% t) j4 y8 ^; \/ y
- - A( D) Y" r5 ~# M3 l& r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ ?0 L' ~3 N0 z; n* ~ - if (cache.containsKey(identifier)) {$ @- O! O% j" e. A& d
- return cache.get(identifier);& |% R0 t5 ~" S4 ~% Y- j; z& O& |( b1 V
- } else {
( K3 b! a* a( P' U4 _7 L, _8 } - final RenderType renderLayer = supplier.get();0 q8 P) b% p5 W) ?$ s
- cache.put(identifier, renderLayer);
+ X$ T" m6 F# j+ E - return renderLayer;; M4 ~- V) J# p0 z$ T% y: C
- }
- E% U( R& b( O. K W - }
! e+ U3 I# W7 I' j2 c4 k) A; D# C, a - }
复制代码 |
|