|
|
( W8 D3 l5 u4 h行,这个怎么样
n( l- G4 z+ Z+ P- y7 n- package com.xhg78999.mtrfac.render;4 P: O6 O6 n) J9 X! I# v
$ U8 E' v0 E! C) @9 n9 |7 S- import com.mojang.blaze3d.vertex.PoseStack;1 N4 a# R$ B) ?9 m0 h* l; I$ u
- import com.mojang.blaze3d.vertex.VertexConsumer;
, I$ X9 \% `) M' j% G# w - import net.minecraft.client.renderer.RenderType; X/ R) [) N6 z( Z+ S3 f7 a+ {
- import net.minecraft.resources.ResourceLocation;2 ^3 T" H# e" u( h5 `, O
+ L& [, s$ S" H/ m9 h+ u8 a4 b5 h- import java.util.*;
0 W1 I2 ?5 c5 A, |; y, z - $ N" L* p! a( z$ @9 ?
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(+ N2 H% {- l |8 y
. u, A4 J& s5 y, e+ c# d) t- public class LineRender{
( U' |7 `: I" E5 a9 Z3 p. r - private final PoseStack pose;
% V; ]% v& f, X, {* `9 _' I0 e - private final MultiBufferSource source;- Z: z0 q3 g7 E; S
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();: S$ q8 x9 ?1 A6 Z; ^ k
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
" F" A0 }0 v3 {+ Y$ o
5 D- m5 O; n; Y
% w6 A8 i6 M! p# @5 ^- K8 l- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){' F3 A# k+ W2 ]: F% R( \% D7 b% }
- if(x1 == x2 && y1 == y2 && z1 == z2){
, z+ g5 m ^- i/ S( N7 a - return;9 J3 g9 {8 L7 r8 I; o9 v
- }1 M2 V7 d& p# U/ i& z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
1 `! x8 Q' p& N4 m! g# A - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");9 n2 g* d6 X3 G7 n# M/ Y
- }1 H" _! o2 {# X
- pose.pushPose();+ ~# v' l2 T& J% r4 z5 \
- final int newLight = convertLight(6);2 n0 D8 N4 H5 {& L Y
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
- m! d2 v* \4 n0 v - final float lineHeightSmall = (y2 - y1);1 e4 w$ C v& t% w( V" }1 {
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
3 ^6 x, b) `, |# x - pose.popPose();
. l6 I% @7 H% Q" L' G - }
# j2 \/ P. v3 ]* M5 B; I8 c5 Q3 r - 5 o0 s/ u4 T6 V+ c5 i, K
- private RenderType getLayers(String texture, int light) {
/ [; v" S" Y: Q: Y - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
! Y- x- @3 V; x) P- N - }
Q+ \$ x: l( u2 t5 q$ W4 I$ y
& \. z6 P. n. T/ E/ A- private RenderType getLightTexture(ResourceLocation texture) {7 K9 \( m) T/ g* l' k) r k2 o! S
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
5 f% W. e! d% F- s& j - }
% e$ u6 n* H7 r: S% m h! f( ? - 9 g! _4 J$ q' I! f4 J$ b K, C
- private RenderType getTexture(ResourceLocation texture) {
0 m4 s) P+ ]5 H1 E" {5 {) S8 F - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 R, K/ Q* Y( P: v! e% S3 {. i; T - }
* L. b- z* ~$ \ - s- R, N- O# t+ Z" Q u
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
! G- }& J2 w" r5 y! z1 K5 k - if (cache.containsKey(identifier)) {
" ?$ }8 F9 _; v - return cache.get(identifier);5 k, r' e7 }2 M* X; m( `. X
- } else {
4 }& q( x8 N7 _9 J6 ?$ P9 E - final RenderType renderLayer = supplier.get();
9 Y6 \- G @% P7 W - cache.put(identifier, renderLayer);5 j% f# k' r& S3 z: |* `
- return renderLayer;
* \7 a' F- \# X: [$ |6 d - }. N$ M3 U- o! Y5 Z$ ]; }" l
- }
% m9 X9 g/ x* b# A - }
复制代码 |
|