|
|
7 t% [* r6 B H Y行,这个怎么样
6 D: c( S9 {1 t' ^- A4 W- package com.xhg78999.mtrfac.render;( ~( z: }! ?# n6 Q& Z
9 L j% U$ G3 W/ ?6 v- import com.mojang.blaze3d.vertex.PoseStack;, K/ W4 W. p9 z+ i7 i" {9 F/ y
- import com.mojang.blaze3d.vertex.VertexConsumer;
5 v, G! ], x8 n - import net.minecraft.client.renderer.RenderType;4 Y6 T& b6 L7 l* [6 Y, h4 p. t
- import net.minecraft.resources.ResourceLocation;& X8 g, a; K" r) n
- 0 ?; J. ^' s I) z2 n
- import java.util.*;- C2 H# {% D0 P- Z
& L7 Y9 Z- y7 q: }- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! i, r; l' |- T% e; u3 q# X; ]
' a; R3 b t/ U* o C- public class LineRender{
* R' r; T7 c! }% ~+ U6 W - private final PoseStack pose;) S; e T9 G6 q2 P3 [2 z
- private final MultiBufferSource source;
. T$ J) ?8 R @' s- T2 K: W - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 a; C5 g- a& v R9 B7 q0 a - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
3 s$ P! I0 o$ ^& ~4 L; U
$ y/ e' ?& i+ |$ R: S, ?5 U* G- M P1 m. C. ?7 U. b
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& r/ A7 T8 V( K0 E, v - if(x1 == x2 && y1 == y2 && z1 == z2){( e7 @$ l3 H/ {0 H
- return;- z1 k- |/ y5 L1 ~
- }
+ s* F4 u" k/ } - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){* j# c. H4 w; L1 O$ Y: h4 I j
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");0 Y; g O2 n9 ?* [
- }$ U- o4 L8 A4 n. F& n
- pose.pushPose();' {& H i3 P, P7 I
- final int newLight = convertLight(6);
% D7 D3 R! w2 C7 D6 ? - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));# F! E ^1 |, @. H, U, R! c' J5 c
- final float lineHeightSmall = (y2 - y1);2 U. O( H* f; s; q8 t& ]
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* d& M# T$ @; K% v, S6 P8 W
- pose.popPose();9 o# ]) a1 o! ]* P n" _1 _ ~
- }! E7 i3 L4 d. t9 H
3 ~9 S! J" I; y4 L4 z- private RenderType getLayers(String texture, int light) {+ q& A6 W) ]+ O& j" C% Z6 L
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
) o5 o ^* E1 ^, ~ - }
4 E4 v5 R. m; B* J8 J* a/ r D
: a. B, b0 ]! r+ h" T- private RenderType getLightTexture(ResourceLocation texture) {5 b( d+ k9 T7 y' [) N o
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& H) Y* a$ X- p/ e+ t$ ] - }2 Z1 D1 b& d/ d0 @0 E
( o- g: K2 C$ A) p- c- private RenderType getTexture(ResourceLocation texture) {
( g: r# n1 [ ?5 z - return this.cache(texture, () -> entityCutout(texture), CACHE_B);) E, a& q1 K" |3 l6 n
- }
5 S" Z# l; s/ `- Z' ~5 l
/ x) j1 M3 P& o( a2 [# n, w j. W: Q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* g4 ]% `0 i9 J. x8 R: L$ L
- if (cache.containsKey(identifier)) {
8 g1 I# K) a. K; @ - return cache.get(identifier);
9 d; }" X6 J9 K4 d, b1 l' X' p - } else {
/ N4 C% y7 D) q - final RenderType renderLayer = supplier.get();
; q) f, M0 G' w" O - cache.put(identifier, renderLayer);
$ T( h/ N0 k& _& p- T - return renderLayer;
6 b7 E6 U' @9 [; S8 m. G - }
4 T) u8 M3 U5 X - }% R: i& I. E5 y( z) \5 p4 i
- }
复制代码 |
|