|
|
$ \3 D2 X! L) n' S% z7 _) U9 l行,这个怎么样
# X$ n+ D2 d, a5 d- package com.xhg78999.mtrfac.render;/ s! x6 u0 q. x+ j' i- t3 `
- 6 D: p1 y+ |+ e. Z. W3 ^* U
- import com.mojang.blaze3d.vertex.PoseStack;
& m* g H, |; T - import com.mojang.blaze3d.vertex.VertexConsumer; U6 d6 @2 V! F' x% R F
- import net.minecraft.client.renderer.RenderType;5 N9 P# A1 Q" W- V+ M+ ~
- import net.minecraft.resources.ResourceLocation;
% Y) j3 y; Y/ |8 c/ \ - 9 A% G' c. h& g% v4 T
- import java.util.*;0 ~% B6 x& W+ P3 B/ s7 W
% l+ z1 m, c! n- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" B8 q* {+ _6 Z+ t* Q# f$ V
( Q. \5 d$ {; r* e( d. j5 I- public class LineRender{* }, _7 a) _& y5 V
- private final PoseStack pose;
/ }: p: a" U4 r; E1 M4 W# v$ z - private final MultiBufferSource source;
* U8 j- d; H; T% b5 @2 ^ - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
/ ]" W( J" x3 |- {5 g - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
4 e5 `' H7 [% h. c- `4 m9 H - % Y7 w( H; ]1 B
$ [! I+ ~& N4 t7 v4 p$ f' r- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 q: ^, l0 e, ~& k; A; W5 [' R
- if(x1 == x2 && y1 == y2 && z1 == z2){
q2 r9 v9 F( L( U6 g. W: G. s - return;' V( _2 ^' y' Z. P; V
- }0 n7 P0 M' s2 Q2 Z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; J @( D$ w Q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
8 p ~) g, h2 I, ?" I - }. R! a7 P' M- {
- pose.pushPose();
. i! r: E( W! K+ Z - final int newLight = convertLight(6);9 y$ l$ x3 ^ R. |. ^
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 E9 X D( i; p - final float lineHeightSmall = (y2 - y1);5 {* @, ~( X4 D* x f+ u" m' H
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);5 S4 b( J# r" C A/ m h X2 ]9 y4 M
- pose.popPose();
( b5 ]# K7 w: V6 g" s$ m/ d - }
3 Y9 [4 I* e( } - * L0 [1 Z2 H/ I1 u, x- x2 ~; o
- private RenderType getLayers(String texture, int light) {
3 N$ d; o. R; b" C k# q3 n - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
% O% I( d5 A/ U - }( T6 x! r, J: H; W t
K' Q9 j( F% `0 d- private RenderType getLightTexture(ResourceLocation texture) {/ ]; v4 l) i3 \' X/ o7 k/ M
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ s; D9 b. b8 V+ ?: p
- }
) r) O4 q; |+ S - 6 J9 X" S% K. h# e+ L) X
- private RenderType getTexture(ResourceLocation texture) {
" N6 H( a) [- B; E% {7 m - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
: P. Y" p- e* C - }
1 {3 {- e* K* Z- v6 Z - ; q" m1 ]' c/ ]
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {1 K$ A Y; L$ ?4 q
- if (cache.containsKey(identifier)) {
7 c* H, }3 j, i" M' _ - return cache.get(identifier);
: ~4 f7 r% b8 ?& b - } else {
1 W m0 V3 o# Y/ x - final RenderType renderLayer = supplier.get();
; h, g& D& d" z - cache.put(identifier, renderLayer);6 s' x# Y4 [& R! q k/ u# L$ [
- return renderLayer;
: ?) H, K n0 E" H/ F - }2 n" ~5 `! A( O6 i. F
- }
; v* ^" j5 b9 I. X - }
复制代码 |
|