|
|
q8 @' D- [ _0 V- ^
行,这个怎么样
" ~8 k* D% m! @ J% c9 A4 Y9 A- package com.xhg78999.mtrfac.render;
2 c$ j5 E% B U, d& G$ g2 z - 2 m; R0 I: a9 ~# S
- import com.mojang.blaze3d.vertex.PoseStack;
- d* K7 T7 u& i6 g( p - import com.mojang.blaze3d.vertex.VertexConsumer;9 U, h2 {( W: ]! @7 x5 Q0 a
- import net.minecraft.client.renderer.RenderType;
3 v( H+ y; ?( b5 N, A - import net.minecraft.resources.ResourceLocation;. h1 j; `, m- v9 N! T9 W
2 i9 m8 ?3 S; y' D1 S- import java.util.*;$ b& Y4 I7 f$ y2 `' M0 z' T. x' i; E
$ \$ X' p: Y: P1 H c1 W- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 r2 W' V ]3 y* ^1 b - 9 T$ ]4 ^: M. M4 f$ \% F, m; i
- public class LineRender{. L+ w$ }, H; ]) U
- private final PoseStack pose;
* e$ c) x' |3 B3 T& y - private final MultiBufferSource source;
: ]8 @- v8 y V4 d$ |; r - private static final Map<String, RenderType> CACHE_A = new HashMap<>();& ^, k* t$ C/ R, [7 G4 a3 k# u
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();( T7 r+ K. z# T: I- ^+ }- M
- \7 K* S* c# S V; H4 l2 c8 a8 q
- 9 `- ]9 y! ]5 B; `
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% L- H: w, k4 c+ \ ^2 g, s- y4 M! `
- if(x1 == x2 && y1 == y2 && z1 == z2){
1 b0 u; \) {& E% ^ - return;
r2 F0 t; `7 O% t+ c+ ?2 } - }: S, B: g) j7 u5 e% r' B
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 U9 I6 ~ V3 z: V
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ n7 @- ?' Z# o0 Y
- }
! E, ?8 j% \4 s - pose.pushPose();
; Q& l- r/ C! N3 S - final int newLight = convertLight(6);/ F9 A @* ~) w5 `) e" k' P
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ D2 y" Z. y& V/ G8 w: K, F3 @) _
- final float lineHeightSmall = (y2 - y1);
& K6 i! Q$ S* D! h% x t4 o+ _ - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);% ]% \+ N8 k! O1 M
- pose.popPose();/ Y' B9 @5 [0 d& m2 b
- }3 o. `0 ]3 `, i( _+ L
7 V: V1 x1 c) ]5 u' K+ |, @- private RenderType getLayers(String texture, int light) {( o7 o+ Q4 Z0 Z' `: m
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
& d% x. n# G4 u$ }/ r5 K - }2 T& V9 w, o* r! w# o. X
- . Z( P" U+ F8 V3 N: G. e) @
- private RenderType getLightTexture(ResourceLocation texture) {, u' ?* h! p& c' U( P! S) S
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);" h' Q2 Q3 h1 ]' `, _
- }' L3 X* m" i5 i$ Y4 F. V- D8 N
% A; I; U, `2 {8 A7 m' w3 `- private RenderType getTexture(ResourceLocation texture) {- \) {" j$ Y0 n7 l0 f
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 L7 X$ K3 U* l* ?% W
- }) P$ H& R5 S0 b
% ^" C$ O$ j3 \1 o- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
% R: o3 A2 t& D( a8 S - if (cache.containsKey(identifier)) {
! c8 U r' \- F4 _: R! T& t - return cache.get(identifier); Q6 A* x3 [0 L+ q: f; b* B' n
- } else {
7 @! L- k( y) M, _' | - final RenderType renderLayer = supplier.get();
' Z% b) i0 \- h; A: \- T: p# | - cache.put(identifier, renderLayer);
. J! X5 V6 I3 L - return renderLayer;* l% g! k3 S/ I: |* F
- }
! k1 ?3 i6 Y/ J+ C/ ` - }; ~! A: a7 h3 P) W
- }
复制代码 |
|