|
|
$ d7 h4 G7 H+ L# t+ D1 C* M行,这个怎么样, h: K& S! s/ m. A( ~9 J6 O
- package com.xhg78999.mtrfac.render;1 F9 p9 m7 k- Y# r
- : R, T1 y' m7 Z; @! a
- import com.mojang.blaze3d.vertex.PoseStack;9 l$ j. @5 B3 i. }
- import com.mojang.blaze3d.vertex.VertexConsumer;/ G; {+ p5 P, ^$ T) s! H
- import net.minecraft.client.renderer.RenderType;
! g: \" h; ^1 o$ L( S1 J6 C$ y4 u - import net.minecraft.resources.ResourceLocation;
9 ?" g: L, {: W% o* o/ r
2 E) K- G+ F# E5 T# u8 A- import java.util.*;
* `% J( x/ ~7 J! p% r - ) U4 U- q7 b0 b- r, ] \
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, R, V4 g* w0 {: B! `% G - . M6 q2 x, B# g8 A
- public class LineRender{1 i8 d) h5 {! {, |
- private final PoseStack pose;) m8 e( G3 p4 A% V0 O
- private final MultiBufferSource source;
" N) J1 `9 {- u* B1 N( r; I- |% ^ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 `% p5 ?1 R) d0 g8 n7 H2 p - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ Y. q2 g) r+ E# |
|4 B5 t. @8 s! P. ?) v" V; n b
( X! A' J; k2 j2 U- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- z) V0 N! k4 | - if(x1 == x2 && y1 == y2 && z1 == z2){& h0 B8 R8 j) a3 a4 m
- return;
6 W- ]6 S( \- d& z' U - }
2 t1 u3 D" A( B1 L% o - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
) P4 q, h$ p7 f - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" C& }, e; U0 M& `" ]
- }3 Q: l; I9 D% C+ n$ t$ T5 v7 n
- pose.pushPose();
D# {3 M" G$ k/ Y - final int newLight = convertLight(6);1 c! m/ B8 `8 b3 X
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 k) K' ?: i) X8 x. q - final float lineHeightSmall = (y2 - y1);
, a: U, b) A1 E5 G7 ?" U$ n - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight); p2 A8 s2 C) e/ s0 J2 |
- pose.popPose();& i! `# @ ^! h6 w3 V
- }
) }6 l/ L1 d3 E0 Q - ! E/ q% G7 z6 z9 q5 M4 E* {
- private RenderType getLayers(String texture, int light) {
~! e7 x( H9 O: M8 [ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! [ r1 B0 k5 O& `" f
- }
. x" [' [ `6 G5 r- R - 1 m9 G. T% o" x8 K
- private RenderType getLightTexture(ResourceLocation texture) {) I/ [; |* J( T0 ?4 @, v! D
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" y' K0 Z# ]1 c; N. p2 D
- }
+ A$ C- T7 V8 \+ S$ q, K
7 L6 w" t' p# B- private RenderType getTexture(ResourceLocation texture) {
' K8 N( k( x) X) p4 A# `1 h - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ w* v% P& Y6 ]4 s - }
( _: @: Y! z+ I8 m
( }% m7 K% K; J. c- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 r) _1 c8 e* C; V/ F+ v. { - if (cache.containsKey(identifier)) {6 S: J! Q; F" @. j- w: J
- return cache.get(identifier);% m, s' g- A& e
- } else {
* M5 T2 e+ c6 ^8 d/ K" o2 U5 q - final RenderType renderLayer = supplier.get();+ {( Q: m+ t4 J, ?
- cache.put(identifier, renderLayer);
' g c( E. l* s8 e: ` - return renderLayer;
) Y/ f% \; r; m - }$ K) }% V' h/ @
- }
7 {# M2 t0 J6 I a3 `$ e0 c6 C - }
复制代码 |
|