|
|
; R. D: u$ T) V8 x8 `0 G行,这个怎么样
# S0 A; n" b! D" W2 K- package com.xhg78999.mtrfac.render;
0 U) V; Q; l4 Z, @' j# f
) u/ D; x) P) g3 Z- import com.mojang.blaze3d.vertex.PoseStack;7 n. J8 n+ {' G/ t! e
- import com.mojang.blaze3d.vertex.VertexConsumer;: P( V" l0 p* t$ I0 g2 y; e1 I9 o( a
- import net.minecraft.client.renderer.RenderType;1 \* D7 k* o/ M& f
- import net.minecraft.resources.ResourceLocation;3 [% ?5 Y2 o( M9 Q" C, F
7 A' h& R5 @1 M r, w- import java.util.*;) Z1 t1 o7 T; c' n$ f
1 k3 O$ E6 Y8 Z6 m$ Z- w- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; S/ B/ z4 O( e( ]# p - 4 }( s& n/ M4 F, b. L& v) ?3 ^' n
- public class LineRender{
" o( r! r( [/ {. I - private final PoseStack pose;
4 d/ V! c; G+ R+ ` - private final MultiBufferSource source;. c. b2 v1 B' r5 X0 j. D
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();% z2 g* V$ J5 g* ^* I8 V- I# O
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();; H% B3 ?/ t) T, X- E2 |4 h5 R
4 q- J/ n7 m: s$ r% `/ [8 S- $ _8 m } _: D8 \; Z3 T h
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){7 r [8 @; B4 H% ?2 k9 Y
- if(x1 == x2 && y1 == y2 && z1 == z2){( W/ _1 c; h' h, j
- return;$ Z! N! f- x) r
- }) g) u2 M2 Z f# y4 I1 x; F/ K' V: m
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
' q" Z* |; _" C" x# d - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");. U: }! e6 P4 f1 U7 r
- }, }4 C% M S0 U' i ^
- pose.pushPose();
1 l6 A% r U7 {6 }9 D! F - final int newLight = convertLight(6);
; R% z6 L4 p, f1 c - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));% d i# Q) ]9 M
- final float lineHeightSmall = (y2 - y1);- m# p% h1 e. E7 n9 t' ], H
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 p1 [3 U) q+ T3 J5 H& a - pose.popPose();3 o- T# ]$ A; o$ W4 c% V
- }2 f z& R+ L& S. i
$ k2 e& U, Y' X/ v2 Y- private RenderType getLayers(String texture, int light) {% M9 a. G1 _" Q/ q @3 {1 E& p
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));- d5 ^0 [. q& [: K' U4 E2 L' _
- } T G( z/ g+ a6 ~7 H6 A/ A% X
1 a# u+ j- v; k+ l- private RenderType getLightTexture(ResourceLocation texture) { ~+ q* [5 e- S( {, j3 _
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);8 c3 {, X& Y" K2 i C
- }
! a4 J U @" M
; X8 N' x' O3 _9 K5 O) g: G- private RenderType getTexture(ResourceLocation texture) {
; s$ q6 Q$ v+ ]% `5 |2 E- ]7 Q - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
2 e3 y( v" D0 s+ r+ _5 E - }
8 e. F l" P$ e, K: m - C2 \0 I; |7 B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 q7 g# E0 B* `; a: ^+ Z
- if (cache.containsKey(identifier)) {
( g* l8 j/ A/ b - return cache.get(identifier);9 ~% E' d( d" Y6 h9 Q/ f4 T
- } else {
+ W* @, E o) u1 o+ _# h8 | - final RenderType renderLayer = supplier.get();
2 M6 A1 t/ L- d$ f5 y* ~; r - cache.put(identifier, renderLayer);
! [3 y3 s8 M/ k# h - return renderLayer;
; D# v' }1 ?5 ^7 G' f9 k3 k0 v - }
( p* X0 E6 \" `; b8 L {+ _6 `5 r/ l- h - } H: U- D4 S& w) ?- }' ^
- }
复制代码 |
|