|
|
& y% e! b2 j' K3 ^9 Q
行,这个怎么样$ J3 B8 U" ~ f& [8 t, O
- package com.xhg78999.mtrfac.render;: F* P) K. H% z$ J, W5 m# |# [
- 0 E( ?$ S R' y
- import com.mojang.blaze3d.vertex.PoseStack;2 T$ M7 P! G. c7 _# j) k
- import com.mojang.blaze3d.vertex.VertexConsumer;7 f' x# S% _! E* T2 D
- import net.minecraft.client.renderer.RenderType;
$ _) ^9 G& n; @ - import net.minecraft.resources.ResourceLocation;2 t% m5 i" Q( m2 J/ X- y& f
- ! a% m. v, r& m
- import java.util.*;
^" l9 l& `- Q# M9 O
# L% S! e @/ y- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. |% b+ g+ U6 I
/ X1 X2 E- ~% G# U1 [- w- public class LineRender{
( Z# t4 z& F" A$ Y - private final PoseStack pose;' ^7 r2 ~$ J+ g6 u" ]* e9 X c, y
- private final MultiBufferSource source;
; v6 v0 F2 ^4 l7 n/ v, \ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();" `$ b" w9 O+ E: x
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();$ V( I) V3 F) C# f
- 2 g/ A, M! I5 R9 \- }9 S
3 R1 e7 d- E4 _! C- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){3 m- O/ O3 N1 p! t7 H
- if(x1 == x2 && y1 == y2 && z1 == z2){( k! `1 X: q0 e( Z& p( u- l
- return;
+ v2 I: z% Q% ?* [8 @5 N! { - }
/ c" A" o7 u7 |$ A - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
R) ?/ P* m5 f - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 l# c$ q4 E' u K! e& a - }; w3 x; K) f) \/ a
- pose.pushPose();
" O% C) p$ r6 E: i - final int newLight = convertLight(6);9 m; H' c+ I7 n4 l3 U
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ S9 M* D# E0 C: M3 I* {
- final float lineHeightSmall = (y2 - y1); V7 O9 C7 ^2 {# |* r' f L
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& d, j# y3 B k! L* r - pose.popPose();8 k5 v' L1 w3 _4 ^6 }8 H1 s
- }
/ P6 y! w4 E. S0 E6 ]
- R" `4 f5 ~9 v1 k- private RenderType getLayers(String texture, int light) {" N# ?7 }' }) ]- L6 T: [8 w+ D% I" f* ]
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ F6 G& T( ~+ p0 u/ k
- }
5 G5 o" n. a& O, } - 8 }7 E: v$ x' z3 |, z
- private RenderType getLightTexture(ResourceLocation texture) {
+ } Y5 c) J: `& ? - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) B# U% h$ X9 ]: l: d7 P7 o
- }
, Y, E+ C) p( a& W8 T4 V/ |$ h - : V! k9 M) h* }) G) u
- private RenderType getTexture(ResourceLocation texture) {
6 m$ C# s, |& U! i7 K - return this.cache(texture, () -> entityCutout(texture), CACHE_B);, Y. z* c, ?# V
- }
' o9 L, V8 P7 G" _ {" n9 ^( Z5 j+ D - ! [) K# F+ E+ Z8 x; V
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; J0 e& r; q4 y' R1 \, N3 @. x - if (cache.containsKey(identifier)) {
2 C C+ C/ H1 v6 p: p1 m - return cache.get(identifier);9 d8 {6 O# d+ ?! Z+ }: x
- } else {
- Z# z- X- R8 q2 D$ ?8 R - final RenderType renderLayer = supplier.get();
8 d& D9 d2 m/ }- ?" l - cache.put(identifier, renderLayer);+ w& K" H! H2 ?; c+ F
- return renderLayer;. `" e/ j5 }# @9 S! R) K
- }
' l8 X. t' X0 S, S& k - }
( G" Q$ ]# U+ X% @% r5 n - }
复制代码 |
|