|
|
1 J$ w5 V7 w! i# H行,这个怎么样
* J3 x! u/ w: Q4 \$ P8 _. c; f- package com.xhg78999.mtrfac.render; F3 {& l: A1 v4 ~' n9 x0 z
! U [# i' V/ e: {. r- import com.mojang.blaze3d.vertex.PoseStack;* D4 T/ H' l5 g% f5 I$ k- J
- import com.mojang.blaze3d.vertex.VertexConsumer;' T( A* Z) | X$ v5 j) ]
- import net.minecraft.client.renderer.RenderType;
0 t L2 Z& ^: O* @ - import net.minecraft.resources.ResourceLocation;
# ~2 f7 h: y" E# n
+ \9 Y6 X @9 k9 x5 ?- import java.util.*;
- `! O/ ?7 V6 f" ] - ( k/ ^/ Q' }$ F% ?* ?2 C
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, v* e. N, b3 j. o' D6 D! @
/ M# N5 I8 d* I$ h5 `- I- public class LineRender{4 _( k4 |$ \( R
- private final PoseStack pose;
; G% a/ ~5 \( a8 ^6 k6 s - private final MultiBufferSource source;8 N5 k$ \! `/ T# L$ F+ I5 v/ }. q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" s0 n, o4 W, |. r% J, b
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
4 K- T8 o- P8 R3 s" v - Q0 a y+ t1 s& w' ~- e. ?
- * E) L+ E; G! n
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
! P5 w, [ @3 ^. ? - if(x1 == x2 && y1 == y2 && z1 == z2){
& E" g. [. R6 q9 t- k) J - return;
8 g6 W" _. z/ V - }; ~! S. L+ E5 L( K# `7 I& E9 D
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){. [; P& ~" o3 y; v/ |
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ c; i' r& P, t
- }2 | O, v9 n: c
- pose.pushPose();
s1 L' j% N3 A7 U - final int newLight = convertLight(6);
4 r- r8 k5 ^( n) C9 r; p - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& q$ \! J9 m: }- k) }6 x& e5 L
- final float lineHeightSmall = (y2 - y1);
9 {/ T. R3 B* v2 B - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# H! R" @3 G2 A
- pose.popPose();
, L7 `% v/ ^$ `0 W, w! `+ B - }' o s- p# T% e! v8 L$ s
/ q e2 D! H7 G% \/ W. A- private RenderType getLayers(String texture, int light) {
6 ^8 B/ T* @+ A' y) E& v5 i - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));5 F2 @6 D, h3 F1 v
- }
( i8 c. x4 ^8 N, U& d. k- [
. h3 W) l3 c, J* y7 E! f- private RenderType getLightTexture(ResourceLocation texture) {2 V5 E* z% L9 b0 L5 A5 q
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 u. C. u. N% p6 s4 D2 x- e' v9 x - }
- D: E1 W' P! J* i4 y' r" a0 E - 9 r7 `4 j5 O9 m, f# R: F, C7 k- J
- private RenderType getTexture(ResourceLocation texture) {
6 U8 U3 s9 v" f+ s, s - return this.cache(texture, () -> entityCutout(texture), CACHE_B);0 G8 c7 h& r9 X) i( G9 F$ |
- }" K# S5 X4 k; t0 s* d" M$ r s5 Q
- . f; h+ k# P/ X3 g9 e: s5 G. K; i
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { v5 P! U2 X* U, S
- if (cache.containsKey(identifier)) {2 T0 C0 Z2 f5 y/ m) u' D
- return cache.get(identifier);" S: R2 V$ s. ]+ R4 F6 e
- } else {* H2 o7 k) s. s4 A
- final RenderType renderLayer = supplier.get();
) B" \- V% t! a! N - cache.put(identifier, renderLayer);* v/ S7 K9 K7 n+ m4 v( A; w( O
- return renderLayer;
9 ~) x5 j+ ?; o7 p6 T - }1 p# `& ], n" o& F8 Q' [0 `
- }* d P, ~* b8 ]/ W' W2 \& \5 u
- }
复制代码 |
|