|
|
, I, \" y7 h2 y5 F
行,这个怎么样! d3 ]: Z) ]( a4 `
- package com.xhg78999.mtrfac.render;
1 l6 P1 p& q7 \+ [! E* Y - ( ?; v. x/ G. ^* p$ ~* O
- import com.mojang.blaze3d.vertex.PoseStack;( I# u# @% `2 J; }' C; j
- import com.mojang.blaze3d.vertex.VertexConsumer;
+ H# m; a* i) G! C - import net.minecraft.client.renderer.RenderType;: c i8 C$ `( P% s6 w
- import net.minecraft.resources.ResourceLocation;
" f9 @! A6 G' ^ - $ L! Q1 t6 X! [- ~6 a9 _2 u! O; R' E
- import java.util.*;. {8 ]5 Y1 s+ g, `2 G* l
- * ]& ^$ o, n7 [( s0 W$ r5 \
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(, H& {5 H- w% r
- $ x2 u% y. V4 a! |, D
- public class LineRender{9 j4 M y2 Y8 I* w; O, n) e
- private final PoseStack pose;& a3 ^( N& O& X$ e# u5 |1 P
- private final MultiBufferSource source;! t; u1 d8 c4 |8 _1 L9 V( T
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
: b; ^0 r) V$ ]' j) j& A( Z - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();5 L; x+ ~! t9 f+ Q- n7 Z
- ) h, N+ g8 x& j4 m
- 6 `5 E5 m& }* U8 v
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 R, O, X: A0 W% _$ i- _8 y
- if(x1 == x2 && y1 == y2 && z1 == z2){
& V; ]+ l9 J- m; u/ f* ~ - return; C/ l# K5 d) N6 @. T7 U
- }
5 j5 Y9 e3 f6 ?0 r$ U3 n - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
q" @- [* V9 a! E2 y6 H - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
5 p+ A. D, Q5 c; T - }
& | b( R9 R, @# c8 ~0 }# _! v - pose.pushPose();( s6 s2 N% F9 N; |/ [" [
- final int newLight = convertLight(6);9 V9 M6 p) a0 u+ y; [
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 j- j2 k; I' ~, [3 c" ~& p
- final float lineHeightSmall = (y2 - y1);9 z" @' ~% N0 a' \
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
" S2 ]8 X: o' r2 e - pose.popPose();
4 N! _( d {8 {+ H- {% u - }( y: Q/ ?: p& N1 z$ |! c
- * b7 q) l2 j5 d# I+ ]) @
- private RenderType getLayers(String texture, int light) {# z/ Q, _8 d" V2 Q2 n' |0 f8 |
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
. r! ^& D7 l( ~, V" A! E - }: @8 v8 J$ F+ D5 O) E
- ) F* s/ H/ s" ~5 f
- private RenderType getLightTexture(ResourceLocation texture) {: s) u' F/ c( Y
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);& h1 h$ W( {( L I: ]: r1 t L I
- }
' P6 C" x/ W! u2 R - / A: E& r1 @2 Y9 w; u
- private RenderType getTexture(ResourceLocation texture) {
, U( S0 i* {+ {6 h3 Q - return this.cache(texture, () -> entityCutout(texture), CACHE_B);7 T% Z' s) @+ h, u
- }9 ^6 o5 s+ h9 e1 V: m- g& P) w
- . b; X) S3 U Y/ t) R* H
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
2 b+ Y D7 l, {4 E/ K - if (cache.containsKey(identifier)) {
6 [7 {- [% W3 U" i9 W$ g - return cache.get(identifier);% `1 S/ {. L5 }1 }: p1 Q
- } else {
) h- C" N3 {9 W, `: x' x4 v) z, C - final RenderType renderLayer = supplier.get();0 P. S/ K! |/ V4 I1 t4 {6 i
- cache.put(identifier, renderLayer);
/ y, v! z$ `( Z) j - return renderLayer;. A( p' I4 g; a! c: y2 {6 h8 f
- }
. X6 x5 T. G' Q. ~& F# ^: J% j3 X - }5 W5 O( e# l. r% U8 U/ D% T+ X) I
- }
复制代码 |
|