|
& q8 G5 U. X" M; g
行,这个怎么样
$ A; Q# `* M( l' f- package com.xhg78999.mtrfac.render;
; b2 {/ D3 H$ L9 D C
- F$ B2 }/ s; c3 z# Y- import com.mojang.blaze3d.vertex.PoseStack;8 ^2 Y* u( w4 Y: d8 h# h4 G- B
- import com.mojang.blaze3d.vertex.VertexConsumer;
. o/ t4 M3 F; Z, X - import net.minecraft.client.renderer.RenderType;7 W& h% O0 _, D
- import net.minecraft.resources.ResourceLocation;
; |$ E# V4 a' F# e2 H
; F7 g) [3 S0 A. p- import java.util.*;9 ?; E# p* G- L6 C( H2 z) \* z* z
- 9 r* T8 k2 s5 E
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
! w) m3 t+ \2 k3 c' N) \$ `
0 u. V( Q" l7 Z$ S" y3 Y3 w2 p. }8 w- public class LineRender{
# U9 F. v/ ?, k! u( ]% u - private final PoseStack pose;
- ]5 A1 x8 B6 M9 `' O - private final MultiBufferSource source;
" m9 w$ E$ r+ m - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
. }: H4 i# I4 _' {# V# x2 `: H( g! [ - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();1 s, G: P5 y$ I/ L
; A2 R# N' e3 d5 B7 Y8 t& p8 M4 D* N- - p; C/ K" U s
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){3 y6 @2 O" Z' k6 [" w
- if(x1 == x2 && y1 == y2 && z1 == z2){
7 `/ h( n! I/ z' G. w4 ], G# u - return;
! H g+ x* Y: r/ W0 b4 Y* n - }# ^* c; V* f6 P+ D8 j
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! K, ?1 S1 {# m$ U - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
! p1 G1 i& k# w: @8 c/ X. P1 j - }) c- q \8 r& Z' d3 D
- pose.pushPose();
8 t1 X9 d% V" T$ x) w% u - final int newLight = convertLight(6);. a% y% c! }& N' Z
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));' s5 ]' s5 B; V6 M
- final float lineHeightSmall = (y2 - y1);
# H, d. n$ Y/ }! E# L - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ i, b& T4 r* _. c$ S! u- P. Y* J
- pose.popPose();
2 t2 B8 `8 H7 i, p - }% O% _: ?3 h1 x% _$ g. X
- ( v/ e8 i0 ^5 a/ b3 `1 M+ T
- private RenderType getLayers(String texture, int light) {9 e% G3 r5 f% Q
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. C- U1 D: I( s - }
: u! I C3 e7 L- f1 m - ! h. T" F, i$ U" Q3 B$ H3 R% j" g0 X6 K
- private RenderType getLightTexture(ResourceLocation texture) {
2 X/ e4 ^" P* m7 { - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 _: c+ T. i( z2 k# t# M6 B
- }# H% o7 ?7 [1 B# {
7 U. G( P7 o- ^, @3 A5 [4 u( ~- private RenderType getTexture(ResourceLocation texture) {( L4 L9 ?+ m/ F( f# C' H
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);' H9 j1 W6 ^% @
- }* i% u( F3 p; L3 S& ^0 g& e% E5 I: Q
: o0 `2 Y8 A8 O+ }7 R: E- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {, a0 d5 z1 D: n1 H# _ N# i
- if (cache.containsKey(identifier)) {
$ D) [# U) Z- ^0 W0 [0 i9 y' ]) t - return cache.get(identifier);; b N1 k0 d4 Q. B* L7 [. L
- } else {" a4 V- V% A7 d: n+ D
- final RenderType renderLayer = supplier.get();8 I- k+ ^8 H5 U: K
- cache.put(identifier, renderLayer);
7 r& U7 y. s8 d0 @: H8 W( R - return renderLayer;0 b( Z2 D9 x3 c4 ]7 _
- }- j O b' w, O v2 i$ T( a* p
- }2 G; u( R: ]9 |' S$ I6 W, `
- }
复制代码 |
|