|
|
& g. `* ^" z$ F; a, n" X" x行,这个怎么样
' |) V. K7 ~# f: J/ @5 d- G- package com.xhg78999.mtrfac.render;
5 I3 J8 g8 Z; F1 L1 |( `: ?- ] - ) W! U* \4 z3 e) u# I. L
- import com.mojang.blaze3d.vertex.PoseStack;
. A; [8 i; P( M. B6 ?* T* W$ k - import com.mojang.blaze3d.vertex.VertexConsumer;7 k4 l w& x# H& h7 j, p
- import net.minecraft.client.renderer.RenderType;) f& `% `% N" v# Q. @
- import net.minecraft.resources.ResourceLocation;
' A) E; b) K7 a* z
: C: i& V, t- s) d; m2 c/ `% K. P- import java.util.*;
' H6 B+ ]. N& W: G7 z4 k* T - * U+ N" @; ~8 N% K
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
: D+ R! L3 L' p8 p& G% q
2 e2 L" F$ B- w0 t/ ?8 C6 S) _" p- public class LineRender{
; \" [$ w K. |& C$ w* F, E - private final PoseStack pose;3 o" R1 E4 }. t# d- K4 \: A
- private final MultiBufferSource source;+ Y# A) |6 K# v9 c0 }: J
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' P- j6 `! \) q - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# ]; ]3 o6 o/ q* ] {: f
$ J5 q( l @* ^5 b- ' z G- m6 J1 b, J$ }! c
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
9 l0 q0 C+ {' i W5 @2 u - if(x1 == x2 && y1 == y2 && z1 == z2){
$ @( L. s; O+ z* U5 l6 [, ` - return;
" A; {2 X4 A$ Z) K: g/ R - }
) B2 k2 p& K& [ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. q) A0 I1 _* ] - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
2 R D: r k0 E y" x7 e4 z - }
0 J; E' t$ H7 ?. a - pose.pushPose();
" b. q. L. n' b8 c0 @* X& { - final int newLight = convertLight(6);
8 N; g& l' P5 r6 t* i" n - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ [0 f( z$ G# @5 y7 F( S. j* h
- final float lineHeightSmall = (y2 - y1);: A5 n& s. E- i* U
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
9 p$ ^3 `* n7 d: A, _- N$ k0 F" x5 D - pose.popPose();1 s7 ?1 j* n1 v. q) m/ Z$ |" d/ J, A
- }8 A+ _, z4 K- r( f! v+ R
- 9 R3 v5 v6 `. U" K; O. b3 R
- private RenderType getLayers(String texture, int light) {$ ~. i6 x) g1 a. k* G/ ?" a
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
x) h$ g" z( | - }
5 u$ l* z( u( u5 T* ?# D - / y: T. }2 z, F! b9 \4 y3 o: ^
- private RenderType getLightTexture(ResourceLocation texture) {+ e# G, _+ O+ Z6 S- j
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);* p4 |- p+ ^/ `4 K' M
- }2 f* g. z' q4 [$ v+ c
- 2 I( p5 N+ n. g0 m9 h" s* w2 ]& t
- private RenderType getTexture(ResourceLocation texture) {
# x4 }8 i# J2 C% d' C; }$ e - return this.cache(texture, () -> entityCutout(texture), CACHE_B);% X" e* Y, j7 C$ H6 E6 R
- }
: ?0 u% a1 {8 \
8 _9 M: b/ w1 c- `) ?3 H8 K- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {0 m- B2 g# N( c2 v) \' m% \) a
- if (cache.containsKey(identifier)) {/ k1 x# Q1 D! h
- return cache.get(identifier);# O5 }, r- i3 M( _
- } else {
1 o! G3 Y2 N( `2 H! L* p - final RenderType renderLayer = supplier.get();
. H7 s9 ? G+ c& Y' Z - cache.put(identifier, renderLayer);# r* f) l! H9 c6 D1 ~" M4 }
- return renderLayer;2 e7 \. W5 o$ C$ Q8 L8 I
- }
# v. A3 c# _) o* v& B - } G4 z; ` ~' C/ O% c( h
- }
复制代码 |
|