|
|
: M/ T8 ~3 S1 E6 ?行,这个怎么样
1 m# O# j3 \7 y/ \" A" q- package com.xhg78999.mtrfac.render;
% }( T0 Y% Y# d/ b
2 @ ]: X& i9 |0 q8 N- import com.mojang.blaze3d.vertex.PoseStack;8 Z, A9 c! l4 s1 U- q; a
- import com.mojang.blaze3d.vertex.VertexConsumer;1 \1 Z, x g* d7 o
- import net.minecraft.client.renderer.RenderType;
, s% K( `* [. Z* t' ~" t - import net.minecraft.resources.ResourceLocation;
8 D3 m* e$ f P d+ A& I8 D
. F, ]) P3 B5 [* W+ N; W1 x- import java.util.*;5 q% [4 ?: _0 F) j
+ ^7 x# [1 n& S1 c) z8 p f- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
* T" e: i5 _# g( q5 T
! l, u% n! A* v$ T4 g- public class LineRender{
% p5 \( o( b9 s - private final PoseStack pose;
6 v- Z2 D! S6 a7 q9 D1 t% f - private final MultiBufferSource source;* k' M3 Z3 `. ]' R5 \# Y9 m
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();: v" L$ _! j- f0 j7 t& }
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
! c) L) q, b# _& _9 i: U$ G! v; n0 p - 2 _/ S9 Q i% J* L$ j R2 z
- 6 V! C7 J$ F I5 h0 {7 \
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){% u& K5 M: p6 ^
- if(x1 == x2 && y1 == y2 && z1 == z2){: r+ Q& W; h$ m0 ^. N( d8 g& l
- return;
* K8 Y+ e' H- i - }
9 k' w+ v1 [# C; s7 k6 O7 A" ~ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
- w2 v# s/ i$ j+ U) Q' ]# ~+ u - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
# y* o# Q& M1 G1 t/ m& @/ H - }9 }: |! a5 |4 e
- pose.pushPose();
6 h3 V3 K4 E/ H - final int newLight = convertLight(6);" n) Q$ } Q' P. J) s
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));6 }. O, W a6 G! g
- final float lineHeightSmall = (y2 - y1);! A: y' l( Y6 _, Q4 w% w. f# h
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( _" V; n: Q, ?# o5 h - pose.popPose();; c/ l8 S, f% P: \, r6 Z* V
- }0 `# {# n- |- ~( @) x9 c' {7 M5 L
+ J2 S" r( f& F5 }- private RenderType getLayers(String texture, int light) {! s2 V% j" Y* U9 f) S
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! d- {7 i4 k& X7 O - }
: x3 v8 Y9 W$ T- p& W k6 h% m& x - 4 \ ~) j5 M' w' V( p- c
- private RenderType getLightTexture(ResourceLocation texture) {
; z. N) ^1 ~! A" x; ~# @* ` - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# p( J* ?8 _# Z3 c0 ^ - }
+ \) t0 _, g& g" o; T, k; k
4 s/ o' `5 I+ }% X2 z3 @- private RenderType getTexture(ResourceLocation texture) {
, g5 t4 \! k8 P- U) _4 ^' I8 x - return this.cache(texture, () -> entityCutout(texture), CACHE_B);/ M, ?) j5 X( M* T
- }
! [6 z8 g2 m: ~7 H9 n& X
]. z6 c) [4 g, j0 @& z/ M# f- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
# j+ _$ u# a9 b/ s' B; a3 ^) S - if (cache.containsKey(identifier)) {
: n, d! e( N- a4 Y: z7 L8 `- c - return cache.get(identifier);
1 n0 |, k$ l8 {8 w - } else {
1 _/ C% K1 ], H - final RenderType renderLayer = supplier.get();; z L0 j2 e4 o& O% ~' l6 e& e& D
- cache.put(identifier, renderLayer);' E. J. j( |2 {
- return renderLayer;
1 u8 K% Q3 V/ ~* F8 O - }1 N: Q# ^3 W5 v6 P
- }
1 {) v' }8 r7 P5 c0 s- C( I - }
复制代码 |
|