|
|
5 U$ D! C) ?( M: T y9 f3 }% r
行,这个怎么样
1 v+ D0 @2 E, `4 h' c& T! q- package com.xhg78999.mtrfac.render;. K. t# M3 K. K+ G' X. U: N
4 R+ ?4 i, I, g& c- import com.mojang.blaze3d.vertex.PoseStack;
+ e' X6 F7 u f: F+ J" k - import com.mojang.blaze3d.vertex.VertexConsumer;
8 h* Z" h6 ]$ P7 S, x9 W9 t( M# G# N - import net.minecraft.client.renderer.RenderType;
2 `( ^: b, X& ^0 `% b0 X: Z; j1 V - import net.minecraft.resources.ResourceLocation;; T8 O2 F! w9 P, N
4 X4 ]3 T) D* M" X. ^4 }- import java.util.*;4 d. j0 x5 A9 d) r. |+ U
! s9 t+ q7 U# w5 u- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
# S' x7 B8 H# x- w" u4 @2 C - 8 A8 n+ v+ ^# v Y
- public class LineRender{) r3 M1 r* v k& {. v9 y
- private final PoseStack pose;
! @. Z+ x. Y: h: _ - private final MultiBufferSource source;
, U- `1 t6 x$ w0 K9 p - private static final Map<String, RenderType> CACHE_A = new HashMap<>();7 ]! O5 v8 X/ x8 R/ C
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 I' s" P3 {! y4 O
1 j9 a& Q" v. E, k. O8 ?
. I. G9 k( W [+ {+ S H- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 O# E! @6 m+ v6 b3 G' R7 b - if(x1 == x2 && y1 == y2 && z1 == z2){
1 Z* r: s) R, W8 w0 h1 |, R - return;2 }% _: w4 ] U. c, t# n- `
- } z1 K0 w" R9 o: z- `( K" E
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){' J7 d" V+ D7 E% O% I& {; a
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
: U6 {+ u; M! k- u' w& i2 R) H - }7 `+ F, r6 j5 L: O) Y
- pose.pushPose();) l, K) u5 s" b2 ]% k3 u1 U: l
- final int newLight = convertLight(6);
1 h4 x: _0 A+ ^# W; G - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
0 f1 E0 u' E- S1 L1 ^3 n - final float lineHeightSmall = (y2 - y1);
; b* v1 m" u: U( o! p: ^& D. \- r - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( @5 C5 q+ V+ n3 m, d9 k) g, l - pose.popPose();3 Z) |0 _2 w6 L( A# v+ |$ A9 I3 I
- }
r% K" L+ T/ A' ? - ' ?; B5 i: l5 M" U
- private RenderType getLayers(String texture, int light) {2 c: m+ \: X w1 A) J; x
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));8 {& t2 G+ z" Y# I9 u8 _: A0 E! f3 q
- }
[$ n! f2 ?. P; Z
; [) d& V. k' \. Q1 ^ z- private RenderType getLightTexture(ResourceLocation texture) {9 x. a6 r, i* v+ I% n1 i. V! v& C- G- Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 v* Z7 \" u4 O" _ - }
- o4 ]1 ~# d: ]" s - 7 z+ }# \2 w! c( {3 }
- private RenderType getTexture(ResourceLocation texture) {
0 e' d4 \! E) W N! e - return this.cache(texture, () -> entityCutout(texture), CACHE_B);6 w* @) e+ M; u) Z" U8 @9 X1 v6 R. k& a
- }
s8 @7 v7 y4 i& U5 T - ' Z7 D; I1 m5 h
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; E7 K! q: s& j% b: z7 ], a - if (cache.containsKey(identifier)) {( E0 {+ v4 d) O4 l7 T1 s/ m7 l |
- return cache.get(identifier);
. e. ]2 E* q& B5 B; K - } else {& y) {, w4 s+ w& p- Z" e0 U( Q
- final RenderType renderLayer = supplier.get();
- H% R' @6 k. ?4 k/ g - cache.put(identifier, renderLayer);: h$ {$ ^+ _5 V/ v
- return renderLayer;& b+ N7 \* D" L
- }( L" A3 {- b5 \
- }0 C0 h w' t' D5 ]2 H
- }
复制代码 |
|