|
|
" I2 g n8 b# o) F/ G
行,这个怎么样
7 D) L. G9 B- v- package com.xhg78999.mtrfac.render;7 O$ }4 x/ V1 |5 R2 B$ O4 T
- ) n* E i1 K& s, j
- import com.mojang.blaze3d.vertex.PoseStack;
. Z- b$ S- g2 x - import com.mojang.blaze3d.vertex.VertexConsumer;
# P, b) T+ \6 \0 C" J4 L0 W - import net.minecraft.client.renderer.RenderType;
0 m r; D; D; [& z( w - import net.minecraft.resources.ResourceLocation;
) ^ Y+ u6 _7 o1 F* R4 z - . q! Z# U5 @) @2 ^" v' j0 \
- import java.util.*;' F! K V' V& U" Q4 J8 M, ]) B1 H
- 9 L9 u) L8 x( G; W# _; _
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& Y6 _) W, `5 M( ?( c. c' O
0 \* R$ M$ S8 ^7 q- public class LineRender{
6 e( a7 B3 ^3 u1 j9 H$ Y3 L - private final PoseStack pose;0 V9 m H2 C& V {
- private final MultiBufferSource source;
; [3 e7 q' t6 w7 j# ^* H5 I - private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 C8 [* E( r2 c
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
# ?3 z: C! w% p) F& e6 N
1 K; U9 h" f E6 K6 `/ e
9 k D# d4 ^+ T- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
" Q8 k: e( Z$ e1 `7 {% k - if(x1 == x2 && y1 == y2 && z1 == z2){/ T5 g6 a5 V7 C$ u% p
- return;3 a$ b7 O3 y% E K
- }4 h7 N" q$ |2 s* t# b8 @
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 Y$ r" a- j4 ]8 ^! A1 Y" Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ i/ Z/ ?4 D8 Q; r
- }
! ]5 {( I% Z1 j8 s - pose.pushPose();
$ i0 o; g) n. l, Z* q6 F - final int newLight = convertLight(6);
: R7 s. p. A0 E' k' } - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
# C3 N0 J: O) D. T; `7 l - final float lineHeightSmall = (y2 - y1);3 W( W1 Q& w0 ^. V: z6 I, p' s7 m
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
8 Z3 Y( n& _, j! C! k - pose.popPose();
" r) e* t) T7 ^ - }) V" E% F2 B5 Q+ ~3 j. Q
3 j. J. t, o; @% q- private RenderType getLayers(String texture, int light) {
% X( z1 b- ^+ r4 Y5 b - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ A2 E3 }; j7 l6 z" J7 x" w: [
- }
* S$ `5 m J& `' Q! c+ c
8 W7 g# \! a. r( ^. l0 P0 _0 }8 F- private RenderType getLightTexture(ResourceLocation texture) {
I. K* c" ^5 B, d - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);, [& V' ]7 ?; T! |% C$ d* Z
- }- o5 N7 ]* M8 D! w
# C- j4 F. ^" ~% g2 l* o; |: f- private RenderType getTexture(ResourceLocation texture) {
% e$ \7 @' U( B% R- s - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ E" g! r i5 ^ A& R/ q5 D - }: \% [9 z4 L; g. \
% ~* [) P/ k/ w' D, E- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {( B% O& s( }5 \* T
- if (cache.containsKey(identifier)) {3 F1 P- r$ a2 \: ^( a& o
- return cache.get(identifier); L5 C9 Y" f+ ^6 w) j* ~! X
- } else {* _1 }1 T/ [8 j9 h$ |4 Z% B/ [1 X7 e* D
- final RenderType renderLayer = supplier.get();
# k; V% h1 k. W* M ^% q - cache.put(identifier, renderLayer);# c# v# _. v0 s* {9 n8 G7 O
- return renderLayer;. ]0 b2 ^$ C- h/ u
- }
7 c* l* T* g. u- B$ p9 W! R - }* `9 z0 H9 \: x4 J6 s6 z5 s
- }
复制代码 |
|