|
|
% g% d) ?' U8 ~4 N行,这个怎么样. w8 s% ?5 w7 I
- package com.xhg78999.mtrfac.render;* v) y6 k7 ] a7 \) u3 L
- & ~7 R+ _! D1 N2 X+ U" \4 C
- import com.mojang.blaze3d.vertex.PoseStack;
2 ?$ K" \' N1 p% u; x - import com.mojang.blaze3d.vertex.VertexConsumer;# S y) Z2 e4 ^7 i
- import net.minecraft.client.renderer.RenderType;
: s5 K4 D) u; M& I+ V, @+ ? - import net.minecraft.resources.ResourceLocation;5 W! ^% q# C7 K% z
4 U9 n- `4 S" F" ]- import java.util.*;7 }3 \1 M2 K8 I8 S6 }
8 C" Q8 C3 _' [# b/ r/ o5 M- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(7 d0 m. J* ^+ a/ O A; w+ U
7 X8 O0 s$ j: Z4 G2 Y7 q- public class LineRender{, _7 `; S F" M( {$ q- J1 c) }
- private final PoseStack pose;
) m3 n/ |; e6 B - private final MultiBufferSource source;& w/ B [2 n. J3 V$ l: T
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
4 U9 Q4 i, A. l. K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 Z! z2 ?- R+ d$ K% t
- 0 l3 Z; A; v, e
% w6 u- y# j* ~3 B& T* V: }- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){$ C: L$ c( o+ Y( V
- if(x1 == x2 && y1 == y2 && z1 == z2){- H! S( ?2 J4 P w% J, T2 n1 m
- return;: N" L8 \9 O, _3 x2 l, C' k6 \+ f
- }1 R/ s8 Z% E( Z4 D p6 Z! m
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){" r8 Z( v; y2 ~' ?( D8 X
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% _% m4 C8 u6 K! u
- }# |5 {- t0 `* A% _. \% X& P
- pose.pushPose();( t3 K6 ~2 D& l4 a; m: O2 S$ l( k+ z
- final int newLight = convertLight(6);
$ f6 l0 u2 z# K; ]2 h( J - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 E/ Y2 ?% l+ B, @/ S/ A+ _ - final float lineHeightSmall = (y2 - y1); `/ m5 X" B6 D% h3 I ~, v+ A- w
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);) J. _5 j- h/ G
- pose.popPose();
* `! A( |- w- @2 J2 w - }
* T0 U$ M/ }3 x: f - * _ t n7 w. e" P" o3 r* X& [
- private RenderType getLayers(String texture, int light) {
- F+ Z+ {( |: x7 m% f, R' ^2 c - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
$ z8 i5 L' A$ N) D3 T% A - }
' G- m9 g1 I8 ], A% [. [
/ M, p2 N/ t% H1 R9 c8 W- private RenderType getLightTexture(ResourceLocation texture) {
8 |6 l& ^% L9 q% n7 A - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 p% }" y0 k% v h/ n6 \ f
- }
3 R8 `7 Y/ D! }- N5 B* p8 g
8 r: Q5 J' m8 P! h; g& {' T- private RenderType getTexture(ResourceLocation texture) {
, z8 V6 Y: z% Y9 y - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
/ U# F2 S, j5 u - }* u d1 B* {. r1 y* E& P/ Z
- 1 q3 e! \ H# p2 N
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 K1 B% {& {5 o6 X - if (cache.containsKey(identifier)) {
* M7 w( f' q7 m9 |2 l - return cache.get(identifier);: U2 c6 c m- s: ?- f2 ^
- } else {4 S7 L, {7 W! H* d; G( r I/ ]
- final RenderType renderLayer = supplier.get();
- _4 y2 z" v* }! S* B% y: y - cache.put(identifier, renderLayer);8 x5 f p& c# v; I4 U, W1 d
- return renderLayer;% [! e0 [+ }6 g9 @
- }
2 H+ E6 A, Q q) k. { - }
% @( D' q- l/ k" h, \ - }
复制代码 |
|