|
|
- t) T9 b: Q+ |& ~9 r, v行,这个怎么样
4 n4 `+ V- H5 ]9 C) Z) K3 w; m- package com.xhg78999.mtrfac.render;3 D3 w# V: O3 H1 H- t+ G
, Z ?& ?, q {8 y: Z& k0 B- import com.mojang.blaze3d.vertex.PoseStack;
1 v& L' g& z1 ]- C H' N - import com.mojang.blaze3d.vertex.VertexConsumer;5 m% C4 k' t% j- U
- import net.minecraft.client.renderer.RenderType;) u2 D. q: E: {" O, C
- import net.minecraft.resources.ResourceLocation;( Q6 f4 r& E$ y' e7 i& U) x
- ; q# T3 C- T P1 r( e+ T
- import java.util.*;" A( y! J! _, @/ M8 U
- 1 _' T: W+ o4 K. Z3 E
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; L& ~! c7 H. d3 m( s1 Y: r
. d7 f# {7 f7 c2 Q- public class LineRender{/ G% ^8 A8 D ^
- private final PoseStack pose;
2 H# D8 U' a* E9 e+ } n! D$ p$ t - private final MultiBufferSource source;, F2 J! h5 U% p {' g
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 w6 H0 e: N, x* b2 Z/ F9 ^% n: |
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
( N5 v$ B% K; ]# c( [# R+ H
3 o9 C2 b* g& l3 ^+ x, d) {
5 g( W5 j P& t- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; f! o; p. b* v - if(x1 == x2 && y1 == y2 && z1 == z2){
4 T8 Y* f p+ t - return;* P; z! N& ]7 W7 G% Q3 a4 ?' @
- }
3 H% Z3 \" [8 \% L) @% d* D - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
z4 p2 |: O! D$ O% q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");' n4 u$ ]0 a" V$ w' R
- }( ^' Q+ D. E+ n: b k) u0 \: j
- pose.pushPose();
+ [' T) }; z3 ]3 K# U9 @ - final int newLight = convertLight(6);
+ k0 {3 H$ v+ G$ g; j7 ]6 | - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
/ h+ J0 \* U5 ?. J v/ ~ - final float lineHeightSmall = (y2 - y1);
8 g. }! p, Q5 ^1 @* z% Q( l - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& F) ?$ ]' W; }
- pose.popPose();& d% I9 E, K' Y
- }& v" u' j: \) c" S, @: k+ G
- N& b+ d2 |6 M- private RenderType getLayers(String texture, int light) {
8 [8 q) k; h+ w& k; q/ e4 ?% f - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. p+ g& q3 l2 n- N2 [ - }
; q7 s% G$ {1 D B! N% \. c' I0 O - 6 u0 W# S5 H* t9 f1 V
- private RenderType getLightTexture(ResourceLocation texture) {/ Q, O( l/ d8 h2 ]
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( V' s8 D0 r) k& `0 ] - }3 t! p/ R* C1 |, Z$ d
- 4 Z0 }; G. B& t. \
- private RenderType getTexture(ResourceLocation texture) {
( A, V; u; ~) ], Z - return this.cache(texture, () -> entityCutout(texture), CACHE_B);! ~. s/ X1 F' y9 `+ D- c) i9 y, c
- }
0 k1 t5 M1 g: H5 a( N, I( D; U - * K( B/ n, W1 ?
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, h# w& u5 H+ D; z' p+ Y - if (cache.containsKey(identifier)) {4 j D2 {5 v' X. E n
- return cache.get(identifier);7 F) E& r% `3 v
- } else {9 A5 q& y F; O
- final RenderType renderLayer = supplier.get();
7 R' |8 z8 L4 M7 M3 J - cache.put(identifier, renderLayer);1 x/ P: J1 \" x/ p2 h; }7 {& v: q
- return renderLayer;$ O, T4 N: l' y d4 g
- }" l( Q8 S" d7 O1 |, z( [# m
- }/ x3 F. v! L1 h' z* T+ R0 q
- }
复制代码 |
|