|
|
+ i8 x6 q D6 ^. L行,这个怎么样
# N# _% @8 y3 Q4 `3 u3 k- package com.xhg78999.mtrfac.render;6 y$ e& J. a& _' O) U
^; P# _. z+ b# s$ r8 z4 Q- import com.mojang.blaze3d.vertex.PoseStack;9 P: Y5 z0 K# y- u: Y7 l
- import com.mojang.blaze3d.vertex.VertexConsumer;
! U0 A) W* b0 g8 G - import net.minecraft.client.renderer.RenderType;
8 g; h. s; m/ E# i r' E: [1 r1 A - import net.minecraft.resources.ResourceLocation;
; l' j- A8 C+ ]. }; B. k7 k
/ o. h2 B5 r( C% |8 w- import java.util.*;
) y2 R/ B/ j2 |3 R1 s- |, r2 B' o - " ^, ]# E1 l( U
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
9 ?, P# H0 f( b9 L L
: t n- }$ R- u+ X j: R% F( a- public class LineRender{; \- Y( |) P4 L/ B5 ^3 A
- private final PoseStack pose;3 j; b/ m5 e* ]2 o1 E
- private final MultiBufferSource source;0 v0 e [, ^2 Q7 U8 z2 N+ w
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; J4 i' r9 `: V. h" P& l - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();; v0 J# K8 E# y( j" ?# _$ {
- : c# `; x9 [( n( J- ]# D! k
1 n) V3 p! F$ h/ L" Z# B. R* r- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, i( Z! _0 A0 }" L* C - if(x1 == x2 && y1 == y2 && z1 == z2){
* j) C# b6 k3 Z$ | - return;
( k4 Z5 ]8 [$ h* A - }
3 _, C. W% ]4 n - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
5 b5 Y2 G, @% e& Y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
6 j( G) J& t) Q [# ] - }
0 T5 ^* Z' C" ?6 j7 J K1 m3 t' v - pose.pushPose();4 ^! R2 E# s; K5 x4 L% Q3 u
- final int newLight = convertLight(6);
7 j9 U% k! D" d! e# e3 M- h - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));4 Z1 A' `' H6 S5 k4 z' O! v
- final float lineHeightSmall = (y2 - y1);
5 Z4 w$ z6 a2 v0 X. M - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
i7 G; X6 x* ~ - pose.popPose();1 V$ g `" Y7 C' M: p
- }, F: N6 l5 N! _' [, X
" |+ a# V- x" d+ X$ z: W+ |! x- private RenderType getLayers(String texture, int light) {
) H2 h. v& p5 Z6 g: E - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ Y! l0 H f, q8 B
- }
8 ?" Y5 p( E2 x5 n( h
- P# D/ I0 T, J/ B- private RenderType getLightTexture(ResourceLocation texture) {8 S$ R, t) q0 c) K
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
{/ ?8 u8 l, G6 a% S - }# _* B. Y/ t! w( c* j) f1 c; M
, ]2 R4 n! ~ H* u1 X( l) D- private RenderType getTexture(ResourceLocation texture) {
~; H" U$ Z8 o7 k" v" i) Y! _ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 T, G" O1 r! t+ I
- }3 p% Q7 W6 X$ t7 z
& F+ V7 Q5 u. S( J; J# F' ]* H- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' R0 e& Z1 Z: r( ~3 y, M0 R2 S
- if (cache.containsKey(identifier)) {
( J4 G W. ?7 E1 B - return cache.get(identifier);
& A' f! a0 c' t. f3 L5 i - } else {% H1 h Z9 {# v7 v# g" {/ p
- final RenderType renderLayer = supplier.get();# u5 N q# c; N
- cache.put(identifier, renderLayer);2 [# T0 P5 n, p
- return renderLayer;
5 A" I' g" a8 O) l% y# T - }
7 L* Q# Q8 R4 S) }, j2 S - }
3 P/ M( b; I& ] - }
复制代码 |
|