|
|
/ ?+ @0 b& D7 h; N行,这个怎么样- |7 g6 W$ Y5 y( j+ f1 _( S1 `
- package com.xhg78999.mtrfac.render;3 A9 M: c) {1 q5 ]% W1 P6 V
- & l- Y' B' E9 [" e5 {
- import com.mojang.blaze3d.vertex.PoseStack;! x1 @5 Q3 ], |
- import com.mojang.blaze3d.vertex.VertexConsumer;/ q( I& E9 W: c9 J
- import net.minecraft.client.renderer.RenderType;( g; j1 k( x( [% g: x. O5 _; @, d* a
- import net.minecraft.resources.ResourceLocation;
, U8 z, t/ c+ c" x8 |
7 l4 z. S: F7 K/ h: z; l4 c* `- import java.util.*;
: ^* [2 H3 V6 l( Y/ m/ b% F5 X6 H
# C U% r9 s4 @# d8 u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, V& w4 B( T; X4 b9 M
/ ?7 z7 Q! d/ m9 {: y( p- public class LineRender{+ `. i3 J# i8 {0 t# B$ j) U; |
- private final PoseStack pose;
2 q6 {! {# M! ]9 H - private final MultiBufferSource source;- C; u0 s8 f6 n% b
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 ]( \: f1 h* s! _( v
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();- e4 o4 U$ a5 v3 m
- $ X0 y' `- ?. H% N# j T5 M
( Z$ L: f' [ Q9 ^' v# s" B7 p- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){9 I$ r2 }( v: W- v" d; v2 h/ R4 I
- if(x1 == x2 && y1 == y2 && z1 == z2){/ u: G% l9 N$ N/ g: r
- return;$ U* C0 i! v) l& L0 W
- }( C) t. B6 Q, k' w5 k7 L
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% A; `- y4 W" _4 [% w - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 _' ~+ M+ v, e& Z g Q
- }
( p" Z$ F& ]" a( k& t. i - pose.pushPose();& @! y7 q: L/ v6 a0 g" g
- final int newLight = convertLight(6);
% {, t+ ]4 H9 G1 B; m1 @ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: P3 ^; N) b1 m+ F7 u' \) ? - final float lineHeightSmall = (y2 - y1);
" H6 U; `6 |! [3 d - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);+ \0 d j4 R8 q! s6 Z
- pose.popPose();* q# I, G/ R. @2 w+ P. ?
- }
* }' r# a& w1 S0 x
& w% B1 I1 `1 }2 a6 v; }; S/ j- private RenderType getLayers(String texture, int light) {' r9 Z$ K8 d0 k/ \
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 G& e$ V; h' q9 b8 @+ F
- }* [3 m- b1 J }& E
; ]/ o1 l9 m9 |( {8 t- private RenderType getLightTexture(ResourceLocation texture) {
# I! u! p2 p, a7 A4 s) o - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* K: S1 y# r& C - }
( e5 q2 l* c- @3 U8 ~
& Y9 [3 L$ K; {9 Q! }" g- private RenderType getTexture(ResourceLocation texture) {
! B9 `: g M' K- L! b; [+ d2 ` - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ D. |+ m, F! t0 Q: X# G - }/ T7 y) B+ M, P. _. Q; q
- ' [' o9 s/ ?' I- v# j6 m! _- v! G
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% f( E6 j3 G4 A4 Z4 w
- if (cache.containsKey(identifier)) {
: ^! h+ p% F2 A" a6 P& k. G - return cache.get(identifier);; X( L/ L' u+ B [
- } else {6 L c- B# V6 d& K$ l! _& {$ m
- final RenderType renderLayer = supplier.get();5 h* }0 ?- R' s: W. W2 D. ]3 w
- cache.put(identifier, renderLayer);
6 X- p" z5 ]/ k+ N- X& h - return renderLayer;
( E% ]. y( g/ F/ w( N - }1 n, O/ d4 V' H& D- [0 e- ^
- }: ?; T% M" N& j5 K9 A4 s
- }
复制代码 |
|