|
|
; Q/ T: E/ y7 O6 c. r; C; `行,这个怎么样, _3 T. a) D% R( c, [" |
- package com.xhg78999.mtrfac.render;! c5 w8 M3 o# `" n9 Y6 ^
- - f) ]+ [ ~/ V9 O& s0 ^$ X8 v: E
- import com.mojang.blaze3d.vertex.PoseStack;9 `# V% H# Q; c4 N# c9 {
- import com.mojang.blaze3d.vertex.VertexConsumer;
3 r4 a/ m# {0 ^ - import net.minecraft.client.renderer.RenderType;, D' t q, S" b0 O* C+ M
- import net.minecraft.resources.ResourceLocation;8 U' F$ F7 K; |0 m
- # b \& |, X! S1 _0 x8 E
- import java.util.*;, W2 ~! h6 [* ? \% P; W
3 l; x. ]9 ?. g- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
0 m& \8 Q6 Z0 G6 [
' q- L# P/ \& W! T2 |9 _# p( F- public class LineRender{
5 [) x0 F6 E; J: c# H D. [ - private final PoseStack pose;
: S! s$ r# a7 B+ B1 U5 z( a - private final MultiBufferSource source;
" V6 p) E: v$ c( j- J* e8 x7 U - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) E2 q: R* W+ J. M0 D) _! M/ n4 b - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# J: Z5 z8 h' Y* _
- / l$ B5 v2 |# @& d/ Y+ C: z
- : c x+ n4 D7 s, p; V. x6 L
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, O4 T7 J) v \6 T3 X1 d - if(x1 == x2 && y1 == y2 && z1 == z2){( a: h9 \0 Y7 `
- return;: j2 [6 v1 ?2 F" E
- }
% u& M. w* D% D9 a( F - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
6 h/ J1 o. W8 ^" L - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 ?1 F: r5 Z0 R8 N! f. ^0 j
- }% e f, M3 W: m, f
- pose.pushPose();
7 y2 n/ h6 F! {* H ]3 a) g - final int newLight = convertLight(6);
* e7 w4 X) ~- ?8 A. K& D8 D1 Q8 ^0 P - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));8 R' x( t: S, e9 S4 H% B. _
- final float lineHeightSmall = (y2 - y1);
1 ~, _/ s; m' p4 Z- N - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
, q4 P; W" z/ _+ O3 V( w - pose.popPose();
. M0 F, [0 H' M) u. G - }
; j0 w" p: e! u) b0 K O9 M
3 T0 B( t. x) k- private RenderType getLayers(String texture, int light) {
* y. x4 l9 |! l& ` - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; a0 U' ^0 d' ?, C2 ~( a
- }
- Q/ }7 g2 v* `2 F
" J) t D: E* m- private RenderType getLightTexture(ResourceLocation texture) {
. m8 u5 z: U" b; W' `7 H: |& b - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ A' t! R+ h/ `6 d: U# B - }
$ U; K9 E4 \( S- e' Q6 K: O0 I) z; T - 5 A9 ~6 H% O8 q3 t3 D2 \; J4 g7 k
- private RenderType getTexture(ResourceLocation texture) {# ?6 P- m7 ~4 `4 \
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 ~4 _# R w5 c1 a$ z2 r
- }
. |$ ?( p% U. R" M% [ - & W1 X* r- Q0 Y& H6 u3 d* V0 o3 r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 J7 v+ B8 y4 p8 {' J - if (cache.containsKey(identifier)) {0 x% w5 ]" o1 c7 a' S" B
- return cache.get(identifier);
, s- n' g0 e7 o j4 ]8 D* Y6 M - } else {
( z/ G1 @' ]; k T! f - final RenderType renderLayer = supplier.get();1 k0 a3 l$ b3 j X4 `; q5 q+ `
- cache.put(identifier, renderLayer);" j3 {3 u t$ Z1 j3 N
- return renderLayer;
2 [& m9 W$ y- ~! G- H7 l% e1 y - }
; ~6 {4 D# B8 b - }: D2 K* Q# B4 ~7 m) n* w; V
- }
复制代码 |
|