|
|
( _8 D. d% y; p, Y! v行,这个怎么样
$ U' N8 d+ V+ z- package com.xhg78999.mtrfac.render;/ R/ `) E$ L3 M& N
/ i1 I& K& ~9 K9 d4 u$ o- import com.mojang.blaze3d.vertex.PoseStack;) W- G5 N5 E0 {" }& e
- import com.mojang.blaze3d.vertex.VertexConsumer;" x1 z+ P9 G8 s+ ]" x+ \) \! K! k. ]
- import net.minecraft.client.renderer.RenderType;9 _5 l: f: I: q" |: L
- import net.minecraft.resources.ResourceLocation;
$ W: L. u8 O, {4 _ S
$ p$ R; D. o1 Y* L9 k- import java.util.*;. W, b( z* B1 Y/ z
- ( y! ]8 s5 }0 k7 m
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ Q( i, K+ S; n7 Z0 d6 o" P9 J$ L - ' r% q) Q' z& `' n8 H) ~* x- A+ m
- public class LineRender{" F9 U( \. i \
- private final PoseStack pose;+ L$ T5 j: n9 u" P$ R% \
- private final MultiBufferSource source;* n: w; K' v }. Y( S2 V
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();5 R$ n9 q* S# _
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ {$ |) E' `8 k& _) m
- 8 G9 H+ E( F, ?& P
- 1 q1 _% c! @, h/ C* Y5 O( g% h+ o0 x
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){9 H) j1 F% B1 i1 |+ u) l5 K
- if(x1 == x2 && y1 == y2 && z1 == z2){
3 n3 h8 o) l, Q - return;: a$ N5 v4 K4 u" b7 z. V
- }* a6 `" m- ?( b) t: `( r. g& l
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: |4 W! w& C T0 c& F0 A1 \6 s - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ [% m7 z/ o; S" ]1 p( ~- z
- }: c2 r1 s, t0 E# ?
- pose.pushPose();1 d. r. l1 B& v/ o3 s+ g# m+ s! T
- final int newLight = convertLight(6);
+ ^2 g- F) ]& T- Y$ ^ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));, P f y- K8 e" ^2 c$ u
- final float lineHeightSmall = (y2 - y1);" E. L5 d3 o( u( @
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 F8 y; Q/ H+ `7 ~( Z7 a
- pose.popPose();' {7 j5 s/ k8 T! i) e
- }
' z$ o, W4 X7 l. |+ V3 p* x
& P1 C2 X2 ^, L3 M8 N( O- private RenderType getLayers(String texture, int light) {
- @4 r4 k2 G7 C! `7 ~+ ~ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));* u2 O, p2 T g' e5 q3 @
- }
/ y# p9 A; J/ V7 S4 c. c - . m3 d" x" R7 Y0 r8 W/ G
- private RenderType getLightTexture(ResourceLocation texture) {
1 @( t" n6 D/ W7 a, W - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ j7 S5 @$ t7 d1 O+ c. N - }
3 J7 G5 ]4 L( z8 T% J. A
* S( x+ X; V9 T8 ^4 u) {) o- private RenderType getTexture(ResourceLocation texture) {
. L+ s+ I1 N) E1 K% l - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 G% O2 h0 _5 @3 w! v; o - }& v$ s# |: G& Y+ k. n
2 I' b5 {7 S% ~" [; {* \* Q& o- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {" b) j5 D7 @# R6 u2 Q
- if (cache.containsKey(identifier)) {
( R1 L, w& K6 U+ s, g4 a! W# f# | - return cache.get(identifier);
9 x U: e2 k/ Q2 p. E - } else {9 Z% l U5 o5 y6 e- P
- final RenderType renderLayer = supplier.get();- i$ h7 { {4 X4 a- _) J
- cache.put(identifier, renderLayer);& b3 Q0 S; K# r( L
- return renderLayer;" [' h( ^9 D: j6 _0 f, U
- }0 ^# [. c4 o- Q8 x U" @( \, D# G
- }0 h3 V! {! H9 ?2 ~
- }
复制代码 |
|