|
|
9 ?: Y" k [- c! ^! [( p
行,这个怎么样2 y; A2 p! h, x8 v0 ~- [2 i5 M# p
- package com.xhg78999.mtrfac.render;* @: |! Q2 p, Q2 c0 B
- # D6 J. n' T$ o" |4 E
- import com.mojang.blaze3d.vertex.PoseStack;1 f) ^$ H9 j ~
- import com.mojang.blaze3d.vertex.VertexConsumer;
3 B1 ~% m3 \5 l6 x0 N$ Y) K4 M - import net.minecraft.client.renderer.RenderType;
7 Q& e3 s8 T; x1 O5 @ - import net.minecraft.resources.ResourceLocation;
3 t. s1 e5 T$ a( u+ w" V7 w; {
! V$ U7 v1 r# c: _6 }$ l- import java.util.*;# z' [- M/ U% n# |" l! l
- / I/ A o( P9 P) u: x! V& n
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 z- _6 r0 a) S' k - - [; J6 N: j4 ?8 O) r! g) ?
- public class LineRender{
5 z$ Q9 u( Q% X - private final PoseStack pose;. Q. J0 b3 r) z
- private final MultiBufferSource source;- l' P5 m( V' N, m
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: L9 p- N" ~+ q; X1 ` - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& E( {; [5 e% |2 G
- $ X' b- w) t9 O E& M
z; J3 a. h+ z' J" W5 L& s- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
" B/ F3 |( U: c; }1 r - if(x1 == x2 && y1 == y2 && z1 == z2){
; `9 u& v4 K! p4 A5 R - return;
* Z; M5 F; A8 T4 X - }- @7 J' R( G2 s1 l' `) S, F0 ?: o9 P5 S8 ^
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
0 R2 d) n; d! N1 `+ P) A7 | - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");; m( ?1 q% Y$ _3 r
- }: e: L2 `! i& {, i! f
- pose.pushPose();4 n. u, r4 d- X G+ d: Q
- final int newLight = convertLight(6);
% [7 R7 N4 F$ W1 D+ w - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
. d- U! g+ V) ]& G, ^ p - final float lineHeightSmall = (y2 - y1);
, q0 F2 u# o, U8 X2 C- |2 w - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);+ l& V8 {' D: ]/ w! M U
- pose.popPose();
% m5 _$ z4 s7 c& v - }, u( O3 R; c2 M7 e, O) [0 E
9 s0 o; \+ J- E$ G! {. q- private RenderType getLayers(String texture, int light) {
6 P- M7 @. L8 [( K0 c! f$ {5 [+ N - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));# ]; q# F# {" q9 F9 c, g1 w3 ?5 N7 i
- }) b5 H; k" r: Y' }) ^8 B9 Z
0 o3 ]! a+ A. X+ N- private RenderType getLightTexture(ResourceLocation texture) {
+ W# `# Z1 B6 v5 n - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 W$ B1 Z7 U6 h L$ R+ \
- }) l7 a' r0 |; `/ y/ m6 y1 W% B3 R
- ) `8 F5 ^ p/ W' Y
- private RenderType getTexture(ResourceLocation texture) {# O4 y9 E* k1 d# R: N8 V; u' u
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 m! H/ H' v, M4 M2 X- ` - }9 j7 Z H H* ^* o. }6 p
# M9 j/ Z ?/ Y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ a& B' M5 L% s; |' I
- if (cache.containsKey(identifier)) {
- W- \ B% N. \6 q( O - return cache.get(identifier);
: P! S7 t) A: G' v3 B1 a - } else {2 M5 k I" T. M# m* N
- final RenderType renderLayer = supplier.get();1 G( ]* [, J' v" ^, ~+ V: p- r
- cache.put(identifier, renderLayer);( v; V8 G- _0 N9 f4 t* _# i! e% e
- return renderLayer;) f+ W( F% N% s3 G7 k6 X
- }
% `. m, [; [4 @& k1 N$ p - }
6 @4 G. K9 j5 h @( n3 @( s - }
复制代码 |
|