|
|
6 ^, a! w0 Y5 a% N
行,这个怎么样' d8 N+ F) }( U: A
- package com.xhg78999.mtrfac.render;- s! `/ G9 o+ m6 f. ^4 K+ g
5 U1 g- D0 {* p9 x5 N; J5 c1 O- import com.mojang.blaze3d.vertex.PoseStack;, A8 ]4 z2 R M/ `% [
- import com.mojang.blaze3d.vertex.VertexConsumer;7 [. r- }3 ~9 V! T4 N# e2 c
- import net.minecraft.client.renderer.RenderType;8 D1 F' P5 \8 c; E' U# z
- import net.minecraft.resources.ResourceLocation;
; u6 c* l( ]3 S7 G1 c - ' Q9 B2 T' Q9 y
- import java.util.*;+ v0 ]9 a S% Z$ L2 c' g
- : y4 l( i; j9 P/ d. f- l
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, u. l) z, G/ W
- 4 X& T9 q( l6 [8 R' k- R$ [7 f8 x% L
- public class LineRender{0 r$ C) \; X0 J$ g# R' M
- private final PoseStack pose;( r& Q8 L6 N' z( F: {; Q9 V4 j
- private final MultiBufferSource source;
' h% Q+ Y. t" F: t' ?! K; i - private static final Map<String, RenderType> CACHE_A = new HashMap<>();# J1 v9 Y w$ A2 ` J% S0 g& M; S ^
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% m: T6 F# ?; b. _6 z+ ?
n2 u$ k. I- ~
- s$ {; B- ~( k- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){) |* y5 w$ u. b6 m/ M8 B
- if(x1 == x2 && y1 == y2 && z1 == z2){
: j$ F3 U2 |4 a- W4 { - return;
0 E* v1 G+ D! f- i, d/ l - }; z; [" o8 a8 e( `/ q' b8 q( _
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 n2 {5 F0 K2 e. t7 |& d* | - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 {4 q% Z G. A
- }
3 B5 _' J1 g& H' D - pose.pushPose();
. F! k' d9 o: {- i; { - final int newLight = convertLight(6);8 j4 t* W1 e( W9 I2 F
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
% q1 e4 X3 l+ m; w: {; V - final float lineHeightSmall = (y2 - y1);
3 y( T6 l4 g/ k+ b - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" |% |1 }3 @/ P4 T% O4 t5 S0 Z' W5 a+ M E - pose.popPose();
) s% M- C7 R5 ^- ] - }8 j/ Z" ]4 V) \6 Z0 {2 s" ?
- 8 m" Z/ ?! H& E/ s! D8 q6 `9 Y
- private RenderType getLayers(String texture, int light) {
3 ]3 y" g. N9 l% p' v5 }1 [1 { - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
1 F# `$ m4 V( \5 B3 j - }+ r' u# e7 V/ t: T* E/ I- L
- * H M& F! X c9 n* c" q5 y
- private RenderType getLightTexture(ResourceLocation texture) {
" _# B$ L |' k1 }- ~* v - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
4 N2 F5 s; W8 Q* p8 Z$ t - }
: ^/ T% G$ A* e/ i6 i
! _: n* L: y; k4 D- private RenderType getTexture(ResourceLocation texture) {4 m2 o# _) J* }7 A2 Z
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
K$ J4 N [" ]+ x - }
$ z! p9 w* A3 |' B ?; m) s - ) J+ p' [$ \/ K1 F8 R8 M
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {. B! P" I# {% l9 P! E& Y, b" U, X
- if (cache.containsKey(identifier)) {
" h1 B8 p6 v5 p3 C& T- ] - return cache.get(identifier);7 r3 c1 r+ Z+ z* ^& {! E0 q
- } else {
* D- |" C1 q& k; _4 }- e - final RenderType renderLayer = supplier.get();
+ j, y4 T, r1 M& D8 S$ }$ _$ D - cache.put(identifier, renderLayer);6 Y" o7 ~) j' Y1 W( |7 `3 \
- return renderLayer;% s( _# q( `4 r* q
- }
% Y( [& l7 G/ n( K8 M0 Z - }
4 g( A9 S8 x0 O% a d: B9 N - }
复制代码 |
|