|
|
" T0 X) E( u- v+ q& I: F行,这个怎么样
& H0 x) o. R9 b1 y. s- package com.xhg78999.mtrfac.render;
, H' a9 j8 r1 J - & z! ^5 `9 u2 P, C! C
- import com.mojang.blaze3d.vertex.PoseStack;
$ U7 p& B8 c' p8 f$ U - import com.mojang.blaze3d.vertex.VertexConsumer;! R4 J! I6 r( C
- import net.minecraft.client.renderer.RenderType;
* Y5 {1 v2 `! X4 ^4 l+ s) t6 ? - import net.minecraft.resources.ResourceLocation;
* y0 b Q' s( q5 ]# U3 w" d% B
0 e1 X5 Q7 L9 I5 s/ H8 E. {! U( @- import java.util.*;4 W1 X7 m8 v5 L, K6 G
- ) t; c& U9 R! d) B @
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" J% q+ h+ y# L# Z0 Y - 2 Y% q9 i8 C2 D$ s9 k7 O
- public class LineRender{' O# D4 t; I. y7 C1 }) L
- private final PoseStack pose;
b# r1 K6 `% | - private final MultiBufferSource source;
! I. d& ~. c; X, {5 b% e - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
3 o" {' C& i- Z9 \ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();* T& j4 L$ K, i- ^4 Q4 v: K/ ~: H0 r
0 \3 y: h: e, ^- Q. @8 t) {1 U1 n
; [4 ^) ]6 c0 B; h, B. L- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' U/ Q9 g& t3 k1 O
- if(x1 == x2 && y1 == y2 && z1 == z2){
5 V4 V( U9 V% L8 T2 m+ W" S - return;3 o" k2 w x. G' M3 v! q) v$ ~
- } Y+ k' [! \1 ^5 n/ p, g3 P% y6 R
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- T2 I6 f* Y7 c$ n - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ n$ W% ]+ I b7 a8 N; m! ]
- }
4 z& |( t& _8 K T - pose.pushPose();# m- ]6 ?! p. V! K
- final int newLight = convertLight(6);1 g7 q5 f3 [8 M5 g6 @7 c* d
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 [6 {0 q$ B5 {; \
- final float lineHeightSmall = (y2 - y1);! z% W/ s: P4 W0 G' V" G
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
0 _0 ?5 B& } d1 C - pose.popPose();9 c0 h) V7 L( v, Y
- }
$ @; ]6 _3 N3 E3 H y; E4 i( v - - |7 e J. K6 b
- private RenderType getLayers(String texture, int light) {
g% K) g$ u6 ~9 P) D - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));# \" @7 Y4 j L- d" a; e5 r- ?
- }( G r5 f' c& m. Q+ b
- 3 ]% f2 x: m, K0 X) V& n7 Q3 T
- private RenderType getLightTexture(ResourceLocation texture) {
, `% ?, T) Q K7 b) u2 Y - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ s& w8 z) s8 P/ B5 ~4 c6 y
- }- g0 \! s- R; m9 s
7 Q0 n$ T2 o6 b- private RenderType getTexture(ResourceLocation texture) {
( t- P. j8 V/ B G - return this.cache(texture, () -> entityCutout(texture), CACHE_B);' O; ?4 M4 \9 s5 X; b) m9 ^' c
- }
8 b( L5 g+ Y! F0 W8 ?& |
# r6 H" J/ x7 W" L- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: C3 G* E3 A/ Y, B: H- ^
- if (cache.containsKey(identifier)) {
; G1 C/ I4 @& R$ T0 H. W/ N - return cache.get(identifier);
3 N) Q, ^6 I% N% _& r- C" I - } else {; b/ Q, j7 h* e% g* p/ I- s4 u
- final RenderType renderLayer = supplier.get();$ c* B" x% B3 f2 b: L R! J
- cache.put(identifier, renderLayer);" l4 J/ M: T- C- D! k1 r* R
- return renderLayer;
, X( g- b2 a2 p" c7 a - }
8 Y5 s2 Y2 s. w - }
; m4 P6 Q- ]1 H - }
复制代码 |
|