|
|
4 m5 H- n# w2 Z* `4 ^# r, d) S: C行,这个怎么样$ E7 a+ E* L- |, M! Y2 O
- package com.xhg78999.mtrfac.render;+ O+ N7 K, E9 k% ~1 w5 G
3 a/ A' g3 F0 G1 z8 V: @' B- import com.mojang.blaze3d.vertex.PoseStack;+ [* u+ a1 `, F" l( |6 X
- import com.mojang.blaze3d.vertex.VertexConsumer;
# I( [; G: ]2 O - import net.minecraft.client.renderer.RenderType;
3 O' @1 i9 w4 q3 }! p1 C; | - import net.minecraft.resources.ResourceLocation; Q# x8 R4 L/ y
+ ]5 ~: Q% \$ U/ Q0 u- import java.util.*;
! o! m8 e* n5 r: {5 p# i3 t" K
3 p9 h. e7 p8 K# O- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(1 w3 O- S( ~( K2 M0 U
- 6 a' W. p- E0 R5 Y4 I; z# W
- public class LineRender{
3 _4 U! q4 X# T* F - private final PoseStack pose;; u. K V2 D- d" u2 z, A. R
- private final MultiBufferSource source; t% h" m3 Z4 ?9 q3 w
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();- R4 j3 m8 I( [5 K/ i) v' O
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 }' c! C. i! Z! @
/ I9 C2 T/ u: g/ j' b" `( S/ Q$ e
# B8 R4 P6 F5 u( l" I$ {- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ ]3 P- S( a% ]. Q+ X7 @" W - if(x1 == x2 && y1 == y2 && z1 == z2){
! v) X/ j) ~: c v8 _, n! G( i - return;9 L) y* _; |* l
- }
" c9 T8 \7 j( ` - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( [( A* [. w( V7 K ?" N e& G
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 A' x% {+ j7 J/ y6 d
- }
% S2 ~$ m$ h, Z+ w. q9 v1 y" b' W - pose.pushPose();5 ~' W- s& s H$ R
- final int newLight = convertLight(6);( B! T4 l# O8 ]* l- e' ^- J
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( q! `; @- f' a4 R - final float lineHeightSmall = (y2 - y1);6 ?6 {% H" A9 k) @1 x+ l: W* q9 _% x
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
: t' Q7 D; H k3 Q( A# m - pose.popPose();- W0 v0 B7 }' q% S, s' C
- }
- A, h6 U* m/ Y( I- d8 F' ?' S - . I( i. d/ ?! S! N% Z8 S* W, Z' W2 z
- private RenderType getLayers(String texture, int light) {
7 g( V, Y- x( X - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));% W9 ^# s/ p; a: S* J( T3 U. m
- }! V' D Y, q+ u( e0 }/ h
- , K |; V1 K, I
- private RenderType getLightTexture(ResourceLocation texture) {
) Q- b" |0 T6 n9 ~ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! `. T$ T# e# D" R5 {/ r - }
6 k; ?! M( h( ?8 t$ j
7 G: ?+ `; `0 f A- private RenderType getTexture(ResourceLocation texture) {9 z9 A0 ^+ }2 m* H
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; @4 P, M6 n9 h - }8 r# t$ M6 p( S$ c- O5 m
- 7 z% J7 v/ l m. q
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
. r7 ?7 q* G, G+ C' N$ A( P v - if (cache.containsKey(identifier)) {% k& h% C: r# u8 n
- return cache.get(identifier);
3 T9 O( e4 n) D0 J3 @1 M* L7 ? - } else {
% f; J2 \5 h: Y; F% u6 ~/ F1 C2 G - final RenderType renderLayer = supplier.get();
. I L& T* V+ q) p7 P+ } - cache.put(identifier, renderLayer);
9 F% u" {0 u5 _! u' G5 g - return renderLayer;1 M( X0 C6 b3 X) ]- J
- }) [# W E, M3 }) r; H) j
- }
! U% {( y4 N3 i9 [. p - }
复制代码 |
|