|
|
7 H c7 ~) L1 E% }/ n& c8 r c行,这个怎么样
# S/ i/ C( V' M- A! g- package com.xhg78999.mtrfac.render;
% I% l6 |3 _( k/ F/ [3 ?* O
# x. i( V3 |. a& z+ O' F# H- import com.mojang.blaze3d.vertex.PoseStack;8 x: F; ~+ P6 f% x1 A$ k
- import com.mojang.blaze3d.vertex.VertexConsumer;: ^. c+ K6 v% o
- import net.minecraft.client.renderer.RenderType; h$ [7 t- f/ K- x* a9 M
- import net.minecraft.resources.ResourceLocation;
: Y, ~' z2 L. l' L$ \ - ( i% D" c) ]( t, q+ C1 U& o# l9 q
- import java.util.*;
7 C7 X9 {$ E& l8 F+ e+ V+ Z - $ U2 ]4 W$ d. X0 I: [4 Z
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(. k1 m3 b4 j5 j4 |. V4 V- g
- 6 f" v2 s9 q% w: \5 P5 V
- public class LineRender{0 h1 j# V7 S' F2 E- f* ~
- private final PoseStack pose;
e' N" C5 s" z+ F9 e; q' ~ - private final MultiBufferSource source;. j7 d! X# x; _+ E/ Q2 q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
# a; G! L4 ]! C. U$ p( D! E' f - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 A8 P, I) N$ k- O0 }4 z" Y, d4 G
- ) M$ B0 ^' ^' V. J4 O" B
; x' e4 {/ R1 l# U! v! S- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){- t, \) ~4 S# h5 ?
- if(x1 == x2 && y1 == y2 && z1 == z2){
) Q% D3 k$ L# i7 n9 L v# f$ c% `! O - return;5 O% U9 r; ]4 `$ l4 Q: ]
- }; P( D1 q4 N7 {% v; q
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 ?* y! c, \" U5 u) y3 m4 F6 C
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) z8 L3 O( x& I7 Y$ Z1 h. ^; {
- } W s o3 r& w O
- pose.pushPose();
$ R) C; ~% L% x2 V$ X, ]1 G - final int newLight = convertLight(6);
1 `6 D! k% A* R+ f - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));: s% ~ ~) t% V2 \: N( L
- final float lineHeightSmall = (y2 - y1);
) w1 I9 W* d6 Q6 T4 Y& e - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& K# \, q+ p% Q
- pose.popPose();
/ i( H @- r! o! W# q - }
- C; j, R% {! X' D - 9 P2 R( _4 \9 j
- private RenderType getLayers(String texture, int light) {
( H2 ]3 p+ p& e9 r& } - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
- x4 F, o* M# `3 n$ E2 K% [' f - }
2 ~# J" S3 P& ^8 X - 2 u( F/ y- \/ U
- private RenderType getLightTexture(ResourceLocation texture) {3 A, o9 f0 w x& d% T
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 X$ A: ` }1 ?. E$ z7 T - }8 }) n, |' T& ]; l! G$ ~2 E! x
: l$ i2 k0 g% w: [( k- private RenderType getTexture(ResourceLocation texture) {, }# y( Q! u" Y1 v3 Y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" I, e* y8 {" j F5 J; d& x - }
) }" |' g% a, I& _, ^ - 4 g0 `) A6 z3 [
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
' P5 Y( W$ f) Y, M - if (cache.containsKey(identifier)) {
% y2 f$ K2 H/ t* q4 D: i+ O - return cache.get(identifier);- Z) w$ W2 j& t7 R9 O8 W- q
- } else {/ H4 p4 A, ]* { @" K
- final RenderType renderLayer = supplier.get();( T7 ~& C) D7 m& I) d% L1 H+ Z" u
- cache.put(identifier, renderLayer);
* {1 g( g/ v; _ - return renderLayer;; r7 H8 P0 G! I4 G" D
- }
% O6 A- K2 { c - }+ s% X5 d) H) z/ U7 H4 Q
- }
复制代码 |
|