|
|
* T" {+ X$ C( @4 f" i% l
行,这个怎么样. ^& g, {, a; s
- package com.xhg78999.mtrfac.render;
P7 {- ?0 l, U( O" Z; \$ ] - / m+ ?: o0 \1 t- K. i
- import com.mojang.blaze3d.vertex.PoseStack;' O# p% h$ B+ h% s9 o
- import com.mojang.blaze3d.vertex.VertexConsumer;
# A0 G7 ^" Y5 b; F5 u. o0 i8 N - import net.minecraft.client.renderer.RenderType;
$ r8 Z( D7 s- N - import net.minecraft.resources.ResourceLocation;1 E, t. J$ E2 o$ R/ F
& O& ^; H: c" O% l. j- import java.util.*;
. w5 m! o- D) N - 4 Q# J1 H. \! u7 W9 m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& }9 K* l( i2 B$ |( T/ ^ - ! C4 j' `1 _- v
- public class LineRender{
% E( G) u5 f' S7 X$ m+ Q - private final PoseStack pose;
$ ^- a3 J. B% e5 V; \2 O) }# P. F' w0 v - private final MultiBufferSource source;
3 y9 K) A: M, O/ b6 d* x! z! a - private static final Map<String, RenderType> CACHE_A = new HashMap<>(); h' f& A1 c6 u4 y8 W1 ]4 L
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
) e6 I, H' ?0 \* h - : H' a t m1 l9 E
8 U1 U0 f' k) {3 f- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 N( D: Z5 p/ x( g; ]
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 M7 R9 B5 p! w4 p8 @. b - return;- \! I# t4 [6 N: F
- }2 Z7 p+ ~) l( \9 a8 Q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){ v: x; B) p* P/ @
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( N9 r* W! H0 N+ I2 o
- }
- S$ s" m% K) R4 C" j+ f" c7 J/ m. o - pose.pushPose();. O6 q7 F5 F4 ?% m2 `. a
- final int newLight = convertLight(6);/ V6 G: H) F. a/ P2 b% b* T. o
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));. V: ^- g2 |6 ]
- final float lineHeightSmall = (y2 - y1);
! N2 `; n! @( W6 e% O8 H; i - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 k: f. X8 Y+ c, {3 R9 O5 {
- pose.popPose();
; _9 v. U) d- h" n; u1 k - }
3 Q7 c& {( y% G5 G
: J& @/ U7 R; S+ u) I8 ~9 s# M# B- private RenderType getLayers(String texture, int light) { s5 m- q+ K2 `7 k; u8 \
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 S8 Y( I: r! c- x- F
- }
3 O3 M, N k1 `2 J9 D
- i! t: k+ F4 D& [) L, U- private RenderType getLightTexture(ResourceLocation texture) {) I7 e5 h( g% d" y8 v( C
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. w/ Y8 X0 `0 G' M" a
- }: f% E$ O& x$ `8 @ ^
- , f- j( u8 S: b, d/ Z
- private RenderType getTexture(ResourceLocation texture) {+ a4 }$ }( Z9 v4 [
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 a' M# I& s& z2 D1 l h - }
2 z# @# g/ k: }0 ~9 x' N# ~ N
% v8 ~/ H, W1 @$ s! G- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 C2 p" F) @* F
- if (cache.containsKey(identifier)) {
w8 ~; W; E& l; v6 U - return cache.get(identifier);. ~ ~8 Y" W9 p% F/ n0 N
- } else {: {) T. i+ j3 ]( k; H
- final RenderType renderLayer = supplier.get();
3 ]! b! E' v2 d D T - cache.put(identifier, renderLayer);. L5 a& }% X j
- return renderLayer;2 a0 Q+ _' G0 a+ s9 a& F
- }: {" o2 v% e+ _" L
- }0 a* y, c; E' V8 ~8 g1 P2 H/ i
- }
复制代码 |
|