|
|
! d2 O/ y: R! _' m行,这个怎么样, R8 h N: F+ F4 s# E% n
- package com.xhg78999.mtrfac.render;! y* C* k2 h4 p+ d0 B
7 h; J1 m1 V, V$ g- import com.mojang.blaze3d.vertex.PoseStack;
5 n5 l- {) g3 A; l/ J - import com.mojang.blaze3d.vertex.VertexConsumer;
2 w7 e& i( e4 H - import net.minecraft.client.renderer.RenderType;1 f# w" G2 l8 L, m9 s. [% O
- import net.minecraft.resources.ResourceLocation;
2 P' V% r, L# b$ i( P0 ]
( ^ Z% S9 n( R. M# {- import java.util.*;
1 y0 H* Z/ k( h - 4 C/ _' @/ D+ w' u/ {" w
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; t9 V. c8 `( ]+ W% |1 C+ e1 l9 C n - - m' x& l0 K( X9 n
- public class LineRender{
8 |1 a Q8 R" b: f S8 z - private final PoseStack pose;
, S2 I8 L' @5 Q# j - private final MultiBufferSource source;/ |/ ]; C, F+ O+ x0 @0 ~5 e3 ~, v
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 N( F8 E$ v0 F5 I( X+ [2 x2 M# p - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ T+ N( u' B) k; g! r8 _7 L% x - 4 e! ~) R( q \2 }1 Y* V/ ]! p
- / F! r" h' N9 Y0 @
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
& M' m7 r4 g7 M0 K - if(x1 == x2 && y1 == y2 && z1 == z2){
( l- M. d- {5 F$ [. x, ^/ _ - return;! {: A$ R1 i% f+ b; v& X
- }$ | _/ S! @% X9 z! T" i9 V" O
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){- u6 ^ N; Z% y1 b. S" n
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 s7 Y4 E9 _# C) r- u+ f9 y
- }6 b$ \, J! b" T
- pose.pushPose();6 @8 v, G8 d2 {9 y+ z- \
- final int newLight = convertLight(6);5 |+ ]3 Z/ M }( j: K3 f" e6 |
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
2 D+ t$ y |) j( g - final float lineHeightSmall = (y2 - y1);
% _- U2 n& i) h! F8 X& C - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);$ M/ X0 O" R! z9 v- W6 w
- pose.popPose();
9 T5 F# r0 g2 S- W - }
% {9 ^8 V( e: Q1 i1 P - % i$ Z$ y% O7 `2 t% m% b
- private RenderType getLayers(String texture, int light) {* c* ?5 @; c7 o9 J& X/ T1 i
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
, Y5 U) s* z' p$ L( z5 {7 z* [ - }
, }! i) k* ?9 p - . I0 E7 {3 K# S. d
- private RenderType getLightTexture(ResourceLocation texture) {! }- ^4 j' @0 _7 E
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
% N. A$ {8 J" J - }5 S6 M% B5 X9 o3 O H0 d/ @0 i
% c z4 I, L- v- private RenderType getTexture(ResourceLocation texture) {! R' U+ k6 y) @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);, _- J" v" Z& z1 e. a, J
- }
' @ K; s* V1 O/ R+ s
4 R8 u3 v! N7 ?# p8 |2 W- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 {& D6 z7 [' n1 a% t9 x3 _
- if (cache.containsKey(identifier)) {
1 ?+ `, a. D4 `- `; L - return cache.get(identifier);/ T' f) Y7 b# `0 @
- } else {, l4 ~+ ?; k; }9 v( b- e; v
- final RenderType renderLayer = supplier.get();
/ x9 I9 g& U8 X9 V2 | - cache.put(identifier, renderLayer);
6 b* ]! P4 j$ \ - return renderLayer;8 N: }% k: k D
- }
! f# n1 C* f% K" K$ [ - }
8 p4 J+ G# R, z - }
复制代码 |
|