|
|
5 l5 t3 |' {6 A5 ~行,这个怎么样. n. z6 s5 B0 M8 `) U
- package com.xhg78999.mtrfac.render;/ a( v1 V6 N; P
( `2 t7 M e9 B& e2 N$ N5 x- import com.mojang.blaze3d.vertex.PoseStack;1 B9 Q8 q" U9 l
- import com.mojang.blaze3d.vertex.VertexConsumer;
3 a1 p7 {( S2 I, t, \5 n5 | - import net.minecraft.client.renderer.RenderType;$ a+ s2 @$ T6 B5 e% G
- import net.minecraft.resources.ResourceLocation;$ V# S# v3 m, a" K
. c3 w& J- ?* \$ L' s4 q' R- import java.util.*;! x( f- i% ~6 g, p$ {
# k# n' D3 E. z% x& h- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" f) c0 p2 Q/ A' |
C- U- w3 ~2 D9 A" M- public class LineRender{9 j1 o4 {: r5 ^- L* i" H
- private final PoseStack pose;
8 r, C4 ^; \& Q1 d( J5 M' Y8 p - private final MultiBufferSource source;
1 x( P/ p5 q7 P+ [% Q+ V - private static final Map<String, RenderType> CACHE_A = new HashMap<>();/ a: m3 d$ d' w; R
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
7 Z& b5 g, W+ i' W
" |& k# b9 Z- J- S6 `2 m
* q; K8 u: j! b, p& o) }, C- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
0 E8 i: d8 B) g4 \1 \5 Y7 l. H - if(x1 == x2 && y1 == y2 && z1 == z2){
" H. i' z) ^8 r t8 o U" B$ N - return;
" O4 h. B. L6 i0 G* m- m - }
, H n- N8 G7 @0 F* B) j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; g2 X) ?7 l' k/ y1 W4 `. ?
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& N) P y$ Z( D; N
- }. P( F6 C5 Y0 }9 l ?
- pose.pushPose();
, g3 {( [/ J* m5 `) M) m: T5 `* r - final int newLight = convertLight(6);; u9 l( @+ ^, f1 b+ {, I' B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 c7 f! w; n+ @$ x - final float lineHeightSmall = (y2 - y1);9 \: c: V2 P# G, {4 N
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* e: Q, e0 [% U3 {+ `' p - pose.popPose();
. H9 v1 D, j5 m7 K* _+ S - }* a; t2 ?9 ?* }6 R
- ' Q$ T) [2 t' h8 q. l
- private RenderType getLayers(String texture, int light) {
- b& z. Z# Q0 k: ~ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( O. M6 H% q5 F+ V9 j' x - }
- o% n4 D& C- ?. `' J4 {( N7 C$ A- S
0 j/ k5 d: M5 N" B" v6 I* T- private RenderType getLightTexture(ResourceLocation texture) {- m3 b) |- Y/ ^
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
7 p' P4 P! Z! L6 X1 p% I - }
$ x3 {: a; t: }( |& T& y# S - 2 V# l& s; M% \; j0 v+ }# ]! H
- private RenderType getTexture(ResourceLocation texture) {
/ D$ x5 D: A0 _7 ] - return this.cache(texture, () -> entityCutout(texture), CACHE_B);3 b; v# K( c. P% o% h3 s+ @4 C
- }1 x4 s( i: x! ]4 G/ ` [0 x) @
0 D0 ~, k$ `* f8 B! n- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {/ ? |9 O h! L
- if (cache.containsKey(identifier)) {
* V0 O; Z3 x8 u4 A- | - return cache.get(identifier);
1 w3 c+ A& h5 }/ c1 g$ v - } else {$ c7 S% z. x% d% y4 ~- ~6 }8 i5 K
- final RenderType renderLayer = supplier.get();* u0 }) W8 C+ A: \1 t
- cache.put(identifier, renderLayer);; A1 J$ j0 T4 k$ {: v/ X
- return renderLayer;+ L& X8 E/ m0 O7 Q( b' L" Z4 w* O
- }
* `* N; ~' b) x* a' `# I - }$ G! A, b5 e$ p( G
- }
复制代码 |
|