|
|
4 ]- Z: }: }9 B2 j行,这个怎么样
: S4 g4 R" e/ g8 i- package com.xhg78999.mtrfac.render;
& X: \# R0 p, X2 J! n5 d
' f0 w( P; d+ e' f5 k& u- import com.mojang.blaze3d.vertex.PoseStack;
! D6 ?3 b1 b0 S. }: e - import com.mojang.blaze3d.vertex.VertexConsumer;, {( H8 l3 C' w4 v
- import net.minecraft.client.renderer.RenderType;
% R2 B; L# v, m' R) I - import net.minecraft.resources.ResourceLocation;
8 K6 \+ E0 M' t# l
# k$ r$ U9 K, b) U: Q5 n$ U9 W- import java.util.*;7 B) K, e( e: `4 j: X
% h+ t1 @3 K7 b; C! o6 Q- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(' p; z, D" W1 \- ]" L Q4 H
- % O; V H; z7 `4 q+ Q
- public class LineRender{$ g' X9 Q& E4 f+ u
- private final PoseStack pose;
! s, n% V1 Z5 v: f8 L9 Z6 I) |3 x! l - private final MultiBufferSource source;
/ z: [% t0 t& h# f4 f1 I3 _ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
! V0 |4 @; q2 S4 w: ^4 _- D3 U - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 N" q3 S: I+ p! [% x6 N
- # x6 [" |* O0 z+ ~
# k. H# @( K0 }( ]. ]- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
Y" K4 ?- `. ?9 s9 ^ - if(x1 == x2 && y1 == y2 && z1 == z2){% p6 K9 E9 |: h+ Q6 O* w
- return;; K1 H. i) f* T6 m! r
- }: A+ a) G! d$ a: D4 l# E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! M. A$ S* _. z% s0 r z - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% g% ~. i5 ^) o8 _3 i1 i - }; e1 f1 y* I9 [
- pose.pushPose();
0 E- L$ L/ Y5 A7 B+ k9 I r - final int newLight = convertLight(6);1 i- }4 B4 J& v3 Q. ^! Y- N
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& d2 J- I' a4 B& E" q1 _- M
- final float lineHeightSmall = (y2 - y1);, x/ c9 S1 m4 e* @
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( ]* x7 M, }9 @3 w8 h - pose.popPose();1 `0 z8 w* |7 r2 X1 l
- }* p$ F" I3 U8 C" j; d' `
- . g6 v7 ?$ ~+ u$ z
- private RenderType getLayers(String texture, int light) {
! J% j( h- V. E P |) C - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
% v- _; Q3 [" t7 r& C - }' W/ } A5 U( k& ?! T
- / x6 {) W( b( |6 n- k; k
- private RenderType getLightTexture(ResourceLocation texture) {* w ?* g2 I& X& Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);7 @: l0 R* N6 e6 P
- }4 h! e) ~$ g3 _. B1 r
- 2 r( `% d! b, s0 h3 ], T
- private RenderType getTexture(ResourceLocation texture) {
$ P6 l# y% T8 {2 ]5 K3 T0 \% o+ ^ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);+ c/ m/ X0 c7 p4 l. ~
- }/ ~2 N1 i+ I3 X0 Y9 H Y
- 4 Q# }0 Z. w6 k5 d9 W
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {) E9 k2 r+ v6 r, [ j% t9 n2 Y
- if (cache.containsKey(identifier)) {1 W9 i! P( z7 L4 G$ I
- return cache.get(identifier);
9 E- r9 _2 Y$ q9 N, k - } else {7 n* Z% N' V5 v; {( r0 c, [& f
- final RenderType renderLayer = supplier.get();
1 N0 ~9 m. {! F7 u- m" O' `2 ` - cache.put(identifier, renderLayer);- Q5 w E0 V* ^- p% @
- return renderLayer;0 j5 D; j1 p8 P
- }& u- o- E0 e, R7 a3 {' I
- }
' L& U# {1 t! Z8 w - }
复制代码 |
|