|
- a" x8 w1 u" i1 R
行,这个怎么样6 H9 e, e7 i: f# {5 N9 g
- package com.xhg78999.mtrfac.render;- O5 c5 n$ r4 E9 ~3 g5 O% p E# c: K
- \ L! H) H" z' c6 o
- import com.mojang.blaze3d.vertex.PoseStack;! B* C- s" e+ B0 C: m2 H5 P
- import com.mojang.blaze3d.vertex.VertexConsumer;
" j7 l# @/ A, y$ F - import net.minecraft.client.renderer.RenderType;
( U4 F: z5 V& W7 u1 i! v; ? - import net.minecraft.resources.ResourceLocation;! e, A6 l) M* z
- - r- {. ?: G7 b. t Y- X
- import java.util.*;' }% \* q# k% @) m7 V, i5 I
0 @5 V& n3 K: |9 w' _- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
- ^- E [1 u7 T" R5 W% r0 ?
) n7 e3 `' g5 E8 ^& x% \/ q" B- public class LineRender{# @, d3 z* ~2 i
- private final PoseStack pose;; x9 R0 `" O* Z s! [1 ~
- private final MultiBufferSource source;! B- {" Q F/ `
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% c# ~: G' x+ q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" I. t/ w5 r1 T, ]3 |* G1 z
x9 T3 l' T) {" y9 X6 A0 B
. [$ s8 U& T7 G/ ]2 }! o1 y- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 U: g" a. i" l# Z7 n - if(x1 == x2 && y1 == y2 && z1 == z2){
" U+ x& I/ O8 E/ m6 {8 C" ]/ P: Y - return;" S) M- d0 y. Z7 Y6 D
- }
( Z: Q( C0 g3 D4 _& }! E - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){; e% [( y/ U; ^: k
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");; a; b1 N* \. k4 ^' y
- }8 {. @' Z l4 ~5 H4 n; l1 r! o0 e6 l/ a
- pose.pushPose();
4 t1 Z: [' t) {5 r) \6 f - final int newLight = convertLight(6);% u: g3 J4 @+ R1 }0 {: ?
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));, J: r" b! J6 c- q" z
- final float lineHeightSmall = (y2 - y1);
- x8 I' S7 `5 p; M. o - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* y8 F6 `4 m: E$ K0 O$ K - pose.popPose();
! s' E: l# `2 _9 F4 }! q: A. E - }$ D( y% `% M R" |$ L# h' Q
' U- x( [0 l0 c- private RenderType getLayers(String texture, int light) {
# e8 s3 W: |% @8 G. h) z" Q$ P0 C - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ i- J; {$ m3 t# b* y
- }1 q2 p1 \7 k @9 l" B& P
; s9 z& o9 v; b+ c4 x- private RenderType getLightTexture(ResourceLocation texture) {
- ?# @ {- j' X0 V7 W - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
L, h* I1 Q8 Z+ n8 |+ V; L0 W% u0 l - }4 ~$ d0 B& ?# B
- 7 \! v& X8 H" ^. |
- private RenderType getTexture(ResourceLocation texture) {
: G4 ~* C+ `( G4 h) n- ^ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% E2 b) W9 q4 Y5 y - }/ ^; y3 n9 W8 A4 _
- " C& {) A Y6 Q7 [7 K
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" e( u4 s8 z% L7 K
- if (cache.containsKey(identifier)) {
/ a5 ? ]$ @! w% r! s - return cache.get(identifier);' ?9 k4 k% f' P' m- t4 w% W( z: Y
- } else { U2 f& h! s& D9 q3 J* b8 M
- final RenderType renderLayer = supplier.get();
% T; A! D! L- J& T - cache.put(identifier, renderLayer);5 k8 Z& t, u6 O+ j0 U/ [( i* k$ l
- return renderLayer;6 p: @6 q. h1 f: b0 `- z
- }* |+ |" Y7 r/ w9 ^! H9 Y$ b
- }8 n# s. E6 o9 k# ?+ U2 x& I1 f0 x% R
- }
复制代码 |
|