|
|
3 g( L- T# ]; w
行,这个怎么样( Q9 r* s |* S+ K$ B( B4 M
- package com.xhg78999.mtrfac.render;3 L( A- K, W- }; G& R3 M
- 1 d: f. H& B6 t
- import com.mojang.blaze3d.vertex.PoseStack;! j! o+ K ?$ P% @2 L0 E& P
- import com.mojang.blaze3d.vertex.VertexConsumer;
* u3 u9 d6 |3 @# I - import net.minecraft.client.renderer.RenderType;. A' i" z9 m$ l. |
- import net.minecraft.resources.ResourceLocation;0 R' v! I% b: h
- K: |3 Q0 e3 s7 s: c5 j- import java.util.*;
8 S( v. `" p0 L+ j; F1 @4 H - . Q. M2 q! p/ M) `) f6 m# q3 K2 a
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
0 m \- X; C. `/ \4 a7 v5 F$ Y
& u4 p8 W4 A. E2 w- public class LineRender{
; {8 ]0 V0 _; H - private final PoseStack pose;
- D! |% p. n$ j8 ?) A O - private final MultiBufferSource source;
3 i2 [: Y: o4 y - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
( L& |0 H" p; G7 a( w' a - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ Z- U1 D. ^5 v* a8 h4 V
+ V: Z! T: c- S( {1 n7 u
- X! z( v( v. t# s- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
1 G9 R/ f" Y R, y- d& g$ v5 q1 q - if(x1 == x2 && y1 == y2 && z1 == z2){
) Z* I! U3 P$ ] - return;/ J( n# `1 L& G
- }
! Q9 l# ^, |5 l - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
8 F" T g* I8 F! z4 p. k, S' ]0 K - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. c, r3 o; V* e- x3 n8 n, [7 e# K
- }' p3 D; h3 L# |) G" L, _8 y( g$ e/ H
- pose.pushPose();
/ V( w) N$ ]+ t$ ^5 X. t4 ~# I - final int newLight = convertLight(6);
: R2 y7 E: [( u; F+ l9 \& R3 [0 v- D8 k - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
: E1 F3 x) u+ z8 }7 C - final float lineHeightSmall = (y2 - y1);
7 t- v( `+ A' p2 u7 m - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% @0 G- A" l, O9 j& ^ q+ R
- pose.popPose();6 D8 G& q" o, [! b: P4 D) [
- }! h( i: l4 k. u
- % G0 `3 o( i/ n K# t4 Z0 Z! ?- E8 W
- private RenderType getLayers(String texture, int light) {
: J; `/ k; v" ~ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));' K. I: Q" w4 ^( g- L! E1 b
- }! l# i6 {* y, l, ]2 z
- . S2 G1 i# g! D4 q1 [4 |
- private RenderType getLightTexture(ResourceLocation texture) {
/ z7 ~4 |+ y$ e8 ?3 U: U9 V0 n5 r - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);1 s& w& l5 H+ X* x- a4 D
- }) |/ k) b, U2 U7 a) f
- f3 ]$ T/ ?1 I' _& \
- private RenderType getTexture(ResourceLocation texture) {
% S6 d. c9 t% d) _9 g* z3 M/ F! a - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
9 g5 S, ?; ~8 x' a9 x - }
% E. e6 e. p9 F# v2 L! j+ x2 H - " a: a0 d% J: z" H: g
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {: o3 q: T. m" W: O6 u' i
- if (cache.containsKey(identifier)) {
1 B4 j) z" q9 a: k9 ]" S4 J5 E) A - return cache.get(identifier);2 E8 `7 r$ }9 g5 O, g3 w
- } else {
4 |1 b( D3 X' [( S5 c U4 j9 G# f - final RenderType renderLayer = supplier.get();
: l, S& }9 X0 w% X* v - cache.put(identifier, renderLayer);9 ^9 `2 e9 \. _( }- k h
- return renderLayer;
u* f1 h3 N: x/ h; O# q" v0 _ - }& G0 ^& t. y" g# q/ c
- }
+ @% I# I- N( \( `2 ^1 P - }
复制代码 |
|