|
|
8 V: @; v, i3 y* B6 j- `
行,这个怎么样
, A* ~3 n+ O' E/ U$ y! {! F; T- package com.xhg78999.mtrfac.render;
1 m# S. Z$ r' M0 `
" \4 U4 L* K" T( |2 f) h- import com.mojang.blaze3d.vertex.PoseStack;% A3 z; b2 y9 _; F6 u' z' h; ]; g+ \8 Z
- import com.mojang.blaze3d.vertex.VertexConsumer;3 E4 \) H' E- W a0 ^/ U
- import net.minecraft.client.renderer.RenderType;
7 m5 C X. l8 R& s" k2 T9 A - import net.minecraft.resources.ResourceLocation;- P) I" j; Q P
" y. j- Y/ }2 M$ p$ o- import java.util.*;
$ g. z- U Q% B9 ?# `' F - 8 c- Q. E2 r. h) R2 U
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
0 b4 [$ _% M2 V3 w - , S. s4 ~; U; Z% R: N
- public class LineRender{) e. J# p4 l" W. e3 r& V9 j6 ]
- private final PoseStack pose;* C( G, u# D1 ~1 h
- private final MultiBufferSource source;
+ T* C3 v' K" w- D - private static final Map<String, RenderType> CACHE_A = new HashMap<>();- E- S# C5 u' M: L! k4 \% {+ y I
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();& V) {) w/ G: N# R% E! Q+ ~0 l) E
7 E+ ]0 g& Y& ^6 U- P6 }: P
. I6 j1 @4 k( g# b& K- L! p8 ^- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){. f% h, G/ U7 W; R, o, g3 C$ _
- if(x1 == x2 && y1 == y2 && z1 == z2){
: M# k9 L. x; D' H+ u1 Y - return;
3 y# V" f N9 k! ]5 J. D - }
8 B: {4 N- a$ c% U$ j2 J+ Z- | - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. ^8 Y; E$ H$ M& p( L; `! Z" o8 m - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");( Q6 [, D8 o; ~7 }0 ^1 E& b
- }! R3 p% n v8 _9 ^& w) t0 | H7 Q$ D
- pose.pushPose(); w7 Z) m' ~! p' s; t
- final int newLight = convertLight(6);
1 Z# @, n, `, u* @ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));( h V, r; n8 D
- final float lineHeightSmall = (y2 - y1);
! Q7 R' N% C: z g3 y3 j1 I - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);( _5 X; ?( _4 q: n
- pose.popPose();
. q& d& b5 j R; W9 s: y# A6 ~1 ^ - }
# S6 \+ m( a' I/ Q9 _
) D+ t& R" p! l/ L- private RenderType getLayers(String texture, int light) {' G7 ~ |, I$ u& d) k6 u, p
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
" F* p5 F/ w- V8 t - }: M2 c+ w2 \! G: D, ?/ ]
7 [$ [& F8 B( y4 B5 A- private RenderType getLightTexture(ResourceLocation texture) {
; _: v6 q- @! ~6 u4 M7 B5 ~" ^# b7 _5 k - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
- { i2 D. b/ {5 y - }
& W B* A2 {2 w0 v
1 U3 Q F" y; E- private RenderType getTexture(ResourceLocation texture) {) F! o/ f. L$ S
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
! J1 l/ p' g! w( ? - }
& P" e7 U+ D2 O8 V - 7 W$ V! Z P# K
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {7 @3 T9 r6 _. B) G2 c
- if (cache.containsKey(identifier)) {3 ]4 B3 j+ I6 {
- return cache.get(identifier);
9 u' k3 I2 o/ y( H7 @ - } else {
: J3 ], R% U v( Y - final RenderType renderLayer = supplier.get();! P6 d( X6 s# c
- cache.put(identifier, renderLayer);
( R# C# `6 |; W0 ~" h - return renderLayer;$ \% ]3 i9 d' c5 |0 q
- }
" |. _- B3 o! E k, z" g# [5 }. | - }" U+ G: J# Y3 @) \% W$ r
- }
复制代码 |
|