|
|
! \% A6 J- [1 V行,这个怎么样
9 ]: ~ e4 O2 Z# f5 l5 x- package com.xhg78999.mtrfac.render;
& f; I- G3 t; ~: e) v5 t5 G
. A' s% k- C6 u. Y+ {* v5 B) D- import com.mojang.blaze3d.vertex.PoseStack;
- ]: {* h* R4 K3 {3 A% n: T9 x+ B6 ] - import com.mojang.blaze3d.vertex.VertexConsumer;
m' c/ `8 h2 B8 ~ - import net.minecraft.client.renderer.RenderType;; G# ~& ?4 M9 D1 E4 F% l# H
- import net.minecraft.resources.ResourceLocation;
- k7 P8 p2 k" B* L! U4 T - / ~- q. b5 P1 d7 W9 t& h
- import java.util.*;
+ [( w$ g) S. t5 z- C# `
0 O) e8 m" E/ F8 G& J1 U- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
- d+ E; k# S: Q* B
5 V! L$ L1 b) k$ m# P- public class LineRender{9 O' h4 `+ s1 O) J H' a9 i5 T
- private final PoseStack pose;
* |' `' v! F g# V8 u# N8 D - private final MultiBufferSource source;
# u) G8 e& k+ r9 R0 t - private static final Map<String, RenderType> CACHE_A = new HashMap<>(); R* q y( w9 D# l/ c
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
+ ~5 S5 z, |$ t( ^& }
$ G" m: L7 l( u! r3 I9 O- p- 8 J; o! n2 x5 s% t8 T
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 t) E9 X) e4 T; p0 c7 n/ m4 p - if(x1 == x2 && y1 == y2 && z1 == z2){3 Z7 R' r$ Z1 u& f
- return;/ x& T# O* W6 C G& w" c9 t' t& x
- }
* s7 }1 @+ X) j - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 Q+ e0 T5 P) R! B2 k - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
" S C9 G1 G! ^7 @1 q - }& W5 C' n8 T3 G* C
- pose.pushPose();3 ]# p9 a' i* n! j+ Q
- final int newLight = convertLight(6);
6 N5 G" J, r' O8 g" L - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 P/ S: R: O# N9 P# d" f1 G( P - final float lineHeightSmall = (y2 - y1);
' X& g& G# V1 K( G$ m! M - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( T7 Z: Q+ o+ H! r( I1 C0 k5 Y - pose.popPose();, W6 ^: c: N" d3 v% C4 |6 W' Q |
- }
4 f, a; K* e( m - . I$ v! w5 r R& y4 y6 G( p
- private RenderType getLayers(String texture, int light) {; q. z0 x+ W) D% }# v- l4 y
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture)); l, l6 W' ] K8 n6 O' d0 I
- }
. E: T7 P4 ~3 K" G
' c' o3 c6 M3 t* H- private RenderType getLightTexture(ResourceLocation texture) {$ l" f* R9 V: t5 p1 Y+ P
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
( _3 f% v7 x1 w k - }# H$ c( k/ z5 L" C2 S! a. S
. p4 P+ h6 r. U8 ~5 j9 M- private RenderType getTexture(ResourceLocation texture) {2 p$ q7 \* Q/ P4 O- _
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 x7 c! t7 d6 a: t @$ ]
- }. H5 P# B; w. ?( \( s
/ I9 K# f, \" V/ x+ K8 s- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, T* c0 A3 F( D: s - if (cache.containsKey(identifier)) {4 B2 z' {0 s, Q! p1 u1 Z* |
- return cache.get(identifier);
, t' Q4 v1 L3 j8 P/ Q - } else {
- m3 p4 @9 {4 q+ { - final RenderType renderLayer = supplier.get();% P& ^6 h9 P* Z5 w/ w, A
- cache.put(identifier, renderLayer);- a$ d; t! T( x2 d) E$ V& _' m
- return renderLayer;
, U, y8 f8 N- R3 _; l: C* d - }
6 R/ Y; j# H0 E1 l - }
& o" Y* q; N0 B3 z - }
复制代码 |
|