|
|
; G7 `& e1 `8 a4 \( g- Q行,这个怎么样
, C9 Q! J) x5 H% _# \- package com.xhg78999.mtrfac.render;$ M v4 h$ u( I$ D2 w I8 }
7 d6 E: S- Z7 ?5 x- import com.mojang.blaze3d.vertex.PoseStack;
0 a' K. ?# _& @& G. k& p B) U - import com.mojang.blaze3d.vertex.VertexConsumer;: M8 G( O+ C# A. `
- import net.minecraft.client.renderer.RenderType;
6 e' \3 N: Y' _$ u7 a - import net.minecraft.resources.ResourceLocation;/ e$ z( l @7 t0 T. T
: t+ ?% C: W1 H- import java.util.*;+ d" o% j2 X8 s; S' A1 T! M
- 0 ~7 {' D* d, {7 ]- ~ R& H
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
3 c" Y% m+ i; p5 Z - 8 n6 F9 w& h% y" z3 y% @! T \
- public class LineRender{( `! t! V4 s. H" z: }8 a
- private final PoseStack pose;
- a7 p2 o7 W7 Q) s1 S - private final MultiBufferSource source;! ~$ e2 p- Q$ ?4 _2 l2 V. b
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();/ l ]# U7 n7 b L
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# L, H$ K5 J$ H2 }; s0 d8 |
5 P6 z, Q6 v9 M! O* v' Z- : i) h, ^3 _$ O7 M8 _( t( e
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 J7 S) O3 S2 r# z - if(x1 == x2 && y1 == y2 && z1 == z2){
- y% }; L6 X/ I' A% \; H - return;3 p3 a6 n' i' q! h9 Z) w" O2 a
- }
+ v7 L# O* k! j0 v$ m) N) a - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
* m- m u2 C7 o9 B/ h - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");0 q6 Q1 ?8 w7 w4 ^
- }
d2 y" C7 J3 y* K, c' n# W: Q' } - pose.pushPose();3 p1 e9 Y1 K. c! k7 U* @+ }
- final int newLight = convertLight(6);4 _0 ?1 c z2 M# p
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));, n, j$ e( S" q+ f
- final float lineHeightSmall = (y2 - y1);
8 M5 M' o1 k8 _% X - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* j( U$ D5 d$ w9 Z) L - pose.popPose();
8 A5 h. M, w+ w$ v - }
6 Q: x* o3 Z7 G6 y8 F - 4 t7 o9 \7 K5 a8 E1 a
- private RenderType getLayers(String texture, int light) {& `+ u/ Z& s% W9 I' ?
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture)); X% U1 X7 D- E# L' ]* k5 |5 E* {
- }) C9 k1 Q! O, T* _; L5 C" A% G
- x$ s) \" k Q! y! f% S- private RenderType getLightTexture(ResourceLocation texture) {7 n2 z3 T1 g: _6 g
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 V- s5 d4 J3 C" q - }
5 ?8 P$ ]4 J& U ^- L' q - ' B$ ]& ~/ x% H3 I) f
- private RenderType getTexture(ResourceLocation texture) { ]* W- V& F3 B7 L5 T; L' Q
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);& {3 Y0 @3 F* P; `$ c
- }
: i s. Y1 `3 [4 G. K# e* V - 6 I8 l# x( u2 E. r, @% G- k9 P: d$ M4 u
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 V& m! M; A0 Z ? - if (cache.containsKey(identifier)) {
1 o/ X, \/ Z4 @$ S - return cache.get(identifier);
2 f+ I# D- j( V" {0 n - } else {* ~* r7 A b; H" K3 n- o4 _
- final RenderType renderLayer = supplier.get();
( o" U8 l# P0 e0 _$ `/ l - cache.put(identifier, renderLayer);5 ^, Y m) U, o
- return renderLayer;, J# g4 m0 r, ~
- }, @2 v, ?3 D/ O" r/ K4 z; r
- }+ W/ m$ i% d* q! F9 p6 r+ \
- }
复制代码 |
|