|
|
* h$ z# v4 N, k: r# g8 b0 Y' E
行,这个怎么样
1 b4 u v* Y% l+ i; q- package com.xhg78999.mtrfac.render;9 \& ]* w: Y+ J
I" d+ C! u+ v8 \7 O9 K: A- import com.mojang.blaze3d.vertex.PoseStack;
- a% J+ _8 m( O - import com.mojang.blaze3d.vertex.VertexConsumer;
4 ~! g. A2 y* { `) R3 { - import net.minecraft.client.renderer.RenderType;
Q: V2 F6 i' J0 p- |1 d2 k - import net.minecraft.resources.ResourceLocation;* ?' `1 x4 |( o9 H. G1 S9 @
% U9 {" t0 j6 a! W- import java.util.*;
- M" N8 \" O- a. U% b) N3 ]0 C1 S/ E
$ g0 C& k+ z% }, G+ T u) d9 \- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(; H6 O# N5 P5 l8 G
* h/ U7 n+ Z* O! }; {/ ?- u- public class LineRender{
+ l2 o. n6 P- v - private final PoseStack pose;0 g/ @/ t4 T# ~
- private final MultiBufferSource source;
7 ~: |0 T% `5 @( c9 C. ` - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ \* e1 k; c' I - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();+ H2 x z( A% n- Z- A% U, f% m! O
( p' T2 I7 v8 R0 S/ z- % v, y8 R& @8 Q+ q2 f n( Z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){: q% A& S7 ^+ e) x
- if(x1 == x2 && y1 == y2 && z1 == z2){. j& B x6 ] W6 [# J7 ?! c
- return;
$ c" n- U& h5 z. L. N - }$ {& j: |7 Z2 t7 c$ ~, z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" M4 o* A$ Q# I5 t' @5 o2 U
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
) |" @. N9 R; j ]3 a) q; X* M - }/ ~! E6 Q: v" T/ `" r
- pose.pushPose();: c) v# [' h5 K4 U& q4 U1 A
- final int newLight = convertLight(6);! G# N" U5 a' o! D
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' g7 q6 ?. k- i3 B: A - final float lineHeightSmall = (y2 - y1);
9 S/ ~8 m. O( h# U- V7 y1 e8 k% a7 e - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 X1 j( u' }: g" `2 B! v* ~' e
- pose.popPose();) J3 ^. Z9 n0 A6 ~
- }
+ Z% I7 K* R% u! Z' V* W7 o
; O& Q$ r* ^: v# P8 n: D% K+ S- private RenderType getLayers(String texture, int light) {
" r/ W) f# L8 o. | - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
1 l* j& [# K% D* W: _2 K - }1 a' @$ b o6 @( B! x( R. `, h
7 ?" T9 V* n$ N7 v1 ]- private RenderType getLightTexture(ResourceLocation texture) {
2 q- C5 D5 k7 _; T r* {' S8 J - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
0 A6 b9 C: `( G# ~ - }
K; b4 [6 |/ D m8 a' ?0 p
3 E. O% N, t3 J, I% s- private RenderType getTexture(ResourceLocation texture) {
, n# d& p1 p/ B2 E" {$ k+ S4 c - return this.cache(texture, () -> entityCutout(texture), CACHE_B);( f! t, U9 P, z, O1 _
- }- p( z. P x. x7 I, J2 z
- " u+ ?) f6 x2 p0 T$ i
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {4 e5 c. i$ G% E, C3 W: r
- if (cache.containsKey(identifier)) {% \5 x4 o1 D3 q5 M. X( e
- return cache.get(identifier);+ V; Q2 S5 A; p& ?
- } else {+ N1 D: o0 ? \: I
- final RenderType renderLayer = supplier.get();/ O9 H# C) S/ G6 p, G
- cache.put(identifier, renderLayer);
4 f4 P5 s; x i3 |& i" _5 Z - return renderLayer;0 ^& q1 d0 O, |/ b
- }* i, g7 t' ^8 B3 v5 U+ [ d
- }* H4 ^5 o* `: J7 M$ y( x
- }
复制代码 |
|