|
|
! d! `9 g k6 y8 M O3 N行,这个怎么样2 g7 r0 h$ G/ t6 I& h# V' W( q
- package com.xhg78999.mtrfac.render;
' Z+ @6 h8 w9 u9 I' S
& L/ A) t: b! F! @4 {- import com.mojang.blaze3d.vertex.PoseStack;
- _) H1 H1 [" E; d* ^/ m4 x/ r - import com.mojang.blaze3d.vertex.VertexConsumer;
]7 p8 h: f- q+ o; f' g& a( Q - import net.minecraft.client.renderer.RenderType;
2 c" y: N+ C0 N3 `4 B" \ - import net.minecraft.resources.ResourceLocation;; c' V+ \) ]/ i- Q! }7 M& M
) \) @; D0 E4 B8 F! t- import java.util.*;
7 n& S- C! @2 y5 A
" R8 I$ r6 P0 m1 B* y! g- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# Y" |: _2 |, ]0 D" L5 o6 t, D - / l+ F9 ]( d5 _3 U$ |# V
- public class LineRender{
h/ U/ h6 H: S. H - private final PoseStack pose;
5 u" B f/ ^. X8 e0 l - private final MultiBufferSource source;5 ~1 K7 n1 i% P2 i# Z% Z0 f; s3 X, t
- private static final Map<String, RenderType> CACHE_A = new HashMap<>(); v0 ^0 s4 H6 x1 u! G! e/ I
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();* Q1 _, ]6 c/ }7 V) I+ F
- ) w% [2 I2 e6 N8 e! Q
1 q( o- [' C( k- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
2 `3 W# q# g& Q4 A, n; \/ ]* N - if(x1 == x2 && y1 == y2 && z1 == z2){2 H d( D, j0 l. l: x
- return;
/ L4 u% j! B' w% i; y( j6 I" A - }
& ]7 e- G4 g! `( \ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
u1 Z1 M& f& B* s! o - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ m' n# A1 r2 S# R" @& f8 N
- }$ L5 F( L2 X% ]$ P6 Z
- pose.pushPose();
e; }! f5 R" V) I3 F - final int newLight = convertLight(6);# M# m% S$ M# F$ ^
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; W7 O) i# q* y/ m. P; n - final float lineHeightSmall = (y2 - y1);
( H' S/ g* O, l. \& q& a - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- L' y' y5 z) K1 X# [4 S9 D6 ~
- pose.popPose();5 d' m4 t- Z5 z
- }2 l K5 i5 E( S. f
- 0 }4 B* X# c0 ^- p$ L/ i
- private RenderType getLayers(String texture, int light) {% J6 y7 t3 y K+ S/ Y% I& D
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
: E* ?8 X1 @3 c$ e - }
1 F. `6 h0 v @8 w/ Z1 U, m
4 H- f) G" l" c0 {- private RenderType getLightTexture(ResourceLocation texture) {
3 J8 }* L4 ^7 Z- i( N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
$ B' X/ h% W8 z& W - }
* r, F4 N! I1 T/ p8 Z) s- R - $ ?4 c( p1 G; N! z1 P0 D$ h9 `
- private RenderType getTexture(ResourceLocation texture) {- r7 k0 S" @+ V& N! ~
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 r7 [" z* }+ R9 y) S - }! x' s) c( ` W4 Y
- 3 V! I- t1 j. l" S
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {, }7 J, G9 J+ l1 |" u1 n
- if (cache.containsKey(identifier)) {% X9 W8 i% _9 k( l; m( S, S
- return cache.get(identifier);
& i9 K' k5 g% J$ w9 ^- X - } else {& n. _6 l* g- k( T! w* I
- final RenderType renderLayer = supplier.get();+ f2 ^4 F2 Q& y- I
- cache.put(identifier, renderLayer);
. q; C/ Q3 u1 \1 c2 G% V - return renderLayer;6 O' @' Y0 m/ l* p
- }
& k8 A9 |- a6 S. L1 K8 @2 Y e' r i - }
8 x$ V8 U& m/ F0 V - }
复制代码 |
|