|
|
: j! q0 J r T U7 j行,这个怎么样
9 Z# h- h, v4 m2 ^, F p- package com.xhg78999.mtrfac.render;
: t/ S9 }5 O9 q$ k( f% y0 c6 j& f - * I: v2 I# U7 T6 W% o8 X, T+ a1 i
- import com.mojang.blaze3d.vertex.PoseStack;' ~! ]2 V( ?2 X0 h
- import com.mojang.blaze3d.vertex.VertexConsumer;
/ n% w: m4 G) h) A, K - import net.minecraft.client.renderer.RenderType;/ U O+ D Y! Y" U% T
- import net.minecraft.resources.ResourceLocation;
9 ~4 C4 p0 z: p0 a- j' e
+ L$ u: o$ v& K( t: v. @- z- import java.util.*;* }' [2 P. k6 ?3 x, B9 R
; i$ Q& f+ W5 b- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
6 b$ S, j( W; N$ }- Z$ O8 a# [; m
4 C$ p, q, U2 j' c4 L& |, j" R- public class LineRender{
: ^( O3 n# d/ b0 H( @9 \ - private final PoseStack pose;+ P3 h# j& l! [- Z1 Y0 ^# h: [
- private final MultiBufferSource source;
9 y1 @+ T; [& J7 {, F% d - private static final Map<String, RenderType> CACHE_A = new HashMap<>();8 `9 b/ Z D. w: O. I% @
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();4 q7 {4 d4 a2 V- x2 }
- 4 \( y5 u0 x9 H5 m* V
- 6 p3 D* r4 F3 g& b
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 ~ R2 S" ?9 i! \1 X# ?3 R$ z
- if(x1 == x2 && y1 == y2 && z1 == z2){
9 ?* |+ s5 T. s. u4 i: p - return;5 }2 S& s9 x+ N9 l6 ~
- }* j m$ O4 F/ L0 P
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){, ? v, w; {$ k
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 L% [) Z' V3 r% z( M - }
8 C9 E+ W. s2 W B) T" R6 f8 u - pose.pushPose();! C8 i4 E0 M5 |: E" N" L
- final int newLight = convertLight(6);; L$ V$ ]- o$ k/ t: f1 `8 I" D. o
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ z) V. {3 m- D0 J - final float lineHeightSmall = (y2 - y1);
( b: @. V! ?7 H9 X, |( R; U - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);- v h& i. o+ {7 F
- pose.popPose();
. K6 `6 F: L8 A - }' e0 h8 Z0 s% V9 [+ T7 [ p
- 1 y0 V$ Y6 e. Z0 y, r4 u/ I
- private RenderType getLayers(String texture, int light) {! v2 l% a$ X/ B9 B b$ `, ?
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
- {/ p- \4 q( L) o/ r6 T$ z0 z, i6 B5 ` - }% c; G* a% m" y+ b8 S
- + z: @& h+ [( L4 p b5 R* k; F
- private RenderType getLightTexture(ResourceLocation texture) {9 M9 \) m$ p- z) Y. c) ~ s' a" I
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& i3 w! x+ t. H2 h# E9 k% g; E: a- W8 w
- }
( ^7 ]8 j0 b6 K. i0 x4 _. F - # q" V4 I. k3 E3 @9 s
- private RenderType getTexture(ResourceLocation texture) {; x9 V' f. j/ O; l7 J# q# Q! u3 C
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: R( u4 z8 Q2 P/ O6 Q - }3 a6 O: p" C& {1 F5 L
. j6 D4 X( c! G) a& V- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 g/ w1 g7 t6 p) X - if (cache.containsKey(identifier)) {
3 Q4 t) }) K# O - return cache.get(identifier);
/ Q- }6 f+ C \6 R - } else {
& f9 U, E5 o7 w6 n - final RenderType renderLayer = supplier.get(); T& K; @4 u9 x4 {, ^
- cache.put(identifier, renderLayer);4 a0 P( \: e* C/ X v' |+ m
- return renderLayer;
0 K- R. t& D* ^. I - }- o% T6 Z/ [- p& x- Z Q( R- J
- }
; _/ F8 \5 F6 U; v7 z6 B - }
复制代码 |
|