|
|
4 Q+ P2 \ q0 W
行,这个怎么样/ X1 B% A8 m$ C9 H8 ~( q
- package com.xhg78999.mtrfac.render;
# i% j& N4 P& q- A+ _' ? - a4 d$ d- u. y! G5 }
- import com.mojang.blaze3d.vertex.PoseStack;
1 \3 ~8 C1 k: V- K1 o% | - import com.mojang.blaze3d.vertex.VertexConsumer;3 G9 R9 w" J" s& `
- import net.minecraft.client.renderer.RenderType;, G4 j3 e8 c$ y- D! v6 E
- import net.minecraft.resources.ResourceLocation;( a% E" |1 Q6 @# @$ I
- + W8 R' h: d, O
- import java.util.*;) r$ G6 H. k9 x, F" q
1 k" @9 [7 |# A- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 W9 _& q/ Y3 y, x5 D - 7 d3 W4 ?1 h, r" v
- public class LineRender{
9 k- X1 Q" K0 v- r - private final PoseStack pose;& ~; X1 S+ U$ q+ e l* D0 a
- private final MultiBufferSource source;
/ K5 z$ Z5 s0 J; ~ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 K# k+ R# k' |. B4 m - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! v" g$ V& _) A* ^# a" r" R - % B- N8 \' a, c5 ~ J
8 v! K7 p$ ~% Q- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' e1 O( l" Y; V( @
- if(x1 == x2 && y1 == y2 && z1 == z2){, J |! K; F, H8 v7 k' {8 s% s
- return;7 H' ^, u% `9 b, P
- }3 h1 p6 B; M4 g
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; _! E" u5 @7 ^# m1 e% } - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)"); e( }# @2 T$ Y0 r* r& R8 J3 w
- }
" i' \7 K6 F6 ~' J8 f, }! R7 X - pose.pushPose();2 w: M7 N) e3 d. `$ S k/ S
- final int newLight = convertLight(6);" h% g B* |3 C' W" i
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ ?2 o0 r r; ^' p" ` E5 f' _ - final float lineHeightSmall = (y2 - y1);
4 f. B2 `3 s) W1 p/ r3 r. I - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);; j# _( B% K/ S6 L2 ?7 r3 L9 R
- pose.popPose();: ?. m4 A. k5 ^0 O7 d$ ^
- }
! w+ U' z, h& P" C9 m
! q% E2 ^6 D$ _' @- private RenderType getLayers(String texture, int light) {" f/ t9 K4 E6 }4 g
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
5 q, l3 Q1 x! f; a9 m - }( v V0 o; C! n# A; G8 s( C
- + }& t5 _8 X C; y) c- y# M
- private RenderType getLightTexture(ResourceLocation texture) {
* y& Q* T: C& {5 E( i - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);/ H: C6 q8 a1 Z0 \# ]
- }( P1 E& ~3 v4 z
- 8 c7 v! H8 B- u3 o+ F5 T: e( X
- private RenderType getTexture(ResourceLocation texture) {/ x/ {7 T7 I. D- h
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);' s9 D& |& V! O7 d8 C- G
- }
* J1 v/ `* m$ n- B& A - ' ]( P7 Y+ Y7 y9 ?, A
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
4 `2 l1 u% x6 t; m5 i+ {9 G$ p - if (cache.containsKey(identifier)) {! |6 p, C0 M$ M7 x0 o5 g# l
- return cache.get(identifier);
" s3 X. j% G6 {- _ - } else {
1 W8 U; a5 d7 o# S9 p - final RenderType renderLayer = supplier.get();
% S( Q+ [1 p' ~" y7 J7 S - cache.put(identifier, renderLayer);- E, {/ d: j( w/ D
- return renderLayer;; |0 M9 k8 V5 l+ R0 O
- }
0 b% S, [+ u; |! f - }
- z' r! p; A% U9 X7 k0 ^ - }
复制代码 |
|