|
|
; a' K* Q, k( P- t) N% ^( X行,这个怎么样# k; M( i2 g) q' t5 a
- package com.xhg78999.mtrfac.render;
, z3 w: S% x6 }( d7 I! x4 m. A; C - 4 [; f9 a- E' l$ L# b4 F( f7 T5 k
- import com.mojang.blaze3d.vertex.PoseStack;; E& q3 B6 @( z: B+ {! P! E
- import com.mojang.blaze3d.vertex.VertexConsumer;
T: J; _7 \- o' J7 V/ F( X - import net.minecraft.client.renderer.RenderType;: z* a9 g3 q0 P$ w/ @
- import net.minecraft.resources.ResourceLocation;7 a) {/ J/ ^& }, F# y# t- ^! {# x
- ; A% M5 W" v2 N6 Q( Y& B$ F! _. B: c
- import java.util.*;' M7 P* u# l7 W9 n9 r2 |9 n* C
- 2 q( T1 `/ {3 a0 G0 t/ b
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
. P0 B6 J) Y) h( [ - - w: e1 c: [4 W0 _, E. u
- public class LineRender{
+ A4 P) T% p1 [$ I8 ~ - private final PoseStack pose;
1 Y$ t) H5 p' K: L! ] - private final MultiBufferSource source;
! F$ p$ y/ A, Q$ L7 M4 Q& F - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' A) l* ^5 \, U0 u5 V9 l5 h - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) ^* H! }, q( s& [9 v8 F. C
- $ ? b0 w Q, U0 V# |* {0 i
/ r$ G( a+ O4 y7 D+ D; I- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){# Q6 ^( F# `6 E6 [, E& T
- if(x1 == x2 && y1 == y2 && z1 == z2){ W* H6 J$ Y- r2 |4 w* ?6 Q" F
- return;
2 F6 e# s! h. h - }5 W8 [+ O/ V& n9 ^0 T" x4 a1 n; X
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" @1 o' ]1 I* s m& r. M# V3 A - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 o. b) L8 t* Q& D# x - }
; F8 b; L" `6 n3 O, k" M - pose.pushPose();
/ F, m& S; F, G" h' A; q - final int newLight = convertLight(6);
* p( \- X/ W$ M1 a - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
" }- E9 F/ I! w, P( a! g - final float lineHeightSmall = (y2 - y1);
" U% N- y0 h3 R' z$ g* R - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
1 X0 n( @( _4 k0 z - pose.popPose();8 K$ c8 t/ |9 W' q; R
- }
. o# w( f2 g( {; q
$ A# u& p+ q" g4 N5 w* l5 p- private RenderType getLayers(String texture, int light) {
+ k/ i3 ~$ H1 r% E2 y6 n - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));1 G8 {5 k ]: T0 G5 Y3 Q1 c0 b6 C' v4 w
- }
& R% ~$ h* |, T4 f
9 F6 N3 ?" R+ o/ ?- private RenderType getLightTexture(ResourceLocation texture) {
) u+ ~; i1 K E - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ g" ?: t( K2 }$ T( k: I - }/ L$ O8 Y1 }) L3 F* X
" k+ t3 ?- R& T: o" S. ^. l- private RenderType getTexture(ResourceLocation texture) {* K- P4 u* J9 B& t
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);, J/ L& ^4 M, }9 [+ R- z
- }- X; c/ q4 |" t
( G; H7 S9 X8 ?6 P9 m5 Q1 j- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 a- B4 ]: M0 _9 s: w: s
- if (cache.containsKey(identifier)) {2 v1 W6 ?+ G+ a! i6 D( M
- return cache.get(identifier);
' }0 y% u( l+ F( l0 n - } else {
: d0 g/ f5 [. t1 j. ?7 k, h - final RenderType renderLayer = supplier.get();
) T: w/ c' J) d- G - cache.put(identifier, renderLayer);+ O" r& v0 V6 D: I& J
- return renderLayer;
3 ~: \4 L& l# y x2 d - }/ L1 A: P/ `% Y
- }5 ?, Y" z7 M2 J# o$ g+ {
- }
复制代码 |
|