|
|
% O( ~+ I- g+ @& t
行,这个怎么样- F0 g2 d+ @0 w2 l* I/ j
- package com.xhg78999.mtrfac.render;
8 S( x t7 v( R# O" Y - 2 p8 ]: v3 B1 M' j2 H$ B
- import com.mojang.blaze3d.vertex.PoseStack;2 [: D* E q" w) E
- import com.mojang.blaze3d.vertex.VertexConsumer;
5 n% b! a. @ ~8 [ - import net.minecraft.client.renderer.RenderType;
, H$ N2 b; Y5 _) I( i% \ f - import net.minecraft.resources.ResourceLocation;6 D- H+ p4 F' u' }5 q
8 k: Y2 }) k! Z, K- import java.util.*;5 z9 P3 o3 k- N2 r! ^
9 [2 b4 C3 e7 B+ \6 F- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(# f) k' }- Q+ T9 f( P& |
- . ?7 \3 G% t2 O5 D- e( S
- public class LineRender{& m4 Y5 h6 }; V* g$ c
- private final PoseStack pose;
. n5 ~' y3 X+ Q9 S5 ] - private final MultiBufferSource source;
5 P& d7 q2 j( t: }; [* | - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
; a6 f6 Q X+ J/ @4 ?6 A# S - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();" Y6 d1 h* I' c! D& q# ?
! L7 {0 \/ Q6 w0 u" J
9 s' M5 T6 }, \: G1 f. S" Z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; t: i6 {9 S: z& b" V& ] - if(x1 == x2 && y1 == y2 && z1 == z2){
* [) v, y% Q4 | ? - return;* A* _& u3 s Q2 _+ X
- }
1 R& D/ J; c- L! d( C - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 g3 J# n$ c1 k- Y3 U/ u) q' e - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");$ T; X2 A t' [
- }
- s' P* P9 A% K0 k ?3 u9 T: `6 w - pose.pushPose();9 q3 X6 U F, ?5 Z/ q, c
- final int newLight = convertLight(6);
/ w& {( C$ q5 H# j: T - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 I7 B; [9 Y' d8 b8 |
- final float lineHeightSmall = (y2 - y1);
2 p" _' C7 `1 }9 Y3 c) I9 B - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
7 N4 P5 A! v A( ]* q - pose.popPose();
9 q$ F* ?+ {6 c3 F& R - }
0 j! i+ T6 w0 U. R7 x
& W0 L& a3 e: Y, n6 `- private RenderType getLayers(String texture, int light) {, ?* n& Y. [1 m4 d! e p
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
9 `+ H, y& |7 v - }
8 d& Q& }# V; P( q
8 j1 n: U' _; V/ r6 U. |- private RenderType getLightTexture(ResourceLocation texture) {
9 r) w# W( T' p" K! H$ F - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
2 X6 ?/ B4 _$ i - }
c( y( G; y; h3 H/ F R - - j: O% ^! R$ Y2 |6 F5 f
- private RenderType getTexture(ResourceLocation texture) {
/ s7 V- X& D; m9 W6 g' M - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 |+ j' }. o( O/ Q6 M& D+ a6 l \
- }
/ ^/ M$ R2 q( Q) a2 a. r o; K6 ~4 G7 f
/ ~- P7 |& Y9 {: R- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {# l6 n( T5 h; j3 P
- if (cache.containsKey(identifier)) {
9 O+ H: T. ]; \, U( @3 j - return cache.get(identifier);- S# p5 z: X4 D% m( C4 c
- } else {
; h) |* Z M% c - final RenderType renderLayer = supplier.get();
, \' s4 F# F/ p9 t8 C: W% A1 _) f - cache.put(identifier, renderLayer);" o5 ]0 m- {" K/ u! q3 s& i! a
- return renderLayer;: p6 h; |' f( l& n! q
- }. Y! U. P3 s. z
- }
9 s$ s" F: g# m. x - }
复制代码 |
|