|
|
- b% h1 ^$ b" u; o; i
行,这个怎么样/ B# Z$ q7 F- |: L; ^2 s
- package com.xhg78999.mtrfac.render;3 E ~# S- |9 x- S( l
4 a B3 I. m5 Q7 D6 W/ q* q( ]( t- import com.mojang.blaze3d.vertex.PoseStack;
$ \: `0 M7 M) o- s( P! S - import com.mojang.blaze3d.vertex.VertexConsumer;
2 @5 m3 c- [4 z) K( P - import net.minecraft.client.renderer.RenderType;- M2 k, a! j j
- import net.minecraft.resources.ResourceLocation;5 @/ K3 [- M2 a' W) G) \
- : R3 g+ s" m% Z Q
- import java.util.*;
: [& k- @- r! o% S5 M1 H
~+ K6 u4 y# O- S" h) I8 B- A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 C" J1 [- a, b" P+ Q" N/ ?( w - $ {- X9 ~9 Q W) I- J% D
- public class LineRender{
( Y# Y9 t# C! v% Y - private final PoseStack pose; q( m. O0 Y8 [3 g2 W9 I& N
- private final MultiBufferSource source;
* s2 S5 |' S. g, O - private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 e# H0 ~- d5 R5 B
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% u, d" _2 @) p" g
- 7 k) k. ~$ s6 w# x4 U) j
" a) o6 ], Z+ Q% e. x5 l- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){ n- h* `# t! |; D2 r \
- if(x1 == x2 && y1 == y2 && z1 == z2){& D: K V k& c6 v% ~9 v
- return;3 M& [5 e& M5 j4 K
- }
, M- t0 |% Q4 S/ Q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){: U1 A _: z/ F
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. @4 x6 w# j7 g, ?/ y - }2 ]1 N( j& ^6 N( y' ~3 L3 k
- pose.pushPose();
; \+ \9 F2 u9 B6 q: M+ V - final int newLight = convertLight(6);
: {% `8 u% d# s# W - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& A e2 c) d& R2 E3 R' S5 P" S0 w
- final float lineHeightSmall = (y2 - y1);2 i# I( j; r& J. S4 |: t
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight); p: e5 i6 V L. @
- pose.popPose();& U. ^$ G2 t5 O
- }
u; i$ w0 @9 g# J/ T - 3 u8 q# N4 T3 z. i4 V# z* L' G
- private RenderType getLayers(String texture, int light) {" ~, N4 D3 {6 @( {7 W$ f- o* c
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
/ Q- M) E4 x1 g8 c2 z! R - }+ \8 f5 G7 ~! b0 k
4 ?& U7 F0 X) f( }- private RenderType getLightTexture(ResourceLocation texture) {
) y$ E: H i+ W) A - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 a; J2 U" c% S$ @" m0 ]' H
- }7 _* ]$ R2 U# O h
; P) @& t, ~! _1 G; T- private RenderType getTexture(ResourceLocation texture) {
" V5 d5 N6 I* X7 H) V) [ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 v) V, i, o5 I6 `
- }
; t, Y5 `: w1 E; l9 W( V- k - 6 j m& Q% {" U8 p/ M1 N
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 g; y' Q) y1 O% Y7 y1 y8 K
- if (cache.containsKey(identifier)) {
4 b. i# z6 u( n6 @+ ?) ? - return cache.get(identifier);2 o9 t4 Q3 h$ Z+ o; W
- } else {) a6 r& o3 @( h
- final RenderType renderLayer = supplier.get();
" b" W$ l& b* ]2 M e7 H, e3 U - cache.put(identifier, renderLayer);$ x% P* O, z* e
- return renderLayer;: |2 Q/ ?6 r& S
- }
7 {) U/ N* S& K- D, f - }. c. u' d& _8 P: m
- }
复制代码 |
|