|
|
k+ s2 O; p6 N3 k- F; v1 c/ @6 g
行,这个怎么样
( h2 f! O& r+ D2 }; S' y: ]- package com.xhg78999.mtrfac.render;. s8 j/ V2 p$ m+ w' z5 r
0 m# F: N& B% h: j5 ]; o- import com.mojang.blaze3d.vertex.PoseStack;7 ^2 D1 H5 _* v3 Y
- import com.mojang.blaze3d.vertex.VertexConsumer;/ l. m% E7 r& Y" i
- import net.minecraft.client.renderer.RenderType;
: m) A; D1 J! V$ I: Y" @( ~ - import net.minecraft.resources.ResourceLocation;
+ S. i* g4 H3 V: j
; Y( D, p9 j/ |1 U3 ?; u& p( z- import java.util.*;; S3 R ~! I- K$ o4 \ E
- 6 w" \; q. E+ D2 p
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(0 }* D* Q* e0 D5 X: d( N9 n
- 0 }! M* v& x! A1 e8 W* v
- public class LineRender{
- L4 b/ H7 ]3 R - private final PoseStack pose;" b% S4 v$ @. d( e U. c
- private final MultiBufferSource source;# U- F$ r7 b$ ~5 j5 z: D# E9 w7 [
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ y$ ?3 B! J6 q2 K: E4 j; B: F% m
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" J% I- ^$ ~6 X* Z, i - 6 q& ?( E* s* i8 f1 E
- + |) K- O0 m4 G" K( h- I
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){2 W( U* y7 L8 g1 S6 G' a
- if(x1 == x2 && y1 == y2 && z1 == z2){
3 s) U( a9 {6 p$ ?5 ?; M - return; G) {3 P+ U5 G4 _. M
- }
. @; A( ^5 ~. }% }9 P* c, D" y) i% e! a - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
: U4 B4 ]: J) e% y1 H. D - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");2 i6 B) R" k; G6 k* G
- }
* [; U& m$ M' R0 C1 ` - pose.pushPose();; u6 [, {. j0 x8 e: w
- final int newLight = convertLight(6);4 D3 y9 w" m! G) B
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));2 u8 z0 W4 ?6 p2 p! z9 \ {
- final float lineHeightSmall = (y2 - y1);
% z, p+ Q: O% z7 z* y - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);8 X* d" D0 q, Y9 s
- pose.popPose();, W3 Q D' r8 ^9 F+ g" |
- }1 E* T+ A c) A8 G- {& r
1 p( n! e4 t1 F7 h- private RenderType getLayers(String texture, int light) {0 Z- j& o$ k7 N* k! k
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));1 v1 I. O% L' m3 h) O- d3 n/ j
- }
. q M; J$ z; u) E& f$ D; v1 P: ?# |' W! ] - - G! a; U0 Y3 k/ m3 D2 r8 d
- private RenderType getLightTexture(ResourceLocation texture) {
F1 y- @3 F w+ q. k - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
! Y9 c0 z) v$ v3 g) } - }
- A& C3 O: v: A$ y% t- r) `8 \ - 6 N- o/ G f& Z& ]% c1 `( }
- private RenderType getTexture(ResourceLocation texture) {6 n8 v$ d! g. F/ F! ?( g. w" p
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
3 P" |- r) U2 D7 n. C - }% I- L4 R; m4 @8 _( R
- % ]' `" K* J" U" ^0 m' o5 r
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
8 l9 U# @. T+ r! [1 ^+ @4 g - if (cache.containsKey(identifier)) {. O& Z/ ^' M' P2 W7 O
- return cache.get(identifier); @! {! l# |8 c
- } else {
C/ d4 d# M, q/ b* D' z - final RenderType renderLayer = supplier.get();
3 H7 _! t9 p; j1 w( ? - cache.put(identifier, renderLayer);
7 H; U& v e! q; w9 B - return renderLayer;$ S+ f' H# [2 A, L8 k
- }# e& M5 z6 F4 Q- z5 ?
- }
/ k2 v( B# u' ]0 _8 t - }
复制代码 |
|