|
|
" h8 x9 V+ s: \
行,这个怎么样
1 K: [3 Z- v# U$ b& `, O- E# w0 ?8 ^4 U- package com.xhg78999.mtrfac.render;9 b+ b' S6 _9 _! Q. J
; s9 P u# _0 F: x- import com.mojang.blaze3d.vertex.PoseStack;" V& @0 k: H9 } g' e
- import com.mojang.blaze3d.vertex.VertexConsumer;3 ^! I- b+ b- D! W% Y6 p- _
- import net.minecraft.client.renderer.RenderType;) o/ V0 F4 a7 I9 F1 K
- import net.minecraft.resources.ResourceLocation;8 s# \$ p% g- {
- $ ?0 B8 w# M% A8 J
- import java.util.*;, F% A, \/ A: c. n& C, u
! y1 r) M$ E B/ U- u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :( G5 z' E" }- ]
: y, S4 h8 S8 X4 g3 o9 i7 w9 G- public class LineRender{
$ I9 N# d# d( Y) ` - private final PoseStack pose;0 u) |& ^% n4 [$ L, G3 e$ g8 F; ~" V
- private final MultiBufferSource source;
) E8 c" G% G0 ~3 D/ t - private static final Map<String, RenderType> CACHE_A = new HashMap<>();# e: z; l$ O9 [" H; C
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();$ P p# G q) [
- $ H5 A0 B: d7 Z) r
- % S' N M H# \1 S: b& H) f. M/ X+ N6 g
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){& k4 @$ y8 a1 Y* g# i% R
- if(x1 == x2 && y1 == y2 && z1 == z2){# k) |. A6 j) N# j( o4 h3 C6 r
- return;
+ H$ j. d2 l9 p+ K - }6 j+ N# s `* V9 ~! }, s
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 |) h/ z( H# N( @ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");- L: _1 a8 Z! u% u" o
- }
$ t7 I3 {3 s- ^& ]. Q8 L - pose.pushPose();
! ?, J7 G, M! l# o( m U4 ^# C - final int newLight = convertLight(6); B. X; Y5 H% T: P6 w: ?7 y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, j. N9 D$ n; b! P8 D! O - final float lineHeightSmall = (y2 - y1);
4 ]( j7 Q1 p" b: Q9 Q% } - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& p/ j# }- X) b; y# M
- pose.popPose();
1 @5 ~, w' n' }4 k% m - }
, I- \2 a. p& z4 [) c0 {
, ]- M7 I U- E+ t r3 {- private RenderType getLayers(String texture, int light) {
- S7 {9 c8 R9 I, `& B - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
' o% E) u4 E4 O5 m1 c4 m8 E9 o - }
6 ?1 i. P! e! n+ }! Z+ r$ D0 [! M - ) z3 G2 w3 K6 X: P o
- private RenderType getLightTexture(ResourceLocation texture) {" m9 z. `/ e! ~; c, I! d' `
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" F+ W; k6 v" ^
- }& b8 W0 m. e' e) Y/ p; f) P
- & Z, O- F4 v; E" c- @- }
- private RenderType getTexture(ResourceLocation texture) {2 k* T: ?7 v$ L$ d) x, u% w# u l
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
5 m! W8 ]7 p1 \- E - }5 |& r$ K+ X! e. x/ T- Q0 L
- 8 u1 _5 n5 S5 R# \% D
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% o% z3 B5 y* c3 h
- if (cache.containsKey(identifier)) {
2 _! z8 u" O6 T! }- Y* y - return cache.get(identifier);& p' M, M3 Q: H0 ~' J r0 `2 g& x
- } else {+ I z& W# N; f
- final RenderType renderLayer = supplier.get();5 [! D* P8 I+ Y j
- cache.put(identifier, renderLayer);7 ?5 J" t3 g/ H, O
- return renderLayer;
! q" @5 o' c+ q3 d6 K3 q - }. V* w) G. R# L- O; W+ f
- }6 S) U, A0 g# x- {) o
- }
复制代码 |
|