|
|
- T1 ^% z. M* o9 j( f" q$ ?行,这个怎么样% N9 l4 m0 \5 V* p7 Q/ r* }
- package com.xhg78999.mtrfac.render;
1 w3 \1 Z& O o. _. s
6 N- i& v1 ~% V- import com.mojang.blaze3d.vertex.PoseStack;
5 h- w8 r& b# W. ? ` - import com.mojang.blaze3d.vertex.VertexConsumer;# _, r, L* k. d- B! ?1 [% b. ^
- import net.minecraft.client.renderer.RenderType;
" `3 H7 @( Q1 e; W- U, t/ H - import net.minecraft.resources.ResourceLocation;# f+ V6 F4 u8 b' M4 g5 U1 \; x
- 4 I* }, `, x2 M/ d3 k/ q
- import java.util.*;
. L( ^3 D& u5 N4 ~4 c) r
9 \* T3 v" J' W: p7 c' Z) y( V- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(" h- d; U0 S1 W5 L8 i
- . b% u' y/ q* {/ B
- public class LineRender{9 ~/ y% Q3 M0 x' @# y! p
- private final PoseStack pose;
1 Y1 \/ v( |4 L# w; ~4 }& F& a - private final MultiBufferSource source;+ S( b: u8 R' l, u9 C( e
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) q+ q# a, S# K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 q5 f! h8 @" t( F$ T& ^! ]7 I
. Z" [, U9 i1 b5 n& D
5 B0 p: ]" v' Y- l! k% w# E- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
% v/ S5 k4 @7 e- N - if(x1 == x2 && y1 == y2 && z1 == z2){
5 R% x6 Q: g5 L; ?# _* Z% H - return;6 p& f6 b; @2 c) a0 A
- }2 Z% ^, B- ]. d
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
7 Z; \- v( V/ N0 u v# N1 ` - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");- Y# K1 X' c6 v9 t( i6 J' G3 t' M. W
- }. L! M& {4 Q) _- y
- pose.pushPose();
# C% a$ r" I' X J$ y - final int newLight = convertLight(6);8 X0 C: v4 i) H5 G6 V; T* ?$ y/ _8 S4 ~
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
s8 }" T: e- x - final float lineHeightSmall = (y2 - y1);/ P& p+ m+ I/ I0 {
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% `. a3 \# q H5 S, y
- pose.popPose();) ] S3 t+ S4 }9 H$ t* A$ H
- }/ D# U! `- V3 S9 C. N6 C+ ~
- 7 e& D* X; S6 |: B
- private RenderType getLayers(String texture, int light) {
V' N8 y3 A1 E - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
1 m% W) ~5 W G$ B, O - }, q; d8 N, G: O: E/ A
b9 H- j1 z1 L' G- private RenderType getLightTexture(ResourceLocation texture) {
" K$ @! W" z$ V: A" u - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ q9 b0 R% _! z3 c; Z3 n9 w
- }
( F- Q r+ D/ ~; U - " [; W2 ~ |5 J2 V; Y) t$ A6 H
- private RenderType getTexture(ResourceLocation texture) {9 X) e8 ?- n" T9 ~- @
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 ~ s% L6 x2 t# X w. f - }1 R9 O G7 M/ |( F
- 2 F9 _8 ]" T) U" G7 ~% g' M5 K4 p3 S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {3 P! l1 B8 r& H$ ^
- if (cache.containsKey(identifier)) {" M4 J" |+ _& m( \1 t/ [
- return cache.get(identifier);! s5 m; ~, L0 }! [8 ~- m2 h
- } else {
! @! b, U/ j) p- V# E3 P* @$ L - final RenderType renderLayer = supplier.get();# n- @$ v8 _. c) L r) k8 e) `
- cache.put(identifier, renderLayer);
2 `+ \" Q! w/ N9 l - return renderLayer; H- E1 c! ^6 [
- }" S: m" l7 a6 E7 {3 |
- }! V& Q. y0 H# T- @" W+ c: [- X' e& c
- }
复制代码 |
|