|
|
9 B, j& w* Y. ^6 `$ Q1 Y行,这个怎么样
3 T4 I7 t: j! F n" F1 X) D- package com.xhg78999.mtrfac.render;8 m2 O; F) x) k2 @8 S% H; q, Z- N
- + F0 g* S* l; y! F W, k
- import com.mojang.blaze3d.vertex.PoseStack;! H5 C5 F; Q* x# F
- import com.mojang.blaze3d.vertex.VertexConsumer;+ E: U ]% Z4 l( \6 |2 B" d/ Y
- import net.minecraft.client.renderer.RenderType;& v; z8 S% X4 T3 l2 u
- import net.minecraft.resources.ResourceLocation;
$ d x, T1 x; o p1 z. n% r2 t - ' |4 Z; {$ R6 s! H
- import java.util.*;
7 J2 R( U. v- n: A - ! H% T) q, w# [" x
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. z# Z& `8 e, v$ z6 E( t7 H
8 k; i2 w! Q# k k- c: H1 K3 u- public class LineRender{0 c! j& [( s T9 O) j& J A) i
- private final PoseStack pose;
+ C7 C. a: r! q - private final MultiBufferSource source;
- [0 o8 x$ S/ K - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
8 @+ T( H! _3 ~0 W - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! w7 _, w, ]5 q1 b - : v! _! D! p8 d
- 6 e5 Q& D, j- r1 v! N# a
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
% o9 y, s' H1 v) s - if(x1 == x2 && y1 == y2 && z1 == z2){, u) [ @5 U: i! z/ s; ^' G
- return;& V s9 b8 |4 _
- }
/ N, s0 @& M/ [$ j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. o ?# I* l: |7 V! n% Z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
& C. W5 P: U1 j- N) K2 R - }
8 X M% Y9 g5 q: C; ^% X - pose.pushPose();
% Q' d' [+ \1 x. z- O - final int newLight = convertLight(6);
3 x# h* z. d- |5 I0 f l - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
+ K' C$ X+ {. @/ p- u - final float lineHeightSmall = (y2 - y1);
8 L' B. X3 Y' [6 Q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);* ~- X7 X" l% p0 m$ s0 E
- pose.popPose();: }) K Z8 m1 P/ S3 _+ ~/ ]
- }+ N) M v/ ?! V, J" M9 }
- 5 J: H8 u7 T9 H; ]3 N* f* H# Z
- private RenderType getLayers(String texture, int light) {
6 z8 X( c% H5 h4 e) n" ^* S8 D! v; z - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));! ~) w4 b& w* U" y3 L( N$ ]
- }
( q. y' b" j, v0 p" g# n - 3 m& p9 o$ i4 V4 D6 D
- private RenderType getLightTexture(ResourceLocation texture) {6 S$ i, \5 [ A" J; y8 f) P2 @
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
6 `% L5 o# C+ m, h1 W: q" e, _ - }* H$ P% ~% e. E0 b3 M& a# E( k
( q4 B7 ~4 U; N, B1 `# W4 c' z2 @- private RenderType getTexture(ResourceLocation texture) {
! M4 K9 m$ C$ Y( W - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( r U/ i5 m6 N; I. @1 f1 b - }
% h$ {6 V2 @7 w - $ W( X% D3 Y3 ]% `/ s) } [/ c
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {+ X5 V9 @3 f% {7 J0 k+ U
- if (cache.containsKey(identifier)) {% Z+ @7 \; I, b O+ s9 o2 ]# e
- return cache.get(identifier);
3 ~% I" t0 P# h2 W - } else {/ `! \, c/ R5 j ~7 l: Y
- final RenderType renderLayer = supplier.get();
; N4 W! E6 E2 R! _6 x+ n+ j( Y - cache.put(identifier, renderLayer);
. _6 H* ~3 u2 B8 W0 R ?7 \ - return renderLayer;8 n% O1 K/ F$ y2 u4 i! c2 K
- }+ @; a- r% H" }, G9 r" l* @1 d
- }
% m" X3 l: X# ^. Z6 Y8 ? - }
复制代码 |
|