|
|
& m6 y% Y9 Y+ I" a3 P" [6 l
行,这个怎么样
5 z4 ]% R; P6 z8 u* L- package com.xhg78999.mtrfac.render;' l+ n4 z( r# Z/ C
9 b& P6 v, s0 p( M+ t( s9 p- import com.mojang.blaze3d.vertex.PoseStack;, F4 Y5 T( X2 o. O0 ]9 B( d
- import com.mojang.blaze3d.vertex.VertexConsumer;& w+ T* N Z% `' Y: `
- import net.minecraft.client.renderer.RenderType;
, G" Z1 v" e* O4 U/ ]4 f% ^ - import net.minecraft.resources.ResourceLocation;
. S8 L8 d7 T% c+ A
- }4 }2 H: q# G- import java.util.*;8 m/ w! ~3 T* u; \
- " C* n5 C( n1 `3 a( ^ R# n- o
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(7 I% D- F) S3 M" q5 \. V* g
- & b- M7 q2 D6 e+ w! ^! B' i! t; m& V% H
- public class LineRender{
3 L0 ?- x" y) e4 |& C! U9 S - private final PoseStack pose;+ ]5 }, a1 t+ P% [ c& M" Y$ z
- private final MultiBufferSource source;
4 o! q- t) K$ S - private static final Map<String, RenderType> CACHE_A = new HashMap<>();4 O* o: `5 \8 q0 j
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();! n, h. c. v. s/ m3 F; h5 `
- + M& {" m6 s" q! ]
( @, Z+ R+ i1 t- y* X- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){, D9 x$ c6 ~6 D# `
- if(x1 == x2 && y1 == y2 && z1 == z2){
. ?$ |( n# m- ^" \ - return;
" n3 H) l' l9 f7 @ - }+ h# e7 Z/ L* n% [0 k3 i/ X4 D h
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){- m5 F" q3 r. G' G) ]
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 V5 [9 v; Q/ J7 O1 `. V- A+ A
- }
+ K4 N/ p' ^$ ]+ x - pose.pushPose();
/ X) p& p& y" [) f0 \! a - final int newLight = convertLight(6);" O v5 |; B% g, J3 `
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 n# D) r3 V" I; ^1 f7 N - final float lineHeightSmall = (y2 - y1);
; \3 q$ [- A; i7 f: Q! q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
& ^. K+ J& w% K9 H/ I - pose.popPose();
" y- ~( e( }/ u% @( Z8 d. j - }
1 R) w* G' \# U3 C: i - $ m. T) |3 i$ A" t
- private RenderType getLayers(String texture, int light) {
O, h8 g! y6 N% ?0 `" D/ L! S - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
* j7 [, J# B( q8 O& X - }1 _# v% K; g; P' V% U: \" a
* X, I) _! r: n5 t8 z+ J- private RenderType getLightTexture(ResourceLocation texture) {
5 L3 p( v! L1 x0 f1 [( Z/ A - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" Y" S! l' M$ X) Y
- }* G- N3 u8 h- x. r! ^4 ]. B' M1 E* u
- 7 |4 X4 z& l" N4 j6 m- @6 a
- private RenderType getTexture(ResourceLocation texture) {
7 ^% U$ m' f# s: F - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 F' E+ z9 z, v% h* m0 a - } e8 z' H/ f0 M* T9 ?5 P7 ]2 m N
- ' F9 h( K0 n/ {2 k1 ]* T. j
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {3 G7 w5 e4 x& k x& ~$ W
- if (cache.containsKey(identifier)) {8 ?& Z0 A2 H) m c' N9 b
- return cache.get(identifier);
; x& s+ m: V9 @( E& { - } else {4 I" I: k( T# ], W1 J% f2 |, \
- final RenderType renderLayer = supplier.get();
1 z4 W! ?/ X* ` - cache.put(identifier, renderLayer);
9 u% h. {% n/ k' I) B' |$ g - return renderLayer;
, z& }" [5 u2 r5 Z2 D9 G - }# ]' T: f5 Q9 U8 U+ Q
- }
8 ~9 [; H/ _$ B9 B% \, \ - }
复制代码 |
|