|
|
- j. w( Q( L3 A+ b行,这个怎么样
3 r% n! T7 j# G- [/ O( P8 g& @- package com.xhg78999.mtrfac.render;
2 C, T! H/ U( M& e- n; s
/ B8 A0 z3 @) l/ s7 l, [# f- import com.mojang.blaze3d.vertex.PoseStack;
5 o1 [' A* W! E6 F4 D. C9 ~# h - import com.mojang.blaze3d.vertex.VertexConsumer;% O n O( c4 V* D
- import net.minecraft.client.renderer.RenderType;
' w9 D3 P s# B3 y - import net.minecraft.resources.ResourceLocation;. b$ W2 Y5 U4 X, t9 M. R0 b# \
- 7 p* A: O( W9 d8 ^' ^
- import java.util.*;
0 z+ F# n" K) w0 M8 P* c; }
2 O1 l% [8 Q6 z9 f% l( u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, P6 ^. p; f" \/ U+ h9 C
- ! ^& T6 Z- Z0 t
- public class LineRender{. V' s1 G7 C/ s+ D9 b* }
- private final PoseStack pose;
0 l8 _8 L* Y6 R' j8 ~7 n4 A6 d - private final MultiBufferSource source;
9 p! H4 x: _- B - private static final Map<String, RenderType> CACHE_A = new HashMap<>();, z3 I1 V2 ~7 k l4 T) C; Z
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% I* x9 j) r3 I( B! t
1 g5 D/ V& g3 \$ Y- $ F& [" o" R9 p3 S8 U! W
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( w. q o L; Z4 A& }4 h1 G
- if(x1 == x2 && y1 == y2 && z1 == z2){& f- |' a% F, y# k9 d
- return;8 X1 b. y/ G4 Z5 h7 U! W
- }) ]. K$ o1 U- Y6 J9 Y
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 b+ R- O+ B* i* A0 u
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. ]# f4 u) L2 q- e" j
- }
. F2 f/ l: N9 U7 b - pose.pushPose();: n% {* ?* b7 v5 i: c* ^
- final int newLight = convertLight(6);; I! [) ^: a% j+ ]
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
. Y% s& h9 q4 B/ c* y$ l - final float lineHeightSmall = (y2 - y1);
; L+ z; E/ V! R O# b; [( y1 H- N5 t - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" ]- `6 q- _! w# ~1 P- ` - pose.popPose();# N# h" @* o" @' S
- }
6 h* J$ K7 U5 Z- N6 q" h( J
: ?! g) j' m$ a1 u' M- private RenderType getLayers(String texture, int light) {2 p4 N) `2 S. r+ q' D0 m# x4 t
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
* ?$ V3 A5 f; z, B - }/ p' v1 T; _- W- m, C5 K. M4 ~
_, H% I0 Z' a- private RenderType getLightTexture(ResourceLocation texture) {1 g" j! D1 K$ W
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ [, }1 j* n" { W( w8 a - }
. R9 b( v/ h+ p4 G0 e1 v; d - * v% O( B" |6 }; _9 [
- private RenderType getTexture(ResourceLocation texture) {
% F' y* W% a, {& Y: I7 Q/ i0 y - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" y/ O' X: e$ ~1 u" c2 S6 A - }0 W5 ^, a* A% Y1 W) t6 {+ b. j' I
. b8 R9 u; p0 _- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: Y% q7 N, N! m! q) Q4 L
- if (cache.containsKey(identifier)) {5 Q7 z( D. L) a3 H$ q4 ?6 Z8 D
- return cache.get(identifier);, f4 F0 K- a: O( ]
- } else {6 w; a" H. X& A7 ?! B
- final RenderType renderLayer = supplier.get();
9 B! [1 V8 \! `+ y2 i6 A2 p8 l - cache.put(identifier, renderLayer);# z- O- O. K0 X/ ]2 B# w
- return renderLayer;3 s+ D4 E5 y- F2 N4 J
- }
7 F* |' c. f9 s4 c; B8 @ - }( o/ ~% @- E$ u8 a D* w% l4 H
- }
复制代码 |
|