|
|
" ]$ g% H2 H( A( V [1 j, b
行,这个怎么样
' Y+ F5 A& v& Y- v, E1 y- package com.xhg78999.mtrfac.render;6 D, R9 ^2 j8 a$ I$ g. \" l2 Z$ K
w* V" @( u0 |3 H; \5 Y- import com.mojang.blaze3d.vertex.PoseStack;0 o' O' |. ~; P$ r9 f4 x$ o
- import com.mojang.blaze3d.vertex.VertexConsumer;! y& V& Z, b( G: n0 g; I. A; G
- import net.minecraft.client.renderer.RenderType;5 `# _1 ^" N3 R5 x4 q% A
- import net.minecraft.resources.ResourceLocation;3 V3 y: k- F; G5 G# v7 n
9 a1 S0 s: s- }3 [- import java.util.*;7 y% u% i5 E* m% k
- * ?3 x+ s6 J# X6 b
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! |2 D: s+ _+ i' Z+ [
& r0 U2 F) z( z& l8 _4 {' q# a- public class LineRender{
% A& g+ P+ A$ U" a; a - private final PoseStack pose;/ l7 F* t0 H3 Q' n! P1 e6 |
- private final MultiBufferSource source;
; s6 D4 I. F1 b" f4 {3 P, ?$ m - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
0 a w* J t+ [0 D+ u0 y - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) d& S6 I5 R, W* @0 w# D. N' Q2 X
( v9 D0 e1 X# Q& F* \3 p- F
( n# u6 o; M6 @- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 n9 B/ M; Y1 @, N3 T- n1 K - if(x1 == x2 && y1 == y2 && z1 == z2){
- d% j* D, k( H, o9 [0 C2 r( J - return;
& x$ Q! g4 Q, z+ \& v - }
, p8 ]6 a) h6 }' Z9 o1 Q7 ?* h& _ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. d' f) A) |! s) X N( z* ` - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% c* T3 E& q2 G; j5 a - }
' f0 j$ Q! x) x5 R - pose.pushPose();0 n5 T2 J3 K Z* M4 g; v
- final int newLight = convertLight(6);
) Q" C3 G* q, i( g - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% r* z9 |: o! z# ]# ^
- final float lineHeightSmall = (y2 - y1);0 }# \0 | n- F, ^
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) w7 E& `# G7 r
- pose.popPose();. u$ u9 g2 U* ~. c
- }% y- E' K% j+ [+ E' \) `
; Y4 U9 E* A( z% E; v: H- private RenderType getLayers(String texture, int light) {
, e% Z7 e3 N" P$ r9 T - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 N4 o. D9 |2 b& H - }
4 W. L4 S! h6 k
- J& ]9 \0 h" v/ q. X- private RenderType getLightTexture(ResourceLocation texture) {
: N% ^7 I6 x+ s! } e( y! d8 a - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 Z6 E1 i, b& V' a
- }
: J$ |3 s4 e% Z: @% a9 v
k4 X& w2 a P M- private RenderType getTexture(ResourceLocation texture) {
R9 C4 M& b1 a/ c' x r - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
W. N) V. ?9 U - }# e) L% ^" y' f0 Q1 a# l) S
- % f; n" \6 e7 r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' r# H9 W8 r6 Y/ R, S( P - if (cache.containsKey(identifier)) {2 l6 [ B1 c3 {' S/ i8 r0 i
- return cache.get(identifier);7 V* E9 i0 n$ @6 N; a' t( J
- } else {
" F2 ^2 T, T0 Q- _9 _& W" e1 { - final RenderType renderLayer = supplier.get();
# c+ ^% B; J' b4 ~ - cache.put(identifier, renderLayer);+ A1 b/ R$ Z2 ]
- return renderLayer;
5 g7 n8 z- `8 Y5 I - }
3 h" S- g) Z1 K3 j6 }# h9 d' A - }
! q% E3 T, f7 U$ B1 _ - }
复制代码 |
|