|
|
5 q: b( n! U' t3 s/ ?# ?7 C0 y5 J
行,这个怎么样
0 o U- a5 L! w& l( ` M' ~- package com.xhg78999.mtrfac.render;
, g' ^3 r4 Y F* S1 b2 a - " W( ?, W% t: N. W0 C5 R
- import com.mojang.blaze3d.vertex.PoseStack;3 J( Q9 s! {. _) f* X+ p4 V
- import com.mojang.blaze3d.vertex.VertexConsumer;4 t- a Z$ _) i; O; z+ o
- import net.minecraft.client.renderer.RenderType;
5 W1 S+ L z+ H7 q) T7 M - import net.minecraft.resources.ResourceLocation;
6 |) w4 ]3 a( ^5 d - " H3 K# X* P1 `) m8 L
- import java.util.*;
# c9 S6 d4 r; `* h1 x$ Q4 n
' V& A2 e$ ~$ x# W; [' v: x- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ W& F b; P: N) r4 A
2 M9 l. O5 x( p# S* \# L; m/ o! R- public class LineRender{
S, _3 O; ] s+ P0 Y- ` - private final PoseStack pose;- x0 [8 Z/ |+ ]0 `' S d
- private final MultiBufferSource source;
0 W: r$ U1 J, i4 ?# s9 \ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();% k4 X2 I$ m: \- Q
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
- m2 N1 t: r: P. H D* G# v- m; H - , x/ H: X5 i- r; F: w/ Q
. d d* x+ t" P" B- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. Q+ |, q; V }8 O% H7 w, p - if(x1 == x2 && y1 == y2 && z1 == z2){
0 V" {3 i) q# L1 ^1 R - return;& _- i a# }' [
- }& Q- @; ]8 e ^# V/ g3 K6 F
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 D) I: {4 k5 `6 r( H W O2 L: v
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. A3 n. \' m* D x: e - }
6 X" V6 \( \4 H$ N6 W" J1 N9 C - pose.pushPose();8 T; z# N0 H: i$ _# G6 n
- final int newLight = convertLight(6);* @6 V# z2 O0 M3 p
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
' b1 A& g- Z" b - final float lineHeightSmall = (y2 - y1);1 v5 N$ _9 N: `2 I7 N8 q) ^5 v
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
4 H' x+ `% R V - pose.popPose();4 \! G. `: @- j( n9 w1 T4 v* ]
- }
$ [% t5 Y" I; C3 m, [ - ; R; L* r' ~7 \0 p+ g& {
- private RenderType getLayers(String texture, int light) {
7 p$ Z$ t& K; t V) h - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 I6 V: X& z- Q# b* ?; H2 |
- }, ~& E5 ] n6 e+ w. D8 y5 \
2 y0 P4 u, L0 j; l- private RenderType getLightTexture(ResourceLocation texture) {
2 P4 F. A3 V3 Q2 R - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. r7 U$ |8 `7 h2 u7 }& Q* @5 x
- }9 I9 {0 p8 o7 K0 c1 H+ `( r
- % v/ `" v3 k: S, o2 L# M
- private RenderType getTexture(ResourceLocation texture) {% ^' r4 s; ]; O0 G+ B6 U9 w4 O3 u
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; ]% J) [8 Q/ W. @, o2 P' [& E5 ` - }" J$ D2 u9 L# V* S
( a+ {6 S2 B& u7 K' V- D- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {. B" ]. U. q' p
- if (cache.containsKey(identifier)) {) o$ ]1 n" q& E* [. ^) @6 l6 z
- return cache.get(identifier);% b7 @$ A% B+ `
- } else {. _. D& _, _' o* I( e( A- s. B
- final RenderType renderLayer = supplier.get();: H m7 b# [4 T2 @) M: \- C: R
- cache.put(identifier, renderLayer);( i0 o: }. ~ W- I. l8 u! _
- return renderLayer;
. k9 `4 \9 H7 E9 [2 N+ c- F - }
% A8 Z" W2 r H& Y A - }
d d" _2 |4 i" q, c/ M - }
复制代码 |
|