|
|
8 K- |: V8 }9 f( e2 _/ y
行,这个怎么样
7 E7 p5 ~* P: F0 x7 L- package com.xhg78999.mtrfac.render;
. Q& ], U, b( ?) [, q - - g7 z7 ~) g0 v2 A
- import com.mojang.blaze3d.vertex.PoseStack;' P( R9 a8 x9 J: i
- import com.mojang.blaze3d.vertex.VertexConsumer;4 r9 m& s1 T* f/ O
- import net.minecraft.client.renderer.RenderType;. {# o2 z# e9 d3 G6 z( ~
- import net.minecraft.resources.ResourceLocation;. Z4 T2 v. |) L6 ]
- ) I3 Q" B8 ~6 g- E4 Y- G9 r A
- import java.util.*;" a4 q. l9 i) Q7 @. X' Z
& |( z! H9 [$ U5 E3 |, x, X- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
e& K' f, V3 K/ N
! \+ [( S: O$ S4 f/ ?# v- public class LineRender{
+ T+ _4 \& N* E7 `# L4 ~' A; W - private final PoseStack pose;$ d1 Q1 T, \# ~) c
- private final MultiBufferSource source;0 h5 Y' y& v* |6 j
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();& {8 n0 b i$ D! \* w% J% R7 W6 j
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();# }* j M* I: d: F; }
- - E$ X% X+ E' G$ R1 ?$ g$ }' v7 Y3 Q
- 3 T1 I2 i! \+ ]4 G( R
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
# p; e' m6 I& x# h. T - if(x1 == x2 && y1 == y2 && z1 == z2){
2 k# X6 ^( R( d& c+ D9 M - return;( @' L/ W8 c( @+ z% q- l8 F! i
- }& s: ^# \* R. }6 N$ X H# |
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){$ W$ f" F2 A4 j9 O7 m7 \7 r2 A; ]+ {7 \; ^
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 l5 d* n2 d1 \* E1 ^
- }
6 J3 f* G' F8 k8 `3 m5 u - pose.pushPose();( E/ ?* g% E2 X$ X( n; [& q
- final int newLight = convertLight(6); c" E4 A5 ]6 W( N- |" x
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 [- b! p/ |% K ?- p! }, I
- final float lineHeightSmall = (y2 - y1);
9 D6 Z* [& d- i3 R6 Q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( d- W; u/ g+ a
- pose.popPose();8 \. x8 _" g+ N+ S- \. [
- }3 D. C2 V$ ^ j6 J- n+ U
& J$ Y+ W* T* F) v- private RenderType getLayers(String texture, int light) {
$ ]. _& e( j9 I- ^1 M% V/ U2 Y) O6 q- g - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, ?+ H$ b9 ]: ~
- }! g9 c6 J4 r& p% Y
& v Z7 y, t+ N, p- private RenderType getLightTexture(ResourceLocation texture) {
# [9 t- A4 r3 v& C9 t& {& c - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);) Z+ V( N+ w. I# j1 {
- }
* h$ I, `) m! q3 d+ i+ u - 0 Y8 o$ p2 j& F0 x* @( ^
- private RenderType getTexture(ResourceLocation texture) {
0 K4 u0 `8 e2 {( P# V; s - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ S1 N2 X" y/ I) f$ s# q - }
9 d' s0 s! S$ u1 X7 ^. y - ) x3 p6 C8 A- J
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
& R h3 G8 ~6 w! l - if (cache.containsKey(identifier)) {
, i3 h: h( p Z {; T" S! P H' D6 S - return cache.get(identifier);
2 \0 s; y6 L' a3 ]# k. n - } else {
" X. Q, Z! ^/ s - final RenderType renderLayer = supplier.get();
: H, w3 r" s1 _. G- d8 Z - cache.put(identifier, renderLayer);
7 y6 T3 O, C1 O4 V - return renderLayer;; Z& C1 R& J6 w$ K
- }, w; F! A! N' i
- }
* o/ Y' `) a9 T' w8 z$ l! y3 R5 r - }
复制代码 |
|