|
|
# Q5 \- Y3 W* C* K3 f& r
行,这个怎么样
& m% l' u. K, l( v- }0 @- package com.xhg78999.mtrfac.render;6 @) }3 {9 |& a# \
- . L* q/ f- M" b. b8 m
- import com.mojang.blaze3d.vertex.PoseStack;
0 \1 v5 ^7 i) `/ r/ p% W1 ] - import com.mojang.blaze3d.vertex.VertexConsumer;
, G$ q! J" `% A, z - import net.minecraft.client.renderer.RenderType;
: A, k& a# E6 r3 | - import net.minecraft.resources.ResourceLocation;
& z1 B2 |1 Q8 C) `9 _, I& N; j7 k - & z# T/ r9 L) K
- import java.util.*;: }- k* r5 w r: o4 t/ ]9 W
- : N" @# t" d' _8 _, ]
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ u$ C2 N" I, |: r) x5 W/ L - % s) l% ~5 j; {# S/ ^. N& C
- public class LineRender{8 A# v/ @. A9 W2 y
- private final PoseStack pose;
# J3 _6 M @1 j - private final MultiBufferSource source;
7 \* T- V$ s7 S. v - private static final Map<String, RenderType> CACHE_A = new HashMap<>();. c) c2 j6 r+ g/ P- R
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" X" J7 G) Q! c" r3 {6 A
* k6 E/ ^5 L: W: i2 t& d- ( n/ E! W c$ w: H
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; {6 s& m2 X5 ^! [ - if(x1 == x2 && y1 == y2 && z1 == z2){: V7 Q* T7 k" y' q, e2 x+ [& x2 b
- return;" M8 P8 d/ i' Y* i8 O$ q! s' z; r: T
- }
5 @! |) x$ i V M }& e8 b8 O - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# K8 }8 Z" [7 H/ L - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 T/ I/ B! m" e6 ` ^ o8 t
- }) j: B& }& s4 `: A/ R! k* P, p
- pose.pushPose(); c0 V3 e R$ d$ I; m( Z, t& e
- final int newLight = convertLight(6);
# B( d/ C6 ^6 ]; } - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));- v; }7 s. \0 h8 F6 x9 e, ?: ~
- final float lineHeightSmall = (y2 - y1);
* U; I7 j. a5 W% ]. K5 s4 V - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);1 O6 i" F; z, c7 w
- pose.popPose();+ G, N: z+ @# R1 [1 r
- }3 u1 H3 f! F( p6 f" p V
3 I5 L/ D, ?: u. a- `. ~- J- private RenderType getLayers(String texture, int light) {
y, C$ b" ~! p; W: V. @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 H$ M$ W% F4 _ - }
, y8 }6 K% t; N5 {( Z
( a6 T1 T1 Y9 ?$ I. g- private RenderType getLightTexture(ResourceLocation texture) {
4 ?- |, C$ Y, A - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);6 E: e& p( b+ {: P9 N3 ] x
- }: U4 x+ }6 f7 U+ Z4 U/ U1 p/ t
s L" h) U" b( w, H+ l- private RenderType getTexture(ResourceLocation texture) {5 }3 R1 ~3 x+ ^; L; c) o# u
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
) X/ z( X2 I. X; S9 O i. } - }% v% U0 c; }" }8 e; w2 u
% W: ~; A X" Y4 C6 c* w- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
: @2 |! S+ D6 t. y1 ~ - if (cache.containsKey(identifier)) {$ Q2 [: a8 F S: D+ s; n
- return cache.get(identifier);* h W( O0 y) g
- } else {2 K1 a% A% ~: a3 j& V
- final RenderType renderLayer = supplier.get();5 ~5 T. Q3 k$ m+ _7 B
- cache.put(identifier, renderLayer);
; c6 t( g# ^" s. c0 H B- x# i* Y! X - return renderLayer;- Z. A" ^4 ?6 Y/ S+ u7 O) h) ]6 E: x
- }/ i' n. f; b8 x5 r; g7 M9 `$ r
- }
+ w; X! L- L* D" H4 B - }
复制代码 |
|