|
|
( G5 U# {( g9 d0 _0 I. M1 @' {/ l7 ?行,这个怎么样
) f8 o' M5 e1 Z( D: L- package com.xhg78999.mtrfac.render;
2 x5 N5 l: F" Y" a
7 L( b3 ~1 Y' d4 \! P0 i2 Q- import com.mojang.blaze3d.vertex.PoseStack;
2 V' P! d, d8 T6 N+ V7 f - import com.mojang.blaze3d.vertex.VertexConsumer;3 W5 F& j* D5 Z! t, |
- import net.minecraft.client.renderer.RenderType;# y* s0 B( k5 b9 `) j
- import net.minecraft.resources.ResourceLocation;8 E0 H! s- U) H. ]: X9 B# ?
9 j$ P: T. J/ A' T9 D- import java.util.*;
" ] O' Q5 t: c+ u1 ^ - 7 W' |' `0 b6 q; p: f, H6 s0 t
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( Z& G# O) u' ?! i: C9 z
r: A, J6 H. g! ]# Q0 ?- public class LineRender{3 j% L g2 y5 W$ ?) }
- private final PoseStack pose;- U- s" {& n L6 }8 T
- private final MultiBufferSource source;
; m9 _2 H. X( [* W' g; C - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 u. N' q% s- r - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 P5 }9 q( B% \5 O! o - $ z- {7 L! l1 N, O
- 7 _' V7 n# |' u3 y1 ]
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){3 D8 t6 T2 Q0 G# B" S4 x# p. g
- if(x1 == x2 && y1 == y2 && z1 == z2){
9 l; _% k% g7 w2 ^" f+ c - return;
$ q5 z6 b% J% n8 {3 V2 ] - }
5 y, d3 K& Z) y' \ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 Y3 X6 O' N1 F9 W5 Z
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 ?: @4 K# L3 {" J, j! H0 O
- }
) {/ U4 j6 i8 t; j1 M8 `) n - pose.pushPose();, s% \, F5 x2 a% c3 m5 ~6 \
- final int newLight = convertLight(6);
: L! w! t+ }8 o- \0 r - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 k) p" y$ O# F
- final float lineHeightSmall = (y2 - y1);
, a" [3 G5 C' r - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# P4 }7 g) r7 [: y N. [
- pose.popPose();* `7 W: E, Y$ q& z" q
- }
( F+ L" T1 _5 V* J6 Z - 9 ^& x5 R( C$ C' k/ U/ C" y
- private RenderType getLayers(String texture, int light) {
1 ?, `; P, o9 O; m! G - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ v2 V3 `! {! W( A6 h0 q% n
- }; {: P) m, H. `. y* g4 v& b
3 E1 o7 L; _; r, D" h2 X8 N1 }+ i U- private RenderType getLightTexture(ResourceLocation texture) {
. M1 \' `7 K. V# B$ l9 p - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& Y8 e/ c6 V2 S/ B
- }' V4 j. F! T0 _- i; r, z( a
- ! Y5 i4 z6 a1 U5 g- s" |1 c/ {
- private RenderType getTexture(ResourceLocation texture) {
y6 l6 O+ ?! t2 e" I7 z) K - return this.cache(texture, () -> entityCutout(texture), CACHE_B);- ?: U8 p0 f- [3 a" l
- }4 @ y/ B, e4 F# C' j
# p2 p8 X( \; |- D; u1 \- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 R7 X" {! N: p% [( V% o) B9 R0 v& O
- if (cache.containsKey(identifier)) {
) L& `( P. s7 G - return cache.get(identifier);: t0 J2 ~7 o E' u3 z
- } else {) C- m% n; u7 G" e
- final RenderType renderLayer = supplier.get();
9 c2 a2 F0 G8 S) c* L - cache.put(identifier, renderLayer);
* {3 s' V* N4 t* ] - return renderLayer;
, C s& U. Q% A7 n4 E - }7 [: m& r+ v1 L/ {
- }
" q' W0 [1 `+ E Q- M$ T - }
复制代码 |
|