|
|
, _$ X5 I; L8 @$ t/ M. y3 f行,这个怎么样- }9 K$ h9 W$ [) G
- package com.xhg78999.mtrfac.render;
: d: N$ X3 w- c
, L8 `3 v/ t% y2 J. q/ x0 s- import com.mojang.blaze3d.vertex.PoseStack;
* k+ o" }: v+ S8 k. G2 Q - import com.mojang.blaze3d.vertex.VertexConsumer;8 i( c! Y7 c8 A- M7 T% m+ q1 k
- import net.minecraft.client.renderer.RenderType;
3 z; h% b( c) O- ^$ j+ I- b+ S4 s - import net.minecraft.resources.ResourceLocation;
" }! _6 ?% K* S: r% L [9 K - 6 [5 V: P/ e. h: X+ a9 S
- import java.util.*;: M3 M# D5 p1 z
- ! u/ {8 ^7 m5 C# [. J
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 |" r$ Z% q% b$ X* O - - n7 F+ c" ^0 F3 h
- public class LineRender{
! D R, a; a+ A - private final PoseStack pose;. [9 e+ o/ y. v8 L
- private final MultiBufferSource source;
. u( b e. N9 `' D - private static final Map<String, RenderType> CACHE_A = new HashMap<>();* \9 a, z b# O/ s9 H6 d) R
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();8 T, m7 k. q, }0 B6 X4 h
$ h+ ^2 |6 S* m* q$ J
# |: D) \* S' a1 M7 f/ W& j- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' ^& C! D _. z - if(x1 == x2 && y1 == y2 && z1 == z2){' ^- c5 K6 p; N3 K0 R# [
- return; ^' g& _$ g/ h4 H! N
- }
6 e/ z4 q& b6 S5 ^ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 ^1 {( k/ s9 F% S - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 Z6 M+ t% I% `* z& U; C3 @7 I - }
# O# n+ C8 z6 B - pose.pushPose();0 d5 ]" p% C9 ~% z8 [+ E J. K
- final int newLight = convertLight(6);
8 `) u% x% ^# p2 c7 H( E3 y* {1 I - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));! D- c; i) s$ m; h
- final float lineHeightSmall = (y2 - y1);
- X0 }0 z% ~ M( h1 O1 S0 A% ~ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);9 s$ v( ]: `6 ?
- pose.popPose();
n9 v( B9 Y+ d( ~* O - }: h) m9 g L0 v( K1 ^3 E
" m0 {' ]4 l5 s x E- private RenderType getLayers(String texture, int light) {9 K: X; g6 E! p8 W( I% \
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 u; {1 l1 e7 w0 m& s; n3 ?- u
- }
- W& o$ G6 A+ \1 ~6 ?) `5 b
' A2 _/ m6 P; H% m0 m! h- private RenderType getLightTexture(ResourceLocation texture) {1 Q8 q4 J6 p/ F6 t& A t
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A); L/ [! I5 D3 \2 h/ V
- }
- |% H5 f" | D Z6 O+ U
/ n* v! Q1 a) ]; x- private RenderType getTexture(ResourceLocation texture) {+ a* x+ t1 P& a' D, w
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ B3 T5 R9 H B% y9 {. P. k - }
& S v- M2 s" z- g# p' z
- O% ^4 q1 T! \+ D" Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) { w9 r/ p% D1 W
- if (cache.containsKey(identifier)) {# b" ~) g4 Z5 `. D
- return cache.get(identifier);
5 \; a$ X3 q: p" _ - } else {
) @/ m+ p, n7 v; A) x8 r" g - final RenderType renderLayer = supplier.get();* k. W4 K6 F4 b2 Y3 s
- cache.put(identifier, renderLayer);! p* Y* J) \; ^1 L+ ]
- return renderLayer;8 l# N7 j$ B/ j, P
- }! x5 Y: y. |' j) n6 ~. q w; R2 c
- }3 b4 A/ d7 a- Y+ {! K
- }
复制代码 |
|