|
|
* S& H1 t! g% Z3 a! ~8 A行,这个怎么样
. F6 L4 M/ N$ d7 f5 L- package com.xhg78999.mtrfac.render;
( M& y. Y B. |' u: ~+ o+ ~ - 5 E- M' \8 J% E
- import com.mojang.blaze3d.vertex.PoseStack;
7 u8 \: j v2 V- p - import com.mojang.blaze3d.vertex.VertexConsumer;: h$ Y4 @* \) n2 B0 p
- import net.minecraft.client.renderer.RenderType;$ A" N2 `5 X9 g# U3 o7 Y
- import net.minecraft.resources.ResourceLocation;
L( k, i: M! w% y' c
- j& Z7 I1 y/ Q$ p- import java.util.*;
2 V7 N" q# j2 W! f: h6 C# z
4 q: D$ D2 [! {* ]- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(! J" O- Q2 e ?; ^9 o/ F
- & T4 `, U! H. Q5 ~
- public class LineRender{& G( @- t" t2 l7 q' [8 D6 n4 i: X
- private final PoseStack pose;) p# D' W7 K, @- j
- private final MultiBufferSource source;. w+ \+ ~8 i. D# w& z' a2 b) e1 \$ _8 Z
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
+ C7 t" L& }* Q) R - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 G" x) o/ N: }5 H$ f - W& |# Y7 c# w( W) o9 g
- 8 |3 B4 s8 f1 G# V: T
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){4 Y4 y" }! W( _8 c" C
- if(x1 == x2 && y1 == y2 && z1 == z2){
# O2 z+ g) A( k7 K6 v( [$ `! W - return;
; w$ h) c: d5 D - }0 C& x3 m& Q$ C7 S d0 W7 O1 {/ u
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% g; |0 J" I8 o2 Q1 W - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
& ?+ ]1 R' Y, M1 C8 Y s* f l - }
# f8 z6 P$ Y: v; ^0 m- V, V - pose.pushPose();
& S8 O' O$ G1 C/ \, ?& S; c - final int newLight = convertLight(6);+ [0 e& _7 `7 D0 Y1 K" I, L
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
, w! I! z6 |0 s! h5 Q" `& @: ?) X - final float lineHeightSmall = (y2 - y1);
2 w7 [/ f# i9 K0 N! V, d - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
* L9 g0 I& }- k( g% s0 W - pose.popPose();; L0 m+ a6 v/ c0 u4 k
- }
. p6 O8 E; j; I6 ] - % x* E& G* g A7 M8 t9 {
- private RenderType getLayers(String texture, int light) {
" x* p+ w+ m! m - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, ^- u5 @1 U" A4 i$ ?4 B
- }
1 E* e" k) Q4 `8 J* ^ - # b% s) H0 d+ A
- private RenderType getLightTexture(ResourceLocation texture) {2 u: Q, a( `/ A# D& y k7 ^7 y* s8 Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
/ g) ?5 i! l3 G$ o) @ - }5 H4 O# i2 n7 ]* R% }" d
8 g. U( x2 o2 Z- private RenderType getTexture(ResourceLocation texture) {6 y0 c( g/ Y- {, V% `
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
) {9 Z/ B- Z: {% d/ a: e - }
1 c H; P9 A3 b
+ ^9 v, p8 M$ o! V( p8 O2 l- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 N; k8 b2 R9 g, \1 J" ]& U1 r8 X, O - if (cache.containsKey(identifier)) { a6 _1 N& z) H* J5 U
- return cache.get(identifier);2 Z% B1 E9 Z6 r. V* r
- } else {
2 I% Z4 R6 a$ z$ f3 X3 _% |6 X- J# B - final RenderType renderLayer = supplier.get();& k# U3 W1 ~) O" J: T
- cache.put(identifier, renderLayer);4 `; z( C- b' t! a4 Z
- return renderLayer;
5 `, E4 A; G- `' D7 o - }" L7 B) W* d4 g# V! n3 i
- }! \5 Y6 L. O8 V- b9 u2 Y8 @
- }
复制代码 |
|