|
|
& e6 |$ P+ t& Q0 @2 x
行,这个怎么样
* U' z6 p) G, x: u- R6 Y- package com.xhg78999.mtrfac.render;
5 O/ x3 n: c6 x5 B+ G5 `" P5 `
+ B% ^$ d R# `( q: V- import com.mojang.blaze3d.vertex.PoseStack;% F. f2 s: _9 H- L2 d0 a
- import com.mojang.blaze3d.vertex.VertexConsumer;* }/ W/ n4 ~) l% l: P/ ?8 s9 B) ~
- import net.minecraft.client.renderer.RenderType;9 S: t* x4 S& z& x+ q) X
- import net.minecraft.resources.ResourceLocation; @0 C* e- w' r: z$ Q' }+ g
2 k8 ]8 T9 g% O/ |! ?7 O+ v- import java.util.*;" V! t; j1 s+ b
- p& u. I* j+ @5 a- J/ S! J
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
9 t6 G/ t7 u4 \9 U) }: ? - 6 v+ K C: \' W% P# Y1 J- r0 l8 {
- public class LineRender{
. ~# Z1 I( n& G6 V' W - private final PoseStack pose;
; T# M- _; P8 w# n - private final MultiBufferSource source;, Y+ H ^% t7 T# p
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();# S* a4 ]5 z1 [! {& z* y
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
6 J+ {- i9 l c/ M% L! B# h - - Z" N- n1 c$ r+ R
1 B: f4 R' o) I. X" }/ V- \- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 e8 n+ Z% ?) ~9 O# c. y - if(x1 == x2 && y1 == y2 && z1 == z2){
" ?( P- l* a) |1 x l8 ~ - return;
/ I, d3 V1 C3 j$ v0 n - }
2 C8 Z2 G- F. ~! c- d+ d - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' M) u# V* a/ ?$ L
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, d+ m `) \* O/ C+ B: J- W* `1 d
- }
a; t" |( U; D# ^ - pose.pushPose(); q* M# R+ v, J+ ~( Z
- final int newLight = convertLight(6);: t$ E! R/ R( \' `) d+ [; j6 u
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( J7 u; ~# V( I7 C# ?- n9 e
- final float lineHeightSmall = (y2 - y1);; {' Q! M: a/ ~" ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);# \. l& I2 @3 C1 \; ?2 r
- pose.popPose();
8 A. j/ N( ~9 ]! w$ v" h' v+ A% Y - }2 R# m* j& _+ G6 w3 r- N- N" z( b
- ! ~+ a7 W8 h# ]4 Y: ]2 {
- private RenderType getLayers(String texture, int light) {$ p# ^( ]3 M- [8 l0 z2 u
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));" b% O3 o- _& A* v& X. ^
- }
! d; }% ~6 m5 n1 u1 @
# t1 b" S6 Z3 v! I- a6 P/ z- private RenderType getLightTexture(ResourceLocation texture) {
; f" R4 c/ e5 u3 P - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 M4 J1 C% G. n' R0 ]( c4 l( D - }
* D! r( j$ C) Q( Z1 n( T - 8 ~' ~, H8 Y) K, U
- private RenderType getTexture(ResourceLocation texture) {
! B, o1 F; ~8 B+ R - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
; G$ Q4 g* |# l - }" |1 B" z9 T0 z& X& |% y
' v) }( {$ s% V! L0 W3 y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 D b R. I. M# | - if (cache.containsKey(identifier)) {
" P: k6 U% W" b6 l - return cache.get(identifier);
- }4 B6 S+ {6 k) g0 C @/ z- P - } else {6 T& }9 V, M( r H" a: a
- final RenderType renderLayer = supplier.get();
& O+ Y( _0 P: c, ~1 ]: u - cache.put(identifier, renderLayer);
$ U! H' g4 x% k, F6 @! F! j6 P3 S - return renderLayer;
, P( x" G! J7 ~, U! o9 I) _ - }
V% a4 ~7 S& g: a( m' g - }
3 V5 U0 i" Q' w' Z+ y& j - }
复制代码 |
|