|
|
* M2 r* L4 Z n7 ~; p! @* Z. C
行,这个怎么样
2 k' Z5 q% C+ `; P. C- package com.xhg78999.mtrfac.render;
" w& G8 n# w/ u$ O* u3 P
: @! h% ?; l( |. v8 H! N, f- import com.mojang.blaze3d.vertex.PoseStack;3 `8 B' [5 X' x& L2 K i
- import com.mojang.blaze3d.vertex.VertexConsumer;
! _9 J1 R0 P" u- d' C$ {1 j6 q( } - import net.minecraft.client.renderer.RenderType;
0 G/ e4 w0 ?6 r) A3 q. y. g/ u - import net.minecraft.resources.ResourceLocation;4 Y7 y0 l4 T) g R3 D
- 3 ^6 T- Q) `) S7 ^ M
- import java.util.*;" Y( V& L' F s
6 m8 x! H$ b- l& k" Z% ]- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(( ~0 q6 _+ N; [! e3 l
' g6 H" b4 F: l: y) }: o' C: o- public class LineRender{) i% N* G6 g4 n. u5 z# R: B
- private final PoseStack pose;. Z* @6 J |" Y2 V4 Q# p+ M
- private final MultiBufferSource source;
2 m: f- y, v, Q$ F - private static final Map<String, RenderType> CACHE_A = new HashMap<>();* E. L+ Y b0 x( ^1 V" `9 d- Q
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 h. E3 I# v o* a$ T+ R3 p
- 8 ^) S5 Y8 n! J+ c, b5 y$ c
- , }; n* n# [+ m$ r5 F, n
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){" B0 @" R1 J$ t! Q; I
- if(x1 == x2 && y1 == y2 && z1 == z2){
; j! Q$ E1 E9 W0 D+ [ - return;' M# [% N+ R8 v
- }
! {% g9 I+ m+ k0 c! b/ D - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- G* O( x( [4 y$ j9 u, ]- l - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 }- [$ b7 D- T4 s
- }
/ _* E* x1 F5 e9 u3 E - pose.pushPose();
4 p, J, g4 j8 P) F: b5 k - final int newLight = convertLight(6);
' V0 y: d Z8 r/ @6 }; \$ ` - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 B2 ]& k Y& p
- final float lineHeightSmall = (y2 - y1);
# W& O1 T( i$ E& x - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);4 Z) S1 ^. e! ^& M- Q& j% g
- pose.popPose();: n+ P0 f: o7 q. R
- }
: V# ~1 j" ?( f# j
5 x& \1 U4 m, K, `- private RenderType getLayers(String texture, int light) {4 h8 I- h" o* p" N' o6 V( q& t3 D
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* j) y! M9 M; h( Z# O
- }
+ D3 V! Z8 v$ ^9 n' I/ W2 `: u - ( _- X2 J1 V" h2 ~6 G& D% y# K$ Z# {
- private RenderType getLightTexture(ResourceLocation texture) {
/ ^" s' o9 r: R# q' r& F: S5 @0 c - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
' G9 J4 o& |/ V - }
( ?# I: z% K: e* {
+ C! Y" Q- Y- Q4 }# |* q- private RenderType getTexture(ResourceLocation texture) {8 S3 J! h1 B; o2 P. ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" N/ E# @8 k f- ~5 M, C' G - }9 X) S7 \* J+ |: Z' u1 S* g
- 4 ?, t% }7 G. X) k& ~3 u: p' \. }
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& O* u9 A; Y; I1 g2 z! u; `, r* J: _ - if (cache.containsKey(identifier)) {; Y4 e4 v2 n& ~6 U- E7 ]: e* G1 t
- return cache.get(identifier);
8 x/ I# e. M, s( ~$ A2 o - } else {
# |" }0 D$ Q" Y0 Z - final RenderType renderLayer = supplier.get();- v6 [; w/ |5 N6 D' [$ E% p3 t
- cache.put(identifier, renderLayer);
1 d: i9 r# e7 E' W/ f! v8 { - return renderLayer;7 W' r8 n) ]; N. q; L
- }
$ u7 p& p, q1 Z( j; L& W - }
" G, H9 A: n9 j! z+ Q5 \2 Y( N: [ - }
复制代码 |
|