|
|
; Q* f& i" l$ ]0 j: Z9 K* }$ u6 E3 r9 f行,这个怎么样- d/ ^' e% {. B2 a+ c& M7 a9 K
- package com.xhg78999.mtrfac.render;
( K/ x) y, r2 y) ~ - : I$ D' w. s$ Q- ]
- import com.mojang.blaze3d.vertex.PoseStack;$ ^2 t5 P3 j0 v z
- import com.mojang.blaze3d.vertex.VertexConsumer;
3 n* N+ z A3 Q9 _2 ~% ~6 k, c - import net.minecraft.client.renderer.RenderType;2 Z) m! @0 X! w9 O
- import net.minecraft.resources.ResourceLocation;1 ?7 {/ d" i$ `' x/ W7 s; J" k
# |( V3 c3 X/ x V5 X& I( w8 J- import java.util.*;
' e9 {# y, d" Y7 R' A. V
( [: Q$ g X6 P+ @, k2 x* j- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
^5 d4 t0 f# K1 C: Z# s - ! R! t% C. C, j& ^: D! N5 l! i$ W
- public class LineRender{. C8 j5 D5 f4 W* h: z1 q
- private final PoseStack pose;
) n: U" s: d1 o6 w) g - private final MultiBufferSource source;( J2 D* ^" { u
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();$ i% Z: u& m _
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 r3 `1 z" u" q4 Z& y4 H# J$ K
- + \, \+ }% z l2 `- j
7 c% q$ g0 F8 G$ P- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){/ N2 @, u# F* P4 O8 V4 A
- if(x1 == x2 && y1 == y2 && z1 == z2){
" G$ L3 ]: y, P$ A2 ^- J - return;6 w- Z \6 _$ q! ]6 k
- }
( E* i9 N# M. q& M' a - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){$ D- X" R! q4 R7 D4 M6 f3 T4 H
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
. u8 i- W/ n. V - }& Z6 |7 Q; s& G; U5 a: q* k$ u% ]
- pose.pushPose(); m8 b, B4 F1 i- k3 R" e6 }" @
- final int newLight = convertLight(6);3 X( k* a0 |- m/ a
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, ]* ~* v- C1 r$ _ - final float lineHeightSmall = (y2 - y1);! k# Y( ]0 D3 I0 \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
2 a% E; d: D& t1 M - pose.popPose();) y0 \1 T" H3 c# H- k
- }, b% D- p- W$ F( n! S }" R
- / g) H$ X) \( v1 U. y' X3 l) T
- private RenderType getLayers(String texture, int light) {: V7 r9 @6 v1 y
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));' ~% |7 d& v7 U8 X9 p& y% ]
- }
$ c" q% {& T+ L - : o- Q0 ~% \6 ?) q
- private RenderType getLightTexture(ResourceLocation texture) {, h( `6 @3 v+ H$ E" c
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 Y' v6 D$ {' ]6 q' q1 J5 S
- }
1 U4 Y. }: d( [& d% z4 E, R
3 @& f; j) ^6 h0 [- A1 B+ x$ D1 ~- private RenderType getTexture(ResourceLocation texture) {% D; z- e# ~" v3 v4 n7 \2 E! O
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% b( {% X% D: p5 \8 C& a: W6 @+ v$ b - }
/ X. b+ J1 h% b! a
& G, W4 Z" U8 Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# p- n; C& k, [' z6 Z5 i0 L! A% }
- if (cache.containsKey(identifier)) {
1 P& Q% ^. ?1 x8 [; u3 I8 \ - return cache.get(identifier);
* Q( v8 u# C8 }: h7 ? - } else {
0 w9 v& X2 x& E; ] - final RenderType renderLayer = supplier.get();4 R* n' j/ o- J l0 K
- cache.put(identifier, renderLayer);) ^: q" a, _* t) M1 o! N- T
- return renderLayer;4 U3 c! y, t; m! ?9 e. t3 x. `
- }) h8 r+ p; u/ K
- }: I7 U4 s# n. I0 P$ \
- }
复制代码 |
|