|
|
- O7 k9 j% S5 q: \
行,这个怎么样3 J3 ^/ a4 J( L0 t a7 R9 m; k
- package com.xhg78999.mtrfac.render;8 X9 h/ `9 j$ J; `1 w1 o2 J8 |
% e6 L" @- F" u- ]+ Y5 x' H! s- n- import com.mojang.blaze3d.vertex.PoseStack;
0 _ |& K- c1 E% J- z - import com.mojang.blaze3d.vertex.VertexConsumer;. ], V9 N0 n9 W- K' G8 A5 Y/ M& |) j
- import net.minecraft.client.renderer.RenderType;- n5 a: {' Z0 H# y, ]8 F7 [
- import net.minecraft.resources.ResourceLocation;
* K& O# M1 m: k; I
* A" b' ~, a. `$ T- `7 @* I- import java.util.*;& o4 M. b* O! v3 @( I; \
- ( k1 m5 k# J5 B2 N; t* I4 h5 i( W
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(4 q/ ^' U) E5 ]& Z
! z( d8 @; L& T4 G n7 }, x; ]! o- public class LineRender{
# T6 ^; S" [' c# k; s - private final PoseStack pose;
( F- J/ G" q- y$ Z2 f* k - private final MultiBufferSource source;8 e4 _/ |+ \! J7 R
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 M& g* m b0 q' O) y
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ t4 T6 x( N) h9 U9 [
# T+ d: [ y- y
% Z; W2 o. L7 z) K8 ?% u- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 X+ G, S; E9 s; I - if(x1 == x2 && y1 == y2 && z1 == z2){( X/ C2 D' I% {6 z) B2 E; E7 Q. _
- return;9 H9 N) G1 H; D6 L1 E
- }+ r1 ]$ g' s% N
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){( ^4 N' f8 m1 |( Q+ T& j% h5 K
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");6 E5 _, ^4 r3 U! L
- }9 g! P* l% C0 n9 _: w& j5 Y& n+ z3 \
- pose.pushPose();
: R& m. M: ]* _ - final int newLight = convertLight(6);
" ~" R) d" t, T$ m! G7 `% L - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
5 `9 v; N6 w D" h# ?1 o# m - final float lineHeightSmall = (y2 - y1);
: n# W( `; o. V - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);+ ~% h1 J- I* P2 R7 b! @
- pose.popPose();
% U2 S' |2 k: t* F$ I2 N - }& x c" x- j7 L q4 {1 y" b% E
- 4 m, t9 \! g2 e, ]: e* n
- private RenderType getLayers(String texture, int light) {
; N6 ^& T/ o' ?# ~ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));0 u4 h. d$ i+ q5 R5 ? z
- }
# r/ ^- |" v3 }$ ^0 N3 S7 A2 U) q
3 A+ t0 y# r5 q7 N- private RenderType getLightTexture(ResourceLocation texture) {
% x) `; f7 n- Y1 r4 C" f6 J - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);* j5 Q# _7 L: W8 i% J( }
- }. G9 [6 D$ U/ d! u2 a
- - L" P3 D4 T& m/ [$ \; y `* j/ q# h
- private RenderType getTexture(ResourceLocation texture) {
! J6 Q' ?# {: Y8 [7 F8 Z8 {! V6 O - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; ]/ b5 x I* ^- R3 n( e - }
) e8 ^% v: A8 I - % b4 ]4 L5 V% B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* _" L& a# I, u" V5 Q. [2 e& Y - if (cache.containsKey(identifier)) {$ ~4 F; F( B4 J" F
- return cache.get(identifier);
0 p* f+ S* W' c/ ]+ [$ V1 [9 I( i; \ - } else {
) [, n: K" `4 j v - final RenderType renderLayer = supplier.get();
9 |7 ^ u) K' A1 e1 L7 n5 S - cache.put(identifier, renderLayer);
! X' @( P) X+ O6 d$ b/ T - return renderLayer;
# `. Q9 \; C2 H" P: ~# ]# b @6 J3 g - }0 t0 o- @+ H* m. {- v) _
- }9 H4 R5 e. i( u; V
- }
复制代码 |
|