|
|
+ w$ M$ N* N p6 F9 C行,这个怎么样3 H7 C2 u/ K7 |; W$ n3 ^. T+ b
- package com.xhg78999.mtrfac.render;3 J, g o5 J' h q) T
( e, c0 Y5 k" O0 |, M. B- import com.mojang.blaze3d.vertex.PoseStack;7 a& p% u: l7 j- i7 X6 l
- import com.mojang.blaze3d.vertex.VertexConsumer;: U" Z* a$ f9 k8 \. S
- import net.minecraft.client.renderer.RenderType;
$ x' ?( a4 r8 L - import net.minecraft.resources.ResourceLocation;
; C6 `/ {7 V0 J - 2 p, T2 Q# |9 r9 v2 T
- import java.util.*;
e; s% ` f5 N4 j! s, u, n - + n/ ~+ C$ j9 c6 P
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
) j: g/ H( G8 l
0 i7 z) ^, \+ m3 s4 z- public class LineRender{1 L7 z6 U$ w- J/ [3 E
- private final PoseStack pose;* b# g u3 I, g. X; s, ~; r! b
- private final MultiBufferSource source;
3 j7 `1 R3 E T; D5 ~ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 K: E9 H1 A0 p6 ?! y1 Q1 V
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>(); n2 h# U1 c/ c1 Q$ z
; L) y2 {5 U) O$ Y0 v$ q! }% p
$ i0 B& _2 ^- r8 {# o6 `! g- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
f/ ~5 F, |( O* H1 h* H - if(x1 == x2 && y1 == y2 && z1 == z2){
h2 X5 P, l" `2 C9 P - return;7 G7 @( t) F: d2 R' H; E- g
- }# ~3 @1 _# {& o Y0 D3 ]
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; V9 Q% R; o1 {% ?# T
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");& N" i6 u, |: z% m8 z* P
- }# T3 i9 `3 S6 d0 @) E9 o
- pose.pushPose();7 w! R0 M- m: f9 Z& L4 v
- final int newLight = convertLight(6);/ o4 c: q" Y& E7 n" M: [, q: x
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 g5 P- V" }5 j, q" {
- final float lineHeightSmall = (y2 - y1);4 |+ R% b* R- f) |( N
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight); }7 Z: U8 {& P' l8 v
- pose.popPose();
( s3 p# }$ e- M* o( d& b, M - }/ t( E0 B9 U" @/ l6 G+ X0 s' a4 Z5 ~
+ D8 C# x6 V; ]; ~; ^& }- private RenderType getLayers(String texture, int light) {# U% b: c: j* r: n8 O' [7 _$ k
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ j, }" Y! q& {9 O0 Z1 {
- }! n! U. w8 x' O' U: N, R; ~
- : u1 P+ J' `9 i/ O& L9 ]/ X
- private RenderType getLightTexture(ResourceLocation texture) {
2 R: ~- O! V, y6 p - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ z$ F& B& ^2 F! i* q
- }7 H8 w2 N4 @2 b8 q# r5 k/ w
- 0 [! m9 I0 T3 M
- private RenderType getTexture(ResourceLocation texture) {+ [9 p! c/ w7 l0 i
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);' P8 _4 {& a0 w. y
- }
0 C3 n. ~4 D7 k" V! C1 u2 ?. f5 G
- f7 v. F5 B' i L w. \: Y) `. F, G- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
( P- g6 \. z* B+ v' D/ `6 c, p2 B: H! L7 m - if (cache.containsKey(identifier)) {5 B/ J! l+ ^% {' [
- return cache.get(identifier);
8 f' X# B( c4 D - } else {9 I2 k5 ]1 O" M) d1 U) |
- final RenderType renderLayer = supplier.get();: l; B1 V; H$ V' Y, J( ?% ?
- cache.put(identifier, renderLayer);
- R8 D! P |, z' Z - return renderLayer;
. u3 e, I7 L% }: A - }
8 z! H7 @5 ~+ }! V - }
% a: U" N1 e7 J* B; M( | - }
复制代码 |
|