|
|
) z( E9 N, ^# H8 i: T行,这个怎么样
0 d( e7 L2 p" o% U- package com.xhg78999.mtrfac.render;. a9 S5 z6 ^, x) { m
- ' W9 G# R# @& e5 H( z
- import com.mojang.blaze3d.vertex.PoseStack;8 N+ g+ p0 z8 f+ Q, q
- import com.mojang.blaze3d.vertex.VertexConsumer;! d( G6 t& \ N
- import net.minecraft.client.renderer.RenderType;. r0 J6 l w( D/ Q1 J* o
- import net.minecraft.resources.ResourceLocation;- ^: |3 m- l7 b0 S7 @$ S& J3 C+ l
% q0 q# e3 j( ~" i& B$ z- import java.util.*;
+ S7 y: }9 G4 n6 P1 J - 2 T$ I5 _$ `/ o$ h
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(& \5 F8 {2 {) }9 x
- 4 m: N+ S/ _1 v
- public class LineRender{
& b& L& B( R k- }7 x$ |# ], J+ D2 e - private final PoseStack pose;
$ R, e! A5 @/ D - private final MultiBufferSource source;" J9 Q+ E( x" k7 v# S( o
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 t, E6 q* |3 I* z1 h
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* \2 a% C$ {) S: u8 u# b! c
: i! V' b, G# p# w
! ~4 C8 o3 T0 r- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){6 f) E5 M8 \0 h* _; h8 I/ H
- if(x1 == x2 && y1 == y2 && z1 == z2){% X( k, V# d+ t0 K- J
- return;. ?3 o6 B) D; p
- }
3 m; R( e1 a. Q" O9 P+ {* X. q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: n7 ~( ^5 h1 `: }; H" [
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
& ? v9 x; Y2 z6 \ - }
& s: ^8 g" K, B" L0 V - pose.pushPose();$ T% J+ R( Y' I0 U) `$ d
- final int newLight = convertLight(6);
1 b* Q3 Z1 p# [$ k* v) a) n: @! o9 f) G - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));4 l% Z, k8 F2 Y6 S# [# A
- final float lineHeightSmall = (y2 - y1);
8 X9 Z, ]% [) ~. z! Y. d - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 A I' e8 ]; l - pose.popPose();0 m7 t4 d( x3 k% E
- }# K2 \. G1 t% @( D: F& r
% |# S& u# w, j3 Z0 g4 s+ Q/ I- private RenderType getLayers(String texture, int light) {
3 P$ J0 e" a6 q/ n( j - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 q/ O2 \6 h5 p+ F
- }
) }# p! H) [* U# L1 c: D6 @ - - s# O/ L! P5 L7 F
- private RenderType getLightTexture(ResourceLocation texture) {
1 H7 j* Q: y7 c% S, s5 h& o. ` - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 |0 m, V, y! c9 |5 K6 H" Q: f- c - }
. p) x3 a& Z" ` - ' B; H/ q. n( f5 I
- private RenderType getTexture(ResourceLocation texture) {
, D0 j' `8 h8 Z - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 e1 Q8 H- U8 f" f3 h6 c - }
& ]6 `& Q, f* Z/ F
/ w. I0 O1 {. n$ X7 L. T! t- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {- V: b+ P+ f7 A% G O3 e
- if (cache.containsKey(identifier)) {
# a! q( J. N# b" [! ~; T - return cache.get(identifier);
6 f4 p/ |% ]3 t7 w - } else {' o2 S9 y# ~ ^) Z. f
- final RenderType renderLayer = supplier.get();! r; j1 K" H5 I3 j; G+ I3 U
- cache.put(identifier, renderLayer);
( D1 u" @. h0 _! y/ [ - return renderLayer;* w9 U* x2 s% P* G, d" c ^' E
- }
K7 t9 V6 Y- \/ A4 { - }/ b7 ^' L. O A& u% V1 M
- }
复制代码 |
|