|
|
6 j9 n$ T0 A" r! ~. u( {
行,这个怎么样
( ?- |/ v& V J8 e1 e- package com.xhg78999.mtrfac.render;
* Z( \1 \8 o9 B' T: m8 M- u
- d t* R& B: j+ @% a- import com.mojang.blaze3d.vertex.PoseStack;
$ J O) E( J% F - import com.mojang.blaze3d.vertex.VertexConsumer;
2 T) z; b# S1 Z% V5 H: G" ~ - import net.minecraft.client.renderer.RenderType;
$ N: O6 Z; s$ l! {0 E9 S. J - import net.minecraft.resources.ResourceLocation;, K7 Y- O# F7 H, r6 O \- ?9 v: H
, G q* _' n7 i4 c$ C5 u; `- import java.util.*;4 _" Z. r' u0 y# ]! S% `, t" D
- I% @ S& g: T
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(" ` G% ?9 g' R
* t/ X5 K& r9 F5 h# t3 v: Z* B) K- public class LineRender{
* }2 c# F( t$ o - private final PoseStack pose;/ D3 ?# ]; V( t- C
- private final MultiBufferSource source;2 L" [" _4 M0 Z5 Q& h2 S+ n
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
9 G" \- L( w" H8 { - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();: G2 ?- P5 C, j4 T" B. o5 s
- 0 I0 m5 X$ a- v/ e2 I
2 y9 d% Y. b2 z( ]- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% K7 N! z% V: u# o3 ^
- if(x1 == x2 && y1 == y2 && z1 == z2){0 \7 X( J9 b+ g
- return;8 N( P- E! }4 V0 m
- }
4 ^( U6 i4 `1 |' U9 _/ C - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' Q( t+ F7 L( t% z- o/ z
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
& S. {3 `5 p5 k/ `4 k - }1 `% Z+ z0 a4 O; A. S4 P1 F' R
- pose.pushPose();' |8 ~7 v: g% h$ K0 E
- final int newLight = convertLight(6);
$ T3 g# A [$ P n6 }- A7 A - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
6 y5 h2 \; T) a8 j! I - final float lineHeightSmall = (y2 - y1);- U7 s* J# ?# l# L0 ]) O5 O" O/ A$ U
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
5 r5 P& z6 S ]2 d - pose.popPose();+ X9 N8 J& T4 C" ?7 X
- }
+ t! E) O, D1 t/ f
# y. W! F0 t7 x5 X$ b- private RenderType getLayers(String texture, int light) {
4 y G( u! X, _ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 S' a# ~1 i* U0 [: L
- }
% ?. W) n2 V. a! p - 2 o# `. f/ J$ Z! O- h3 Q
- private RenderType getLightTexture(ResourceLocation texture) {
8 `0 r9 j4 M" J5 Y9 ? - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ h% W0 }# ^9 R2 c0 u( }# P, O5 \
- }
! q3 H9 W# U! r3 l
- y2 w0 m2 x/ u* V3 J- private RenderType getTexture(ResourceLocation texture) {
* }' |4 x- g7 S1 Q p: f - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
6 Q6 \3 V0 u& a+ e - }9 Q+ ^, G. h+ Z. B8 [
- 0 }' T7 ~' E9 P Y
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {6 g8 w4 y& a/ k1 F9 ~# d9 Z
- if (cache.containsKey(identifier)) {
3 D& {, ~+ O/ d& M5 Y+ a- G7 m - return cache.get(identifier);8 \' \ J2 K5 _" {0 s! E. a
- } else {
& {% H \, J& H& T/ { - final RenderType renderLayer = supplier.get();' Q# j G6 \* e; p u3 k3 i
- cache.put(identifier, renderLayer);
2 _( E* H6 t; V: T; q6 x% { - return renderLayer;
[8 k& B. t; B+ K - }( i2 e" o0 i* S& R4 _
- }$ ~6 c$ Z6 |7 N) O
- }
复制代码 |
|