|
|
1 G C3 ?9 \ }+ `: M G
行,这个怎么样
/ i/ x& m( M6 l" n* h; T/ H O- package com.xhg78999.mtrfac.render;
% M: `5 _- O7 U. { - 4 i) h5 ~1 H$ j* R" z2 L6 c
- import com.mojang.blaze3d.vertex.PoseStack;
: `2 x! D+ J) h3 @2 o! ]8 ] - import com.mojang.blaze3d.vertex.VertexConsumer;
: S: S$ u/ j" K( a - import net.minecraft.client.renderer.RenderType;; N. W2 o$ ?% a' R- [8 Y+ {2 j! V' ~
- import net.minecraft.resources.ResourceLocation;+ Y: m4 ^+ y4 _: K1 {
* `6 X7 c: B# [4 W& I% g- import java.util.*;
) u w* c d, ?8 o - " B/ f7 C* g9 c7 d
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
" [! Z, P. T/ ?6 z1 ~ H" P; T
# M( C9 O8 z: e4 l. l- public class LineRender{9 I( B8 T, o- E X5 O9 \
- private final PoseStack pose;" M. C6 C- c3 S1 d `- G+ N
- private final MultiBufferSource source;
9 d1 n' \7 T" C$ h! k# h. L - private static final Map<String, RenderType> CACHE_A = new HashMap<>();: G9 p3 X3 D" \& `
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
0 H: d. }, j S
- s( D9 R! s5 N8 ^ x- 6 T& \3 a5 R' J: M) p
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 [+ v8 w' b, ` K/ x3 E - if(x1 == x2 && y1 == y2 && z1 == z2){ S; y0 h; r5 z$ M* \' `5 O; m
- return;$ b7 `. j: A% a9 x
- }
4 S1 D1 I4 Z7 D) q' K7 {+ R7 ~ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
2 r- R# @; m3 s w* ~: I. ] - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ O% O( ]3 X& w" a; [; u
- }
3 c/ V9 L. g; t2 i0 p/ Q - pose.pushPose();3 M1 X; K4 |; S: l+ U
- final int newLight = convertLight(6);* t, r+ {$ ~9 m: w7 j; G5 [
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
9 x s! j1 Q2 k - final float lineHeightSmall = (y2 - y1);" o# E- n1 K; _$ H9 ~
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 ?9 Q9 S; E1 g7 W! o9 {; ?' n
- pose.popPose();
' e1 o! k& r9 J R1 E* f - }# J% ]" F4 S I
' k7 P# g5 j$ @- U- private RenderType getLayers(String texture, int light) {
* i1 ]7 e& d/ w5 `# s' T( s - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# A$ C% e3 B- C - }
# |' e; h0 P2 J- v# ~/ b Y& Y
# |! g+ V1 x' _9 D) ^* l! m# Z- private RenderType getLightTexture(ResourceLocation texture) {
# G9 K, T$ M/ z- {$ E+ |. @ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
; m$ R! H2 e: h2 @ | - }
& r. ~& h+ ^: k" c - + ?% R8 @& U4 f
- private RenderType getTexture(ResourceLocation texture) {
0 ?9 N2 f' w6 J- Q$ B+ _ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. {' d& u% x8 Z3 J1 H - }7 G3 K. u5 Y5 V2 h D4 n( w
/ ~5 K5 \: B, @8 x9 [9 R- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
1 _" V. e# G7 ]: Z- p1 K - if (cache.containsKey(identifier)) {
, T: [, T: l4 P3 V1 v( V" L! z# L! M - return cache.get(identifier);# F0 \- F2 f- W6 t+ d5 I
- } else {
4 Q* a& T2 x* e4 v# R5 E3 c# F8 p - final RenderType renderLayer = supplier.get();* q! F9 E- ~* \# Y& ^# c
- cache.put(identifier, renderLayer);
4 W2 r1 f1 N( }" F u" j; x" Y" P - return renderLayer;8 O- q3 ^7 q/ \! W- N; O8 C- e
- }
8 ~4 t& P, E; g+ ]4 Y- j6 r - }
/ D. A0 D) ^2 {6 {- { - }
复制代码 |
|