|
|
' b* |' s6 P4 D: q5 M) h. O行,这个怎么样
5 w) n) g: A& `* b: ?# d6 ^- package com.xhg78999.mtrfac.render;
2 J1 E3 f, p; I/ x; L v
9 a/ F# q- j( U: @- import com.mojang.blaze3d.vertex.PoseStack;
, U; w# {, s1 b3 p - import com.mojang.blaze3d.vertex.VertexConsumer;
( X+ l$ d5 c0 m) s, b, a% C+ q - import net.minecraft.client.renderer.RenderType;
5 V, R: G& e% x - import net.minecraft.resources.ResourceLocation;* t& h1 L0 f6 t0 r& q
2 T- z- B- I- D4 e9 A0 y- import java.util.*;( {& ?( @0 J* {; Q# X, ]3 A- a
% k6 x5 `" _, t- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
; ]1 g( v8 n( O' l, @
3 L2 Z4 g! b1 {* d0 R, u' o- public class LineRender{
# o$ V# Q; x) ` - private final PoseStack pose;/ ~7 B8 v/ y; @/ [/ H: S! ^/ e
- private final MultiBufferSource source;
. a- x2 V4 x; w/ t1 a - private static final Map<String, RenderType> CACHE_A = new HashMap<>();* x6 h& j) R+ q; k7 [. U) ^' {
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 P; E3 c7 C' y2 f& e
) D R. \1 @/ h5 N- 0 s3 z$ X. }* H) s W
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
$ v: p* z+ e( D5 d' U/ w6 Y' O - if(x1 == x2 && y1 == y2 && z1 == z2){
& h$ v8 N4 D4 u$ T( O - return;( k) l+ f% I \- R; ?4 Q/ x9 v
- }
" `2 f# [9 D3 K; ?/ P - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 U* [% N) a2 E% s - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
0 g) B$ \* I T5 J, ~! c2 l& { - }% O+ z; s; h) ]6 n1 N# L |
- pose.pushPose();
! t* V/ \& ^; m, x - final int newLight = convertLight(6);
( y) ^5 o( d' ^% g+ [: U X - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));1 L+ T/ T0 L0 h3 u" g) o1 k; K& N
- final float lineHeightSmall = (y2 - y1);" V7 ~+ a( f/ A- p% a2 N& v
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);/ W U/ W# T4 U5 q% N/ ^" L3 e
- pose.popPose();
- ^) b/ {$ m) r) Q - }
: |6 z: h5 Z1 Q5 }$ g
* P5 A( N, M$ t: t3 p- private RenderType getLayers(String texture, int light) {
" w' T' Q/ N( ^ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
8 e! ^: U3 o, F7 n6 Z- } - }
6 f% j) a/ ?# b2 e% ?/ i+ p% \' g - ; M O7 K: u! M% y1 }0 B
- private RenderType getLightTexture(ResourceLocation texture) {
- l) C$ L% R4 \# l - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);+ F% z4 W1 M C6 S/ i$ {' G
- }
6 Y$ C4 I4 k$ }# ]- l7 f" B! l" N
! {% p; f o# B- private RenderType getTexture(ResourceLocation texture) {
1 j) D5 S) j6 y/ O' F/ [ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);4 d8 ]' Z: q1 L
- }
( z$ w- F3 L6 X
+ w- c' \4 l( X4 [0 W! ^- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
$ ^ d5 c3 I7 B/ v - if (cache.containsKey(identifier)) {+ e; `+ h3 }' U- U
- return cache.get(identifier);7 R- |0 U+ O# Z w& B
- } else {
7 v; {& B X3 M3 X' O - final RenderType renderLayer = supplier.get();; o! t S3 U* \. d
- cache.put(identifier, renderLayer);5 T9 r. I7 K0 }
- return renderLayer;
* y" A$ P; _ \' N - }% C; j7 u( f1 @% P! z8 Z$ w
- }
' j3 j4 c& w* K4 t5 ` - }
复制代码 |
|