|
|
, Q& Q' j6 S* l f6 e1 x* X, f: a
行,这个怎么样
$ p; A' e9 @2 B+ l0 A. x- package com.xhg78999.mtrfac.render;2 `- r) q/ ]4 N& {5 W
/ x- L; t5 R! d/ u: N" D- import com.mojang.blaze3d.vertex.PoseStack;
K4 {# r! h4 n% L - import com.mojang.blaze3d.vertex.VertexConsumer;1 ?0 G5 h0 P6 ]# i; h
- import net.minecraft.client.renderer.RenderType;" J$ m7 C; t3 s; {4 ^% {
- import net.minecraft.resources.ResourceLocation;& N( B7 B5 c" v! W( p
- $ `$ Z& _+ h6 L# t
- import java.util.*;$ \! q n3 ]7 V; `
. b% V6 E* t+ b$ k8 y* }- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ u, h6 D9 O% y - - x9 Q7 q4 T' M+ }
- public class LineRender{
1 M* M! T' Y/ U1 W) u4 D8 [3 D( d8 ^ - private final PoseStack pose;
% z8 X9 ?0 N/ D6 P0 V - private final MultiBufferSource source; ?7 w/ Z2 i# h- x. ]9 |7 g
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();" ?0 d7 i! b5 D
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();$ u; H- ?% b4 R; w
- 9 \% @3 }+ S2 l# W- B$ w2 A
- - Y' k/ z j3 r
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){, `2 e2 l7 s6 }* o1 u
- if(x1 == x2 && y1 == y2 && z1 == z2){0 W% w n* M; j
- return;
5 |0 w0 v! r& H! H4 S6 v0 M: L - }: s! Q2 w8 I+ V& i0 Q2 e
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; m+ M! h1 s! ]3 O3 s - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
# \: i6 ?; e% |) v; p& C# \ - }
( Q6 t/ o% z3 ^* ^ - pose.pushPose();
L6 d2 ?% L* u D X" F - final int newLight = convertLight(6);! y* u3 V( L6 n* E
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( J! E1 z; r2 V' c* p$ _2 |$ K
- final float lineHeightSmall = (y2 - y1);0 @/ \# r2 `- n+ ]3 J
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 r: L: M9 U/ e8 {
- pose.popPose();
3 \6 E8 \' w: X! d$ \7 B- i' n5 A - }
9 |# ]% [5 T S# c4 J& K* ^
6 M4 [8 ]9 ^/ o/ g- private RenderType getLayers(String texture, int light) {% g9 J# b& F' e. v
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 \* T! n# ]7 K8 |' F
- }
* T/ I1 B5 l& ]; E - , S6 `$ o, h3 a! ^, G
- private RenderType getLightTexture(ResourceLocation texture) {! K3 z- r; s+ c ~, Y( o
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);- M) h' R1 b$ I+ |7 L
- }
) [/ {: K: Z) q( _2 U- Z5 C/ p - ; j/ R/ l9 ^5 l
- private RenderType getTexture(ResourceLocation texture) {, f, b: _1 I! O! f& ^
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);. h( C; {7 W0 j. z S3 n8 n7 t7 t
- }
2 P$ M7 |1 W, r7 z9 o3 d2 G- r/ E - 3 l; N s$ M2 r3 F' C% T2 V" J
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {; S( I+ f1 n- J
- if (cache.containsKey(identifier)) {
' N/ L( \* l, c2 V9 [ - return cache.get(identifier);
$ f( H& b+ w2 \6 ?9 W% R* w$ R - } else {
4 Y& y1 j8 m7 `% @/ P - final RenderType renderLayer = supplier.get();
$ b: g, \% a3 p0 W - cache.put(identifier, renderLayer);+ L/ h9 U( h K" q) @$ w
- return renderLayer;, M7 q* h! e$ w Z ]& y: w
- }7 C: w3 o- o8 X2 ]/ ~8 T- F( J! R; F
- }
1 T( h7 P7 ]. T. ]/ S - }
复制代码 |
|