|
|
+ Z* y- M7 M3 Q* m
行,这个怎么样
1 k# E5 w- N3 p5 j# Z- package com.xhg78999.mtrfac.render;
I; a' z& T# O2 C' a5 P1 V2 z7 M
1 W/ e" ^2 {6 T0 ]) P: z! r- import com.mojang.blaze3d.vertex.PoseStack;
! X3 R% I+ |, ?# X6 C - import com.mojang.blaze3d.vertex.VertexConsumer;" Z3 y$ g2 c: U: z* Z7 A1 T
- import net.minecraft.client.renderer.RenderType;
4 J! X9 A$ t2 _8 Y6 h* s - import net.minecraft.resources.ResourceLocation;1 ]- x" N. J1 d
; ^% q- C2 G( ]- import java.util.*;9 J- u' \, P" V+ L8 u
- 8 }6 W: a' u6 K9 Q& o
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(- }" o- i, X* T* W* z" ]: R
# O! ]+ O& v, E6 \1 E- public class LineRender{
6 \8 ?1 E- M' j2 t - private final PoseStack pose;
3 z/ |$ z& l0 b* m - private final MultiBufferSource source;
: D+ C# ~% v u1 H7 p6 t - private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 D- O' G! `/ j! e3 u' t) r
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( I2 W3 C6 m+ Q+ c) r+ u% ]! d1 a+ S
- 1 b h% g/ Q+ U/ Z
- * r i9 s+ B, E
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ ?3 t2 Y _( L, U
- if(x1 == x2 && y1 == y2 && z1 == z2){3 A/ v4 b0 Q" Z% l7 c! M
- return;
1 E& \- h$ V! Z. w - }& `; ]) d. \- ^7 ]: `4 O
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" p0 y0 `- ~; g - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
3 R3 P" O+ d K& B - }
* z) g/ t2 {+ |1 v2 Y$ F - pose.pushPose();% K3 y3 x! M5 q" v% g
- final int newLight = convertLight(6); U" H: ^8 S$ M2 d! p4 A
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
7 H/ }1 \% }( e - final float lineHeightSmall = (y2 - y1);
: [+ r# o) O" D+ y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);' a# H; u2 V* M( `* S0 S8 e3 M/ U
- pose.popPose();
. n' j7 t, t) H. Z9 Y - }
0 R4 O9 P' Y) T* Y8 ] - , T7 f/ v5 W& h4 T6 ]- f& m# S
- private RenderType getLayers(String texture, int light) {3 P$ S/ l$ x; H5 J. z
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 o8 n6 I, s" x- B) x
- }# k& X( [6 U) n8 N. q }
( c; }, c% g: ]5 a) |6 u5 W9 i- private RenderType getLightTexture(ResourceLocation texture) {1 I% J O6 Y8 a# O. C
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
0 `& b4 ^: m3 x. Q, U! c d/ ~" u1 d - }
2 L- t& Y( z6 J, m. k9 R
5 A( A- P; i d& y# v- private RenderType getTexture(ResourceLocation texture) {
1 v4 i: ~5 @7 z7 [ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! P/ A- k1 C* t8 [5 G - }
# {& h- [. e/ r: O k( d
% O) ?0 Y/ e: K8 i4 Y- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {* W0 J( p! c! w" S$ j
- if (cache.containsKey(identifier)) {3 h5 |3 u4 x5 Y4 t- ?3 ?
- return cache.get(identifier);
+ j# P F v, G% z" r - } else {6 t' P& _- f6 _1 n8 t
- final RenderType renderLayer = supplier.get();
* A, G6 R p1 q: u - cache.put(identifier, renderLayer);
, Y D& [# r; O. z0 m' Y& O - return renderLayer;
* Q# p" r1 V, j1 X$ A - }
8 o2 F$ b) @' u& ]6 P - }( q/ _2 A! o! ?! l7 B
- }
复制代码 |
|