|
|
, F: U/ C0 }+ Y2 g- W1 u( t9 L, R行,这个怎么样
9 x- O: ?8 D8 U% n5 |) y+ ?3 \- package com.xhg78999.mtrfac.render;
5 [" ~. J7 d/ W( ] - 0 X! ~+ K( G! @! Z
- import com.mojang.blaze3d.vertex.PoseStack;
, e* K- H* G- y4 [ - import com.mojang.blaze3d.vertex.VertexConsumer;
+ w: i2 o$ E; v, }: N! ~ - import net.minecraft.client.renderer.RenderType;& h' v: X8 ?, Z1 {) L8 n+ l8 h9 F
- import net.minecraft.resources.ResourceLocation;% c8 K; _- g3 R" ]5 Y3 C$ S8 _
. u2 [' f2 n. [% t- import java.util.*;. \* R# s+ J+ L* F0 k0 t# K$ [
7 ~! O" R' G: K3 z- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
7 U, Q3 I; `- p }9 T
, M/ B, ]% P9 Z) I3 S( i- public class LineRender{
: Z5 J& l# j% b1 J- l) h - private final PoseStack pose;& p, {* E- T/ F
- private final MultiBufferSource source;3 L$ Z1 r+ H/ M
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: j7 Z( ~& S7 X4 v# D% F3 K - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 z D5 S0 z- b# @
- ' c" Y9 j& \9 B5 a
o: t1 P; {* S. @2 R9 r |- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. g, z% S7 k. L& ]5 z! I) d9 N
- if(x1 == x2 && y1 == y2 && z1 == z2){
% m' b3 ]. p8 G' T% S2 V& N - return;2 h7 d$ R6 e: N5 g: X S5 B& ~
- }: g4 E" F; \( |7 \; q: V2 O
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
# m# u1 I; O& C; m6 y - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
( [; N$ Y* F6 M, G3 X1 g& X: e+ F - }$ c3 ^' V/ Y; z. E. z& d
- pose.pushPose();
- X1 m/ X( t. t7 i# U8 i% X - final int newLight = convertLight(6);
# y% f& R$ W( \ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));, [8 W" C, T3 _- P. a# E6 o, v
- final float lineHeightSmall = (y2 - y1);0 V# B* R' P& m( C' {! H8 K+ `! P
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 m6 m. q3 O. k* Q1 L; s
- pose.popPose();: K L% V i% K# a v' l
- }/ e: `7 f, @; G+ _, R) a0 ~
- 2 D/ |! I4 T" y
- private RenderType getLayers(String texture, int light) {
, h R. R+ A! i - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
( O5 Q3 c8 p R4 g; B; D0 M - }- h8 |, Q: t( r0 ~) @& S9 }9 A
- ; o+ |( Y1 r( A
- private RenderType getLightTexture(ResourceLocation texture) {$ x1 S0 s, |: ? q. q5 N
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
- g( v. h0 J8 R - }
$ w9 W$ a. h; ]% o0 k - ; Z6 G1 k" ^# E
- private RenderType getTexture(ResourceLocation texture) {
. c+ Y2 J9 N: i& o/ E) A ~9 p - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
% F; X! ^! b) v$ s) _/ O' Z - }
0 D- B8 t; Q0 \" i- U; Q, {
* h& ]* T% S7 b. H/ l2 y5 n- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
5 ]! @' v% E' g* s K: K! ^ - if (cache.containsKey(identifier)) {
: w1 S7 [0 q, V# j8 | - return cache.get(identifier);$ `0 i7 \1 D, e) h/ ?. b( ^* F- O4 V
- } else {
! _$ F9 p: v4 X; _" }6 j: o% S - final RenderType renderLayer = supplier.get();" m$ A& O+ V& Q" X6 z% t
- cache.put(identifier, renderLayer);
" Q" t: p# S! g& L6 K x - return renderLayer;4 `8 g6 w& n. F: {0 T- y, n
- }# D5 `5 X9 d, p8 M
- }
9 M$ n4 p/ ]! H) Q/ Q) ]0 ] - }
复制代码 |
|