|
|
% [) ?0 P1 S! O- C# m行,这个怎么样
$ F+ B( ~" {- Q. {: x- package com.xhg78999.mtrfac.render;
. F9 G3 t7 a" @) g1 Y& N
, w7 ?0 O4 r" P6 ^- import com.mojang.blaze3d.vertex.PoseStack;
, t- \8 B6 y( [) o% A4 M y" o - import com.mojang.blaze3d.vertex.VertexConsumer;0 o/ ~, v1 K( u& c. l/ {
- import net.minecraft.client.renderer.RenderType;
9 K( S0 }5 |. Z7 g2 c! M - import net.minecraft.resources.ResourceLocation;
, X& [6 m- c3 {7 W - / N: Z3 o& t: h- I7 t# m4 D7 W
- import java.util.*;
9 L3 X, E; b' g- M* ~! J
6 I, `( p- q9 R* N3 e% ^- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
' E S) h% P: c' y( O
1 ]. ? j5 I$ N5 @- public class LineRender{
( i2 U7 }2 u0 L/ l0 ^ g5 m - private final PoseStack pose;. p, Z8 V- z u+ S5 ^
- private final MultiBufferSource source;
3 g0 L5 u! O C - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
) Y0 d: d. P$ @1 s - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! q( ^% z) K. F' {4 M5 j1 [3 T! ~
. `; _: p( H6 y- `4 K! _# a1 d- 0 W3 i3 X( R& s7 t9 {) o; B# ?
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){( _/ R* u. `2 A- T& a1 v
- if(x1 == x2 && y1 == y2 && z1 == z2){8 w+ ]: a1 t/ k# u- g) m; m$ M
- return;( Z: Z1 m# K9 b3 v+ K- v% |
- }3 L% x3 z# k. C- O
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){0 ?3 v' A0 M, o" B/ P
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 l8 y! d6 n1 p, Q$ p9 A - }$ ]8 n/ e' c) @. K
- pose.pushPose();6 E# o" ~) k: ~, Y8 N
- final int newLight = convertLight(6);0 l" a7 D5 g6 k' t. @! n
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
; M. p& C" C' i - final float lineHeightSmall = (y2 - y1);
! x/ Q5 N( k9 l0 q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
) h. Y: c! W+ \8 j - pose.popPose();
$ x0 E( E5 D: ~0 }* @9 U - }
0 e: p4 h8 @- j" ? - $ ^0 j& q; O1 z& Q0 u1 [" O5 {
- private RenderType getLayers(String texture, int light) {
' g$ l1 I) g$ Y5 \ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. d2 I( o' T" J* Z6 Z2 G" d- K7 i - }
! S, Z+ ] z2 H/ }
; l7 {2 B% y, T' z' M- private RenderType getLightTexture(ResourceLocation texture) {
) \8 ], f# d9 T& X+ `3 R - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);5 X4 C9 P7 Z" l; n1 o: C) n2 J
- } b c. U; k9 o `, m- T3 P' I u
! [/ s' B9 d* n, U" E8 v R- private RenderType getTexture(ResourceLocation texture) {
; x0 |( v" E, D% o/ z0 D - return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 E8 p4 U8 g" Z" s% r6 H7 m. ?( c
- }
3 S0 M& T% J1 z9 s5 h$ p - 4 U4 @2 F! p, |' |! L
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {! J; Q0 @, D; g# ~0 v7 W. Z
- if (cache.containsKey(identifier)) {
/ |1 S h' d. |6 O7 b5 Z; @4 q - return cache.get(identifier);
3 t1 T% N0 | n7 V" o ^ - } else {! |# x7 t4 n2 A% b7 V
- final RenderType renderLayer = supplier.get();
2 P; C$ e) b1 @; \ - cache.put(identifier, renderLayer);% q2 [. _3 S3 |' `. P# P
- return renderLayer;0 A" p) @ }' ~$ `3 G5 N
- }1 m* ^: g* e; g! C( J
- }2 U( l* F/ ~3 @* ?% P# v- L
- }
复制代码 |
|