|
|
2 P' I' a4 v" ?行,这个怎么样$ u$ q- r, E! a
- package com.xhg78999.mtrfac.render;' w/ p3 e% V. i0 G
% g3 u/ ^' \ P* I* b- import com.mojang.blaze3d.vertex.PoseStack;" t; Z; y, g8 A% q
- import com.mojang.blaze3d.vertex.VertexConsumer;1 K% Q8 ?, V0 A2 D! Q
- import net.minecraft.client.renderer.RenderType;+ N. Q* ]; h5 v" |; h& M# T
- import net.minecraft.resources.ResourceLocation;& Q; V8 `) N0 t; P
- % k7 w: e0 h" W e& U
- import java.util.*;9 C/ P: W4 k& O6 @5 [1 R% k5 E5 Q1 g
- % H" F7 d: A2 g- q" Q3 F
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 T" `! l/ P# r - " K* o2 h r6 S E; X; A2 a$ `
- public class LineRender{4 D- Q2 G6 m3 F R1 F) Q
- private final PoseStack pose;; s$ b6 g; }2 L4 M8 ]0 v
- private final MultiBufferSource source;! A. ?! j" h. T2 n. W9 y8 h
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();, W/ l7 n M) M0 ^$ [
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
9 r9 d, B/ x5 G& B
5 @ T0 e1 n7 [! S- / R5 A9 r* M% u: _
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ J* V: V$ \0 u) w- J3 T7 f& T - if(x1 == x2 && y1 == y2 && z1 == z2){( [6 p2 `: V' b& `
- return;; b, Q* G7 {6 W8 z6 J
- }9 {. a. T/ `$ E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 q- G4 f9 v R$ S4 ^8 l% L" Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: q8 v6 a) b d+ |# B - }
' s7 s7 ?6 m4 T# W6 Q5 W- M5 G - pose.pushPose();
: k# t" Q7 C; _: B& U" [ - final int newLight = convertLight(6);; g/ d7 l9 j" E9 e
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ d1 }" Y. U! k6 E, V& g9 }+ j
- final float lineHeightSmall = (y2 - y1);9 {8 S% S( D8 v2 B6 l. V
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
' s4 G i9 E) T2 I$ t+ b! s - pose.popPose();" l w* J* u( }0 y! {- R- O
- }
/ ~0 n) F, A3 F6 v* Q! f
! S! {. N. W$ s i/ ?+ C' m; h- private RenderType getLayers(String texture, int light) {/ u- [" d8 N) A; L5 u6 x# e* s6 s8 b
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));3 n6 S- n' t7 n0 y; O0 w4 O9 y* v
- }
- g @* x, N, p) U - / U# q: P% B3 w# b* S4 j. c; A+ M
- private RenderType getLightTexture(ResourceLocation texture) {; h8 k2 G- a. [- x
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);# f Q2 X: Y2 V4 x- r3 F: [
- }' }. U& Y: C- L4 e) ]3 k
- & i' N6 s1 V/ {5 h1 a4 o
- private RenderType getTexture(ResourceLocation texture) {% e/ _# u3 G6 a+ X# f
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);, @& {* O* f4 j5 z% K7 u
- }# M+ E, Q ^, ^8 N* Y y
4 C$ Y2 T7 W: a9 G- a k5 y3 A" |# P- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% i* |8 N/ W- s5 W, g
- if (cache.containsKey(identifier)) {
1 Q% F' I* j! u5 F4 I9 p - return cache.get(identifier);
5 {1 M9 C$ }- H2 K- N/ ^/ C - } else {
$ H, I. c: S: b% l* a4 `- S6 B0 | - final RenderType renderLayer = supplier.get();
' E, K8 x7 `, a - cache.put(identifier, renderLayer);
- k# T U7 l( k* y( L - return renderLayer;% z3 R4 t# l& Q: A$ E
- }
' X* Y% s: t! r: @ - }& T* p. |+ z( V+ J) @+ M( {2 v
- }
复制代码 |
|