|
|
1 Z/ O" d! v4 N4 z行,这个怎么样# ~, h8 ^5 e- c6 [( T# ?4 r
- package com.xhg78999.mtrfac.render;/ [- I/ I# h& u% Z1 W# r
( ?3 t, P6 Z0 c* j" V2 ~- import com.mojang.blaze3d.vertex.PoseStack;/ u- k1 X, o; v
- import com.mojang.blaze3d.vertex.VertexConsumer;
3 J& H+ S3 @" o( ~4 I8 Y) N" c - import net.minecraft.client.renderer.RenderType;
' v Z% d+ t. q- h - import net.minecraft.resources.ResourceLocation;
\. D# E, g* s, r - 3 S* d2 m1 |$ Z% q- z% x
- import java.util.*;5 W5 v/ U& v. W% `
6 X" z0 c( L, H$ e6 c# R) v7 }- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 v7 P, i4 q7 p9 R# a
' k- ~+ d7 _9 L: Z0 K, \) v1 d- public class LineRender{
& h0 H9 j) ]* V9 u) M0 a0 a - private final PoseStack pose;/ `3 V8 ?# R8 Y0 a
- private final MultiBufferSource source;
3 [" Y- X/ I( X+ Z! n5 c- k - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) f" M" ]! L+ k( P/ V - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( a7 c' _7 M% c3 S2 g9 Y - 9 u4 \* e: e! K+ S
- r) V* D" Q2 B+ Y' |
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 z0 g6 ~; S3 Q5 u5 X* j- z& S
- if(x1 == x2 && y1 == y2 && z1 == z2){1 {" z" q3 j k
- return;7 a0 K6 q8 M7 ?. Y2 ^* }/ Z4 x3 x
- }
% v' N0 G6 J3 c5 R2 _, e: q0 ` - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 v" Y0 U0 T8 {8 z/ B - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");/ q# N. D. _0 N
- }, k% `* C1 `! }) I) B
- pose.pushPose();
/ j9 x; `; h1 w7 Z6 @$ J - final int newLight = convertLight(6);
7 p' r) A% R, i - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! {2 }6 v% U: g1 f& k; W6 ? - final float lineHeightSmall = (y2 - y1);
- {8 {9 Z1 H+ t8 h& | - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# ^$ |- @" ?/ k( D' `# S+ }+ @2 t
- pose.popPose();* q4 Z7 x% C! A2 z8 f
- }
) T7 c5 B; x, Z1 q - 1 b. k3 z$ P* C8 T) T1 b: v# P3 U9 t
- private RenderType getLayers(String texture, int light) {
8 Z" t& j4 w( E1 m. l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( b5 {% D5 P4 P - }5 _/ @& ?# \+ O" H4 \7 K- t) G
- & ]4 r! ^! n: F0 f4 V
- private RenderType getLightTexture(ResourceLocation texture) {+ h5 f% O* b+ t
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. }4 S6 H3 W) e: s3 O, M7 w
- }* a1 @& m, \' r6 F
, _% l' X0 b: j/ \+ N# ^- private RenderType getTexture(ResourceLocation texture) {! x# `/ i. N/ |- ]7 Q* j( \1 Q
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);1 [0 w% S5 X, \9 N$ j3 s# J
- }2 H6 p1 v( r; q2 V$ Z
- + p' I0 Z" Q0 l6 w% v6 n
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
+ A# m9 v3 ?, L4 z7 ` - if (cache.containsKey(identifier)) {! m& P4 H3 @: h/ T1 J2 [$ u
- return cache.get(identifier);. L# }2 m# V6 e# v" A
- } else {
; X$ a" h, g( d5 E# j# g4 T - final RenderType renderLayer = supplier.get();
* U; r& h+ V: n( s% W) r8 o( k! V; j - cache.put(identifier, renderLayer);% ^5 y5 k; E3 z w6 b
- return renderLayer;+ G) W1 [- w. b1 d
- }
& n4 g. U0 W& l( N! J" n3 a& V, n3 X - }9 a0 J' X5 \* H' v( B
- }
复制代码 |
|