|
|
; {5 A- w; A% S8 I" W& O; [" H行,这个怎么样
# ~9 ^, b( w/ s# k D- package com.xhg78999.mtrfac.render;5 f9 V& a& O/ _4 a
, ^, H. j$ q) T( J; S% O- import com.mojang.blaze3d.vertex.PoseStack;; _2 z1 m' Y- e! F. K+ k$ v; v, ?7 c
- import com.mojang.blaze3d.vertex.VertexConsumer;
1 ?8 \$ a. E8 Z2 e' ?+ a - import net.minecraft.client.renderer.RenderType;
9 A% z/ I/ y- e) F0 E0 m; U - import net.minecraft.resources.ResourceLocation;& z9 O \% l( j7 ` \6 _: } K6 Z) I
y& q+ M. Z( u. ~/ _5 R- import java.util.*;
2 g8 Z+ \8 k3 ^7 H3 X; C; r
H) M( f1 |( f I% Z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
6 e/ J7 c. E6 Y6 C' }2 M
) u1 \+ I# p' @) x- public class LineRender{
% `' k) C; G8 m6 N2 y8 I a - private final PoseStack pose;, Q( u& p* f# c3 |6 ~- y$ y% l# X( @
- private final MultiBufferSource source;
t4 v5 i; w3 o i% k - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
5 e8 `( m" K( [' p. w1 v7 c - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 Q* f' C/ Z- a* T0 a6 b1 S - w$ K/ e; g K
- 4 f. q# A; l1 B8 E$ v/ C! p2 }! P$ p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ A/ R7 j7 H8 { - if(x1 == x2 && y1 == y2 && z1 == z2){
7 c, J3 C1 H" Q |( T" h - return;5 V9 `& }4 J1 Q# V' K! c
- }+ k7 F# T( t. k4 q9 e7 g- [: k6 {5 b
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
4 ]/ ^3 N* c3 @- w - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: s- e( d* E* k1 J, W( A! S) Y, o - }
0 K- S: F; O4 j% g. ~8 ~ - pose.pushPose();
i N& A2 a v, i& |' ^% o$ p - final int newLight = convertLight(6);
9 O0 C$ h Z- C* D - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! R9 b& ?! o7 ^* u$ ~6 v$ ^9 x; { - final float lineHeightSmall = (y2 - y1); B7 m% Q9 ?7 C' A5 K
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' a& i9 w' V' c; L5 j8 r" m G6 n - pose.popPose();5 Y: I5 f0 U' t
- }
. N+ }4 x3 C& u% ~9 ?
3 x$ {, [+ }5 B1 I- private RenderType getLayers(String texture, int light) {
1 D1 ~4 Y7 ]9 G- E - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, Y9 A: @7 Y) V6 b1 S0 x- k
- }
1 K! c1 {' w2 E n - 2 a* w; ]0 {% ?3 j5 c
- private RenderType getLightTexture(ResourceLocation texture) {! b2 T% O. d# i5 j8 q# B6 E' ~
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, l$ Z8 `% M! w) Z: _
- }
8 m/ l3 a6 P; O# U - . G6 M3 _. e5 g t/ G) R# p
- private RenderType getTexture(ResourceLocation texture) {. ^6 j+ h+ M* D' u8 r
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
N! b. W% n7 M3 X& J- S - }, a! l' O3 _, j) {3 M6 N
6 `* H& i( o/ {' }8 I- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { C9 Z, p) k6 z8 D+ p! }
- if (cache.containsKey(identifier)) {
5 j s# T" B# Y- a$ A. V - return cache.get(identifier);
' y. L. q. N3 n/ m - } else {
! l, [# r7 Q w0 q" J - final RenderType renderLayer = supplier.get();
" ]6 h! [0 k+ o- N - cache.put(identifier, renderLayer);; h! E! h' q1 z# {5 H+ W; [5 T
- return renderLayer;; n( Q' h9 G: c3 Z
- }( h5 t) k7 s4 B- \6 ?& S1 o. b
- }
8 |% O/ F7 t% ], I1 ]* f: j - }
复制代码 |
|