|
|
9 W$ @/ i' }7 q/ \* H _1 e行,这个怎么样
2 v4 l$ ~; c1 l/ E- package com.xhg78999.mtrfac.render;
- f) j5 K! m, w5 g
& W2 C, d+ }9 f3 d! W- import com.mojang.blaze3d.vertex.PoseStack;) M, h5 u/ |0 K; \9 J+ C! W" W% |5 l
- import com.mojang.blaze3d.vertex.VertexConsumer;
W; q- T- o' Q" ]: H4 m - import net.minecraft.client.renderer.RenderType;
0 L2 g1 t* {6 u6 Q - import net.minecraft.resources.ResourceLocation;
4 ]2 w4 V+ L* A4 h! n m4 s - . D( D- t5 `) j
- import java.util.*;
" C" l* j- S$ p g, V - ' ~ S: w; j( n- K. Y+ P! z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
4 J \0 A1 c' P* `# D
8 I1 v: f# r) a: f+ g' D, I6 M- public class LineRender{9 w- c9 Z1 K" l |6 H
- private final PoseStack pose;' x- C% b2 m9 [
- private final MultiBufferSource source;' }. d- R3 P6 x2 W- d
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 q; u) y5 ^& r - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
# T* _/ g6 _. t$ J( Z
+ J3 S# n/ X! E
+ h/ ^8 j+ `+ {$ E- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 r& }/ z6 W/ c: _; K) x; [ - if(x1 == x2 && y1 == y2 && z1 == z2){
/ {8 |2 V L( W% v9 f/ F' r - return;
9 y! n1 O7 x. [* S - }3 Z4 K& [4 S: \) T" y) r
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){. L9 c: X5 @) w
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, _' R" J9 \6 H/ C
- }
' e. f' y: h" ? - pose.pushPose();
q* t6 U3 L% P: i) a2 Y! ~ - final int newLight = convertLight(6);
# Q8 y, m: u% y W - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));; n9 k0 d5 v9 G( g
- final float lineHeightSmall = (y2 - y1);
6 }$ j9 ~* H6 t* p5 E - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight); g, Q' a/ n' t s% c; L; o8 [
- pose.popPose(); _$ z* ~8 Y" h6 F0 K% z
- }9 J- E4 u: q" ?( R
* f" L" {1 U0 r( A- private RenderType getLayers(String texture, int light) {
f+ k& G% _; J: D - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));6 n" i+ M# h6 |; s! g( z" j
- }
9 c+ s- h' h; N% V, n5 j5 }- B) | - ; P2 y( E% `7 q2 m; A
- private RenderType getLightTexture(ResourceLocation texture) {
7 t% y' H) r: M0 Q* I5 J - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
& u& T2 b% y+ h( K/ X - }
. N( g' X' T; u8 q5 i9 S) g) i - 3 b' z0 `. `+ V2 u% m
- private RenderType getTexture(ResourceLocation texture) {6 u- o7 V* X6 L6 L( c' ]
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
) l9 B4 e9 b/ G+ y) F. X0 h% V) y - }
5 ^; R+ R* h; v P - & i# k, p j8 G, E, v3 {7 U
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ \' z# K( n" U; Y% t; t8 e( _" \ - if (cache.containsKey(identifier)) {, n' X/ p w( s+ a1 f1 y
- return cache.get(identifier);
8 m5 g3 v8 R0 N6 A( a# F - } else {
/ Z& @; R/ _+ b( s6 t/ r6 a( L; F - final RenderType renderLayer = supplier.get();
; I5 f3 o* V, Y5 U - cache.put(identifier, renderLayer);! C9 Q% u; }5 [" ]8 }# M) ^- `2 f
- return renderLayer;& b; G. ? d6 Y$ h; {' B9 \
- }# l1 ]% @% S2 b8 v, \
- }
5 j2 u, X8 u$ k2 v* n% I h3 G - }
复制代码 |
|