|
|
% d$ Z0 P8 A* G% d% x* ]* E, g+ S行,这个怎么样
# B4 T: {5 Z( U5 G. ?3 P! L c2 Z- package com.xhg78999.mtrfac.render;
% U8 a5 F( g; i. x: h7 u# Q3 Z
- i3 Y1 b K% T+ l- import com.mojang.blaze3d.vertex.PoseStack;
, R: {% F' ]' f% r& t4 J - import com.mojang.blaze3d.vertex.VertexConsumer;
V6 \4 m* ]2 `9 j0 b3 d - import net.minecraft.client.renderer.RenderType;5 p$ |+ d; y/ r) y1 ]
- import net.minecraft.resources.ResourceLocation;
* k% V* T; b$ i9 ] - 3 A6 s" V6 X' D1 `) q
- import java.util.*;
1 V2 c; H. v# N+ ~5 \5 Q0 y C! i
5 c- ?3 }/ u3 Z- ?2 Q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
+ | q# u- \) k1 q: y4 J - . s8 l, U$ l1 B# d
- public class LineRender{
" ]7 I* o' Z+ O' B$ [ L - private final PoseStack pose;
1 E6 ?% X4 E9 M! S) l - private final MultiBufferSource source;
t" l8 g- k2 m9 }6 M - private static final Map<String, RenderType> CACHE_A = new HashMap<>();. f m' W* e! R9 m6 l; D. e
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 G) o) k Y! x: a5 S - ; A5 J5 ]% ?" m7 _
- , Y3 ]+ b5 ]3 @- P; v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){7 \ n$ J5 x, T; X! z: ^
- if(x1 == x2 && y1 == y2 && z1 == z2){# N2 o3 \- D, J5 E8 l* Q
- return;- l8 A( C- ]9 }
- }
" e, P% {& q. g% J, N - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" C% V/ @5 t( j m3 \
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: J* \1 H/ v0 X. B4 h - }9 f- [3 p3 g9 X# T7 c4 }) @) \, ?
- pose.pushPose();
" L2 u2 k4 _: f* N% Y5 }4 E+ V+ W - final int newLight = convertLight(6);7 [- B/ L2 d5 s8 c9 w3 T- [! k
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));: o& W w, a. T. L1 Q- F* Q
- final float lineHeightSmall = (y2 - y1);% I z5 u# i9 H& h4 z
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
0 L0 p9 n) d: K" w* L. e; e6 x - pose.popPose(); T0 X* \4 T1 \0 i: F
- }; p# V7 a, K l8 y+ `! T
- 9 c8 U7 M! o1 z6 C' i& |
- private RenderType getLayers(String texture, int light) {
& F" \/ T% ]- w - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));4 B6 c- t7 i) G( M
- }
/ f9 h+ p5 v7 @8 |
, D" e/ f& E k- private RenderType getLightTexture(ResourceLocation texture) {
, a8 Q7 r, b* e, E" ?+ e' M/ b- I: o - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);; E" z4 l& l2 ]5 R! Q1 S
- }
G, {8 k$ z, f5 H( f" V" I- e! B - # V! E7 I. A, W X
- private RenderType getTexture(ResourceLocation texture) {( E) q- t, [0 j, w* ` ]: D- c
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
, W a) J, r7 r" d' [6 D) r - }
5 d; }6 g# I) C# T7 I- a
* u9 @/ j/ R6 D; d2 O- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
7 _+ g5 L- v8 u4 \$ Z5 Y - if (cache.containsKey(identifier)) {
I c, k. ~% x - return cache.get(identifier);% _( H: a4 B8 p$ J$ j$ V( O
- } else {
# |" a$ g, `( X" U+ l, \# ? - final RenderType renderLayer = supplier.get();! w* ]0 F; {/ R3 Z" b
- cache.put(identifier, renderLayer);
1 k& N: ~7 j9 k Q& x }- L - return renderLayer;
2 m: M' R- H* H - }
& v0 }4 @$ R3 H4 @, ^8 |: Z) A - }$ J1 k$ \3 b$ q! e* a
- }
复制代码 |
|