|
|
7 N6 g/ B4 _" B. k8 X
行,这个怎么样. C1 d+ E5 T4 h4 E9 U
- package com.xhg78999.mtrfac.render;" P$ _1 \! u( p: i: ?7 h
- ' @& u7 Y# A' v* r
- import com.mojang.blaze3d.vertex.PoseStack;
# L+ ]! s% O: r/ x* X. L% H - import com.mojang.blaze3d.vertex.VertexConsumer;
; m* s& {9 ?5 g$ K" F% I" G - import net.minecraft.client.renderer.RenderType;: O) s3 E/ x' F2 m# ^
- import net.minecraft.resources.ResourceLocation;
' Z( o) U% T" T- p9 x# y1 Y2 M - 6 F7 U; s- F7 L7 T' E4 \
- import java.util.*;9 ?% Q. r& g, F% Z4 c: y
- + W% J- Y) Q$ F' P1 O. L
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(6 h8 W( g; _/ L) h) M) l5 q
- ; [3 o( k. L* m
- public class LineRender{
$ W; @1 M4 n0 C& a; I3 u - private final PoseStack pose;
* ?1 Z0 B/ O1 o2 e4 ^4 X9 s - private final MultiBufferSource source;0 D" I' f6 t: J: J+ j) Q, ?0 J
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: r+ C( ^# ]6 v6 {! [, u8 Y# E - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
3 q0 C4 R: ^/ ~9 ^& W% ~ - 4 {& z' i. S2 H) U8 b" Y9 H' G
+ F& }- e( D! j, @- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){; G ] l- c* m' [
- if(x1 == x2 && y1 == y2 && z1 == z2){
9 G, {# j8 K2 l8 l - return;
( C' E- c. z8 q$ X - }
$ S& G* t0 ^" z9 s$ P1 V9 t5 b - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
1 s9 i3 y& M7 y0 M; F - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");4 z$ r5 i- e" E, ~
- }# G, X' L' |$ @
- pose.pushPose();# S( L9 O8 `, }
- final int newLight = convertLight(6);
( ^+ X6 I4 M: |+ R - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 I: ]( a# U" Q# B! ?3 x" a - final float lineHeightSmall = (y2 - y1);7 m) Q2 j: a+ e" `+ w
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" A. W+ B, T% Q5 G9 Q, l2 C - pose.popPose();
3 T- U. }6 X, v! d4 w+ Z - }
7 l/ T# w, p- C, ~
c" h# Q" D5 |( ]- private RenderType getLayers(String texture, int light) {
& p) {9 r% Z$ [) b# X - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, _( M% D! A( M; w
- }1 T7 i, b s4 _4 l! A, b! B
- ^* R( W5 o J+ F9 b- private RenderType getLightTexture(ResourceLocation texture) {
* \2 {% w% I; p1 l; S - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);. X. M4 C3 F& w6 M
- }6 ^7 L9 f7 E, }! W* K. q
# d [- u, Q1 h5 O- ]& x2 C9 M- private RenderType getTexture(ResourceLocation texture) { h7 l: x$ a# o
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: e; i: i! w; R% C" [/ Z - }+ X' H: ~8 n8 O9 U9 B: @
% ?- C" v1 }$ O \6 Z7 I- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 Z8 i8 E- |5 H" s5 a - if (cache.containsKey(identifier)) {
/ }% E( y/ @; W - return cache.get(identifier);
- @, E& f/ d0 n% o/ T0 T - } else {
y. n Q' n" ^ - final RenderType renderLayer = supplier.get();( t# m" |2 s+ e0 Q ~& M4 x$ S$ W7 K9 Y
- cache.put(identifier, renderLayer);
' o- ?9 N+ ]3 U. n" x - return renderLayer;
9 u; R4 ^4 D! Q0 }- B5 m! ~ - }2 V/ S* P; P0 x Y# U$ G* V( D
- }
! i+ b. C0 X8 y8 o2 u - }
复制代码 |
|