|
|
; c" H3 u' x0 w5 P: }3 G
行,这个怎么样
. i+ ^2 F6 h2 ~$ ~- ~% v2 q( \- package com.xhg78999.mtrfac.render;
) a7 e: J7 v2 b' s
& f, V- T" \3 \$ D6 [, }1 h- import com.mojang.blaze3d.vertex.PoseStack;( F& D7 l! j) G5 ~4 e) |
- import com.mojang.blaze3d.vertex.VertexConsumer;
4 p" s. `6 U U7 N/ I4 y) l - import net.minecraft.client.renderer.RenderType;
- H9 G5 f; Z: G) k# T4 \ - import net.minecraft.resources.ResourceLocation;
+ H9 S. y5 ~ P3 w - 3 K: g6 m& W) f9 ?% S5 U/ I
- import java.util.*;
8 h) h7 R( p9 \8 h
* Q0 k- U. v; y0 o3 y( p3 I- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
+ \7 A9 l, a6 V3 \- h* U* r
) z: J! L e- c0 z4 {+ N3 R2 t$ a- public class LineRender{
. b* ]3 M9 b* d0 J - private final PoseStack pose;
5 o9 P2 |! U) o. q1 l/ a8 z+ u - private final MultiBufferSource source;
' ]9 @+ X# p8 k: K. O! C - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
. `) }* B- ]% E - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
& u/ s& k2 k% e - 6 z" K5 l/ C. b
- + E! { W/ j, _7 I' N7 t
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ a; m8 n* n8 y; u1 S$ V+ y7 w8 O - if(x1 == x2 && y1 == y2 && z1 == z2){
' X* k, L7 g1 c$ T P2 W" \ - return;
( k+ C+ z# f; d2 } - }
/ e- C* I5 Z5 ?, I4 ?; d - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
9 V' w2 M* h# T' ^2 E - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 C B* R: R1 @0 ]( I/ C. ~
- }
5 \9 [8 x6 x8 P7 m' Q - pose.pushPose(); x3 U& }% \: H( `4 H
- final int newLight = convertLight(6);
+ Z% _/ M3 L# `6 K( Y5 a/ [ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, j$ b3 }* Z7 o4 n: ] - final float lineHeightSmall = (y2 - y1);
/ l8 G8 K+ w* y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
# U X' M' ^; E, w1 o - pose.popPose();& `" o, J+ n. i. u# Z
- }6 q( }! C) U$ p
" }8 J& z" Z" I) a- x8 D- private RenderType getLayers(String texture, int light) {
" \9 W% M8 A* g( l - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));; [5 M+ h! p- l4 t+ a& h
- }0 |" d( ~# S. F' `3 `
- & I% Z) E! G g2 g5 ]! R! O
- private RenderType getLightTexture(ResourceLocation texture) {
9 Z; ^0 L& a2 q& W4 t - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* q8 _3 r- Q3 P7 x* S - }8 L4 S# x. f! N/ K
- / ^8 w5 A- d' a. U5 l
- private RenderType getTexture(ResourceLocation texture) {
3 g+ c2 p* C$ j: U - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
7 M! I, i8 h6 A3 t2 B( P- B4 @ - }
% d- z2 I* g9 G
3 o b1 d/ _" z6 E2 r- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
/ k- B. Y* R0 {6 e8 R9 K9 y - if (cache.containsKey(identifier)) {
, ~$ v5 v8 y9 I. h - return cache.get(identifier);
: \5 V% a5 n" R* T - } else {
; c% m. \; |. j) c1 l - final RenderType renderLayer = supplier.get();. d+ I1 u3 B/ _4 E# ]; M
- cache.put(identifier, renderLayer);1 K$ }( E/ y! S# E
- return renderLayer;
2 ^# o$ n$ m( g) U( W. Z: \2 a - }7 z' g1 O! h$ N# W
- }
6 `$ n: O$ n8 ^ - }
复制代码 |
|