|
|
0 ? p0 }5 |. \7 C( S" o7 r行,这个怎么样- f7 D9 z9 ^) O7 Z
- package com.xhg78999.mtrfac.render;
3 q/ J6 u U: \ - 6 R4 R7 P) q8 Z6 i0 ?3 B
- import com.mojang.blaze3d.vertex.PoseStack;$ w9 ^2 z9 ~4 I/ B/ D" p
- import com.mojang.blaze3d.vertex.VertexConsumer;# A# Y, {' L8 K; [9 ]
- import net.minecraft.client.renderer.RenderType;+ z, Y U- t. x; j* {
- import net.minecraft.resources.ResourceLocation;3 b: M$ N5 ~5 x- M* p3 @3 x8 [3 [
* T D( l) A' ~$ u" g, c9 s- import java.util.*;, N4 g I8 s0 u" ]4 c
- - ]' U& m4 m$ F& K9 N D
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* I! X/ T* N/ j' r; K
- + [) I6 i0 k( e! q7 [8 W
- public class LineRender{
% ~& q t% Y& p# t - private final PoseStack pose;5 `* g# m5 U* _) z
- private final MultiBufferSource source;4 l" z8 \) r5 Z" ^* Z* P n
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
% U, V9 H# Q$ p+ W9 D - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();/ k8 @0 ~, v+ M5 |$ e3 J5 a
- 5 N7 A3 ~7 T# g4 I2 }9 y
- . P l/ n( `9 r6 ~" F `9 S
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
/ y1 G8 X" D9 I+ `/ j4 m! Y% L - if(x1 == x2 && y1 == y2 && z1 == z2){3 ?6 q2 K" @0 v0 E' _
- return;0 p; M# D: g$ A- ~1 H
- }+ L) i# \' h% N6 V Q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){/ G3 ~/ e; [9 d8 Y: S5 [
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 H$ e) p1 c' ?) Q1 h1 X! a
- }
) Q: [6 q3 |: G. e$ _: g - pose.pushPose();% v% s6 o+ D6 k; ^
- final int newLight = convertLight(6);* o) s' f+ ~! w: m
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ q1 y1 Z6 s' @' Y - final float lineHeightSmall = (y2 - y1);
8 F" u" m* {* x: Y2 F+ y1 ] - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; F+ a+ |+ E- D8 ?' e8 B2 }% U - pose.popPose();
0 Z; F8 G6 j; ]- ?# l5 h - }4 |; a. F# V4 @; @
- . W' H; R. {* y* k& N. k0 ]
- private RenderType getLayers(String texture, int light) {2 S. i, P2 `. B6 ?* d$ `8 [
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));9 F+ y1 l: V2 P) r; ^
- }
! a) F) C* U @. ?
* S) N2 M$ k" V* Y: M- private RenderType getLightTexture(ResourceLocation texture) {
$ k: D8 i D, E+ @- w) t" a - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 c1 q$ {; _) Z) T, `
- }5 Z# v1 K7 x# f) r% n$ F( C
- - h# e D, C3 j5 K. I& `+ Y3 r
- private RenderType getTexture(ResourceLocation texture) {3 M0 P8 i H8 K3 i& K
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);) C) ]4 a, z8 e) [* {" A; d
- }. V4 p( }5 l% i u
- ( G) F) ^ t( ?0 q: w/ g
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {' W; ~0 _" D2 h, ^0 w4 P( ]- d6 Y; c
- if (cache.containsKey(identifier)) {; J+ z2 a% l/ y2 z
- return cache.get(identifier);
/ G2 _) a% q0 ^2 p. `) x" E - } else {
* a3 r5 S& m' Z! s5 S4 f4 [ - final RenderType renderLayer = supplier.get();, b% b# U9 `9 J. Y: G$ o5 q
- cache.put(identifier, renderLayer);$ c* E$ k/ P" B7 q( ]
- return renderLayer;5 B1 ~/ m% c$ O
- }
6 B. M5 e. j s% A; Y( h - }
. r) [& l1 r, @- V+ @: F - }
复制代码 |
|