|
|
* y% i- s1 M, P7 z
行,这个怎么样
! V* J+ J: Q0 G: X7 j- l5 @% ?6 ?3 t- package com.xhg78999.mtrfac.render;
, V, x- V. K$ p( `9 b! q, }
8 T5 s0 u0 B& z. r$ |/ S0 A- import com.mojang.blaze3d.vertex.PoseStack;( m% a" ]; _: E7 ?( q* a
- import com.mojang.blaze3d.vertex.VertexConsumer; V& }8 U, r' \, Q o; n1 Z
- import net.minecraft.client.renderer.RenderType;6 v# a* o: J+ a0 p
- import net.minecraft.resources.ResourceLocation;2 x1 I5 ^! A- p# R
- % X% O0 K6 u7 C0 @5 m0 `/ I) a
- import java.util.*;1 w+ Z6 A3 S2 t5 T; v2 G& F
- , ?# X% e0 k# Y+ c( [( q
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; r, h/ G5 o' @; K7 Z
4 b- N7 V# S4 G' V- J! V/ y/ P- public class LineRender{. X4 K" X6 x- `' }* [8 r
- private final PoseStack pose;6 }5 G. i1 u9 ?% w7 n
- private final MultiBufferSource source;
( Q6 r0 e7 q. d/ A - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
2 D/ F. I" j" w - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( P: H8 _7 m, X9 t; L
- 1 X* G U4 b. c. ^2 [8 v8 w
' c( l8 _& a2 w4 i t- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ T/ A& x4 m) ^* ]# V+ d; w' ^
- if(x1 == x2 && y1 == y2 && z1 == z2){- o+ h' N1 h7 Y7 F
- return;
- m7 e+ I" H* G# `' k1 b" M, e - }
* X# v& w" j; Z% Y+ R8 i - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 k3 P! N: v, M5 W" M& V8 S0 G$ m! K
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, q# e9 W, w1 q0 e# m
- }9 Q. J- N( h5 P' v& O* Y; _
- pose.pushPose();
# L+ U3 J# S5 C0 \/ z - final int newLight = convertLight(6);
" w6 F6 K0 T/ O; P' X4 \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
! z5 V( ^3 x- n8 Z4 Q - final float lineHeightSmall = (y2 - y1);
6 A$ T" q- c0 ^$ q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 ?- `( m: r: G; h
- pose.popPose();
9 i7 ]1 q4 c0 @$ g - }2 l2 |, M- h: J3 i
- , E% v9 {9 k# P+ g# N
- private RenderType getLayers(String texture, int light) {0 K, a0 f% |. N% m/ N2 a
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
% M+ r0 Y! Q0 w4 h. x - }
/ ]( g9 d0 K0 _4 Y - 1 k; s) q' n9 d2 l7 J9 V) B
- private RenderType getLightTexture(ResourceLocation texture) {2 b$ }) s0 N) I5 v& i1 _1 }+ y# |
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: b( `2 ` t( E7 N* Q8 Q - }
% k9 u9 H2 s# z7 }7 S$ `
1 z/ I: F0 i5 J2 F: ]- private RenderType getTexture(ResourceLocation texture) {
7 R, O% V: u, b2 @# S$ X - return this.cache(texture, () -> entityCutout(texture), CACHE_B);& E% v& `/ v3 u+ F
- }
; T1 X8 _7 b0 A; c( H! w1 e* T7 `. `
) t8 e* l+ ?; ^, `0 a1 X- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {% g: J2 n _% o, T3 h. a
- if (cache.containsKey(identifier)) {
3 P9 E: i. B+ O/ v: i, g - return cache.get(identifier);
4 K# ?2 @3 {: E - } else {
$ G7 q# S0 `% c; J" ^; c, t - final RenderType renderLayer = supplier.get();
! e' c9 O* x! i% h) |0 X' q/ `5 o - cache.put(identifier, renderLayer);6 y( t/ ] h4 w1 d8 s9 |: `/ _* |
- return renderLayer;2 E/ f, V: H _( B( c7 V: Q* ^8 p E
- }+ _0 x" P2 h$ C' N
- }
$ }; l/ e% _ r3 L - }
复制代码 |
|