|
|
" F* v t0 O6 }
行,这个怎么样
x: P7 _' M, `2 m0 Q- package com.xhg78999.mtrfac.render;* F+ G$ N/ T2 z
- 4 S4 w( n- q: M; g& R
- import com.mojang.blaze3d.vertex.PoseStack;: L! A6 v2 p7 p( b
- import com.mojang.blaze3d.vertex.VertexConsumer;# {8 k' O& E+ s4 P% s! s" }9 e h! O4 e6 `
- import net.minecraft.client.renderer.RenderType;/ S. O( H7 Y0 m8 S8 m* e
- import net.minecraft.resources.ResourceLocation;
9 d/ k2 Q, W( [4 V) Q$ s - 1 g( k& |6 a$ ?! w
- import java.util.*;& i1 ]8 y- g+ H- |, [
1 E, U) R& j/ @& p# b' i- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 V- {" R& f* [4 O$ p+ A
e& q! F+ Z5 f! [- public class LineRender{
G0 J) ~' l U1 L3 R - private final PoseStack pose;
. v6 y. c; O( y7 v) X- e - private final MultiBufferSource source;
+ p) s# _3 l( a7 y - private static final Map<String, RenderType> CACHE_A = new HashMap<>();* L3 N' I! N! {3 A6 X
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();; t2 j0 D& `* v& x3 j
- ; r0 e3 s4 i; G: ~5 D& ^) w
- 9 z, M1 |3 ?$ @& a$ @& e5 D! Z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){9 k( }! o6 Z( J" Z$ c8 P
- if(x1 == x2 && y1 == y2 && z1 == z2){
" _- `% {0 Z0 t6 m4 e - return;
* T# R# U4 J7 p2 B4 u, G - }: T0 v2 h' n6 ?( H% W/ z. h
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ M( z" u5 \, v/ i9 h
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 W! |( q& \9 v% G' s% g
- }
! y8 ]- _9 m' z" T - pose.pushPose();
3 O' F' t8 Y: O3 `, u - final int newLight = convertLight(6);% \. e7 t0 @! k4 H9 j* l# x
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));0 |* Z3 u; k8 c
- final float lineHeightSmall = (y2 - y1);9 W |& [6 R' X) F* Q
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( C7 W( G6 R) B% @ u0 w
- pose.popPose();
8 {$ w# G6 Y& K( j6 c0 h" h5 l - }7 _0 }; J2 W$ V
, z# \5 d/ i& u9 H- c9 _- private RenderType getLayers(String texture, int light) {
# @8 b2 k: Q1 L) H' R5 D3 \3 L7 @ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));' m. ^( D% h+ m. ?
- }
3 j, j" a$ S4 s; a - ' B, l. l! H: G2 @( M) A1 ^* U" i
- private RenderType getLightTexture(ResourceLocation texture) {! V3 g. s A* b' x+ }/ t" Y. N
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( Q, z. g$ ?# G5 V) @- y5 e' | - }5 d; u, ^/ f0 b; D" E( I' r
( G6 K1 c' {0 v* s+ x5 D- private RenderType getTexture(ResourceLocation texture) {
- d3 ]3 F; Y" S0 T1 n; d - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 q% Z9 U! J! t' ^* i6 w - }- e' W, a8 O/ R7 @! ^
f3 j1 V4 b/ z" E" [+ d- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 B7 S8 E# v5 b9 h* |: ? - if (cache.containsKey(identifier)) {6 I- e9 c" P0 u- @) t
- return cache.get(identifier);3 G Z, o" y$ h G5 a4 Q* f0 a
- } else {
$ p, u2 D: E! p# J& f8 @6 ~: J - final RenderType renderLayer = supplier.get();
8 ]7 C7 F! T/ P, H - cache.put(identifier, renderLayer);
% R P$ D3 u) d% R& O - return renderLayer;6 H7 {; q# c8 ~7 t2 E! {
- }" }+ L* z4 X/ b; ]
- }
2 ?& C. O3 l2 A1 C3 X& f U - }
复制代码 |
|